Debian Codegraph @

src/cmdline.c

raw symbols SCIP
1 /*
2 * Copyright (c) 2015, 2017 Moritz Grimm <[email protected]>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17 #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:412:9`!
18 # include "config.h"cxx . . $ `<file>/src/config.h`/
19 #endif /* HAVE_CONFIG_H */
20
21 #include "compat.h"cxx . . $ `<file>/compat/compat.h`/
22
23 #include <assert.h>
24 #include <stdio.h>
25 #ifdef HAVE_UNISTD_Hcxx . . $ `./config.h:68:9`!
26 # include <unistd.h>
27 #endif /* HAVE_UNISTD_H */
28
29 #include <string.h>
30
31 #include "cfg.h"cxx . . $ `<file>/src/cfg.h`/
32 #include "cmdline.h"cxx . . $ `<file>/src/cmdline.h`/
33 #include "playlist.h"cxx . . $ `<file>/src/playlist.h`/
34 #include "util.h"cxx . . $ `<file>/src/util.h`/
35
36 #define OPTSTRINGcxx . . $ `src/cmdline.c:36:9`! "c:hp:qrs:Vv"
37 enum opt_valscxx . . $ opt_vals# {
38 OPT_CONFIGFILEcxx . . $ OPT_CONFIGFILE. = 'c',
39 OPT_HELPcxx . . $ OPT_HELP. = 'h',
40 OPT_PIDFILEcxx . . $ OPT_PIDFILE. = 'p',
41 OPT_QUIETSTDERRcxx . . $ OPT_QUIETSTDERR. = 'q',
42 OPT_RTSTATUScxx . . $ OPT_RTSTATUS. = 'r',
43 OPT_SHUFFLEFILEcxx . . $ OPT_SHUFFLEFILE. = 's',
44 OPT_VERSIONcxx . . $ OPT_VERSION. = 'V',
45 OPT_VERBOSEcxx . . $ OPT_VERBOSE. = 'v',
46 OPT_INVALIDcxx . . $ OPT_INVALID. = '?'
47 };
48
49 static void _usagecxx . . $ _usage(49f6e7a06ebc5aa8).(void);
50 static void _usage_helpcxx . . $ _usage_help(49f6e7a06ebc5aa8).(void);
51
52 static void
53 _usagecxx . . $ _usage(49f6e7a06ebc5aa8).(void)
54 {
55 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "usage: %s [-hqrVv] -c cfgfile [-p pidfile]\n",
56 cfg_get_program_namecxx . . $ cfg_get_program_name(33a1f659e94feb42).());
57 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, " %s -s file\n",
58 cfg_get_program_namecxx . . $ cfg_get_program_name(33a1f659e94feb42).());
59 }
60
61 static void
62 _usage_helpcxx . . $ _usage_help(49f6e7a06ebc5aa8).(void)
63 {
64 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "\n");
65 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, " -c cfgfile use XML configuration in cfgfile\n");
66 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, " -h print this help and exit\n");
67 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, " -p pidfile write PID to pidfile\n");
68 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, " -q suppress STDERR output from external en-/decoders\n");
69 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, " -r show real-time stream information on stdout\n");
70 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, " -s file read lines from file, shuffle, print to STDOUT, then exit\n");
71 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, " -V print the version number and exit\n");
72 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, " -v increase logging verbosity\n");
73 }
74
75 int
76 cmdline_parsecxx . . $ cmdline_parse(e4d6922c49795a40).(int argc, char *argv[], int *ret_p)
77 {
78 const char *playlistFile = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
79 unsigned int verbosity = 0;
80 const char *err_str;
81
82 (void)cfg_set_program_namecxx . . $ cfg_set_program_name(2ef3bc9ee8f8b3e9).(util_get_prognamecxx . . $ util_get_progname(fb58d2e09a2a1ce6).(argv[0]), NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
83
84 optindcxx . . $ optind. = 1;
85 for (;;) {
86 int ch;
87
88 ch = getoptcxx . . $ getopt(2483c31ff9bab884).(argc, argv, OPTSTRINGcxx . . $ `src/cmdline.c:36:9`!);
89 if (0 > ch)
90 break;
91
92 switch (ch) {
93 case OPT_CONFIGFILEcxx . . $ OPT_CONFIGFILE.:
94 assertcxx . . $ `<external>/4398592474888995393/assert.h:156:12`!(0 == cfg_set_program_config_type(CFG_TYPE_XMLFILE,
95 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!));
96 if (0 > cfg_set_program_config_filecxx . . $ cfg_set_program_config_file(2ef3bc9ee8f8b3e9).(optargcxx . . $ optarg., &err_str)) {
97 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "-%c: argument %s\n",
98 OPT_CONFIGFILEcxx . . $ OPT_CONFIGFILE., err_str);
99 _usagecxx . . $ _usage(49f6e7a06ebc5aa8).();
100 *ret_p = 2;
101 return (-1);
102 }
103 break;
104 case OPT_HELPcxx . . $ OPT_HELP.:
105 _usagecxx . . $ _usage(49f6e7a06ebc5aa8).();
106 _usage_helpcxx . . $ _usage_help(49f6e7a06ebc5aa8).();
107 *ret_p = 0;
108 return (-1);
109 case OPT_PIDFILEcxx . . $ OPT_PIDFILE.:
110 if (0 > cfg_set_program_pid_filecxx . . $ cfg_set_program_pid_file(2ef3bc9ee8f8b3e9).(optargcxx . . $ optarg., &err_str)) {
111 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "-%c: argument %s\n",
112 OPT_PIDFILEcxx . . $ OPT_PIDFILE., err_str);
113 _usagecxx . . $ _usage(49f6e7a06ebc5aa8).();
114 *ret_p = 2;
115 return (-1);
116 }
117 break;
118 case OPT_RTSTATUScxx . . $ OPT_RTSTATUS.:
119 cfg_set_program_rtstatus_outputcxx . . $ cfg_set_program_rtstatus_output(d8e43b79a186046c).(1, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
120 /* FALLTHROUGH */
121 case OPT_QUIETSTDERRcxx . . $ OPT_QUIETSTDERR.:
122 cfg_set_program_quiet_stderrcxx . . $ cfg_set_program_quiet_stderr(d8e43b79a186046c).(1, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
123 break;
124 case OPT_SHUFFLEFILEcxx . . $ OPT_SHUFFLEFILE.:
125 playlistFile = optargcxx . . $ optarg.;
126 break;
127 case OPT_VERSIONcxx . . $ OPT_VERSION.:
128 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:158:9`!, "%s version %s\n",
129 PACKAGE_NAMEcxx . . $ `./config.h:86:9`!, PACKAGE_VERSIONcxx . . $ `./config.h:98:9`!);
130 *ret_p = 0;
131 return (-1);
132 case OPT_VERBOSEcxx . . $ OPT_VERBOSE.:
133 verbosity++;
134 break;
135 case OPT_INVALIDcxx . . $ OPT_INVALID.:
136 default:
137 _usagecxx . . $ _usage(49f6e7a06ebc5aa8).();
138 *ret_p = 2;
139 return (-1);
140 }
141 }
142 argc -= optindcxx . . $ optind.;
143 argv += optindcxx . . $ optind.;
144
145 cfg_set_program_verbositycxx . . $ cfg_set_program_verbosity(c6b276b6d3495d5b).(verbosity, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
146
147 if (playlistFile) {
148 playlist_tcxx . . $ playlist_t# pl;
149
150 if (0 > playlist_initcxx . . $ playlist_init(b126dc7c1de90089).()) {
151 *ret_p = 1;
152 return (-1);
153 }
154 if (0 == strcmpcxx . . $ strcmp(5ae29d726ae57f88).(playlistFile, "-")) {
155 pl = playlist_readcxx . . $ playlist_read(ea32118fbd7a0ccc).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
156 } else {
157 pl = playlist_readcxx . . $ playlist_read(ea32118fbd7a0ccc).(playlistFile);
158 }
159 if (pl == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
160 *ret_p = 1;
161 } else {
162 const char *entry;
163
164 playlist_shufflecxx . . $ playlist_shuffle(fbb1db036548eb22).(pl);
165 while (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! != (entry = playlist_get_nextcxx . . $ playlist_get_next(4a6773dfaf0af90e).(pl)))
166 printfcxx . . $ printf(581fddd72a8db8fc).("%s\n", entry);
167 playlist_freecxx . . $ playlist_free(d6737836562b4329).(&pl);
168 *ret_p = 0;
169 }
170 playlist_exitcxx . . $ playlist_exit(49f6e7a06ebc5aa8).();
171 return (-1);
172 }
173
174 if (!cfg_get_program_config_filecxx . . $ cfg_get_program_config_file(33a1f659e94feb42).()) {
175 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "either -%c or -%c must be provided\n",
176 OPT_CONFIGFILEcxx . . $ OPT_CONFIGFILE., OPT_SHUFFLEFILEcxx . . $ OPT_SHUFFLEFILE.);
177 _usagecxx . . $ _usage(49f6e7a06ebc5aa8).();
178 *ret_p = 2;
179 return (-1);
180 }
181
182 return (0);
183 }