1 /*
2 * Mach Operating System
3 * Copyright (c) 1991,1990 Carnegie Mellon University
4 * All Rights Reserved.
5 *
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.
11 *
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.
15 *
16 * Carnegie Mellon requests users of this software to return to
17 *
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
22 *
23 * any improvements or extensions that they make and grant Carnegie the
24 * rights to redistribute these changes.
25 *
26 * $FreeBSD$
27 */
28
29 /*
30 * Author: David B. Golub, Carnegie Mellon University
31 * Date: 7/90
32 */
33
34 #include <sys/param.h>
35 #include <sys/systm.h>
36
37 #include <ddb/ddb.h>
38 #include <ddb/db_lex.h>
39 #include <ddb/db_variables.h>
40
41 static int db_find_variable __P((struct db_variable **varp));
42 static void db_write_variable __P((struct db_variable *, db_expr_t *));
43
44 #ifdef notused
45 static int db_set_variable __P((db_expr_t value));
46 #endif
47
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 },
53 };
54 static struct db_variable *db_evars =
55 db_vars + sizeof(db_vars)/sizeof(db_vars[0]);
56
57 static int
58 db_find_variable(varp)
59 struct db_variable **varp;
60 {
61 int t;
62 struct db_variable *vp;
63
64 t = db_read_token();
65 if (t == tIDENT) {
66 for (vp = db_vars; vp < db_evars; vp++) {
67 if (!strcmp(db_tok_string, vp->name)) {
68 *varp = vp;
69 return (1);
70 }
71 }
72 for (vp = db_regs; vp < db_eregs; vp++) {
73 if (!strcmp(db_tok_string, vp->name)) {
74 *varp = vp;
75 return (1);
76 }
77 }
78 }
79 db_error("Unknown variable\n");
80 return (0);
81 }
82
83 int
84 db_get_variable(valuep)
85 db_expr_t *valuep;
86 {
87 struct db_variable *vp;
88
89 if (!db_find_variable(&vp))
90 return (0);
91
92 db_read_variable(vp, valuep);
93
94 return (1);
95 }
96
97 #ifdef notused
98 static int
99 db_set_variable(value)
100 db_expr_t value;
101 {
102 struct db_variable *vp;
103
104 if (!db_find_variable(&vp))
105 return (0);
106
107 db_write_variable(vp, &value);
108
109 return (1);
110 }
111 #endif
112
113 void
114 db_read_variable(vp, valuep)
115 struct db_variable *vp;
116 db_expr_t *valuep;
117 {
118 db_varfcn_t *func = vp->fcn;
119
120 if (func == FCN_NULL)
121 *valuep = *(vp->valuep);
122 else
123 (*func)(vp, valuep, DB_VAR_GET);
124 }
125
126 static void
127 db_write_variable(vp, valuep)
128 struct db_variable *vp;
129 db_expr_t *valuep;
130 {
131 db_varfcn_t *func = vp->fcn;
132
133 if (func == FCN_NULL)
134 *(vp->valuep) = *valuep;
135 else
136 (*func)(vp, valuep, DB_VAR_SET);
137 }
138
139 void
140 db_set_cmd(dummy1, dummy2, dummy3, dummy4)
141 db_expr_t dummy1;
142 boolean_t dummy2;
143 db_expr_t dummy3;
144 char * dummy4;
145 {
146 db_expr_t value;
147 struct db_variable *vp;
148 int t;
149
150 t = db_read_token();
151 if (t != tDOLLAR) {
152 db_error("Unknown variable\n");
153 return;
154 }
155 if (!db_find_variable(&vp)) {
156 db_error("Unknown variable\n");
157 return;
158 }
159
160 t = db_read_token();
161 if (t != tEQ)
162 db_unread_token(t);
163
164 if (!db_expression(&value)) {
165 db_error("No value\n");
166 return;
167 }
168 if (db_read_token() != tEOL) {
169 db_error("?\n");
170 }
171
172 db_write_variable(vp, &value);
173 }
Cache object: 2ae17d1ff15467bff143974eaab03896
|