version 1.10, 2003/06/21 01:39:07 |
version 1.11, 2004/07/06 02:46:06 |
|
|
fprintf(stderr, |
fprintf(stderr, |
"usage: %s [-f file] [-n] -a\n" |
"usage: %s [-f file] [-n] -a\n" |
" %s [-f file] [-n] name [...]\n" |
" %s [-f file] [-n] name [...]\n" |
" %s [-f file] [-n] -w name=value [...]\n", __progname, |
" %s [-f file] [-n] name=value [...]\n", __progname, |
__progname, __progname); |
__progname, __progname); |
|
|
exit(1); |
exit(1); |
|
|
main(int argc, char **argv) |
main(int argc, char **argv) |
{ |
{ |
int fd, i, ch; |
int fd, i, ch; |
int aflag = 0, wflag = 0; |
int aflag = 0, canwrite, writeinfo = 0; |
struct stat dstat, ostat; |
struct stat dstat, ostat; |
|
struct field *p; |
char *file; |
char *file; |
char *sep = "="; |
char *sep = "="; |
|
|
|
|
aflag++; |
aflag++; |
break; |
break; |
case 'w': |
case 'w': |
wflag++; |
/* backward compatibility */ |
break; |
break; |
case 'n': |
case 'n': |
sep = 0; |
sep = 0; |
|
|
case 'f': |
case 'f': |
file = optarg; |
file = optarg; |
break; |
break; |
case '?': |
|
default: |
default: |
usage(); |
usage(); |
} |
} |
} |
} |
argc -= optind; |
argc -= optind; |
argv += optind; |
argv += optind; |
|
|
|
if ((fd = open(file, O_RDWR)) < 0) { |
|
if ((fd = open(file, O_RDONLY)) < 0) |
|
err(1, "%s", file); |
|
canwrite = 0; |
|
} else |
|
canwrite = 1; |
|
|
if ((fd = open(file, wflag ? O_RDWR : O_RDONLY)) < 0) |
|
err(1, "%s", file); |
|
|
|
/* Check if stdout is the same device as the audio device. */ |
/* Check if stdout is the same device as the audio device. */ |
if (fstat(fd, &dstat) < 0) |
if (fstat(fd, &dstat) < 0) |
err(1, "fstat au"); |
err(1, "fstat au"); |
|
|
/* We can't write to stdout so use stderr */ |
/* We can't write to stdout so use stderr */ |
out = stderr; |
out = stderr; |
|
|
if (!wflag) |
if (!argc && !aflag) |
getinfo(fd); |
usage(); |
|
|
if (!argc && aflag && !wflag) { |
getinfo(fd); |
for(i = 0; fields[i].name; i++) { |
|
|
if (aflag) { |
|
for (i = 0; fields[i].name; i++) { |
if (!(fields[i].flags & ALIAS)) { |
if (!(fields[i].flags & ALIAS)) { |
prfield(&fields[i], sep); |
prfield(&fields[i], sep); |
fprintf(out, "\n"); |
fprintf(out, "\n"); |
} |
} |
} |
} |
} else if (argc > 0 && !aflag) { |
} else { |
struct field *p; |
while (argc--) { |
if (wflag) { |
char *q; |
AUDIO_INITINFO(&info); |
|
while(argc--) { |
|
char *q; |
|
|
|
if ((q = strchr(*argv, '='))) { |
if ((q = strchr(*argv, '=')) != NULL) { |
*q++ = 0; |
*q++ = 0; |
p = findfield(*argv); |
p = findfield(*argv); |
if (p == 0) |
if (p == 0) |
warnx("field `%s' does not exist", *argv); |
warnx("field `%s' does not exist", *argv); |
|
else { |
|
if (!canwrite) |
|
errx(1, "%s: permission denied", |
|
*argv); |
|
if (p->flags & READONLY) |
|
warnx("`%s' is read only", *argv); |
else { |
else { |
if (p->flags & READONLY) |
rdfield(p, q); |
warnx("`%s' is read only", *argv); |
if (p->valp == &fullduplex) |
else { |
if (ioctl(fd, AUDIO_SETFD, |
rdfield(p, q); |
&fullduplex) < 0) |
if (p->valp == &fullduplex) |
err(1, "set failed"); |
if (ioctl(fd, AUDIO_SETFD, &fullduplex) < 0) |
|
err(1, "set failed"); |
|
} |
|
} |
} |
} else |
writeinfo = 1; |
warnx("No `=' in %s", *argv); |
|
argv++; |
|
} |
|
if (ioctl(fd, AUDIO_SETINFO, &info) < 0) |
|
err(1, "set failed"); |
|
if (sep) { |
|
getinfo(fd); |
|
for(i = 0; fields[i].name; i++) { |
|
if (fields[i].flags & SET) { |
|
fprintf(out, "%s: -> ", fields[i].name); |
|
prfield(&fields[i], 0); |
|
fprintf(out, "\n"); |
|
} |
|
} |
} |
} |
} else { |
} else { |
|
while(argc--) { |
|
p = findfield(*argv); |
p = findfield(*argv); |
if (p == 0) { |
if (p == 0) |
if (strchr(*argv, '=')) |
warnx("field %s does not exist", *argv); |
warnx("field %s does not exist (use -w to set a variable)", *argv); |
else { |
else |
|
warnx("field %s does not exist", *argv); |
|
} else { |
|
prfield(p, sep); |
prfield(p, sep); |
fprintf(out, "\n"); |
fprintf(out, "\n"); |
} |
} |
argv++; |
|
} |
} |
|
argv++; |
} |
} |
} else |
if (writeinfo && ioctl(fd, AUDIO_SETINFO, &info) < 0) |
usage(); |
err(1, "set failed"); |
|
if (sep) { |
|
getinfo(fd); |
|
for (i = 0; fields[i].name; i++) { |
|
if (fields[i].flags & SET) { |
|
fprintf(out, "%s: -> ", fields[i].name); |
|
prfield(&fields[i], 0); |
|
fprintf(out, "\n"); |
|
} |
|
} |
|
} |
|
} |
exit(0); |
exit(0); |
} |
} |