More headers for pc64 platform kernel build/linking
[dragonfly/port-amd64.git] / sys / ddb / db_variables.c
blobf88690181263c6f7c0ab669f9d27ef642addc648
1 /*
2 * Mach Operating System
3 * Copyright (c) 1991,1990 Carnegie Mellon University
4 * All Rights Reserved.
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.
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.
16 * Carnegie Mellon requests users of this software to return to
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
23 * any improvements or extensions that they make and grant Carnegie the
24 * rights to redistribute these changes.
26 * $FreeBSD: src/sys/ddb/db_variables.c,v 1.18 1999/08/28 00:41:11 peter Exp $
27 * $DragonFly: src/sys/ddb/db_variables.c,v 1.4 2005/12/23 21:35:44 swildner Exp $
31 * Author: David B. Golub, Carnegie Mellon University
32 * Date: 7/90
35 #include <sys/param.h>
36 #include <sys/systm.h>
38 #include <ddb/ddb.h>
39 #include <ddb/db_lex.h>
40 #include <ddb/db_variables.h>
42 static int db_find_variable (struct db_variable **varp);
43 static void db_write_variable (struct db_variable *, db_expr_t *);
45 #ifdef notused
46 static int db_set_variable (db_expr_t value);
47 #endif
49 static struct db_variable db_vars[] = {
50 { "radix", &db_radix, FCN_NULL },
51 { "maxoff", &db_maxoff, FCN_NULL },
52 { "maxwidth", &db_max_width, FCN_NULL },
53 { "tabstops", &db_tab_stop_width, FCN_NULL },
55 static struct db_variable *db_evars =
56 db_vars + sizeof(db_vars)/sizeof(db_vars[0]);
58 static int
59 db_find_variable(struct db_variable **varp)
61 int t;
62 struct db_variable *vp;
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);
72 for (vp = db_regs; vp < db_eregs; vp++) {
73 if (!strcmp(db_tok_string, vp->name)) {
74 *varp = vp;
75 return (1);
79 db_error("Unknown variable\n");
80 return (0);
83 int
84 db_get_variable(db_expr_t *valuep)
86 struct db_variable *vp;
88 if (!db_find_variable(&vp))
89 return (0);
91 db_read_variable(vp, valuep);
93 return (1);
96 #ifdef notused
97 static int
98 db_set_variable(db_expr_t value)
100 struct db_variable *vp;
102 if (!db_find_variable(&vp))
103 return (0);
105 db_write_variable(vp, &value);
107 return (1);
109 #endif
111 void
112 db_read_variable(struct db_variable *vp, db_expr_t *valuep)
114 db_varfcn_t *func = vp->fcn;
116 if (func == FCN_NULL)
117 *valuep = *(vp->valuep);
118 else
119 (*func)(vp, valuep, DB_VAR_GET);
122 static void
123 db_write_variable(struct db_variable *vp, db_expr_t *valuep)
125 db_varfcn_t *func = vp->fcn;
127 if (func == FCN_NULL)
128 *(vp->valuep) = *valuep;
129 else
130 (*func)(vp, valuep, DB_VAR_SET);
133 void
134 db_set_cmd(db_expr_t dummy1, boolean_t dummy2, db_expr_t dummy3, char *dummy4)
136 db_expr_t value;
137 struct db_variable *vp;
138 int t;
140 t = db_read_token();
141 if (t != tDOLLAR) {
142 db_error("Unknown variable\n");
143 return;
145 if (!db_find_variable(&vp)) {
146 db_error("Unknown variable\n");
147 return;
150 t = db_read_token();
151 if (t != tEQ)
152 db_unread_token(t);
154 if (!db_expression(&value)) {
155 db_error("No value\n");
156 return;
158 if (db_read_token() != tEOL) {
159 db_error("?\n");
162 db_write_variable(vp, &value);