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 $
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 (struct db_variable
**varp
);
42 static void db_write_variable (struct db_variable
*, db_expr_t
*);
45 static int db_set_variable (db_expr_t value
);
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
},
54 static struct db_variable
*db_evars
= db_vars
+ NELEM(db_vars
);
57 db_find_variable(struct db_variable
**varp
)
60 struct db_variable
*vp
;
64 for (vp
= db_vars
; vp
< db_evars
; vp
++) {
65 if (!strcmp(db_tok_string
, vp
->name
)) {
70 for (vp
= db_regs
; vp
< db_eregs
; vp
++) {
71 if (!strcmp(db_tok_string
, vp
->name
)) {
77 db_error("Unknown variable\n");
82 db_get_variable(db_expr_t
*valuep
)
84 struct db_variable
*vp
;
86 if (!db_find_variable(&vp
))
89 db_read_variable(vp
, valuep
);
96 db_set_variable(db_expr_t value
)
98 struct db_variable
*vp
;
100 if (!db_find_variable(&vp
))
103 db_write_variable(vp
, &value
);
110 db_read_variable(struct db_variable
*vp
, db_expr_t
*valuep
)
112 db_varfcn_t
*func
= vp
->fcn
;
115 *valuep
= *(vp
->valuep
);
117 (*func
)(vp
, valuep
, DB_VAR_GET
);
121 db_write_variable(struct db_variable
*vp
, db_expr_t
*valuep
)
123 db_varfcn_t
*func
= vp
->fcn
;
126 *(vp
->valuep
) = *valuep
;
128 (*func
)(vp
, valuep
, DB_VAR_SET
);
132 db_set_cmd(db_expr_t dummy1
, boolean_t dummy2
, db_expr_t dummy3
, char *dummy4
)
135 struct db_variable
*vp
;
140 db_error("Unknown variable\n");
143 if (!db_find_variable(&vp
)) {
144 db_error("Unknown variable\n");
152 if (!db_expression(&value
)) {
153 db_error("No value\n");
156 if (db_read_token() != tEOL
) {
160 db_write_variable(vp
, &value
);