Remove pca and speaker device remains (both deleted).
[dragonfly.git] / sys / ddb / db_variables.c
1 /*
2  * Mach Operating System
3  * Copyright (c) 1991,1990 Carnegie Mellon University
4  * All Rights Reserved.
5  *
6  * Permission to use, copy, modify and distribute this software and its
7  * documentation is hereby granted, provided that both the copyright
8  * notice and this permission notice appear in all copies of the
9  * software, derivative works or modified versions, and any portions
10  * thereof, and that both notices appear in supporting documentation.
11  *
12  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
13  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
15  *
16  * Carnegie Mellon requests users of this software to return to
17  *
18  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
19  *  School of Computer Science
20  *  Carnegie Mellon University
21  *  Pittsburgh PA 15213-3890
22  *
23  * any improvements or extensions that they make and grant Carnegie the
24  * rights to redistribute these changes.
25  *
26  * $FreeBSD: src/sys/ddb/db_variables.c,v 1.18 1999/08/28 00:41:11 peter Exp $
27  */
28
29 /*
30  *      Author: David B. Golub, Carnegie Mellon University
31  *      Date:   7/90
32  */
33
34 #include <sys/param.h>
35 #include <sys/systm.h>
36
37 #include <ddb/ddb.h>
38 #include <ddb/db_lex.h>
39 #include <ddb/db_variables.h>
40
41 static int      db_find_variable (struct db_variable **varp);
42 static void     db_write_variable (struct db_variable *, db_expr_t *);
43
44 #ifdef notused
45 static int      db_set_variable (db_expr_t value);
46 #endif
47
48 static struct db_variable db_vars[] = {
49         { "radix",      &db_radix, NULL },
50         { "maxoff",     &db_maxoff, NULL },
51         { "maxwidth",   &db_max_width, NULL },
52         { "tabstops",   &db_tab_stop_width, NULL },
53 };
54 static struct db_variable *db_evars = db_vars + NELEM(db_vars);
55
56 static int
57 db_find_variable(struct db_variable **varp)
58 {
59         int     t;
60         struct db_variable *vp;
61
62         t = db_read_token();
63         if (t == tIDENT) {
64             for (vp = db_vars; vp < db_evars; vp++) {
65                 if (!strcmp(db_tok_string, vp->name)) {
66                     *varp = vp;
67                     return (1);
68                 }
69             }
70             for (vp = db_regs; vp < db_eregs; vp++) {
71                 if (!strcmp(db_tok_string, vp->name)) {
72                     *varp = vp;
73                     return (1);
74                 }
75             }
76         }
77         db_error("Unknown variable\n");
78         return (0);
79 }
80
81 int
82 db_get_variable(db_expr_t *valuep)
83 {
84         struct db_variable *vp;
85
86         if (!db_find_variable(&vp))
87             return (0);
88
89         db_read_variable(vp, valuep);
90
91         return (1);
92 }
93
94 #ifdef notused
95 static int
96 db_set_variable(db_expr_t value)
97 {
98         struct db_variable *vp;
99
100         if (!db_find_variable(&vp))
101             return (0);
102
103         db_write_variable(vp, &value);
104
105         return (1);
106 }
107 #endif
108
109 void
110 db_read_variable(struct db_variable *vp, db_expr_t *valuep)
111 {
112         db_varfcn_t     *func = vp->fcn;
113
114         if (func == NULL)
115             *valuep = *(vp->valuep);
116         else
117             (*func)(vp, valuep, DB_VAR_GET);
118 }
119
120 static void
121 db_write_variable(struct db_variable *vp, db_expr_t *valuep)
122 {
123         db_varfcn_t     *func = vp->fcn;
124
125         if (func == NULL)
126             *(vp->valuep) = *valuep;
127         else
128             (*func)(vp, valuep, DB_VAR_SET);
129 }
130
131 void
132 db_set_cmd(db_expr_t dummy1, boolean_t dummy2, db_expr_t dummy3, char *dummy4)
133 {
134         db_expr_t       value;
135         struct db_variable *vp;
136         int     t;
137
138         t = db_read_token();
139         if (t != tDOLLAR) {
140             db_error("Unknown variable\n");
141             return;
142         }
143         if (!db_find_variable(&vp)) {
144             db_error("Unknown variable\n");
145             return;
146         }
147
148         t = db_read_token();
149         if (t != tEQ)
150             db_unread_token(t);
151
152         if (!db_expression(&value)) {
153             db_error("No value\n");
154             return;
155         }
156         if (db_read_token() != tEOL) {
157             db_error("?\n");
158         }
159
160         db_write_variable(vp, &value);
161 }