X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=audioc.c;h=337c8062e2b4257f47e7412d3d1ca631edd503a1;hp=b2c6786a6573ba2636606cde09403e38a590e0c6;hb=224ab3f14af8e08a8a7159160eccea75be30ffd1;hpb=f8931d4607fdf8cb98761b9814d068256d2925a3 diff --git a/audioc.c b/audioc.c index b2c6786a..337c8062 100644 --- a/audioc.c +++ b/audioc.c @@ -1,14 +1,18 @@ /* - * Copyright (C) 2005-2013 Andre Noll + * Copyright (C) 2005 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ /** \file audioc.c The client program used to connect to para_audiod. */ +#include +#include #include #include -#include +#include +#include +#include #include #include "audioc.cmdline.h" @@ -17,6 +21,7 @@ #include "net.h" #include "string.h" #include "fd.h" +#include "ggo.h" #include "version.h" INIT_AUDIOC_ERRLISTS; @@ -66,14 +71,14 @@ fail: #include "sched.h" #include "buffer_tree.h" #include "interactive.h" -#include "audiod_completion.h" +#include "audiod.completion.h" static struct sched sched; struct audioc_task { int fd; struct btr_node *btrn; - struct task task; + struct task *task; }; static struct i9e_completer audiod_completers[]; @@ -91,6 +96,15 @@ static void help_completer(struct i9e_completion_info *ci, result->matches = i9e_complete_commands(ci->word, audiod_completers); } +static void version_completer(struct i9e_completion_info *ci, + struct i9e_completion_result *cr) +{ + char *opts[] = {"-v", NULL}; + + if (ci->word_num <= 2 && ci->word && ci->word[0] == '-') + i9e_complete_option(opts, ci, cr); +} + static void stat_completer(struct i9e_completion_info *ci, struct i9e_completion_result *cr) { @@ -115,9 +129,9 @@ static struct i9e_completer audiod_completers[] = { {.name = NULL} }; -static void audioc_pre_select(struct sched *s, struct task *t) +static void audioc_pre_select(struct sched *s, void *context) { - struct audioc_task *at = container_of(t, struct audioc_task, task); + struct audioc_task *at = context; int ret = btr_node_status(at->btrn, 0, BTR_NT_ROOT); if (ret < 0) @@ -125,10 +139,10 @@ static void audioc_pre_select(struct sched *s, struct task *t) para_fd_set(at->fd, &s->rfds, &s->max_fileno); } -static int audioc_post_select(struct sched *s, struct task *t) +static int audioc_post_select(struct sched *s, void *context) { char *buf = NULL; - struct audioc_task *at = container_of(t, struct audioc_task, task); + struct audioc_task *at = context; int ret = btr_node_status(at->btrn, 0, BTR_NT_ROOT); if (ret < 0) @@ -153,13 +167,7 @@ out: return ret; } -static struct audioc_task audioc_task = { - .task = { - .pre_select = audioc_pre_select, - .post_select = audioc_post_select, - .status = "audioc task" - }, -}, *at = &audioc_task; +static struct audioc_task audioc_task, *at = &audioc_task; static int audioc_i9e_line_handler(char *line) { @@ -173,6 +181,8 @@ static int audioc_i9e_line_handler(char *line) conf.inputs_num = ret; args = concat_args(conf.inputs_num, conf.inputs); free_argv(conf.inputs); + if (!args) + return 0; conf.inputs_num = 0; /* required for audioc_cmdline_parser_free() */ ret = connect_audiod(socket_name, args); if (ret < 0) @@ -185,8 +195,12 @@ static int audioc_i9e_line_handler(char *line) args = NULL; at->btrn = btr_new_node(&(struct btr_node_description) EMBRACE(.name = "audioc line handler")); - at->task.error = 0; - register_task(&sched, &at->task); + at->task = task_register(&(struct task_info) { + .name = "audioc", + .pre_select = audioc_pre_select, + .post_select = audioc_post_select, + .context = at, + }, &sched); i9e_attach_to_stdout(at->btrn); return 1; close: @@ -208,7 +222,7 @@ __noreturn static void interactive_session(void) .loglevel = loglevel, .completers = audiod_completers, }; - PARA_NOTICE_LOG("\n%s\n", VERSION_TEXT("audioc")); + PARA_NOTICE_LOG("\n%s\n", version_text("audioc")); if (conf.history_file_given) history_file = para_strdup(conf.history_file_arg); else { @@ -231,6 +245,7 @@ __noreturn static void interactive_session(void) goto out; para_log = i9e_log; ret = schedule(&sched); + sched_shutdown(&sched); i9e_close(); para_log = stderr_log; out: @@ -277,6 +292,15 @@ static char *configfile_exists(void) return NULL; } +__noreturn static void print_help_and_die(void) +{ + struct ggo_help h = DEFINE_GGO_HELP(audioc); + bool d = conf.detailed_help_given; + + ggo_print_help(&h, d? GPH_STANDARD_FLAGS_DETAILED : GPH_STANDARD_FLAGS); + exit(0); +} + /** * The client program to connect to para_audiod. * @@ -295,29 +319,29 @@ static char *configfile_exists(void) */ int main(int argc, char *argv[]) { - int ret = -E_AUDIOC_SYNTAX, fd; + int ret, fd; char *cf, *buf = NULL, *args = NULL; size_t bufsize; - if (audioc_cmdline_parser(argc, argv, &conf)) - goto out; - HANDLE_VERSION_FLAG("audioc", conf); + audioc_cmdline_parser(argc, argv, &conf); + loglevel = get_loglevel_by_name(conf.loglevel_arg); + version_handle_flag("audioc", conf.version_given); + if (conf.help_given || conf.detailed_help_given) + print_help_and_die(); cf = configfile_exists(); if (cf) { struct audioc_cmdline_parser_params params = { .override = 0, .initialize = 0, .check_required = 0, - .check_ambiguity = 0 + .check_ambiguity = 0, + .print_errors = 1, + }; - ret = audioc_cmdline_parser_config_file(cf, &conf, ¶ms); + audioc_cmdline_parser_config_file(cf, &conf, ¶ms); free(cf); - if (ret) { - fprintf(stderr, "parse error in config file\n"); - exit(EXIT_FAILURE); - } + loglevel = get_loglevel_by_name(conf.loglevel_arg); } - loglevel = get_loglevel_by_name(conf.loglevel_arg); if (conf.socket_given) socket_name = para_strdup(conf.socket_arg); else {