db_variables.c revision 1.5 1 1.1 cgd /*
2 1.1 cgd * Mach Operating System
3 1.1 cgd * Copyright (c) 1991,1990 Carnegie Mellon University
4 1.1 cgd * All Rights Reserved.
5 1.1 cgd *
6 1.1 cgd * Permission to use, copy, modify and distribute this software and its
7 1.1 cgd * documentation is hereby granted, provided that both the copyright
8 1.1 cgd * notice and this permission notice appear in all copies of the
9 1.1 cgd * software, derivative works or modified versions, and any portions
10 1.1 cgd * thereof, and that both notices appear in supporting documentation.
11 1.1 cgd *
12 1.1 cgd * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
13 1.1 cgd * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14 1.1 cgd * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
15 1.1 cgd *
16 1.1 cgd * Carnegie Mellon requests users of this software to return to
17 1.1 cgd *
18 1.1 cgd * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
19 1.1 cgd * School of Computer Science
20 1.1 cgd * Carnegie Mellon University
21 1.1 cgd * Pittsburgh PA 15213-3890
22 1.1 cgd *
23 1.1 cgd * any improvements or extensions that they make and grant Carnegie the
24 1.1 cgd * rights to redistribute these changes.
25 1.2 cgd *
26 1.5 mycroft * $Id: db_variables.c,v 1.5 1993/12/18 04:46:42 mycroft Exp $
27 1.1 cgd */
28 1.1 cgd
29 1.5 mycroft #include <sys/param.h>
30 1.5 mycroft #include <sys/proc.h>
31 1.5 mycroft
32 1.1 cgd #include <machine/db_machdep.h>
33 1.1 cgd
34 1.1 cgd #include <ddb/db_lex.h>
35 1.1 cgd #include <ddb/db_variables.h>
36 1.1 cgd
37 1.1 cgd extern unsigned int db_maxoff;
38 1.1 cgd
39 1.1 cgd extern int db_radix;
40 1.1 cgd extern int db_max_width;
41 1.1 cgd extern int db_tab_stop_width;
42 1.3 brezak extern int db_max_line;
43 1.1 cgd
44 1.1 cgd struct db_variable db_vars[] = {
45 1.1 cgd { "radix", &db_radix, FCN_NULL },
46 1.1 cgd { "maxoff", (int *)&db_maxoff, FCN_NULL },
47 1.1 cgd { "maxwidth", &db_max_width, FCN_NULL },
48 1.1 cgd { "tabstops", &db_tab_stop_width, FCN_NULL },
49 1.3 brezak { "lines", &db_max_line, FCN_NULL },
50 1.1 cgd };
51 1.1 cgd struct db_variable *db_evars = db_vars + sizeof(db_vars)/sizeof(db_vars[0]);
52 1.1 cgd
53 1.1 cgd int
54 1.1 cgd db_find_variable(varp)
55 1.1 cgd struct db_variable **varp;
56 1.1 cgd {
57 1.1 cgd int t;
58 1.1 cgd struct db_variable *vp;
59 1.1 cgd
60 1.1 cgd t = db_read_token();
61 1.1 cgd if (t == tIDENT) {
62 1.1 cgd for (vp = db_vars; vp < db_evars; vp++) {
63 1.1 cgd if (!strcmp(db_tok_string, vp->name)) {
64 1.1 cgd *varp = vp;
65 1.1 cgd return (1);
66 1.1 cgd }
67 1.1 cgd }
68 1.1 cgd for (vp = db_regs; vp < db_eregs; vp++) {
69 1.1 cgd if (!strcmp(db_tok_string, vp->name)) {
70 1.1 cgd *varp = vp;
71 1.1 cgd return (1);
72 1.1 cgd }
73 1.1 cgd }
74 1.1 cgd }
75 1.1 cgd db_error("Unknown variable\n");
76 1.1 cgd return (0);
77 1.1 cgd }
78 1.1 cgd
79 1.1 cgd int
80 1.1 cgd db_get_variable(valuep)
81 1.1 cgd db_expr_t *valuep;
82 1.1 cgd {
83 1.1 cgd struct db_variable *vp;
84 1.1 cgd
85 1.1 cgd if (!db_find_variable(&vp))
86 1.1 cgd return (0);
87 1.1 cgd
88 1.1 cgd db_read_variable(vp, valuep);
89 1.1 cgd
90 1.1 cgd return (1);
91 1.1 cgd }
92 1.1 cgd
93 1.1 cgd int
94 1.1 cgd db_set_variable(value)
95 1.1 cgd db_expr_t value;
96 1.1 cgd {
97 1.1 cgd struct db_variable *vp;
98 1.1 cgd
99 1.1 cgd if (!db_find_variable(&vp))
100 1.1 cgd return (0);
101 1.1 cgd
102 1.1 cgd db_write_variable(vp, &value);
103 1.1 cgd
104 1.1 cgd return (1);
105 1.1 cgd }
106 1.1 cgd
107 1.1 cgd
108 1.1 cgd db_read_variable(vp, valuep)
109 1.1 cgd struct db_variable *vp;
110 1.1 cgd db_expr_t *valuep;
111 1.1 cgd {
112 1.1 cgd int (*func)() = vp->fcn;
113 1.1 cgd
114 1.1 cgd if (func == FCN_NULL)
115 1.1 cgd *valuep = *(vp->valuep);
116 1.1 cgd else
117 1.1 cgd (*func)(vp, valuep, DB_VAR_GET);
118 1.1 cgd }
119 1.1 cgd
120 1.1 cgd db_write_variable(vp, valuep)
121 1.1 cgd struct db_variable *vp;
122 1.1 cgd db_expr_t *valuep;
123 1.1 cgd {
124 1.1 cgd int (*func)() = vp->fcn;
125 1.1 cgd
126 1.1 cgd if (func == FCN_NULL)
127 1.1 cgd *(vp->valuep) = *valuep;
128 1.1 cgd else
129 1.1 cgd (*func)(vp, valuep, DB_VAR_SET);
130 1.1 cgd }
131 1.1 cgd
132 1.1 cgd void
133 1.1 cgd db_set_cmd()
134 1.1 cgd {
135 1.1 cgd db_expr_t value;
136 1.1 cgd int (*func)();
137 1.1 cgd struct db_variable *vp;
138 1.1 cgd int t;
139 1.1 cgd
140 1.1 cgd t = db_read_token();
141 1.1 cgd if (t != tDOLLAR) {
142 1.1 cgd db_error("Unknown variable\n");
143 1.1 cgd return;
144 1.1 cgd }
145 1.1 cgd if (!db_find_variable(&vp)) {
146 1.1 cgd db_error("Unknown variable\n");
147 1.1 cgd return;
148 1.1 cgd }
149 1.1 cgd
150 1.1 cgd t = db_read_token();
151 1.1 cgd if (t != tEQ)
152 1.1 cgd db_unread_token(t);
153 1.1 cgd
154 1.1 cgd if (!db_expression(&value)) {
155 1.1 cgd db_error("No value\n");
156 1.1 cgd return;
157 1.1 cgd }
158 1.1 cgd if (db_read_token() != tEOL) {
159 1.1 cgd db_error("?\n");
160 1.1 cgd }
161 1.1 cgd
162 1.1 cgd db_write_variable(vp, &value);
163 1.1 cgd }
164