diff --git a/src/cli.c b/src/cli.c index 280b507..cc1a9d9 100644 --- a/src/cli.c +++ b/src/cli.c @@ -44,8 +44,7 @@ const struct option longOptions[] = { {"debug", no_argument, NULL, 'd'}, {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'v'}, - {0, 0, 0, 0} -}; + {0, 0, 0, 0}}; static void show_help() { diff --git a/src/espeak.c b/src/espeak.c index acee6e1..6f64901 100644 --- a/src/espeak.c +++ b/src/espeak.c @@ -18,12 +18,12 @@ */ #define _GNU_SOURCE +#include #include +#include #include #include #include -#include -#include #include "espeakup.h" @@ -47,10 +47,10 @@ const int volumeMultiplier = 22; volatile int stop_requested = 0; int paused_espeak = 1; -static int callback(short *wav, int numsamples, espeak_EVENT * events) +static int callback(short *wav, int numsamples, espeak_EVENT *events) { int i; - for (i = 0; events[i].type != espeakEVENT_LIST_TERMINATED; i++) { + for (i = 0; events[i].type != espeakEVENT_LIST_TERMINATED; i++) { if (events[i].type == espeakEVENT_MARK) { int mark = atoi(events[i].id.name); if ((mark < 0) || (mark > 255)) @@ -62,7 +62,7 @@ static int callback(short *wav, int numsamples, espeak_EVENT * events) } static espeak_ERROR set_frequency(struct synth_t *s, int freq, - enum adjust_t adj) + enum adjust_t adj) { espeak_ERROR rc; @@ -76,8 +76,7 @@ static espeak_ERROR set_frequency(struct synth_t *s, int freq, return rc; } -static espeak_ERROR set_pitch(struct synth_t *s, int pitch, - enum adjust_t adj) +static espeak_ERROR set_pitch(struct synth_t *s, int pitch, enum adjust_t adj) { espeak_ERROR rc; @@ -91,8 +90,7 @@ static espeak_ERROR set_pitch(struct synth_t *s, int pitch, return rc; } -static espeak_ERROR set_range(struct synth_t *s, int range, - enum adjust_t adj) +static espeak_ERROR set_range(struct synth_t *s, int range, enum adjust_t adj) { espeak_ERROR rc; @@ -107,7 +105,7 @@ static espeak_ERROR set_range(struct synth_t *s, int range, } static espeak_ERROR set_punctuation(struct synth_t *s, int punct, - enum adjust_t adj) + enum adjust_t adj) { espeak_ERROR rc; @@ -121,8 +119,7 @@ static espeak_ERROR set_punctuation(struct synth_t *s, int punct, return rc; } -static espeak_ERROR set_rate(struct synth_t *s, int rate, - enum adjust_t adj) +static espeak_ERROR set_rate(struct synth_t *s, int rate, enum adjust_t adj) { espeak_ERROR rc; @@ -130,8 +127,7 @@ static espeak_ERROR set_rate(struct synth_t *s, int rate, rate = -rate; if (adj != ADJ_SET) rate += s->rate; - rc = espeak_SetParameter(espeakRATE, - rate * rateMultiplier + rateOffset, 0); + rc = espeak_SetParameter(espeakRATE, rate * rateMultiplier + rateOffset, 0); if (rc == EE_OK) s->rate = rate; return rc; @@ -143,8 +139,7 @@ static espeak_ERROR set_voice(struct synth_t *s, char *voice) espeak_VOICE voice_select; rc = espeak_SetVoiceByName(voice); - if (rc != EE_OK) - { + if (rc != EE_OK) { memset(&voice_select, 0, sizeof(voice_select)); voice_select.languages = voice; rc = espeak_SetVoiceByProperties(&voice_select); @@ -161,27 +156,23 @@ static void set_alsa_volume(int vol) int err; err = snd_mixer_open(&m, 0); - if (err < 0) - { + if (err < 0) { fprintf(stderr, "ALSA mixer open error: %s\n", snd_strerror(err)); return; } err = snd_mixer_attach(m, "default"); - if (err < 0) - { + if (err < 0) { fprintf(stderr, "ALSA mixer attach error: %s\n", snd_strerror(err)); return; } err = snd_mixer_selem_register(m, NULL, NULL); - if (err < 0) - { + if (err < 0) { fprintf(stderr, "ALSA mixer load error: %s\n", snd_strerror(err)); return; } err = snd_mixer_load(m); - if (err < 0) - { + if (err < 0) { fprintf(stderr, "ALSA mixer load error: %s\n", snd_strerror(err)); return; } @@ -192,10 +183,9 @@ static void set_alsa_volume(int vol) * volume (80%), and make higher values increase ALSA volume, up to * 100%. */ - int volume = (vol+1) * 50 / 10 + 50; + int volume = (vol + 1) * 50 / 10 + 50; - for (e = snd_mixer_first_elem(m); e; e = snd_mixer_elem_next(e)) - { + for (e = snd_mixer_first_elem(m); e; e = snd_mixer_elem_next(e)) { if (snd_mixer_elem_get_type(e) != SND_MIXER_ELEM_SIMPLE) continue; if (snd_mixer_selem_is_enumerated(e)) @@ -212,13 +202,12 @@ static void set_alsa_volume(int vol) if (err == 0 && min < max) { if (max - min < 2400) { /* 24dB amplitude is too small for using a logscale */ - set = min + volume * (max-min) / 100; + set = min + volume * (max - min) / 100; } else { /* Use a logscale */ double volf = volume / 100.; - if (min != SND_CTL_TLV_DB_GAIN_MUTE) - { - double minf = pow(10, (min-max) / 6000.); + if (min != SND_CTL_TLV_DB_GAIN_MUTE) { + double minf = pow(10, (min - max) / 6000.); volf = volf * (1 - minf) + minf; } set = 6000. * log10(volf) + max; @@ -227,15 +216,14 @@ static void set_alsa_volume(int vol) } else { /* No dB setting, try a linear scale */ snd_mixer_selem_get_playback_volume_range(e, &min, &max); - set = min + volume * (max-min) / 100; + set = min + volume * (max - min) / 100; snd_mixer_selem_set_playback_volume_all(e, set); } } } } -static espeak_ERROR set_volume(struct synth_t *s, int vol, - enum adjust_t adj) +static espeak_ERROR set_volume(struct synth_t *s, int vol, enum adjust_t adj) { espeak_ERROR rc; @@ -243,10 +231,8 @@ static espeak_ERROR set_volume(struct synth_t *s, int vol, vol = -vol; if (adj != ADJ_SET) vol += s->volume; - rc = espeak_SetParameter(espeakVOLUME, (vol + 1) * volumeMultiplier, - 0); - if (rc == EE_OK) - { + rc = espeak_SetParameter(espeakVOLUME, (vol + 1) * volumeMultiplier, 0); + if (rc == EE_OK) { s->volume = vol; if (alsaVolume) set_alsa_volume(vol); @@ -276,24 +262,24 @@ static espeak_ERROR speak_text(struct synth_t *s) int n; if (s->buf[0] == ' ') n = asprintf(&buf, - " "); + " "); else n = asprintf(&buf, - "%c", - s->buf[0]); + "%c", + s->buf[0]); if (n == -1) { /* D'oh. Not much to do on allocation failure. * Perhaps espeak will happen to say the character */ - rc = espeak_Synth(s->buf, s->len + 1, 0, POS_CHARACTER, - 0, synth_mode, NULL, NULL); + rc = espeak_Synth(s->buf, s->len + 1, 0, POS_CHARACTER, 0, + synth_mode, NULL, NULL); } else { - rc = espeak_Synth(buf, n + 1, 0, POS_CHARACTER, 0, - espeakSSML, NULL, NULL); + rc = espeak_Synth(buf, n + 1, 0, POS_CHARACTER, 0, espeakSSML, NULL, + NULL); free(buf); } } else - rc = espeak_Synth(s->buf, s->len + 1, 0, POS_CHARACTER, 0, - synth_mode, NULL, NULL); + rc = espeak_Synth(s->buf, s->len + 1, 0, POS_CHARACTER, 0, synth_mode, + NULL, NULL); return rc; } @@ -361,9 +347,10 @@ static void queue_process_entry(struct synth_t *s) error = set_frequency(s, current->value, current->adjust); break; case CMD_SET_MARK: - snprintf(markbuff, sizeof(markbuff), "", current->value); - error = espeak_Synth(markbuff, strlen(markbuff)+1, 0, POS_CHARACTER, - 0, espeakSSML, NULL, NULL); + snprintf(markbuff, sizeof(markbuff), "", + current->value); + error = espeak_Synth(markbuff, strlen(markbuff) + 1, 0, POS_CHARACTER, + 0, espeakSSML, NULL, NULL); break; case CMD_SET_PITCH: error = set_pitch(s, current->value, current->adjust); @@ -452,14 +439,13 @@ int initialize_espeak(struct synth_t *s) * The main thread can add items to the queue in exactly two situations: * 1. We are waiting on runner_awake, or * 2. We are processing an entry that has just been removed from the queue. -*/ + */ void *espeak_thread(void *arg) { struct synth_t *s = (struct synth_t *) arg; pthread_mutex_lock(&queue_guard); while (should_run) { - while (should_run && !queue_peek(synth_queue) && !stop_requested) pthread_cond_wait(&runner_awake, &queue_guard); diff --git a/src/espeakup.c b/src/espeakup.c index eda3e9c..3328d74 100644 --- a/src/espeakup.c +++ b/src/espeakup.c @@ -18,13 +18,13 @@ */ #include +#include #include #include #include #include -#include -#include #include +#include #include "espeakup.h" @@ -78,7 +78,7 @@ int espeakup_start_daemon(void) /* Child */ if (chdir("/") < 0) { c = 1; - (void)write(fds[1], &c, 1); + (void) write(fds[1], &c, 1); exit(1); } return fds[1]; @@ -99,14 +99,12 @@ int espeakup_is_running(void) } if (flock(pidFile, LOCK_EX) < 0) { - printf("Can not lock the pid file %s: %s\n", pidPath, - strerror(errno)); + printf("Can not lock the pid file %s: %s\n", pidPath, strerror(errno)); goto error; } n = read(pidFile, s, sizeof(s) - 1); if (n < 0) { - printf("Can not read the pid file %s: %s\n", pidPath, - strerror(errno)); + printf("Can not read the pid file %s: %s\n", pidPath, strerror(errno)); goto error; } s[n] = 0; @@ -197,13 +195,13 @@ int main(int argc, char **argv) sigaddset(&sigset, SIGTERM); sigprocmask(SIG_BLOCK, &sigset, NULL); -/* Initialize espeak */ + /* Initialize espeak */ if (initialize_espeak(&s) < 0) { ret = 2; goto out; } -/* open the softsynth */ + /* open the softsynth */ if (open_softsynth() < 0) { ret = 2; goto out; @@ -224,7 +222,7 @@ int main(int argc, char **argv) } if (!debug && espeakup_mode == ESPEAKUP_MODE_SPEAKUP) - (void)write(fd, &ret, 1); + (void) write(fd, &ret, 1); /* wait for the threads to shut down. */ pthread_join(signal_thread_id, NULL); @@ -240,7 +238,7 @@ out: if (ret != 1) unlink(pidPath); if (ret != 0) - (void)write(fd, &ret, 1); + (void) write(fd, &ret, 1); /* If ret was 0, the status byte was written before joining * the threads. */ } diff --git a/src/espeakup.h b/src/espeakup.h index d6daaf0..6629371 100644 --- a/src/espeakup.h +++ b/src/espeakup.h @@ -21,8 +21,8 @@ #define __ESPEAKUP_H /* This was added for gcc 4.3 */ -#include #include +#include #include @@ -30,12 +30,14 @@ #define PACKAGE_BUGREPORT "https://github.com/linux-speakup/espeakup/issues" -enum espeakup_mode_t { +enum espeakup_mode_t +{ ESPEAKUP_MODE_SPEAKUP, ESPEAKUP_MODE_ACSINT }; -enum command_t { +enum command_t +{ CMD_SET_FREQUENCY, CMD_SET_MARK, CMD_SET_PITCH, @@ -50,7 +52,8 @@ enum command_t { CMD_UNKNOWN, }; -enum adjust_t { +enum adjust_t +{ ADJ_DEC, ADJ_SET, ADJ_INC, diff --git a/src/queue.h b/src/queue.h index 249f3ba..a6a2a76 100644 --- a/src/queue.h +++ b/src/queue.h @@ -20,7 +20,7 @@ #ifndef __QUEUE_H #define __QUEUE_H -struct queue_t; /* An opaque type. */ +struct queue_t; /* An opaque type. */ extern struct queue_t *new_queue(void); extern int queue_add(struct queue_t *q, void *entry); diff --git a/src/signal.c b/src/signal.c index 3096b30..f6a6a39 100644 --- a/src/signal.c +++ b/src/signal.c @@ -40,7 +40,7 @@ void *signal_thread(void *arg) sigset_t sigset; int sig; - memset(&temp, 0, sizeof (struct sigaction)); + memset(&temp, 0, sizeof(struct sigaction)); /* install dummy handlers for the signals we want to process */ temp.sa_handler = dummy_handler; sigemptyset(&temp.sa_mask); diff --git a/src/softsynth.c b/src/softsynth.c index 9e1d66f..085582d 100644 --- a/src/softsynth.c +++ b/src/softsynth.c @@ -17,14 +17,14 @@ * along with this program. If not, see . */ +#include #include #include #include #include -#include -#include #include -#include +#include +#include #include "espeakup.h" #include "stringhandling.h" @@ -155,8 +155,7 @@ static int process_command(struct synth_t *s, char *buf, int start) } if (cmd != CMD_FLUSH && cmd != CMD_UNKNOWN) { - if (espeakup_mode == ESPEAKUP_MODE_ACSINT - && textAccumulator_l != 0) { + if (espeakup_mode == ESPEAKUP_MODE_ACSINT && textAccumulator_l != 0) { queue_add_text(textAccumulator, textAccumulator_l); free(textAccumulator); textAccumulator = initString(&textAccumulator_l); @@ -177,7 +176,8 @@ static void process_buffer(struct synth_t *s, char *buf, ssize_t length) start = 0; end = 0; while (start < length) { - while ((buf[end] < 0 || buf[end] >= ' ' || buf[end] == '\n') && end < length) + while ((buf[end] < 0 || buf[end] >= ' ' || buf[end] == '\n') && + end < length) end++; if (end != start) { txtLen = end - start; @@ -192,8 +192,7 @@ static void process_buffer(struct synth_t *s, char *buf, ssize_t length) } } -static void process_buffer_acsint(struct synth_t *s, char *buf, - ssize_t length) +static void process_buffer_acsint(struct synth_t *s, char *buf, ssize_t length) { int start = 0; int i; @@ -207,8 +206,8 @@ static void process_buffer_acsint(struct synth_t *s, char *buf, break; } if (i > start) - stringAndBytes(&textAccumulator, &textAccumulator_l, - buf + start, i - start); + stringAndBytes(&textAccumulator, &textAccumulator_l, buf + start, + i - start); if (flushIt) { if (textAccumulator != EMPTYSTRING) { queue_add_text(textAccumulator, textAccumulator_l); @@ -228,9 +227,10 @@ static void request_espeak_stop(void) { pthread_mutex_lock(&queue_guard); stop_requested = 1; - pthread_cond_signal(&runner_awake); /* Wake runner, if necessary. */ + pthread_cond_signal(&runner_awake); /* Wake runner, if necessary. */ while (should_run && stop_requested) - pthread_cond_wait(&stop_acknowledged, &queue_guard); /* wait for acknowledgement. */ + pthread_cond_wait(&stop_acknowledged, + &queue_guard); /* wait for acknowledgement. */ pthread_mutex_unlock(&queue_guard); } diff --git a/src/stringhandling.c b/src/stringhandling.c index 8c18a39..1adf7ae 100644 --- a/src/stringhandling.c +++ b/src/stringhandling.c @@ -75,9 +75,9 @@ void stringAndString(char **s, int *l, const char *t) oldlen = *l; newlen = oldlen + strlen(t); *l = newlen; - ++newlen; /* room for the 0 */ + ++newlen; /* room for the 0 */ x = oldlen ^ newlen; - if (x > oldlen) { /* must realloc */ + if (x > oldlen) { /* must realloc */ newlen |= (newlen >> 1); newlen |= (newlen >> 2); newlen |= (newlen >> 4); @@ -98,7 +98,7 @@ void stringAndBytes(char **s, int *l, const char *t, int cnt) *l = newlen; ++newlen; x = oldlen ^ newlen; - if (x > oldlen) { /* must realloc */ + if (x > oldlen) { /* must realloc */ newlen |= (newlen >> 1); newlen |= (newlen >> 2); newlen |= (newlen >> 4);