2 * Mach Operating System
3 * Copyright (c) 1991,1990 Carnegie Mellon University
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.
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.
16 * Carnegie Mellon requests users of this software to return to
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
23 * any improvements or extensions that they make and grant Carnegie the
24 * rights to redistribute these changes.
30 * Author: David B. Golub, Carnegie Mellon University
34 #include <sys/param.h>
35 #include <sys/systm.h>
38 #include <ddb/db_lex.h>
39 #include <ddb/db_variables.h>
41 static int db_find_variable __P((struct db_variable **varp));
42 static void db_write_variable __P((struct db_variable *, db_expr_t *));
45 static int db_set_variable __P((db_expr_t value));
48 static struct db_variable db_vars[] = {
49 { "radix", &db_radix, FCN_NULL },
50 { "maxoff", &db_maxoff, FCN_NULL },
51 { "maxwidth", &db_max_width, FCN_NULL },
52 { "tabstops", &db_tab_stop_width, FCN_NULL },
54 static struct db_variable *db_evars =
55 db_vars + sizeof(db_vars)/sizeof(db_vars[0]);
58 db_find_variable(varp)
59 struct db_variable **varp;
62 struct db_variable *vp;
66 for (vp = db_vars; vp < db_evars; vp++) {
67 if (!strcmp(db_tok_string, vp->name)) {
72 for (vp = db_regs; vp < db_eregs; vp++) {
73 if (!strcmp(db_tok_string, vp->name)) {
79 db_error("Unknown variable\n");
84 db_get_variable(valuep)
87 struct db_variable *vp;
89 if (!db_find_variable(&vp))
92 db_read_variable(vp, valuep);
99 db_set_variable(value)
102 struct db_variable *vp;
104 if (!db_find_variable(&vp))
107 db_write_variable(vp, &value);
114 db_read_variable(vp, valuep)
115 struct db_variable *vp;
118 db_varfcn_t *func = vp->fcn;
120 if (func == FCN_NULL)
121 *valuep = *(vp->valuep);
123 (*func)(vp, valuep, DB_VAR_GET);
127 db_write_variable(vp, valuep)
128 struct db_variable *vp;
131 db_varfcn_t *func = vp->fcn;
133 if (func == FCN_NULL)
134 *(vp->valuep) = *valuep;
136 (*func)(vp, valuep, DB_VAR_SET);
140 db_set_cmd(dummy1, dummy2, dummy3, dummy4)
147 struct db_variable *vp;
152 db_error("Unknown variable\n");
155 if (!db_find_variable(&vp)) {
156 db_error("Unknown variable\n");
164 if (!db_expression(&value)) {
165 db_error("No value\n");
168 if (db_read_token() != tEOL) {
172 db_write_variable(vp, &value);