ao, shairport: fix option parsing

- don't push unrecognised args to the audio driver
- get ao to parse from first argument
- ao checks for unrecognised options
This commit is contained in:
James Laird
2013-06-19 13:56:11 +10:00
parent 7f7dd51761
commit 706e4d6518
2 changed files with 9 additions and 1 deletions
+6 -1
View File
@@ -47,7 +47,9 @@ static int init(int argc, char **argv) {
int driver = ao_default_driver_id();
ao_option *ao_opts = NULL;
optind = 0;
optind = 1; // optind=0 is equivalent to optind=1 plus special behaviour
argv--; // so we shift the arguments to satisfy getopt()
argc++;
// some platforms apparently require optreset = 1; - which?
int opt;
char *mid;
@@ -80,6 +82,9 @@ static int init(int argc, char **argv) {
}
}
if (optind < argc)
die("Invalid audio argument: %s", argv[optind]);
ao_sample_format fmt;
memset(&fmt, 0, sizeof(fmt));
+3
View File
@@ -88,6 +88,9 @@ void usage(char *progname) {
}
int parse_options(int argc, char **argv) {
// prevent unrecognised arguments from being shunted to the audio driver
setenv("POSIXLY_CORRECT", "", 1);
int opt;
while ((opt = getopt(argc, argv, "+hdvp:a:o:b:B:E:")) > 0) {
switch (opt) {