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 * $Id: db_variables.c,v 1.5 1994/08/18 22:34:27 wollman Exp $ 27 */ 28 29 /* 30 * Author: David B. Golub, Carnegie Mellon University 31 * Date: 7/90 32 */ 33 34 #include <sys/param.h> 35 #include <sys/systm.h> 36 #include <sys/proc.h> 37 #include <ddb/ddb.h> 38 39 #include <ddb/db_lex.h> 40 #include <ddb/db_variables.h> 41 42 static void db_write_variable(struct db_variable *, db_expr_t *); 43 44 struct db_variable db_vars[] = { 45 { "radix", &db_radix, FCN_NULL }, 46 { "maxoff", (int *)&db_maxoff, FCN_NULL }, 47 { "maxwidth", &db_max_width, FCN_NULL }, 48 { "tabstops", &db_tab_stop_width, FCN_NULL }, 49 }; 50 struct db_variable *db_evars = db_vars + sizeof(db_vars)/sizeof(db_vars[0]); 51 52 int 53 db_find_variable(varp) 54 struct db_variable **varp; 55 { 56 int t; 57 struct db_variable *vp; 58 59 t = db_read_token(); 60 if (t == tIDENT) { 61 for (vp = db_vars; vp < db_evars; vp++) { 62 if (!strcmp(db_tok_string, vp->name)) { 63 *varp = vp; 64 return (1); 65 } 66 } 67 for (vp = db_regs; vp < db_eregs; vp++) { 68 if (!strcmp(db_tok_string, vp->name)) { 69 *varp = vp; 70 return (1); 71 } 72 } 73 } 74 db_error("Unknown variable\n"); 75 return (0); 76 } 77 78 int 79 db_get_variable(valuep) 80 db_expr_t *valuep; 81 { 82 struct db_variable *vp; 83 84 if (!db_find_variable(&vp)) 85 return (0); 86 87 db_read_variable(vp, valuep); 88 89 return (1); 90 } 91 92 int 93 db_set_variable(value) 94 db_expr_t value; 95 { 96 struct db_variable *vp; 97 98 if (!db_find_variable(&vp)) 99 return (0); 100 101 db_write_variable(vp, &value); 102 103 return (1); 104 } 105 106 107 void 108 db_read_variable(vp, valuep) 109 struct db_variable *vp; 110 db_expr_t *valuep; 111 { 112 int (*func)() = vp->fcn; 113 114 if (func == FCN_NULL) 115 *valuep = *(vp->valuep); 116 else 117 (*func)(vp, valuep, DB_VAR_GET); 118 } 119 120 static void 121 db_write_variable(vp, valuep) 122 struct db_variable *vp; 123 db_expr_t *valuep; 124 { 125 int (*func)() = vp->fcn; 126 127 if (func == FCN_NULL) 128 *(vp->valuep) = *valuep; 129 else 130 (*func)(vp, valuep, DB_VAR_SET); 131 } 132 133 void 134 db_set_cmd(db_expr_t dummy1, int dummy2, db_expr_t dummy3, char *dummy4) 135 { 136 db_expr_t value; 137 struct db_variable *vp; 138 int t; 139 140 t = db_read_token(); 141 if (t != tDOLLAR) { 142 db_error("Unknown variable\n"); 143 return; 144 } 145 if (!db_find_variable(&vp)) { 146 db_error("Unknown variable\n"); 147 return; 148 } 149 150 t = db_read_token(); 151 if (t != tEQ) 152 db_unread_token(t); 153 154 if (!db_expression(&value)) { 155 db_error("No value\n"); 156 return; 157 } 158 if (db_read_token() != tEOL) { 159 db_error("?\n"); 160 } 161 162 db_write_variable(vp, &value); 163 } 164