Annotation of src/usr.bin/aucat/opt.c, Revision 1.14
1.14 ! ratchov 1: /* $OpenBSD: opt.c,v 1.13 2012/04/11 06:05:43 ratchov Exp $ */
1.1 ratchov 2: /*
3: * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
4: *
5: * Permission to use, copy, modify, and distribute this software for any
6: * purpose with or without fee is hereby granted, provided that the above
7: * copyright notice and this permission notice appear in all copies.
8: *
9: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15: * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16: */
1.14 ! ratchov 17: #include <err.h>
1.1 ratchov 18: #include <stdio.h>
19: #include <stdlib.h>
20: #include <string.h>
21:
1.10 ratchov 22: #include "dev.h"
1.1 ratchov 23: #include "conf.h"
24: #include "opt.h"
1.4 ratchov 25: #ifdef DEBUG
26: #include "dbg.h"
27: #endif
1.1 ratchov 28:
1.11 ratchov 29: struct opt *opt_list = NULL;
1.1 ratchov 30:
1.11 ratchov 31: struct opt *
1.12 ratchov 32: opt_new(char *name, struct dev *dev,
33: struct aparams *wpar, struct aparams *rpar,
1.13 ratchov 34: int maxweight, int mmc, int join, unsigned int mode)
1.1 ratchov 35: {
1.11 ratchov 36: struct opt *o, **po;
1.13 ratchov 37: unsigned int len;
1.1 ratchov 38: char c;
39:
40: for (len = 0; name[len] != '\0'; len++) {
1.14 ! ratchov 41: if (len == OPT_NAMEMAX)
! 42: errx(1, "%s: name too long", name);
1.1 ratchov 43: c = name[len];
1.12 ratchov 44: if ((c < 'a' || c > 'z') &&
1.14 ! ratchov 45: (c < 'A' || c > 'Z'))
! 46: errx(1, "%s: '%c' not allowed", name, c);
1.1 ratchov 47: }
48: o = malloc(sizeof(struct opt));
1.14 ! ratchov 49: if (o == NULL)
! 50: err(1, "opt_new: malloc");
1.7 ratchov 51: if (mode & MODE_RECMASK)
52: o->wpar = (mode & MODE_MON) ? *rpar : *wpar;
53: if (mode & MODE_PLAY)
54: o->rpar = *rpar;
1.1 ratchov 55: o->maxweight = maxweight;
1.3 ratchov 56: o->mmc = mmc;
1.8 ratchov 57: o->join = join;
1.7 ratchov 58: o->mode = mode;
1.11 ratchov 59: o->dev = dev;
1.12 ratchov 60: memcpy(o->name, name, len + 1);
1.11 ratchov 61: for (po = &opt_list; *po != NULL; po = &(*po)->next) {
1.12 ratchov 62: if (o->dev->num == (*po)->dev->num &&
1.14 ! ratchov 63: strcmp(o->name, (*po)->name) == 0)
! 64: errx(1, "%s: already defined", o->name);
1.11 ratchov 65: }
66: o->next = NULL;
67: *po = o;
1.4 ratchov 68: #ifdef DEBUG
69: if (debug_level >= 2) {
1.12 ratchov 70: dev_dbg(o->dev);
71: dbg_puts(".");
1.4 ratchov 72: dbg_puts(o->name);
1.7 ratchov 73: dbg_puts(":");
1.11 ratchov 74: if (o->mode & MODE_REC) {
1.7 ratchov 75: dbg_puts(" rec=");
76: dbg_putu(o->wpar.cmin);
77: dbg_puts(":");
78: dbg_putu(o->wpar.cmax);
79: }
1.11 ratchov 80: if (o->mode & MODE_PLAY) {
1.7 ratchov 81: dbg_puts(" play=");
82: dbg_putu(o->rpar.cmin);
83: dbg_puts(":");
84: dbg_putu(o->rpar.cmax);
85: dbg_puts(" vol=");
86: dbg_putu(o->maxweight);
87: }
1.11 ratchov 88: if (o->mode & MODE_MON) {
1.7 ratchov 89: dbg_puts(" mon=");
90: dbg_putu(o->wpar.cmin);
91: dbg_puts(":");
92: dbg_putu(o->wpar.cmax);
93: }
1.11 ratchov 94: if (o->mode & (MODE_RECMASK | MODE_PLAY)) {
95: if (o->mmc)
96: dbg_puts(" mmc");
97: if (o->join)
98: dbg_puts(" join");
99: }
100: if (o->mode & MODE_MIDIIN)
101: dbg_puts(" midi/in");
102: if (o->mode & MODE_MIDIOUT)
103: dbg_puts(" midi/out");
1.4 ratchov 104: dbg_puts("\n");
105: }
106: #endif
1.11 ratchov 107: return o;
1.1 ratchov 108: }
109:
110: struct opt *
1.13 ratchov 111: opt_byname(char *name, unsigned int num)
1.1 ratchov 112: {
113: struct opt *o;
114:
1.11 ratchov 115: for (o = opt_list; o != NULL; o = o->next) {
1.12 ratchov 116: if (o->dev->num != num)
117: continue;
118: if (strcmp(name, o->name) == 0)
1.1 ratchov 119: return o;
1.4 ratchov 120: }
1.1 ratchov 121: return NULL;
122: }
123: