]> code.delx.au - pulseaudio/blob - src/cmdline.c
rename configuration file
[pulseaudio] / src / cmdline.c
1 /* $Id$ */
2
3 /***
4 This file is part of polypaudio.
5
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.
10
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.
15
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
19 USA.
20 ***/
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <string.h>
27 #include <assert.h>
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <getopt.h>
31
32 #include "cmdline.h"
33 #include "util.h"
34 #include "strbuf.h"
35
36 void pa_cmdline_help(const char *argv0) {
37 const char *e;
38
39 if ((e = strrchr(argv0, '/')))
40 e++;
41 else
42 e = argv0;
43
44 printf("%s [options]\n"
45 " -L MODULE Load the specified plugin module with the specified argument\n"
46 " -F FILE Run the specified script\n"
47 " -C Open a command line on the running TTY\n"
48 " -D Daemonize after loading the modules\n"
49 " -f Dont quit when the startup fails\n"
50 " -v Verbose startup\n"
51 " -h Show this help\n", e);
52 }
53
54 struct pa_cmdline* pa_cmdline_parse(int argc, char * const argv []) {
55 char c;
56 struct pa_cmdline *cmdline = NULL;
57 struct pa_strbuf *buf = NULL;
58 assert(argc && argv);
59
60 cmdline = malloc(sizeof(struct pa_cmdline));
61 assert(cmdline);
62 cmdline->daemonize = cmdline->help = cmdline->verbose = 0;
63 cmdline->fail = 1;
64
65 buf = pa_strbuf_new();
66 assert(buf);
67
68 while ((c = getopt(argc, argv, "L:F:CDhfv")) != -1) {
69 switch (c) {
70 case 'L':
71 pa_strbuf_printf(buf, "load %s\n", optarg);
72 break;
73 case 'F':
74 pa_strbuf_printf(buf, ".include %s\n", optarg);
75 break;
76 case 'C':
77 pa_strbuf_puts(buf, "load module-cli\n");
78 break;
79 case 'D':
80 cmdline->daemonize = 1;
81 break;
82 case 'h':
83 cmdline->help = 1;
84 break;
85 case 'f':
86 cmdline->fail = 0;
87 break;
88 case 'v':
89 cmdline->verbose = 0;
90 break;
91 default:
92 goto fail;
93 }
94 }
95
96 cmdline->cli_commands = pa_strbuf_tostring_free(buf);
97 return cmdline;
98
99 fail:
100 if (cmdline)
101 pa_cmdline_free(cmdline);
102 if (buf)
103 pa_strbuf_free(buf);
104 return NULL;
105 }
106
107 void pa_cmdline_free(struct pa_cmdline *cmd) {
108 assert(cmd);
109 free(cmd->cli_commands);
110 free(cmd);
111 }