|
|
1.1 root 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 [email protected]
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: * HISTORY
28: * $Log: db_variables.c,v $
29: * Revision 1.1 1992/03/25 21:45:33 pace
30: * Initial revision
31: *
32: * Revision 2.3 91/02/05 17:07:19 mrt
33: * Changed to new Mach copyright
34: * [91/01/31 16:19:46 mrt]
35: *
36: * Revision 2.2 90/08/27 21:53:24 dbg
37: * New db_read/write_variable functions. Should be used instead
38: * of dereferencing valuep directly, which might not be a true
39: * pointer if there is an fcn() access function.
40: * [90/08/20 af]
41: *
42: * Fix declarations.
43: * Check for trailing garbage after last expression on command line.
44: * [90/08/10 14:34:54 dbg]
45: *
46: * Created.
47: * [90/07/25 dbg]
48: *
49: */
50: /*
51: * Author: David B. Golub, Carnegie Mellon University
52: * Date: 7/90
53: */
54:
55: #include "param.h"
56: #include "proc.h"
57: #include <machine/db_machdep.h>
58:
59: #include <ddb/db_lex.h>
60: #include <ddb/db_variables.h>
61:
62: extern unsigned int db_maxoff;
63:
64: extern int db_radix;
65: extern int db_max_width;
66: extern int db_tab_stop_width;
67:
68: struct db_variable db_vars[] = {
69: { "radix", &db_radix, FCN_NULL },
70: { "maxoff", (int *)&db_maxoff, FCN_NULL },
71: { "maxwidth", &db_max_width, FCN_NULL },
72: { "tabstops", &db_tab_stop_width, FCN_NULL },
73: };
74: struct db_variable *db_evars = db_vars + sizeof(db_vars)/sizeof(db_vars[0]);
75:
76: int
77: db_find_variable(varp)
78: struct db_variable **varp;
79: {
80: int t;
81: struct db_variable *vp;
82:
83: t = db_read_token();
84: if (t == tIDENT) {
85: for (vp = db_vars; vp < db_evars; vp++) {
86: if (!strcmp(db_tok_string, vp->name)) {
87: *varp = vp;
88: return (1);
89: }
90: }
91: for (vp = db_regs; vp < db_eregs; vp++) {
92: if (!strcmp(db_tok_string, vp->name)) {
93: *varp = vp;
94: return (1);
95: }
96: }
97: }
98: db_error("Unknown variable\n");
99: return (0);
100: }
101:
102: int
103: db_get_variable(valuep)
104: db_expr_t *valuep;
105: {
106: struct db_variable *vp;
107:
108: if (!db_find_variable(&vp))
109: return (0);
110:
111: db_read_variable(vp, valuep);
112:
113: return (1);
114: }
115:
116: int
117: db_set_variable(value)
118: db_expr_t value;
119: {
120: struct db_variable *vp;
121:
122: if (!db_find_variable(&vp))
123: return (0);
124:
125: db_write_variable(vp, &value);
126:
127: return (1);
128: }
129:
130:
131: db_read_variable(vp, valuep)
132: struct db_variable *vp;
133: db_expr_t *valuep;
134: {
135: int (*func)() = vp->fcn;
136:
137: if (func == FCN_NULL)
138: *valuep = *(vp->valuep);
139: else
140: (*func)(vp, valuep, DB_VAR_GET);
141: }
142:
143: db_write_variable(vp, valuep)
144: struct db_variable *vp;
145: db_expr_t *valuep;
146: {
147: int (*func)() = vp->fcn;
148:
149: if (func == FCN_NULL)
150: *(vp->valuep) = *valuep;
151: else
152: (*func)(vp, valuep, DB_VAR_SET);
153: }
154:
155: void
156: db_set_cmd()
157: {
158: db_expr_t value;
159: int (*func)();
160: struct db_variable *vp;
161: int t;
162:
163: t = db_read_token();
164: if (t != tDOLLAR) {
165: db_error("Unknown variable\n");
166: return;
167: }
168: if (!db_find_variable(&vp)) {
169: db_error("Unknown variable\n");
170: return;
171: }
172:
173: t = db_read_token();
174: if (t != tEQ)
175: db_unread_token(t);
176:
177: if (!db_expression(&value)) {
178: db_error("No value\n");
179: return;
180: }
181: if (db_read_token() != tEOL) {
182: db_error("?\n");
183: }
184:
185: db_write_variable(vp, &value);
186: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.