bsd.lib.mk: Add INTERNALLIBPROF knob.
[dragonfly.git] / sys / ddb / db_variables.c
blobca2b99ef00913111aa74371f94b222c132ea8d29
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 $
30 * Author: David B. Golub, Carnegie Mellon University
31 * Date: 7/90
34 #include <sys/param.h>
35 #include <sys/systm.h>
37 #include <ddb/ddb.h>
38 #include <ddb/db_lex.h>
39 #include <ddb/db_variables.h>
41 static int db_find_variable (struct db_variable **varp);
42 static void db_write_variable (struct db_variable *, db_expr_t *);
44 #ifdef notused
45 static int db_set_variable (db_expr_t value);
46 #endif
48 static struct db_variable db_vars[] = {
49 { "radix", &db_radix, NULL },
50 { "maxoff", &db_maxoff, NULL },
51 { "maxwidth", &db_max_width, NULL },
52 { "tabstops", &db_tab_stop_width, NULL },
54 static struct db_variable *db_evars = db_vars + NELEM(db_vars);
56 static int
57 db_find_variable(struct db_variable **varp)
59 int t;
60 struct db_variable *vp;
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);
70 for (vp = db_regs; vp < db_eregs; vp++) {
71 if (!strcmp(db_tok_string, vp->name)) {
72 *varp = vp;
73 return (1);
77 db_error("Unknown variable\n");
78 return (0);
81 int
82 db_get_variable(db_expr_t *valuep)
84 struct db_variable *vp;
86 if (!db_find_variable(&vp))
87 return (0);
89 db_read_variable(vp, valuep);
91 return (1);
94 #ifdef notused
95 static int
96 db_set_variable(db_expr_t value)
98 struct db_variable *vp;
100 if (!db_find_variable(&vp))
101 return (0);
103 db_write_variable(vp, &value);
105 return (1);
107 #endif
109 void
110 db_read_variable(struct db_variable *vp, db_expr_t *valuep)
112 db_varfcn_t *func = vp->fcn;
114 if (func == NULL)
115 *valuep = *(vp->valuep);
116 else
117 (*func)(vp, valuep, DB_VAR_GET);
120 static void
121 db_write_variable(struct db_variable *vp, db_expr_t *valuep)
123 db_varfcn_t *func = vp->fcn;
125 if (func == NULL)
126 *(vp->valuep) = *valuep;
127 else
128 (*func)(vp, valuep, DB_VAR_SET);
131 void
132 db_set_cmd(db_expr_t dummy1, boolean_t dummy2, db_expr_t dummy3, char *dummy4)
134 db_expr_t value;
135 struct db_variable *vp;
136 int t;
138 t = db_read_token();
139 if (t != tDOLLAR) {
140 db_error("Unknown variable\n");
141 return;
143 if (!db_find_variable(&vp)) {
144 db_error("Unknown variable\n");
145 return;
148 t = db_read_token();
149 if (t != tEQ)
150 db_unread_token(t);
152 if (!db_expression(&value)) {
153 db_error("No value\n");
154 return;
156 if (db_read_token() != tEOL) {
157 db_error("?\n");
160 db_write_variable(vp, &value);