Fix Lancer-patched libvorbis-aoTuV so it builds with GCC.
[vorbis-lancer-gcc.git] / vorbis-tools-1.2.0 / ogg123 / cmdline_options.c
bloba0d5df04d74c7b3348bd2528ecf042a1982a24d0
1 /********************************************************************
2 * *
3 * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
4 * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
5 * THE GNU PUBLIC LICENSE 2, WHICH IS INCLUDED WITH THIS SOURCE. *
6 * PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
7 * *
8 * THE Ogg123 SOURCE CODE IS (C) COPYRIGHT 2000-2001 *
9 * by Stan Seibert <volsung@xiph.org> AND OTHER CONTRIBUTORS *
10 * http://www.xiph.org/ *
11 * *
12 ********************************************************************
14 last mod: $Id: cmdline_options.c,v 1.15 2003/09/01 23:54:01 volsung Exp $
16 ********************************************************************/
18 #ifdef HAVE_CONFIG_H
19 #include <config.h>
20 #endif
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <ao/ao.h>
26 #include "getopt.h"
27 #include "cmdline_options.h"
28 #include "status.h"
29 #include "i18n.h"
31 #define MIN_INPUT_BUFFER_SIZE 8
33 extern double strtotime(char *s);
34 extern void set_seek_opt(ogg123_options_t *ogg123_opts, char *buf);
36 struct option long_options[] = {
37 /* GNU standard options */
38 {"help", no_argument, 0, 'h'},
39 {"version", no_argument, 0, 'V'},
40 /* ogg123-specific options */
41 {"buffer", required_argument, 0, 'b'},
42 {"config", optional_argument, 0, 'c'},
43 {"device", required_argument, 0, 'd'},
44 {"file", required_argument, 0, 'f'},
45 {"skip", required_argument, 0, 'k'},
46 {"end", required_argument, 0, 'K'},
47 {"delay", required_argument, 0, 'l'},
48 {"device-option", required_argument, 0, 'o'},
49 {"prebuffer", required_argument, 0, 'p'},
50 {"quiet", no_argument, 0, 'q'},
51 {"remote", no_argument, 0, 'R'},
52 {"verbose", no_argument, 0, 'v'},
53 {"nth", required_argument, 0, 'x'},
54 {"ntimes", required_argument, 0, 'y'},
55 {"shuffle", no_argument, 0, 'z'},
56 {"random", no_argument, 0, 'Z'},
57 {"list", required_argument, 0, '@'},
58 {"audio-buffer", required_argument, 0, 0},
59 {"repeat", no_argument, 0, 'r'},
60 {0, 0, 0, 0}
63 int parse_cmdline_options (int argc, char **argv,
64 ogg123_options_t *ogg123_opts,
65 file_option_t *file_opts)
67 int option_index = 1;
68 ao_option *temp_options = NULL;
69 ao_option ** current_options = &temp_options;
70 ao_info *info;
71 int temp_driver_id = -1;
72 audio_device_t *current;
73 int ret;
75 while (-1 != (ret = getopt_long(argc, argv, "b:c::d:f:hl:k:K:o:p:qrRvVx:y:zZ@:",
76 long_options, &option_index))) {
78 switch (ret) {
79 case 0:
80 if(!strcmp(long_options[option_index].name, "audio-buffer")) {
81 ogg123_opts->buffer_size = 1024 * atoi(optarg);
82 } else {
83 status_error(_("Internal error parsing command line options.\n"));
84 exit(1);
86 break;
87 case 'b':
88 ogg123_opts->input_buffer_size = atoi(optarg) * 1024;
89 if (ogg123_opts->input_buffer_size < MIN_INPUT_BUFFER_SIZE * 1024) {
90 status_error(_("Input buffer size smaller than minimum size of %dkB."),
91 MIN_INPUT_BUFFER_SIZE);
92 ogg123_opts->input_buffer_size = MIN_INPUT_BUFFER_SIZE * 1024;
94 break;
96 case 'c':
97 if (optarg) {
98 char *tmp = strdup (optarg);
99 parse_code_t pcode = parse_line(file_opts, tmp);
101 if (pcode != parse_ok)
102 status_error(_("=== Error \"%s\" while parsing config option from command line.\n"
103 "=== Option was: %s\n"),
104 parse_error_string(pcode), optarg);
105 free (tmp);
107 else {
108 /* not using the status interface here */
109 fprintf (stdout, _("Available options:\n"));
110 file_options_describe(file_opts, stdout);
111 exit (0);
113 break;
115 case 'd':
116 temp_driver_id = ao_driver_id(optarg);
117 if (temp_driver_id < 0) {
118 status_error(_("=== No such device %s.\n"), optarg);
119 exit(1);
122 current = append_audio_device(ogg123_opts->devices,
123 temp_driver_id,
124 NULL, NULL);
125 if(ogg123_opts->devices == NULL)
126 ogg123_opts->devices = current;
127 current_options = &current->options;
128 break;
130 case 'f':
131 if (temp_driver_id >= 0) {
133 info = ao_driver_info(temp_driver_id);
134 if (info->type == AO_TYPE_FILE) {
135 free(current->filename);
136 current->filename = strdup(optarg);
137 } else {
138 status_error(_("=== Driver %s is not a file output driver.\n"),
139 info->short_name);
140 exit(1);
142 } else {
143 status_error(_("=== Cannot specify output file without specifying a driver.\n"));
144 exit (1);
146 break;
148 case 'k':
149 set_seek_opt(ogg123_opts, optarg);
150 break;
152 case 'K':
153 ogg123_opts->endpos = strtotime(optarg);
154 break;
156 case 'l':
157 ogg123_opts->delay = atoi(optarg);
158 break;
160 case 'o':
161 if (optarg && !add_ao_option(current_options, optarg)) {
162 status_error(_("=== Incorrect option format: %s.\n"), optarg);
163 exit(1);
165 break;
167 case 'h':
168 cmdline_usage();
169 exit(0);
170 break;
172 case 'p':
173 ogg123_opts->input_prebuffer = atof (optarg);
174 if (ogg123_opts->input_prebuffer < 0.0f ||
175 ogg123_opts->input_prebuffer > 100.0f) {
177 status_error (_("--- Prebuffer value invalid. Range is 0-100.\n"));
178 ogg123_opts->input_prebuffer =
179 ogg123_opts->input_prebuffer < 0.0f ? 0.0f : 100.0f;
181 break;
183 case 'q':
184 ogg123_opts->verbosity = 0;
185 break;
187 case 'r':
188 ogg123_opts->repeat = 1;
189 break;
191 case 'R':
192 ogg123_opts->remote = 1;
193 ogg123_opts->verbosity = 0;
194 break;
196 case 'v':
197 ogg123_opts->verbosity++;
198 break;
200 case 'V':
201 status_error(_("ogg123 from %s %s"), PACKAGE, VERSION);
202 exit(0);
203 break;
205 case 'x':
206 ogg123_opts->nth = atoi(optarg);
207 if (ogg123_opts->nth == 0) {
208 status_error(_("--- Cannot play every 0th chunk!\n"));
209 ogg123_opts->nth = 1;
211 break;
213 case 'y':
214 ogg123_opts->ntimes = atoi(optarg);
215 if (ogg123_opts->ntimes == 0) {
216 status_error(_("--- Cannot play every chunk 0 times.\n"
217 "--- To do a test decode, use the null output driver.\n"));
218 ogg123_opts->ntimes = 1;
220 break;
222 case 'z':
223 ogg123_opts->shuffle = 1;
224 break;
226 case 'Z':
227 ogg123_opts->repeat = ogg123_opts->shuffle = 1;
228 break;
230 case '@':
231 if (playlist_append_from_file(ogg123_opts->playlist, optarg) == 0)
232 status_error(_("--- Cannot open playlist file %s. Skipped.\n"),
233 optarg);
234 break;
236 case '?':
237 break;
239 default:
240 cmdline_usage();
241 exit(1);
245 /* Sanity check bad option combinations */
246 if (ogg123_opts->endpos > 0.0 &&
247 ogg123_opts->seekoff > ogg123_opts->endpos) {
248 status_error(_("=== Option conflict: End time is before start time.\n"));
249 exit(1);
253 /* Add last device to device list or use the default device */
254 if (temp_driver_id < 0) {
256 /* First try config file setting */
257 if (ogg123_opts->default_device) {
258 temp_driver_id = ao_driver_id(ogg123_opts->default_device);
260 if (temp_driver_id < 0)
261 status_error(_("--- Driver %s specified in configuration file invalid.\n"),
262 ogg123_opts->default_device);
265 /* Then try libao autodetect */
266 if (temp_driver_id < 0)
267 temp_driver_id = ao_default_driver_id();
269 /* Finally, give up */
270 if (temp_driver_id < 0) {
271 status_error(_("=== Could not load default driver and no driver specified in config file. Exiting.\n"));
272 exit(1);
275 ogg123_opts->devices = append_audio_device(ogg123_opts->devices,
276 temp_driver_id,
277 temp_options,
278 NULL);
282 return optind;
285 #define LIST_SEP(x) ((x)==0?' ':',')
287 void cmdline_usage (void)
289 int i, j, driver_count;
290 ao_info **devices = ao_driver_info_list(&driver_count);
292 printf (_("ogg123 from %s %s\n"
293 " by the Xiph.Org Foundation (http://www.xiph.org/)\n\n"), PACKAGE, VERSION);
295 printf (_("Usage: ogg123 [options] file ...\n"
296 "Play Ogg audio files and network streams.\n\n"));
298 printf (_("Available codecs: "));
300 #ifdef HAVE_LIBFLAC
301 printf (_("FLAC, "));
302 #endif
304 #ifdef HAVE_LIBSPEEX
305 printf (_("Speex, "));
306 #endif
308 printf (_("Ogg Vorbis.\n\n"));
310 printf (_("Output options\n"));
311 printf (_(" -d dev, --device dev Use output device \"dev\". Available devices:\n"));
312 printf (" ");
313 printf (_("Live:"));
315 for(i = 0, j = 0; i < driver_count; i++) {
316 if (devices[i]->type == AO_TYPE_LIVE) {
317 printf ("%c %s", LIST_SEP(j), devices[i]->short_name);
318 j++;
321 printf ("\n ");
322 printf (_("File:"));
323 for(i = 0, j = 0; i < driver_count; i++) {
324 if (devices[i]->type == AO_TYPE_FILE) {
325 printf ("%c %s", LIST_SEP(j), devices[i]->short_name);
326 j++;
329 printf ("\n\n");
331 printf (_(" -f file, --file file Set the output filename for a file device\n"
332 " previously specified with --device.\n"));
333 printf ("\n");
334 printf (_(" --audio-buffer n Use an output audio buffer of 'n' kilobytes\n"));
335 printf (_(" -o k:v, --device-option k:v\n"
336 " Pass special option 'k' with value 'v' to the\n"
337 " device previously specified with --device. See\n"
338 " the ogg123 man page for available device options.\n"));
339 printf ("\n");
341 printf (_("Playlist options\n"));
342 printf (_(" -@ file, --list file Read playlist of files and URLs from \"file\"\n"));
343 printf (_(" -r, --repeat Repeat playlist indefinitely\n"));
344 printf (_(" -R, --remote Use remote control interface\n"));
345 printf (_(" -z, --shuffle Shuffle list of files before playing\n"));
346 printf (_(" -Z, --random Play files randomly until interrupted\n"));
347 printf ("\n");
349 printf (_("Input options\n"));
350 printf (_(" -b n, --buffer n Use an input buffer of 'n' kilobytes\n"));
351 printf (_(" -p n, --prebuffer n Load n%% of the input buffer before playing\n"));
352 printf ("\n");
354 printf (_("Decode options\n"));
355 printf (_(" -k n, --skip n Skip the first 'n' seconds (or hh:mm:ss format)\n"));
356 printf (_(" -K n, --end n End at 'n' seconds (or hh:mm:ss format)\n"));
357 printf (_(" -x n, --nth n Play every 'n'th block\n"));
358 printf (_(" -y n, --ntimes n Repeat every played block 'n' times\n"));
359 printf ("\n");
361 printf (_("Miscellaneous options\n"));
362 printf (_(" -l s, --delay s Set termination timeout in milliseconds. ogg123\n"
363 " will skip to the next song on SIGINT (Ctrl-C),\n"
364 " and will terminate if two SIGINTs are received\n"
365 " within the specified timeout 's'. (default 500)\n"));
366 printf ("\n");
367 printf (_(" -h, --help Display this help\n"));
368 printf (_(" -q, --quiet Don't display anything (no title)\n"));
369 printf (_(" -v, --verbose Display progress and other status information\n"));
370 printf (_(" -V, --version Display ogg123 version\n"));
371 printf ("\n");