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 /*
27 * Author: David B. Golub, Carnegie Mellon University
28 * Date: 7/90
29 */
30
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD: releng/5.3/sys/ddb/db_variables.c 131952 2004-07-10 23:47:20Z marcel $");
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(struct db_variable **varp);
42
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 };
49 static struct db_variable *db_evars =
50 db_vars + sizeof(db_vars)/sizeof(db_vars[0]);
51
52 static int
53 db_find_variable(struct db_variable **varp)
54 {
55 struct db_variable *vp;
56 int t;
57
58 t = db_read_token();
59 if (t == tIDENT) {
60 for (vp = db_vars; vp < db_evars; vp++) {
61 if (!strcmp(db_tok_string, vp->name)) {
62 *varp = vp;
63 return (1);
64 }
65 }
66 for (vp = db_regs; vp < db_eregs; vp++) {
67 if (!strcmp(db_tok_string, vp->name)) {
68 *varp = vp;
69 return (1);
70 }
71 }
72 }
73 db_error("Unknown variable\n");
74 return (0);
75 }
76
77 int
78 db_get_variable(db_expr_t *valuep)
79 {
80 struct db_variable *vp;
81
82 if (!db_find_variable(&vp))
83 return (0);
84
85 return (db_read_variable(vp, valuep));
86 }
87
88 int
89 db_set_variable(db_expr_t value)
90 {
91 struct db_variable *vp;
92
93 if (!db_find_variable(&vp))
94 return (0);
95
96 return (db_write_variable(vp, value));
97 }
98
99 int
100 db_read_variable(struct db_variable *vp, db_expr_t *valuep)
101 {
102 db_varfcn_t *func = vp->fcn;
103
104 if (func == FCN_NULL) {
105 *valuep = *(vp->valuep);
106 return (1);
107 }
108 return ((*func)(vp, valuep, DB_VAR_GET));
109 }
110
111 int
112 db_write_variable(struct db_variable *vp, db_expr_t value)
113 {
114 db_varfcn_t *func = vp->fcn;
115
116 if (func == FCN_NULL) {
117 *(vp->valuep) = value;
118 return (1);
119 }
120 return ((*func)(vp, &value, DB_VAR_SET));
121 }
122
123 void
124 db_set_cmd(db_expr_t dummy1, boolean_t dummy2, db_expr_t dummy3, char *dummy4)
125 {
126 struct db_variable *vp;
127 db_expr_t value;
128 int t;
129
130 t = db_read_token();
131 if (t != tDOLLAR) {
132 db_error("Unknown variable\n");
133 return;
134 }
135 if (!db_find_variable(&vp)) {
136 db_error("Unknown variable\n");
137 return;
138 }
139
140 t = db_read_token();
141 if (t != tEQ)
142 db_unread_token(t);
143
144 if (!db_expression(&value)) {
145 db_error("No value\n");
146 return;
147 }
148 if (db_read_token() != tEOL)
149 db_error("?\n");
150
151 db_write_variable(vp, value);
152 }
Cache object: 7cbaf92d38e38493a273211783af71dd
|