t->error = ret;
}
-__malloc static void *alsa_parse_config_or_die(const char *options)
+__malloc static void *alsa_parse_config_or_die(int argc, char **argv)
{
struct alsa_write_args_info *conf = para_calloc(sizeof(*conf));
/* exits on errors */
- alsa_cmdline_parser_string(options, conf, "alsa_write");
+ alsa_cmdline_parser(argc, argv, conf);
return conf;
}
t->error = ret;
}
-__malloc static void *aow_parse_config_or_die(const char *options)
+__malloc static void *aow_parse_config_or_die(int argc, char **argv)
{
struct ao_write_args_info *conf = para_calloc(sizeof(*conf));
/* exits on errors */
- ao_cmdline_parser_string(options, conf, "ao_write");
+ ao_cmdline_parser(argc, argv, conf);
return conf;
}
}
/* Use default writer for audio formats which are not yet set up. */
FOR_EACH_AUDIO_FORMAT(i) {
- struct writer *w = writers + DEFAULT_WRITER;
+ void *writer_conf;
+ int writer_num;
a = afi + i;
if (a->num_writers > 0)
continue; /* already set up */
- PARA_INFO_LOG("%s writer: %s (default)\n", audio_formats[i],
- writer_names[DEFAULT_WRITER]);
+ writer_conf = check_writer_arg_or_die(NULL, &writer_num);
a->writer_nums = para_malloc(sizeof(int));
- a->writer_nums[0] = DEFAULT_WRITER;
+ a->writer_nums[0] = writer_num;
a->writer_conf = para_malloc(sizeof(void *));
- a->writer_conf[0] = w->parse_config_or_die("");
+ a->writer_conf[0] = writer_conf;
a->num_writers = 1;
+ PARA_INFO_LOG("%s writer: %s (default)\n", audio_formats[i],
+ writer_names[writer_num]);
}
return 1;
}
t->error = ret;
}
-__malloc static void *file_write_parse_config_or_die(const char *options)
+__malloc static void *file_write_parse_config_or_die(int argc, char **argv)
{
struct file_write_args_info *conf = para_calloc(sizeof(*conf));
/* exits on errors */
- file_cmdline_parser_string(options, conf, "file_write");
+ file_cmdline_parser(argc, argv, conf);
return conf;
}
--func-name=$(subst _filter.ggo,,$(<F))_cmdline_parser < $<
$(cmdline_dir)/%_write.cmdline.h $(cmdline_dir)/%_write.cmdline.c: $(ggo_dir)/%_write.ggo | $(cmdline_dir)
@[ -z "$(Q)" ] || echo 'GGO $<'
- $(Q) $(GENGETOPT) -S $(module_ggo_opts) \
+ $(Q) $(GENGETOPT) $(module_ggo_opts) \
--output-dir=$(cmdline_dir) \
--set-package=$(subst .ggo,,$(<F)) \
--arg-struct-name=$(subst .ggo,,$(<F))_args_info \
btr_remove_node(&wn->btrn);
}
-__malloc static void *oss_parse_config_or_die(const char *options)
+__malloc static void *oss_parse_config_or_die(int argc, char **argv)
{
struct oss_write_args_info *conf = para_calloc(sizeof(*conf));
/* exits on errors */
- oss_cmdline_parser_string(options, conf, "oss_write");
+ oss_cmdline_parser(argc, argv, conf);
return conf;
}
return ret;
}
-__malloc static void *osx_write_parse_config_or_die(const char *options)
+__malloc static void *osx_write_parse_config_or_die(int argc, char **argv)
{
struct osx_write_args_info *conf = para_calloc(sizeof(*conf));
/* exits on errors */
- osx_cmdline_parser_string(options, conf, "osx_write");
+ osx_cmdline_parser(argc, argv, conf);
return conf;
}
static void setup_writer_node(const char *arg, struct btr_node *parent,
struct writer_node *wn, struct sched *s)
{
- if (arg)
- wn->conf = check_writer_arg_or_die(arg, &wn->writer_num);
- else {
- wn->writer_num = DEFAULT_WRITER;
- wn->conf = writers[DEFAULT_WRITER].parse_config_or_die("");
- }
+ wn->conf = check_writer_arg_or_die(arg, &wn->writer_num);
register_writer_node(wn, parent, s);
}
/**
* The command line parser of the writer.
*
- * It should check whether the command line options given by \a options
- * are valid and return a pointer to the writer-specific configuration
- * data determined by \a options. This function must either succeed or
- * call exit(). Note that parse_config_or_die() might be called more
- * than once with different values of \a options. \sa \ref
- * free_config().
+ * It should check whether the command line options given by \a argv
+ * and \a argc are valid and return a pointer to the writer-specific
+ * configuration data determined by these options. This function must
+ * either succeed or call exit(). Note that parse_config_or_die() might
+ * be called more than once with different values of \a options. \sa
+ * \ref free_config().
*/
- void *(*parse_config_or_die)(const char *options);
+ void *(*parse_config_or_die)(int argc, char **argv);
/**
* Dellocate all configuration resources.
*
*/
void *check_writer_arg_or_die(const char *wa, int *writer_num)
{
- int i;
-
+ int i, ret, argc;
+ const char *cmdline;
+ char **argv;
+ void *conf;
+
+ if (!wa || !*wa) {
+ i = DEFAULT_WRITER;
+ cmdline = NULL;
+ goto check;
+ }
PARA_INFO_LOG("checking %s\n", wa);
FOR_EACH_WRITER(i) {
const char *name = writer_names[i];
size_t len = strlen(name);
char c;
+
if (strlen(wa) < len)
continue;
if (strncmp(name, wa, len))
continue;
c = wa[len];
- if (c && c != ' ')
- continue;
- *writer_num = i;
- return writers[i].parse_config_or_die(c? wa + len + 1 : "");
+ if (!c || c == ' ') {
+ cmdline = c? wa + len + 1 : NULL;
+ goto check;
+ }
}
PARA_EMERG_LOG("invalid writer %s\n", wa);
exit(EXIT_FAILURE);
+check:
+ ret = create_shifted_argv(cmdline, " \t", &argv);
+ if (ret < 0) {
+ PARA_EMERG_LOG("%s: %s\n", wa, para_strerror(-ret));
+ exit(EXIT_FAILURE);
+ }
+ argc = ret;
+ argv[0] = make_message("%s_write", writer_names[i]);
+ *writer_num = i;
+ conf = writers[i].parse_config_or_die(argc, argv);
+ free_argv(argv);
+ return conf;
}
/**