4 This file is part of polypaudio.
6 polypaudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published
8 by the Free Software Foundation; either version 2 of the License,
9 or (at your option) any later version.
11 polypaudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with polypaudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
38 #define ENV_CONFIG_FILE "POLYP_CONFIG"
40 char* config_file(void) {
43 if ((p
= getenv(ENV_CONFIG_FILE
)))
46 if ((h
= getenv("HOME"))) {
48 p
= pa_sprintf_malloc("%s/.polypaudio", h
);
49 if (stat(p
, &st
) >= 0)
55 return pa_xstrdup(DEFAULT_CONFIG_FILE
);
58 void pa_cmdline_help(const char *argv0
) {
60 char *cfg
= config_file();
62 if ((e
= strrchr(argv0
, '/')))
67 printf("%s [options]\n"
68 " -r Try to set high process priority (only available as root)\n"
69 " -R Don't drop root if SETUID root\n"
70 " -L MODULE Load the specified plugin module with the specified argument\n"
71 " -F FILE Run the specified script\n"
72 " -C Open a command line on the running TTY\n"
73 " -n Don't load configuration file (%s)\n"
74 " -D Daemonize after loading the modules\n"
75 " -d Disallow module loading after startup\n"
76 " -f Dont quit when the startup fails\n"
77 " -v Verbose startup\n"
78 " -X SECS Terminate the daemon after the last client quit and this time passed\n"
79 " -h Show this help\n"
80 " -l TARGET Specify the log target (syslog, stderr, auto)\n"
81 " -V Show version\n", e
, cfg
);
86 struct pa_cmdline
* pa_cmdline_parse(int argc
, char * const argv
[]) {
88 struct pa_cmdline
*cmdline
= NULL
;
89 struct pa_strbuf
*buf
= NULL
;
90 int no_default_config_file
= 0;
93 cmdline
= pa_xmalloc(sizeof(struct pa_cmdline
));
97 cmdline
->high_priority
=
100 cmdline
->disallow_module_loading
= 0;
101 cmdline
->fail
= cmdline
->auto_log_target
= 1;
102 cmdline
->quit_after_last_client_time
= -1;
103 cmdline
->log_target
= -1;
105 buf
= pa_strbuf_new();
108 while ((c
= getopt(argc
, argv
, "L:F:CDhfvrRVndX:l:")) != -1) {
111 pa_strbuf_printf(buf
, "load %s\n", optarg
);
114 pa_strbuf_printf(buf
, ".include %s\n", optarg
);
117 pa_strbuf_puts(buf
, "load module-cli\n");
120 cmdline
->daemonize
= 1;
129 cmdline
->verbose
= 1;
132 cmdline
->high_priority
= 1;
135 cmdline
->stay_root
= 1;
138 cmdline
->version
= 1;
141 no_default_config_file
= 1;
144 cmdline
->disallow_module_loading
= 1;
147 cmdline
->quit_after_last_client_time
= atoi(optarg
);
150 if (!strcmp(optarg
, "syslog")) {
151 cmdline
->auto_log_target
= 0;
152 cmdline
->log_target
= PA_LOG_SYSLOG
;
153 } else if (!strcmp(optarg
, "stderr")) {
154 cmdline
->auto_log_target
= 0;
155 cmdline
->log_target
= PA_LOG_STDERR
;
156 } else if (!strcmp(optarg
, "auto"))
157 cmdline
->auto_log_target
= 1;
159 pa_log(__FILE__
": Invalid log target: use either 'syslog', 'stderr' or 'auto'.\n");
168 if (!no_default_config_file
) {
170 pa_strbuf_printf(buf
, ".include %s\n", cfg
);
174 cmdline
->cli_commands
= pa_strbuf_tostring_free(buf
);
179 pa_cmdline_free(cmdline
);
185 void pa_cmdline_free(struct pa_cmdline
*cmd
) {
187 pa_xfree(cmd
->cli_commands
);