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