Commit | Line | Data |
---|---|---|
15637ed4 RG |
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. | |
15637ed4 | 25 | * |
78ed81a3 | 26 | * $Id$ |
15637ed4 | 27 | */ |
78ed81a3 | 28 | |
15637ed4 RG |
29 | /* |
30 | * Author: David B. Golub, Carnegie Mellon University | |
31 | * Date: 7/90 | |
32 | */ | |
33 | ||
34 | #include "param.h" | |
35 | #include "proc.h" | |
36 | #include <machine/db_machdep.h> | |
37 | ||
38 | #include <ddb/db_lex.h> | |
39 | #include <ddb/db_variables.h> | |
40 | ||
41 | extern unsigned int db_maxoff; | |
42 | ||
43 | extern int db_radix; | |
44 | extern int db_max_width; | |
45 | extern int db_tab_stop_width; | |
46 | ||
47 | struct db_variable db_vars[] = { | |
48 | { "radix", &db_radix, FCN_NULL }, | |
49 | { "maxoff", (int *)&db_maxoff, FCN_NULL }, | |
50 | { "maxwidth", &db_max_width, FCN_NULL }, | |
51 | { "tabstops", &db_tab_stop_width, FCN_NULL }, | |
52 | }; | |
53 | struct db_variable *db_evars = db_vars + sizeof(db_vars)/sizeof(db_vars[0]); | |
54 | ||
55 | int | |
56 | db_find_variable(varp) | |
57 | struct db_variable **varp; | |
58 | { | |
59 | int t; | |
60 | struct db_variable *vp; | |
61 | ||
62 | t = db_read_token(); | |
63 | if (t == tIDENT) { | |
64 | for (vp = db_vars; vp < db_evars; vp++) { | |
65 | if (!strcmp(db_tok_string, vp->name)) { | |
66 | *varp = vp; | |
67 | return (1); | |
68 | } | |
69 | } | |
70 | for (vp = db_regs; vp < db_eregs; vp++) { | |
71 | if (!strcmp(db_tok_string, vp->name)) { | |
72 | *varp = vp; | |
73 | return (1); | |
74 | } | |
75 | } | |
76 | } | |
77 | db_error("Unknown variable\n"); | |
78 | return (0); | |
79 | } | |
80 | ||
81 | int | |
82 | db_get_variable(valuep) | |
83 | db_expr_t *valuep; | |
84 | { | |
85 | struct db_variable *vp; | |
86 | ||
87 | if (!db_find_variable(&vp)) | |
88 | return (0); | |
89 | ||
90 | db_read_variable(vp, valuep); | |
91 | ||
92 | return (1); | |
93 | } | |
94 | ||
95 | int | |
96 | db_set_variable(value) | |
97 | db_expr_t value; | |
98 | { | |
99 | struct db_variable *vp; | |
100 | ||
101 | if (!db_find_variable(&vp)) | |
102 | return (0); | |
103 | ||
104 | db_write_variable(vp, &value); | |
105 | ||
106 | return (1); | |
107 | } | |
108 | ||
109 | ||
110 | db_read_variable(vp, valuep) | |
111 | struct db_variable *vp; | |
112 | db_expr_t *valuep; | |
113 | { | |
114 | int (*func)() = vp->fcn; | |
115 | ||
116 | if (func == FCN_NULL) | |
117 | *valuep = *(vp->valuep); | |
118 | else | |
119 | (*func)(vp, valuep, DB_VAR_GET); | |
120 | } | |
121 | ||
122 | db_write_variable(vp, valuep) | |
123 | struct db_variable *vp; | |
124 | db_expr_t *valuep; | |
125 | { | |
126 | int (*func)() = vp->fcn; | |
127 | ||
128 | if (func == FCN_NULL) | |
129 | *(vp->valuep) = *valuep; | |
130 | else | |
131 | (*func)(vp, valuep, DB_VAR_SET); | |
132 | } | |
133 | ||
134 | void | |
135 | db_set_cmd() | |
136 | { | |
137 | db_expr_t value; | |
138 | int (*func)(); | |
139 | struct db_variable *vp; | |
140 | int t; | |
141 | ||
142 | t = db_read_token(); | |
143 | if (t != tDOLLAR) { | |
144 | db_error("Unknown variable\n"); | |
145 | return; | |
146 | } | |
147 | if (!db_find_variable(&vp)) { | |
148 | db_error("Unknown variable\n"); | |
149 | return; | |
150 | } | |
151 | ||
152 | t = db_read_token(); | |
153 | if (t != tEQ) | |
154 | db_unread_token(t); | |
155 | ||
156 | if (!db_expression(&value)) { | |
157 | db_error("No value\n"); | |
158 | return; | |
159 | } | |
160 | if (db_read_token() != tEOL) { | |
161 | db_error("?\n"); | |
162 | } | |
163 | ||
164 | db_write_variable(vp, &value); | |
165 | } |