diff options
author | Lennart Poettering <lennart@poettering.net> | 2004-07-17 14:12:30 +0000 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2004-07-17 14:12:30 +0000 |
commit | 41f6aea8fdbc744c13bc461056a2d694a5c4d06f (patch) | |
tree | 1e23911c1f61c66df3fba272af53475508a7a7ce /polyp/cmdline.c | |
parent | 563201e128d600ec1ae4a33ca81d03b776501f82 (diff) |
rename src to polyp
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@90 fefdeb5f-60dc-0310-8127-8f9354f1896f
Diffstat (limited to 'polyp/cmdline.c')
-rw-r--r-- | polyp/cmdline.c | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/polyp/cmdline.c b/polyp/cmdline.c new file mode 100644 index 00000000..a3330145 --- /dev/null +++ b/polyp/cmdline.c @@ -0,0 +1,111 @@ +/* $Id$ */ + +/*** + This file is part of polypaudio. + + polypaudio is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 2 of the License, + or (at your option) any later version. + + polypaudio is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with polypaudio; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA. +***/ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <string.h> +#include <assert.h> +#include <stdlib.h> +#include <stdio.h> +#include <getopt.h> + +#include "cmdline.h" +#include "util.h" +#include "strbuf.h" + +void pa_cmdline_help(const char *argv0) { + const char *e; + + if ((e = strrchr(argv0, '/'))) + e++; + else + e = argv0; + + printf("%s [options]\n" + " -L MODULE Load the specified plugin module with the specified argument\n" + " -F FILE Run the specified script\n" + " -C Open a command line on the running TTY\n" + " -D Daemonize after loading the modules\n" + " -f Dont quit when the startup fails\n" + " -v Verbose startup\n" + " -h Show this help\n", e); +} + +struct pa_cmdline* pa_cmdline_parse(int argc, char * const argv []) { + char c; + struct pa_cmdline *cmdline = NULL; + struct pa_strbuf *buf = NULL; + assert(argc && argv); + + cmdline = malloc(sizeof(struct pa_cmdline)); + assert(cmdline); + cmdline->daemonize = cmdline->help = cmdline->verbose = 0; + cmdline->fail = 1; + + buf = pa_strbuf_new(); + assert(buf); + + while ((c = getopt(argc, argv, "L:F:CDhfv")) != -1) { + switch (c) { + case 'L': + pa_strbuf_printf(buf, "load %s\n", optarg); + break; + case 'F': + pa_strbuf_printf(buf, ".include %s\n", optarg); + break; + case 'C': + pa_strbuf_puts(buf, "load module-cli\n"); + break; + case 'D': + cmdline->daemonize = 1; + break; + case 'h': + cmdline->help = 1; + break; + case 'f': + cmdline->fail = 0; + break; + case 'v': + cmdline->verbose = 0; + break; + default: + goto fail; + } + } + + cmdline->cli_commands = pa_strbuf_tostring_free(buf); + return cmdline; + +fail: + if (cmdline) + pa_cmdline_free(cmdline); + if (buf) + pa_strbuf_free(buf); + return NULL; +} + +void pa_cmdline_free(struct pa_cmdline *cmd) { + assert(cmd); + free(cmd->cli_commands); + free(cmd); +} |