summaryrefslogtreecommitdiff
path: root/usr.bin/aucat/wav.c
diff options
context:
space:
mode:
authorAlexandre Ratchov <ratchov@cvs.openbsd.org>2011-06-03 10:05:28 +0000
committerAlexandre Ratchov <ratchov@cvs.openbsd.org>2011-06-03 10:05:28 +0000
commit46f85188c75fff49f7295ee4761f7b573ab029cc (patch)
tree4b478cbba95aa825d34922ec7a9c28f539aea081 /usr.bin/aucat/wav.c
parenta03e1c8277627b56bbf035a78c69e465f7de914d (diff)
Reorganize the way command line options are parsed and stored.
No behaviour change.
Diffstat (limited to 'usr.bin/aucat/wav.c')
-rw-r--r--usr.bin/aucat/wav.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/usr.bin/aucat/wav.c b/usr.bin/aucat/wav.c
index ca51f48cb85..9be0ec4c18c 100644
--- a/usr.bin/aucat/wav.c
+++ b/usr.bin/aucat/wav.c
@@ -14,9 +14,10 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
-#include <fcntl.h>
+#include <string.h>
#include <unistd.h>
#include "abuf.h"
@@ -661,6 +662,25 @@ wav_quitreq(void *arg)
}
/*
+ * determine the header by the file name
+ */
+unsigned
+wav_autohdr(char *name, unsigned hdr)
+{
+ size_t len;
+
+ if (hdr != HDR_AUTO)
+ return hdr;
+ if (name == NULL)
+ return HDR_RAW;
+ len = strlen(name);
+ if (len >= 4 && strcasecmp(name + len - 4, ".wav") == 0)
+ return HDR_WAV;
+ else
+ return HDR_RAW;
+}
+
+/*
* create a file reader in the ``INIT'' state
*/
struct wav *
@@ -671,6 +691,7 @@ wav_new_in(struct fileops *ops,
int fd;
struct wav *f;
+ hdr = wav_autohdr(name, hdr);
if (name != NULL) {
fd = open(name, O_RDONLY | O_NONBLOCK, 0666);
if (fd < 0) {
@@ -726,7 +747,7 @@ wav_new_in(struct fileops *ops,
f->join = join;
f->mode = mode;
f->hpar = *par;
- f->hdr = 0;
+ f->hdr = hdr;
f->xrun = xrun;
f->maxweight = MIDI_TO_ADATA(volctl);
f->slot = ctl_slotnew(f->dev->midi, "play", &ctl_wavops, f, 1);
@@ -760,6 +781,7 @@ wav_new_out(struct fileops *ops,
int fd;
struct wav *f;
+ hdr = wav_autohdr(name, hdr);
if (name == NULL) {
name = "stdout";
fd = STDOUT_FILENO;