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.
26 * $FreeBSD: src/sys/ddb/db_variables.c,v 1.18 1999/08/28 00:41:11 peter Exp $
27 * $DragonFly: src/sys/ddb/db_variables.c,v 1.3 2003/08/27 10:47:13 rob Exp $
31 * Author: David B. Golub, Carnegie Mellon University
35 #include <sys/param.h>
36 #include <sys/systm.h>
39 #include <ddb/db_lex.h>
40 #include <ddb/db_variables.h>
42 static int db_find_variable (struct db_variable **varp);
43 static void db_write_variable (struct db_variable *, db_expr_t *);
46 static int db_set_variable (db_expr_t value);
49 static struct db_variable db_vars[] = {
50 { "radix", &db_radix, FCN_NULL },
51 { "maxoff", &db_maxoff, FCN_NULL },
52 { "maxwidth", &db_max_width, FCN_NULL },
53 { "tabstops", &db_tab_stop_width, FCN_NULL },
55 static struct db_variable *db_evars =
56 db_vars + sizeof(db_vars)/sizeof(db_vars[0]);
59 db_find_variable(varp)
60 struct db_variable **varp;
63 struct db_variable *vp;
67 for (vp = db_vars; vp < db_evars; vp++) {
68 if (!strcmp(db_tok_string, vp->name)) {
73 for (vp = db_regs; vp < db_eregs; vp++) {
74 if (!strcmp(db_tok_string, vp->name)) {
80 db_error("Unknown variable\n");
85 db_get_variable(valuep)
88 struct db_variable *vp;
90 if (!db_find_variable(&vp))
93 db_read_variable(vp, valuep);
100 db_set_variable(value)
103 struct db_variable *vp;
105 if (!db_find_variable(&vp))
108 db_write_variable(vp, &value);
115 db_read_variable(vp, valuep)
116 struct db_variable *vp;
119 db_varfcn_t *func = vp->fcn;
121 if (func == FCN_NULL)
122 *valuep = *(vp->valuep);
124 (*func)(vp, valuep, DB_VAR_GET);
128 db_write_variable(vp, valuep)
129 struct db_variable *vp;
132 db_varfcn_t *func = vp->fcn;
134 if (func == FCN_NULL)
135 *(vp->valuep) = *valuep;
137 (*func)(vp, valuep, DB_VAR_SET);
141 db_set_cmd(dummy1, dummy2, dummy3, dummy4)
148 struct db_variable *vp;
153 db_error("Unknown variable\n");
156 if (!db_find_variable(&vp)) {
157 db_error("Unknown variable\n");
165 if (!db_expression(&value)) {
166 db_error("No value\n");
169 if (db_read_token() != tEOL) {
173 db_write_variable(vp, &value);