From 51806621006a9d54d368c7c033e59b2a3818f5ae Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Sat, 26 Feb 2022 23:34:42 -0500 Subject: Implement args_concat() in src/vox.c Implement args_concat() in src/vox.c to prepare to allow passing arbitrary arguments to text2wave --- include/xas/vox.h | 5 ++++- src/vox.c | 67 ++++++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 58 insertions(+), 14 deletions(-) diff --git a/include/xas/vox.h b/include/xas/vox.h index fd442a8..917eda1 100644 --- a/include/xas/vox.h +++ b/include/xas/vox.h @@ -11,13 +11,16 @@ #define XAS_VOX_ACTIVE (1 << 0) typedef struct _xas_vox { - const char *text2wave_path; xas_audio_format format; size_t buffer_size; int flags; + const char *text2wave_path; + int argn; + char **args; + int pid, stdin, diff --git a/src/vox.c b/src/vox.c index efe5346..697ff95 100644 --- a/src/vox.c +++ b/src/vox.c @@ -46,6 +46,35 @@ error_waitpid: return -1; } +static char **args_concat(int argn1, char **args1, + int argn2, char **args2, + int *total) { + char **ret; + + int count = argn1 + argn2, + i, o; + + if ((ret = malloc((count + 1) * sizeof(char *))) == NULL) { + goto error_malloc; + } + + for (i=0, o=0; itext2wave_path, - "-F", - sample_rate, - "-", - "-o", - "-", - NULL - }; - - snprintf(sample_rate, sizeof(sample_rate)-1, "%zu", vox->format.sample_rate); - if (vox->flags & XAS_VOX_ACTIVE) { (void)vox_stop(vox); } @@ -83,8 +100,27 @@ static int vox_start(xas_vox *vox) { } if (pid == 0) { + char *args[] = { + (char *)vox->text2wave_path, + "-F", + sample_rate, + "-", + "-o", + "-", + NULL + }; + + int argc; + char **argv; + int fd; + snprintf(sample_rate, sizeof(sample_rate)-1, "%zu", vox->format.sample_rate); + + if ((argv = args_concat(6, args, vox->argn, vox->args, &argc)) == NULL) { + goto error_child; + } + if ((fd = open("/dev/null", O_WRONLY)) < 0) { goto error_child; } @@ -104,7 +140,7 @@ static int vox_start(xas_vox *vox) { goto error_child; } - if (execv(vox->text2wave_path, args) < 0) { + if (execv(vox->text2wave_path, argv) < 0) { goto error_child; } @@ -194,6 +230,11 @@ xas_vox *xas_vox_new(const char *text2wave_path, vox->stdout = -1; vox->in = NULL; + vox->argn = 0; + vox->args = NULL; + + memset(vox->tmpfile, '\0', sizeof(vox->tmpfile)); + return vox; error_malloc_vox: -- cgit v1.2.3