indentation fixes

This commit is contained in:
William Hubbs 2008-09-01 12:50:16 -05:00
commit 5ddeb1e978
5 changed files with 70 additions and 61 deletions

View file

@ -54,7 +54,7 @@ int espeakup_is_running(void)
if (pidFile) {
fscanf(pidFile, "%d", &pid);
fclose(pidFile);
if (! kill(pid, 0) || errno != ESRCH)
if (!kill(pid, 0) || errno != ESRCH)
rc = 1;
}
return rc;
@ -65,19 +65,19 @@ int create_pid_file(void)
FILE *pidFile;
pidFile = fopen(pidPath, "w");
if (! pidFile)
if (!pidFile)
return -1;
fprintf(pidFile, "%d\n", getpid());
fclose(pidFile);
return 0;
}
void espeakup_sighandler(int sig)
{
if (debug)
printf("Caught signal %i\n", sig);
/* clear the queue */
queue_clear();
@ -85,7 +85,7 @@ void espeakup_sighandler(int sig)
espeak_Terminate();
close_softsynth();
if (! debug)
if (!debug)
unlink(pidPath);
exit(0);
}
@ -113,7 +113,7 @@ void process_cli(int argc, char **argv)
int opt;
while ((opt = getopt(argc, argv, shortOptions)) != -1) {
switch(opt) {
switch (opt) {
case 'd':
debug = 1;
break;
@ -137,7 +137,7 @@ int main(int argc, char **argv)
/* process command line options */
process_cli(argc, argv);
if (! debug) {
if (!debug) {
if (espeakup_is_running()) {
printf("Espeakup is already running!\n");
return 1;
@ -161,9 +161,9 @@ int main(int argc, char **argv)
espeak_SetSynthCallback(SynthCallback);
/* Setup initial voice parameters */
set_frequency (&s, defaultFrequency, ADJ_SET);
set_pitch (&s, defaultPitch, ADJ_SET);
set_rate (&s, defaultRate, ADJ_SET);
set_frequency(&s, defaultFrequency, ADJ_SET);
set_pitch(&s, defaultPitch, ADJ_SET);
set_rate(&s, defaultRate, ADJ_SET);
set_volume(&s, defaultVolume, ADJ_SET);
/* register signal handler */
@ -171,7 +171,7 @@ int main(int argc, char **argv)
signal(SIGTERM, espeakup_sighandler);
/* run the main loop */
main_loop (&s);
main_loop(&s);
return 0;
}

View file

@ -55,19 +55,25 @@ struct synth_t {
extern int debug;
extern void queue_clear(void);
extern void queue_add_cmd(enum command_t cmd, enum adjust_t adj, int value);
extern void queue_add_cmd(enum command_t cmd, enum adjust_t adj,
int value);
extern void queue_add_text(char *txt, size_t length);
extern void queue_process_entry(struct synth_t *s);
extern int SynthCallback(short *wav, int numsamples, espeak_EVENT *events);
extern espeak_ERROR set_frequency(struct synth_t *s, int freq, enum adjust_t adj);
extern espeak_ERROR set_pitch(struct synth_t *s, int pitch, enum adjust_t adj);
extern espeak_ERROR set_rate(struct synth_t *s, int rate, enum adjust_t adj);
extern int SynthCallback(short *wav, int numsamples,
espeak_EVENT * events);
extern espeak_ERROR set_frequency(struct synth_t *s, int freq,
enum adjust_t adj);
extern espeak_ERROR set_pitch(struct synth_t *s, int pitch,
enum adjust_t adj);
extern espeak_ERROR set_rate(struct synth_t *s, int rate,
enum adjust_t adj);
extern espeak_ERROR set_voice(struct synth_t *s);
extern espeak_ERROR set_volume(struct synth_t *s, int vol, enum adjust_t adj);
extern espeak_ERROR set_volume(struct synth_t *s, int vol,
enum adjust_t adj);
extern espeak_ERROR stop_speech(void);
extern espeak_ERROR speak_text(struct synth_t *s);
extern void open_softsynth(void);
extern void close_softsynth(void);
extern void main_loop (struct synth_t *s);
extern void main_loop(struct synth_t *s);
#endif

16
queue.c
View file

@ -40,9 +40,9 @@ static void queue_add(struct queue_entry_t *entry)
{
assert(entry);
entry->next = NULL;
if (! last)
if (!last)
last = entry;
if (! first) {
if (!first) {
first = entry;
} else {
first->next = entry;
@ -60,13 +60,13 @@ static void queue_remove(void)
if (temp->cmd == CMD_SPEAK_TEXT)
free(temp->buf);
free(temp);
if (! last)
if (!last)
first = last;
}
void queue_clear(void)
{
while(last)
while (last)
queue_remove();
}
@ -75,7 +75,7 @@ void queue_add_cmd(enum command_t cmd, enum adjust_t adj, int value)
struct queue_entry_t *entry;
entry = malloc(sizeof(struct queue_entry_t));
if (! entry) {
if (!entry) {
perror("unable to allocate memory for queue entry");
return;
}
@ -90,14 +90,14 @@ void queue_add_text(char *txt, size_t length)
struct queue_entry_t *entry;
entry = malloc(sizeof(struct queue_entry_t));
if (! entry) {
if (!entry) {
perror("unable to allocate memory for queue entry");
return;
}
entry->cmd = CMD_SPEAK_TEXT;
entry->adjust = ADJ_SET;
entry->buf = strdup(txt);
if (! entry->buf) {
if (!entry->buf) {
perror("unable to allocate space for text");
free(entry);
return;
@ -110,7 +110,7 @@ void queue_process_entry(struct synth_t *s)
{
espeak_ERROR error;
if(! last)
if (!last)
return;
switch (last->cmd) {

View file

@ -36,8 +36,8 @@ static int process_command(struct synth_t *s, char *buf, int start)
int value;
enum adjust_t adj;
enum command_t cmd;
cp = buf+start;
cp = buf + start;
switch (*cp) {
case 1:
cp++;
@ -56,7 +56,7 @@ static int process_command(struct synth_t *s, char *buf, int start)
}
value = 0;
while(isdigit(*cp)) {
while (isdigit(*cp)) {
value = value * 10 + (*cp - '0');
cp++;
}
@ -89,7 +89,7 @@ static int process_command(struct synth_t *s, char *buf, int start)
return cp - (buf + start);
}
static void process_buffer (struct synth_t *s, char *buf, ssize_t length)
static void process_buffer(struct synth_t *s, char *buf, ssize_t length)
{
int start;
int end;
@ -102,13 +102,13 @@ static void process_buffer (struct synth_t *s, char *buf, ssize_t length)
while (buf[end] >= 32 && end < length)
end++;
if (end != start) {
txtLen = end-start;
strncpy (txtBuf, buf + start, txtLen);
*(txtBuf+txtLen) = 0;
txtLen = end - start;
strncpy(txtBuf, buf + start, txtLen);
*(txtBuf + txtLen) = 0;
queue_add_text(txtBuf, txtLen);
}
if (end < length)
start = end = end+process_command (s, buf, end);
start = end = end + process_command(s, buf, end);
else
start = length;
}
@ -116,7 +116,7 @@ static void process_buffer (struct synth_t *s, char *buf, ssize_t length)
void open_softsynth(void)
{
softFD = open ("/dev/softsynth", O_RDWR | O_NONBLOCK);
softFD = open("/dev/softsynth", O_RDWR | O_NONBLOCK);
if (softFD < 0) {
perror("Unable to open the softsynth device");
exit(3);
@ -128,7 +128,7 @@ void close_softsynth(void)
close(softFD);
}
void main_loop (struct synth_t *s)
void main_loop(struct synth_t *s)
{
fd_set set;
struct timeval tv;
@ -136,42 +136,42 @@ void main_loop (struct synth_t *s)
int j;
ssize_t length;
char buf[maxBufferSize];
while (1) {
queue_process_entry(s);
FD_ZERO (&set);
FD_SET (softFD, &set);
FD_ZERO(&set);
FD_SET(softFD, &set);
tv.tv_sec = 0;
tv.tv_usec = 500;
i = select (softFD+1, &set, NULL, NULL, &tv);
i = select(softFD + 1, &set, NULL, NULL, &tv);
if (i < 0) {
if (errno == EINTR)
continue;
perror("Select failed");
break;
}
if (! FD_ISSET(softFD, &set))
if (!FD_ISSET(softFD, &set))
continue;
length = read (softFD, buf, maxBufferSize - 1);
length = read(softFD, buf, maxBufferSize - 1);
if (length < 0) {
if (errno == EAGAIN || errno == EINTR)
continue;
perror("Read from softsynth failed");
break;
}
*(buf+length) = 0;
for(i = length; i >= 0; i--)
if (*(buf+i) == 0x18) { /* synth flush char. */
*(buf + length) = 0;
for (i = length; i >= 0; i--)
if (*(buf + i) == 0x18) { /* synth flush char. */
queue_clear();
stop_speech();
j = length-i;
for(length = 0; length <= j; length++)
*(buf+length) = *(buf+i++);
j = length - i;
for (length = 0; length <= j; length++)
*(buf + length) = *(buf + i++);
break;
}
process_buffer (s, buf, length);
process_buffer(s, buf, length);
}
}

25
synth.c
View file

@ -26,12 +26,12 @@ const int rateMultiplier = 34;
const int rateOffset = 84;
const int volumeMultiplier = 11;
int SynthCallback(short *wav, int numsamples, espeak_EVENT *events)
int SynthCallback(short *wav, int numsamples, espeak_EVENT * events)
{
return 0;
}
espeak_ERROR set_frequency(struct synth_t *s, int freq, enum adjust_t adj)
espeak_ERROR set_frequency(struct synth_t * s, int freq, enum adjust_t adj)
{
espeak_ERROR rc;
@ -45,7 +45,7 @@ espeak_ERROR set_frequency(struct synth_t *s, int freq, enum adjust_t adj)
return rc;
}
espeak_ERROR set_pitch(struct synth_t *s, int pitch, enum adjust_t adj)
espeak_ERROR set_pitch(struct synth_t * s, int pitch, enum adjust_t adj)
{
espeak_ERROR rc;
@ -59,7 +59,7 @@ espeak_ERROR set_pitch(struct synth_t *s, int pitch, enum adjust_t adj)
return rc;
}
espeak_ERROR set_rate(struct synth_t *s, int rate, enum adjust_t adj)
espeak_ERROR set_rate(struct synth_t * s, int rate, enum adjust_t adj)
{
espeak_ERROR rc;
@ -67,18 +67,19 @@ espeak_ERROR set_rate(struct synth_t *s, int rate, enum adjust_t adj)
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;
}
espeak_ERROR set_voice(struct synth_t *s)
espeak_ERROR set_voice(struct synth_t * s)
{
return (espeak_SetVoiceByName(s->voice));
}
espeak_ERROR set_volume(struct synth_t *s, int vol, enum adjust_t adj)
espeak_ERROR set_volume(struct synth_t * s, int vol, enum adjust_t adj)
{
espeak_ERROR rc;
@ -86,10 +87,11 @@ espeak_ERROR set_volume(struct synth_t *s, int vol, enum adjust_t adj)
vol = -vol;
if (adj != ADJ_SET)
vol += s->volume;
rc = espeak_SetParameter(espeakVOLUME, (vol+1) * volumeMultiplier, 0);
rc = espeak_SetParameter(espeakVOLUME, (vol + 1) * volumeMultiplier,
0);
if (rc == EE_OK)
s->volume = vol;
return rc;
}
@ -98,10 +100,11 @@ espeak_ERROR stop_speech(void)
return (espeak_Cancel());
}
espeak_ERROR speak_text(struct synth_t *s)
espeak_ERROR speak_text(struct synth_t * s)
{
espeak_ERROR rc;
rc = espeak_Synth(s->buf, s->len + 1, 0, POS_CHARACTER, 0, 0, NULL, NULL);
rc = espeak_Synth(s->buf, s->len + 1, 0, POS_CHARACTER, 0, 0, NULL,
NULL);
return rc;
}