From 1b608481a4062f3a8f98192e50acfcb73cf577e2 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Sun, 5 Oct 2008 16:22:16 -0500 Subject: [PATCH] the main loop now uses strrchr and strcpy The idea for this change came from another patch submitted by Chris Brannon. We now use strrchr to look for the flush character and strcpy to move the remainder of the buffer to the beginning. --- softsynth.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/softsynth.c b/softsynth.c index e964b70..67998e3 100644 --- a/softsynth.c +++ b/softsynth.c @@ -135,10 +135,9 @@ void main_loop(struct synth_t *s) { fd_set set; struct timeval tv; - int i; - int j; ssize_t length; char buf[maxBufferSize]; + char *cp; while (1) { queue_process_entry(s); @@ -165,16 +164,13 @@ void main_loop(struct synth_t *s) break; } *(buf + length) = 0; - /* *(buf+length) is not 0x18 */ - for (i = length - 1; i >= 0; i--) - if (*(buf + i) == synthFlushChar) { - queue_clear(); - stop_speech(); - j = length - i; - for (length = 0; length <= j; length++) - *(buf + length) = *(buf + i++); - break; - } + cp = strrchr(buf, synthFlushChar); + if (cp) { + queue_clear(); + stop_speech(); + strcpy(buf, cp+1); + length = strlen(buf); + } process_buffer(s, buf, length); } }