diff options
author | XANTRONIX Development | 2022-02-26 23:34:42 -0500 |
---|---|---|
committer | XANTRONIX Development | 2022-02-26 23:34:42 -0500 |
commit | 51806621006a9d54d368c7c033e59b2a3818f5ae (patch) | |
tree | 9e047779811e429248246fec20074d9317e633bb /src | |
parent | 83dfce31edeed5e33b981c9aa78278ed7fa2a979 (diff) | |
download | xas-51806621006a9d54d368c7c033e59b2a3818f5ae.tar.gz xas-51806621006a9d54d368c7c033e59b2a3818f5ae.tar.bz2 xas-51806621006a9d54d368c7c033e59b2a3818f5ae.zip |
Implement args_concat() in src/vox.c
Implement args_concat() in src/vox.c to prepare to allow passing
arbitrary arguments to text2wave
Diffstat (limited to 'src')
-rw-r--r-- | src/vox.c | 67 |
1 files changed, 54 insertions, 13 deletions
@@ -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; i<argn1; i++, o++) { + ret[o] = args1[i]; + } + + for (i=0; i<argn2; i++, o++) { + ret[o] = args2[i]; + } + + *total = count; + ret[o] = NULL; + + return ret; + +error_malloc: + return NULL; +} + static int vox_start(xas_vox *vox) { int pipe_stdin[2], pipe_stdout[2]; @@ -54,18 +83,6 @@ static int vox_start(xas_vox *vox) { char sample_rate[40]; - char *args[] = { - (char *)vox->text2wave_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: |