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