summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2000-07-01 19:54:37 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2000-07-01 19:54:37 +0000
commit98c6903a9c867b13b04b71235196f2fe74bc1742 (patch)
treec85425169df6d065f10c6c845f4374599b86d79f /usr.bin
parent052d1c1f129072f1d430eced26a46a905459a057 (diff)
Add -f option to specify audio device, honor AUDIODEVICE environment vairable,
and some KNF.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/aucat/aucat.127
-rw-r--r--usr.bin/aucat/aucat.c108
2 files changed, 87 insertions, 48 deletions
diff --git a/usr.bin/aucat/aucat.1 b/usr.bin/aucat/aucat.1
index 977f157e110..1c690afabfc 100644
--- a/usr.bin/aucat/aucat.1
+++ b/usr.bin/aucat/aucat.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: aucat.1,v 1.8 2000/03/23 21:10:13 aaron Exp $
+.\" $OpenBSD: aucat.1,v 1.9 2000/07/01 19:54:36 millert Exp $
.\"
.\" Copyright (c) 1997 Kenneth Stailey. All rights reserved.
.\"
@@ -42,12 +42,17 @@
.Nd concatenate and play audio files
.Sh SYNOPSIS
.Nm aucat
-.Op Ar
+.Op Fl f Ar device
+.Ar file ...
.Sh DESCRIPTION
The
.Nm
-utility reads files sequentially, writing them to
-.Pa /dev/audio .
+utility reads files sequentially, writing them to the specified device.
+By default,
+.Nm
+plays audio through the
+.Pa /dev/audio
+device.
The
.Ar file
operands are processed in command line order.
@@ -58,10 +63,24 @@ Otherwise, the
entire file is copied to
.Pa /dev/audio .
.Pp
+The options are as follows:
+.Bl -tag -width "-f device"
+.It Fl f Ar device
+Specifies an alternate audio device.
+.El
+.Pp
The
.Nm
utility exits 0 on success or >0 if an error occurred.
+.Sh ENVIRONMENT
+The following environment variables affect the execution of
+.Nm aucat :
+.Bl -tag -width AUDIODEVICE
+.It Ev AUDIODEVICE
+The audio device to use.
+.El
.Sh SEE ALSO
+.Xr mixerctl 1 ,
.Xr audio 4
.Sh HISTORY
An
diff --git a/usr.bin/aucat/aucat.c b/usr.bin/aucat/aucat.c
index 6730c5ffc1b..7ba67214b8e 100644
--- a/usr.bin/aucat/aucat.c
+++ b/usr.bin/aucat/aucat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: aucat.c,v 1.3 1997/01/05 19:00:51 kstailey Exp $ */
+/* $OpenBSD: aucat.c,v 1.4 2000/07/01 19:54:36 millert Exp $ */
/*
* Copyright (c) 1997 Kenneth Stailey. All rights reserved.
*
@@ -32,7 +32,9 @@
#include <machine/endian.h>
#include <fcntl.h>
#include <stdio.h>
+#include <stdlib.h>
#include <unistd.h>
+#include <err.h>
/*
* aucat: concatinate and play Sun 8-bit .au files
@@ -43,55 +45,73 @@
* device. Return 0 on sucess, -1 on failure.
*/
int
-playfile(int fd)
+playfile(fd, dev)
+ int fd;
+ char *dev;
{
- static int afd = -1;
- int rd;
- char buf[5120];
+ static int afd = -1;
+ int rd;
+ char buf[5120];
- if (afd == -1)
- if ((afd = open("/dev/audio", O_WRONLY)) < 0) {
- perror("open /dev/audio");
- return(-1);
- }
- while ((rd = read(fd, buf, sizeof(buf))) > 0) {
- write(afd, buf, rd);
- if (rd < sizeof(buf))
- break;
- }
-
- return (0);
+ if (afd == -1 && (afd = open(dev, O_WRONLY)) < 0) {
+ warn("can't open %s", dev);
+ return(-1);
+ }
+ while ((rd = read(fd, buf, sizeof(buf))) > 0) {
+ write(afd, buf, rd);
+ if (rd < sizeof(buf))
+ break;
+ }
+
+ return (0);
}
int
-main(int argc, char **argv)
+main(argc, argv)
+ int argc;
+ char **argv;
{
- int fd;
- int argcInc = 0; /* incrementing version of argc */
- unsigned long data;
- char magic[5];
+ int fd, ch;
+ unsigned long data;
+ char magic[5];
+ char *dev;
+
+ dev = getenv("AUDIODEVICE");
+ if (dev == 0)
+ dev = "/dev/audio";
+
+ while ((ch = getopt(argc, argv, "f:")) != -1) {
+ switch(ch) {
+ case 'f':
+ dev = optarg;
+ break;
+ }
+ }
+ argc -= optind;
+ argv += optind;
- while (--argc) {
- ++argcInc;
- if ((fd = open(argv[argcInc], O_RDONLY)) < 0) {
- perror("open file");
- exit(1);
- }
+ while (argc) {
+ if ((fd = open(*argv, O_RDONLY)) < 0)
+ err(1, "cannot open %s", *argv);
- read(fd, magic, 4);
- magic[4] = '\0';
- if (strcmp(magic, ".snd")) {
- /* not an .au file, bad header. Assume raw audio data since that's
- * what /dev/audio generates by default.
- */
- lseek(fd, 0, SEEK_SET);
- } else {
- read(fd, &data, sizeof(data));
- data = ntohl(data);
- lseek(fd, (off_t)data, SEEK_SET);
- }
- if (playfile(fd) < 0)
- exit(1);
- }
- exit(0);
+ read(fd, magic, 4);
+ magic[4] = '\0';
+ if (strcmp(magic, ".snd")) {
+ /*
+ * not an .au file, bad header.
+ * Assume raw audio data since that's
+ * what /dev/audio generates by default.
+ */
+ lseek(fd, 0, SEEK_SET);
+ } else {
+ read(fd, &data, sizeof(data));
+ data = ntohl(data);
+ lseek(fd, (off_t)data, SEEK_SET);
+ }
+ if (playfile(fd, dev) < 0)
+ exit(1);
+ argc--;
+ argv++;
+ }
+ exit(0);
}