summaryrefslogtreecommitdiffstats
path: root/src/vox.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/vox.c')
-rw-r--r--src/vox.c67
1 files changed, 54 insertions, 13 deletions
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; 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: