Annotation of src/usr.bin/aucat/opt.c, Revision 1.6
1.5 ratchov 1: /* $OpenBSD: opt.c,v 1.4 2010/01/10 21:47:41 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: */
17: #include <stdio.h>
18: #include <stdlib.h>
19: #include <string.h>
20:
21: #include "conf.h"
22: #include "opt.h"
1.4 ratchov 23: #ifdef DEBUG
24: #include "dbg.h"
25: #endif
1.1 ratchov 26:
27: struct optlist opt_list = SLIST_HEAD_INITIALIZER(&opt_list);
28:
29: void
1.6 ! ratchov 30: opt_new(char *name,
! 31: struct aparams *wpar, struct aparams *rpar, int maxweight, int mmc)
1.1 ratchov 32: {
33: struct opt *o;
34: unsigned len;
35: char c;
36:
37: for (len = 0; name[len] != '\0'; len++) {
38: if (len == OPT_NAMEMAX) {
39: fprintf(stderr, "%s: name too long\n", name);
40: exit(1);
41: }
42: c = name[len];
43: if (c < 'a' && c > 'z' &&
44: c < 'A' && c > 'Z' &&
45: c < '0' && c > '9' &&
46: c != '_') {
47: fprintf(stderr, "%s: '%c' not allowed\n", name, c);
48: exit(1);
49: }
50: }
51: o = malloc(sizeof(struct opt));
52: if (o == NULL) {
53: perror("opt_new: malloc");
54: exit(1);
55: }
56: memcpy(o->name, name, len + 1);
1.6 ! ratchov 57: o->wpar = *wpar;
! 58: o->rpar = *rpar;
1.1 ratchov 59: o->maxweight = maxweight;
1.3 ratchov 60: o->mmc = mmc;
1.4 ratchov 61: #ifdef DEBUG
62: if (debug_level >= 2) {
63: dbg_puts(o->name);
1.6 ! ratchov 64: dbg_puts(": rec ");
! 65: aparams_dbg(&o->wpar);
! 66: dbg_puts(", play ");
! 67: aparams_dbg(&o->rpar);
! 68: dbg_puts(", vol ");
! 69: dbg_putu(o->maxweight);
1.4 ratchov 70: if (o->mmc)
1.6 ! ratchov 71: dbg_puts(", mmc");
1.4 ratchov 72: dbg_puts("\n");
73: }
74: #endif
1.1 ratchov 75: SLIST_INSERT_HEAD(&opt_list, o, entry);
76: }
77:
78: struct opt *
79: opt_byname(char *name)
80: {
81: struct opt *o;
82:
83: SLIST_FOREACH(o, &opt_list, entry) {
84: if (strcmp(name, o->name) == 0) {
1.4 ratchov 85: #ifdef DEBUG
86: if (debug_level >= 3) {
87: dbg_puts(o->name);
88: dbg_puts(": option found\n");
89: }
90: #endif
1.1 ratchov 91: return o;
92: }
93: }
1.4 ratchov 94: #ifdef DEBUG
95: if (debug_level >= 3) {
96: dbg_puts(name);
97: dbg_puts(": option not found\n");
98: }
99: #endif
1.1 ratchov 100: return NULL;
101: }
102: