X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=audioc.c;h=af67063367044b675877173a1ed351bdd28f2dd1;hp=1d69b2c15f7e6f3fb2683d107f04e738ecfc83cf;hb=HEAD;hpb=10a62b85c43319d9cdefd7d04823aaed47b3817e diff --git a/audioc.c b/audioc.c index 1d69b2c1..f2e4cb91 100644 --- a/audioc.c +++ b/audioc.c @@ -1,8 +1,4 @@ -/* - * Copyright (C) 2005 Andre Noll - * - * Licensed under the GPL v2. For licencing details see COPYING. - */ +/* Copyright (C) 2005 Andre Noll , see file COPYING. */ /** \file audioc.c The client program used to connect to para_audiod. */ @@ -21,6 +17,7 @@ #include "para.h" #include "error.h" +#include "lsu.h" #include "net.h" #include "string.h" #include "fd.h" @@ -99,9 +96,21 @@ I9E_DUMMY_COMPLETER(tasks); I9E_DUMMY_COMPLETER(term); static void help_completer(struct i9e_completion_info *ci, - struct i9e_completion_result *result) + struct i9e_completion_result *cr) { - result->matches = i9e_complete_commands(ci->word, audiod_completers); + char *opts[] = {LSG_AUDIOD_CMD_HELP_OPTS, NULL}; + + if (ci->word[0] == '-') { + i9e_complete_option(opts, ci, cr); + return; + } + cr->matches = i9e_complete_commands(ci->word, audiod_completers); +} + +static void ll_completer(struct i9e_completion_info *ci, + struct i9e_completion_result *cr) +{ + i9e_ll_completer(ci, cr); } static void version_completer(struct i9e_completion_info *ci, @@ -116,7 +125,7 @@ static void version_completer(struct i9e_completion_info *ci, static void stat_completer(struct i9e_completion_info *ci, struct i9e_completion_result *cr) { - char *sia[] = {STATUS_ITEM_ARRAY NULL}; + char *sia[] = {STATUS_ITEMS NULL}; char *opts[] = {LSG_AUDIOD_CMD_STAT_OPTS, NULL}; if (ci->word_num <= 2 && ci->word && ci->word[0] == '-') @@ -140,17 +149,17 @@ static struct i9e_completer audiod_completers[] = { {.name = NULL} }; -static void audioc_pre_select(struct sched *s, void *context) +static void audioc_pre_monitor(struct sched *s, void *context) { struct audioc_task *at = context; int ret = btr_node_status(at->btrn, 0, BTR_NT_ROOT); if (ret < 0) sched_min_delay(s); - para_fd_set(at->fd, &s->rfds, &s->max_fileno); + sched_monitor_readfd(at->fd, s); } -static int audioc_post_select(struct sched *s, void *context) +static int audioc_post_monitor(struct sched *s, void *context) { char *buf = NULL; struct audioc_task *at = context; @@ -159,14 +168,14 @@ static int audioc_post_select(struct sched *s, void *context) if (ret < 0) goto out; - if (!FD_ISSET(at->fd, &s->rfds)) + if (!sched_read_ok(at->fd, s)) return 0; bufsize = PARA_MAX(1024U, OPT_UINT32_VAL(BUFSIZE)); - buf = para_malloc(bufsize); + buf = alloc(bufsize); ret = recv_bin_buffer(at->fd, buf, bufsize); PARA_DEBUG_LOG("recv: %d\n", ret); if (ret == 0) - ret = -E_AUDIOC_EOF; + ret = -E_EOF; if (ret < 0) goto out; btr_add_output(buf, ret, at->btrn); @@ -208,8 +217,8 @@ static int audioc_i9e_line_handler(char *line) EMBRACE(.name = "audioc line handler")); at->task = task_register(&(struct task_info) { .name = "audioc", - .pre_select = audioc_pre_select, - .post_select = audioc_post_select, + .pre_monitor = audioc_pre_monitor, + .post_monitor = audioc_post_monitor, .context = at, }, &sched); i9e_attach_to_stdout(at->btrn); @@ -247,9 +256,9 @@ __noreturn static void interactive_session(void) sigemptyset(&act.sa_mask); act.sa_flags = 0; sigaction(SIGINT, &act, NULL); - sched.select_function = i9e_select; + sched.poll_function = i9e_poll; - sched.default_timeout.tv_sec = 1; + sched.default_timeout = 1000; ret = i9e_open(&ici, &sched); if (ret < 0) goto out; @@ -288,20 +297,6 @@ __noreturn static void print_completions(void) #endif /* HAVE_READLINE */ -static char *configfile_exists(void) -{ - char *config_file; - struct stat statbuf; - char *home = para_homedir(); - - config_file = make_message("%s/.paraslash/audioc.conf", home); - free(home); - if (!stat(config_file, &statbuf)) - return config_file; - free(config_file); - return NULL; -} - static void handle_help_flag(void) { char *help; @@ -335,54 +330,21 @@ static void handle_help_flag(void) */ int main(int argc, char *argv[]) { - const struct lls_command *cmd = CMD_PTR; int ret, fd; - char *cf = NULL, *buf, *args, *errctx = NULL; + char *buf, *args, *errctx = NULL; size_t bufsize; - struct lls_parse_result *lpr1, *lpr2, *lpr3; unsigned num_inputs; - ret = lls(lls_parse(argc, argv, cmd, &lpr1, &errctx)); + ret = lls(lls_parse(argc, argv, CMD_PTR, &lpr, &errctx)); if (ret < 0) goto fail; - lpr = lpr1; - loglevel = OPT_UINT32_VAL(LOGLEVEL); version_handle_flag("audioc", OPT_GIVEN(VERSION)); handle_help_flag(); - cf = configfile_exists(); - if (cf) { - void *map; - size_t sz; - int cf_argc; - char **cf_argv; - ret = mmap_full_file(cf, O_RDONLY, &map, &sz, NULL); - if (ret != -E_EMPTY) { - if (ret < 0) - goto out; - ret = lls(lls_convert_config(map, sz, NULL, &cf_argv, - &errctx)); - para_munmap(map, sz); - if (ret < 0) { - PARA_ERROR_LOG("syntax error in %s\n", cf); - goto out; - } - cf_argc = ret; - ret = lls(lls_parse(cf_argc, cf_argv, cmd, &lpr2, - &errctx)); - lls_free_argv(cf_argv); - if (ret < 0) { - PARA_ERROR_LOG("parse error in %s\n", cf); - goto out; - } - ret = lls(lls_merge(lpr1, lpr2, cmd, &lpr3, &errctx)); - lls_free_parse_result(lpr2, cmd); - if (ret < 0) - goto out; - lls_free_parse_result(lpr1, cmd); - lpr = lpr3; - loglevel = OPT_UINT32_VAL(LOGLEVEL); - } - } + ret = lsu_merge_config_file_options(NULL, "audioc.conf", + &lpr, CMD_PTR, audioc_suite, 0 /* default flags */); + if (ret < 0) + goto fail; + loglevel = OPT_UINT32_VAL(LOGLEVEL); if (OPT_GIVEN(COMPLETE)) print_completions(); if (OPT_GIVEN(SOCKET)) @@ -408,7 +370,7 @@ int main(int argc, char *argv[]) if (ret < 0) goto out; bufsize = PARA_MAX(1024U, OPT_UINT32_VAL(BUFSIZE)); - buf = para_malloc(bufsize); + buf = alloc(bufsize); do { size_t n = ret = recv_bin_buffer(fd, buf, bufsize); if (ret <= 0) @@ -417,8 +379,7 @@ int main(int argc, char *argv[]) } while (ret >= 0); free(buf); out: - lls_free_parse_result(lpr, cmd); - free(cf); + lls_free_parse_result(lpr, CMD_PTR); fail: if (errctx) PARA_ERROR_LOG("%s\n", errctx);