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.
27 * Author: David B. Golub, Carnegie Mellon University
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
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(struct db_variable **varp);
43 static struct db_variable db_vars[] = {
44 { "radix", &db_radix, FCN_NULL },
45 { "maxoff", &db_maxoff, FCN_NULL },
46 { "maxwidth", &db_max_width, FCN_NULL },
47 { "tabstops", &db_tab_stop_width, FCN_NULL },
48 { "lines", &db_lines_per_page, FCN_NULL },
50 static struct db_variable *db_evars =
51 db_vars + sizeof(db_vars)/sizeof(db_vars[0]);
54 db_find_variable(struct db_variable **varp)
56 struct db_variable *vp;
61 for (vp = db_vars; vp < db_evars; vp++) {
62 if (!strcmp(db_tok_string, vp->name)) {
67 for (vp = db_regs; vp < db_eregs; vp++) {
68 if (!strcmp(db_tok_string, vp->name)) {
74 db_error("Unknown variable\n");
79 db_get_variable(db_expr_t *valuep)
81 struct db_variable *vp;
83 if (!db_find_variable(&vp))
86 return (db_read_variable(vp, valuep));
90 db_set_variable(db_expr_t value)
92 struct db_variable *vp;
94 if (!db_find_variable(&vp))
97 return (db_write_variable(vp, value));
101 db_read_variable(struct db_variable *vp, db_expr_t *valuep)
103 db_varfcn_t *func = vp->fcn;
105 if (func == FCN_NULL) {
106 *valuep = *(vp->valuep);
109 return ((*func)(vp, valuep, DB_VAR_GET));
113 db_write_variable(struct db_variable *vp, db_expr_t value)
115 db_varfcn_t *func = vp->fcn;
117 if (func == FCN_NULL) {
118 *(vp->valuep) = value;
121 return ((*func)(vp, &value, DB_VAR_SET));
125 db_set_cmd(db_expr_t dummy1, boolean_t dummy2, db_expr_t dummy3, char *dummy4)
127 struct db_variable *vp;
133 db_error("Unknown variable\n");
136 if (!db_find_variable(&vp)) {
137 db_error("Unknown variable\n");
145 if (!db_expression(&value)) {
146 db_error("No value\n");
149 if (db_read_token() != tEOL)
152 db_write_variable(vp, value);