mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-03 09:01:50 -05:00
add preliminary command line parsing
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@64 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
parent
d4e0d51c15
commit
b69178b067
4 changed files with 138 additions and 1 deletions
|
|
@ -84,7 +84,8 @@ polypaudio_SOURCES = idxset.c idxset.h \
|
||||||
sconv-s16le.c sconv-s16le.h \
|
sconv-s16le.c sconv-s16le.h \
|
||||||
sconv-s16be.c sconv-s16be.h \
|
sconv-s16be.c sconv-s16be.h \
|
||||||
sioman.c sioman.h \
|
sioman.c sioman.h \
|
||||||
modargs.c modargs.h
|
modargs.c modargs.h \
|
||||||
|
cmdline.c cmdline.h
|
||||||
|
|
||||||
polypaudio_CFLAGS = $(AM_CFLAGS) $(LIBSAMPLERATE_CFLAGS)
|
polypaudio_CFLAGS = $(AM_CFLAGS) $(LIBSAMPLERATE_CFLAGS)
|
||||||
polypaudio_INCLUDES = $(INCLTDL)
|
polypaudio_INCLUDES = $(INCLTDL)
|
||||||
|
|
|
||||||
102
src/cmdline.c
Normal file
102
src/cmdline.c
Normal file
|
|
@ -0,0 +1,102 @@
|
||||||
|
#include <string.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <getopt.h>
|
||||||
|
|
||||||
|
#include "cmdline.h"
|
||||||
|
#include "util.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 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"
|
||||||
|
" -D Daemonize after loading the modules\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;
|
||||||
|
assert(argc && argv);
|
||||||
|
|
||||||
|
cmdline = malloc(sizeof(struct pa_cmdline));
|
||||||
|
assert(cmdline);
|
||||||
|
cmdline->daemonize = cmdline->help = 0;
|
||||||
|
cmdline->first_module = cmdline->last_module = NULL;
|
||||||
|
|
||||||
|
while ((c = getopt(argc, argv, "L:F:CDh")) != -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);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'F':
|
||||||
|
add_module(cmdline, strdup("module-cli"), pa_sprintf_malloc("file='%s'", optarg));
|
||||||
|
break;
|
||||||
|
case 'C':
|
||||||
|
add_module(cmdline, strdup("module-cli"), NULL);
|
||||||
|
break;
|
||||||
|
case 'D':
|
||||||
|
cmdline->daemonize = 1;
|
||||||
|
break;
|
||||||
|
case 'h':
|
||||||
|
cmdline->help = 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return cmdline;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
if (cmdline)
|
||||||
|
pa_cmdline_free(cmdline);
|
||||||
|
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);
|
||||||
|
}
|
||||||
19
src/cmdline.h
Normal file
19
src/cmdline.h
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
#ifndef foocmdlinehfoo
|
||||||
|
#define foocmdlinehfoo
|
||||||
|
|
||||||
|
struct pa_cmdline_module {
|
||||||
|
char *name, *arguments;
|
||||||
|
struct pa_cmdline_module *next;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct pa_cmdline {
|
||||||
|
int daemonize, help;
|
||||||
|
struct pa_cmdline_module *first_module, *last_module;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct pa_cmdline* pa_cmdline_parse(int argc, char * const argv []);
|
||||||
|
void pa_cmdline_free(struct pa_cmdline *cmd);
|
||||||
|
|
||||||
|
void pa_cmdline_help(const char *argv0);
|
||||||
|
|
||||||
|
#endif
|
||||||
15
src/main.c
15
src/main.c
|
|
@ -9,6 +9,7 @@
|
||||||
#include "mainloop.h"
|
#include "mainloop.h"
|
||||||
#include "module.h"
|
#include "module.h"
|
||||||
#include "mainloop-signal.h"
|
#include "mainloop-signal.h"
|
||||||
|
#include "cmdline.h"
|
||||||
|
|
||||||
static struct pa_mainloop *mainloop;
|
static struct pa_mainloop *mainloop;
|
||||||
|
|
||||||
|
|
@ -26,8 +27,20 @@ static void aux_signal_callback(void *id, int sig, void *userdata) {
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
struct pa_core *c;
|
struct pa_core *c;
|
||||||
|
struct pa_cmdline *cmdline = NULL;
|
||||||
int r, retval = 0;
|
int r, retval = 0;
|
||||||
|
|
||||||
|
if (!(cmdline = pa_cmdline_parse(argc, argv))) {
|
||||||
|
fprintf(stderr, "Failed to parse command line.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cmdline->help) {
|
||||||
|
pa_cmdline_help(argv[0]);
|
||||||
|
pa_cmdline_free(cmdline);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
r = lt_dlinit();
|
r = lt_dlinit();
|
||||||
assert(r == 0);
|
assert(r == 0);
|
||||||
|
|
||||||
|
|
@ -67,6 +80,8 @@ int main(int argc, char *argv[]) {
|
||||||
pa_signal_done();
|
pa_signal_done();
|
||||||
pa_mainloop_free(mainloop);
|
pa_mainloop_free(mainloop);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
lt_dlexit();
|
lt_dlexit();
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue