mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-02 09:01:46 -05:00
complete implementation of the command line
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@65 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
parent
b69178b067
commit
e61e9244aa
12 changed files with 663 additions and 509 deletions
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include "cmdline.h"
|
||||
#include "util.h"
|
||||
#include "strbuf.h"
|
||||
|
||||
void pa_cmdline_help(const char *argv0) {
|
||||
const char *e;
|
||||
|
|
@ -17,56 +18,38 @@ void pa_cmdline_help(const char *argv0) {
|
|||
|
||||
printf("%s [options]\n"
|
||||
" -L MODULE Load the specified plugin module with the specified argument\n"
|
||||
" -F FILE A shortcut for '-L module-cli file=FILE', i.e. run the specified script after startup\n"
|
||||
" -C A shortcut for '-L module-cli', i.e. open a command line on the running TTY\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);
|
||||
}
|
||||
|
||||
static void add_module(struct pa_cmdline *cmdline, char *name, char *arguments) {
|
||||
struct pa_cmdline_module *m;
|
||||
assert(cmdline && name);
|
||||
|
||||
m = malloc(sizeof(struct pa_cmdline_module));
|
||||
assert(m);
|
||||
m->name = name;
|
||||
m->arguments = name;
|
||||
m->next = NULL;
|
||||
|
||||
if (cmdline->last_module)
|
||||
cmdline->last_module->next = m;
|
||||
else {
|
||||
assert(!cmdline->first_module);
|
||||
cmdline->first_module = m;
|
||||
}
|
||||
cmdline->last_module = m;
|
||||
}
|
||||
|
||||
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 = 0;
|
||||
cmdline->first_module = cmdline->last_module = NULL;
|
||||
cmdline->daemonize = cmdline->help = cmdline->verbose = 0;
|
||||
cmdline->fail = 1;
|
||||
|
||||
buf = pa_strbuf_new();
|
||||
assert(buf);
|
||||
|
||||
while ((c = getopt(argc, argv, "L:F:CDh")) != -1) {
|
||||
while ((c = getopt(argc, argv, "L:F:CDhfv")) != -1) {
|
||||
switch (c) {
|
||||
case 'L': {
|
||||
char *space;
|
||||
if ((space = strchr(optarg, ' ')))
|
||||
add_module(cmdline, strndup(optarg, space-optarg), space+1);
|
||||
else
|
||||
add_module(cmdline, strdup(optarg), NULL);
|
||||
case 'L':
|
||||
pa_strbuf_printf(buf, "load %s\n", optarg);
|
||||
break;
|
||||
}
|
||||
case 'F':
|
||||
add_module(cmdline, strdup("module-cli"), pa_sprintf_malloc("file='%s'", optarg));
|
||||
pa_strbuf_printf(buf, ".include %s\n", optarg);
|
||||
break;
|
||||
case 'C':
|
||||
add_module(cmdline, strdup("module-cli"), NULL);
|
||||
pa_strbuf_puts(buf, "load module-cli\n");
|
||||
break;
|
||||
case 'D':
|
||||
cmdline->daemonize = 1;
|
||||
|
|
@ -74,29 +57,30 @@ struct pa_cmdline* pa_cmdline_parse(int argc, char * const argv []) {
|
|||
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) {
|
||||
struct pa_cmdline_module *m;
|
||||
assert(cmd);
|
||||
|
||||
while ((m = cmd->first_module)) {
|
||||
cmd->first_module = m->next;
|
||||
free(m->name);
|
||||
free(m->arguments);
|
||||
free(m);
|
||||
}
|
||||
|
||||
free(cmd->cli_commands);
|
||||
free(cmd);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue