summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Labrecque <vincent@cvs.openbsd.org>2004-07-06 02:46:07 +0000
committerVincent Labrecque <vincent@cvs.openbsd.org>2004-07-06 02:46:07 +0000
commitbc4d619f49723064239cc713d932886e6b4fba75 (patch)
tree2f2aa9e1a3bc20a3d67e2b801e1f3dc18c9be678
parent18ed22eb2b008fe9e027301b4f34881167911f78 (diff)
make -w optional to set options, so audioctl is consistent with
"new" sysctl/mixerctl ok millert@, "go for it" deraadt@
-rw-r--r--usr.bin/audioctl/audioctl.19
-rw-r--r--usr.bin/audioctl/audioctl.c113
2 files changed, 60 insertions, 62 deletions
diff --git a/usr.bin/audioctl/audioctl.1 b/usr.bin/audioctl/audioctl.1
index b92ecab3fe0..e4628030758 100644
--- a/usr.bin/audioctl/audioctl.1
+++ b/usr.bin/audioctl/audioctl.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: audioctl.1,v 1.17 2004/05/09 03:37:45 beck Exp $
+.\" $OpenBSD: audioctl.1,v 1.18 2004/07/06 02:46:06 vincent Exp $
.\" $NetBSD: audioctl.1,v 1.7 1998/04/27 16:55:23 augustss Exp $
.\" Copyright (c) 1997 The NetBSD Foundation, Inc.
.\" All rights reserved.
@@ -52,7 +52,6 @@
.Nm audioctl
.Op Fl f Ar file
.Op Fl n
-.Fl w
.Ar name=value
.Op Ar ...
.Sh DESCRIPTION
@@ -72,7 +71,7 @@ The options are as follows:
.Bl -tag -width Ds
.It Fl a
Print all device variables and their current values.
-.It Fl w Ar name=value
+.It Ar name=value
Attempt to set the specified variable
.Ar name
to
@@ -95,7 +94,7 @@ default audio control device
.Sh EXAMPLES
To set the playing sampling rate to 11025 you can enter
.Pp
-.Dl $ audioctl -w play.sample_rate=11025
+.Dl $ audioctl play.sample_rate=11025
.Pp
Note that many of the variables that can be inspected and changed
are reset when the
@@ -106,7 +105,7 @@ This can be circumvented like so:
.Dl $ (cat file.au; audioctl -f /dev/audioctl -a) > /dev/audio
or
.Bd -literal -offset indent -compact
-$ (audioctl -f /dev/audioctl -w blocksize=1024; cat file.au) \e
+$ (audioctl -f /dev/audioctl blocksize=1024; cat file.au) \e
> /dev/audio
.Ed
.Sh SEE ALSO
diff --git a/usr.bin/audioctl/audioctl.c b/usr.bin/audioctl/audioctl.c
index 57e55a66114..fe6b0246b3d 100644
--- a/usr.bin/audioctl/audioctl.c
+++ b/usr.bin/audioctl/audioctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: audioctl.c,v 1.10 2003/06/21 01:39:07 deraadt Exp $ */
+/* $OpenBSD: audioctl.c,v 1.11 2004/07/06 02:46:06 vincent Exp $ */
/* $NetBSD: audioctl.c,v 1.14 1998/04/27 16:55:23 augustss Exp $ */
/*
@@ -324,7 +324,7 @@ usage(void)
fprintf(stderr,
"usage: %s [-f file] [-n] -a\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);
exit(1);
@@ -334,8 +334,9 @@ int
main(int argc, char **argv)
{
int fd, i, ch;
- int aflag = 0, wflag = 0;
+ int aflag = 0, canwrite, writeinfo = 0;
struct stat dstat, ostat;
+ struct field *p;
char *file;
char *sep = "=";
@@ -348,7 +349,7 @@ main(int argc, char **argv)
aflag++;
break;
case 'w':
- wflag++;
+ /* backward compatibility */
break;
case 'n':
sep = 0;
@@ -356,16 +357,19 @@ main(int argc, char **argv)
case 'f':
file = optarg;
break;
- case '?':
default:
usage();
}
}
argc -= optind;
argv += optind;
-
- if ((fd = open(file, wflag ? O_RDWR : O_RDONLY)) < 0)
- err(1, "%s", file);
+
+ if ((fd = open(file, O_RDWR)) < 0) {
+ if ((fd = open(file, O_RDONLY)) < 0)
+ err(1, "%s", file);
+ canwrite = 0;
+ } else
+ canwrite = 1;
/* Check if stdout is the same device as the audio device. */
if (fstat(fd, &dstat) < 0)
@@ -378,70 +382,65 @@ main(int argc, char **argv)
/* We can't write to stdout so use stderr */
out = stderr;
- if (!wflag)
- getinfo(fd);
+ if (!argc && !aflag)
+ usage();
+
+ getinfo(fd);
- if (!argc && aflag && !wflag) {
- for(i = 0; fields[i].name; i++) {
+ if (aflag) {
+ for (i = 0; fields[i].name; i++) {
if (!(fields[i].flags & ALIAS)) {
prfield(&fields[i], sep);
fprintf(out, "\n");
}
}
- } else if (argc > 0 && !aflag) {
- struct field *p;
- if (wflag) {
- AUDIO_INITINFO(&info);
- while(argc--) {
- char *q;
+ } else {
+ while (argc--) {
+ char *q;
- if ((q = strchr(*argv, '='))) {
- *q++ = 0;
- p = findfield(*argv);
- if (p == 0)
- warnx("field `%s' does not exist", *argv);
+ if ((q = strchr(*argv, '=')) != NULL) {
+ *q++ = 0;
+ p = findfield(*argv);
+ if (p == 0)
+ 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 {
- if (p->flags & READONLY)
- warnx("`%s' is read only", *argv);
- else {
- rdfield(p, q);
- if (p->valp == &fullduplex)
- if (ioctl(fd, AUDIO_SETFD, &fullduplex) < 0)
- err(1, "set failed");
- }
- }
- } else
- 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");
+ rdfield(p, q);
+ if (p->valp == &fullduplex)
+ if (ioctl(fd, AUDIO_SETFD,
+ &fullduplex) < 0)
+ err(1, "set failed");
}
+ writeinfo = 1;
}
- }
- } else {
- while(argc--) {
+ } else {
p = findfield(*argv);
- if (p == 0) {
- if (strchr(*argv, '='))
- warnx("field %s does not exist (use -w to set a variable)", *argv);
- else
- warnx("field %s does not exist", *argv);
- } else {
+ if (p == 0)
+ warnx("field %s does not exist", *argv);
+ else {
prfield(p, sep);
fprintf(out, "\n");
}
- argv++;
}
+ argv++;
}
- } else
- usage();
+ if (writeinfo && 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");
+ }
+ }
+ }
+ }
exit(0);
}