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.4 2005/12/23 21:35:44 swildner 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(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(db_expr_t
*valuep
)
86 struct db_variable
*vp
;
88 if (!db_find_variable(&vp
))
91 db_read_variable(vp
, valuep
);
98 db_set_variable(db_expr_t value
)
100 struct db_variable
*vp
;
102 if (!db_find_variable(&vp
))
105 db_write_variable(vp
, &value
);
112 db_read_variable(struct db_variable
*vp
, db_expr_t
*valuep
)
114 db_varfcn_t
*func
= vp
->fcn
;
116 if (func
== FCN_NULL
)
117 *valuep
= *(vp
->valuep
);
119 (*func
)(vp
, valuep
, DB_VAR_GET
);
123 db_write_variable(struct db_variable
*vp
, db_expr_t
*valuep
)
125 db_varfcn_t
*func
= vp
->fcn
;
127 if (func
== FCN_NULL
)
128 *(vp
->valuep
) = *valuep
;
130 (*func
)(vp
, valuep
, DB_VAR_SET
);
134 db_set_cmd(db_expr_t dummy1
, boolean_t dummy2
, db_expr_t dummy3
, char *dummy4
)
137 struct db_variable
*vp
;
142 db_error("Unknown variable\n");
145 if (!db_find_variable(&vp
)) {
146 db_error("Unknown variable\n");
154 if (!db_expression(&value
)) {
155 db_error("No value\n");
158 if (db_read_token() != tEOL
) {
162 db_write_variable(vp
, &value
);