db_variables.c revision 2056
14Srgrimes/* 24Srgrimes * Mach Operating System 34Srgrimes * Copyright (c) 1991,1990 Carnegie Mellon University 44Srgrimes * All Rights Reserved. 54Srgrimes * 64Srgrimes * Permission to use, copy, modify and distribute this software and its 74Srgrimes * documentation is hereby granted, provided that both the copyright 84Srgrimes * notice and this permission notice appear in all copies of the 94Srgrimes * software, derivative works or modified versions, and any portions 104Srgrimes * thereof, and that both notices appear in supporting documentation. 114Srgrimes * 124Srgrimes * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS 134Srgrimes * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 144Srgrimes * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 154Srgrimes * 164Srgrimes * Carnegie Mellon requests users of this software to return to 174Srgrimes * 184Srgrimes * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 194Srgrimes * School of Computer Science 204Srgrimes * Carnegie Mellon University 214Srgrimes * Pittsburgh PA 15213-3890 224Srgrimes * 234Srgrimes * any improvements or extensions that they make and grant Carnegie the 244Srgrimes * rights to redistribute these changes. 254Srgrimes * 262056Swollman * $Id: db_variables.c,v 1.3 1993/11/25 01:30:13 wollman Exp $ 274Srgrimes */ 28623Srgrimes 294Srgrimes/* 304Srgrimes * Author: David B. Golub, Carnegie Mellon University 314Srgrimes * Date: 7/90 324Srgrimes */ 334Srgrimes 342056Swollman#include <sys/param.h> 352056Swollman#include <sys/systm.h> 362056Swollman#include <sys/proc.h> 372056Swollman#include <ddb/ddb.h> 384Srgrimes 394Srgrimes#include <ddb/db_lex.h> 404Srgrimes#include <ddb/db_variables.h> 414Srgrimes 42798Swollmanvoid db_read_variable(struct db_variable *, db_expr_t *); 43798Swollmanstatic void db_write_variable(struct db_variable *, db_expr_t *); 444Srgrimes 454Srgrimesstruct db_variable db_vars[] = { 464Srgrimes { "radix", &db_radix, FCN_NULL }, 474Srgrimes { "maxoff", (int *)&db_maxoff, FCN_NULL }, 484Srgrimes { "maxwidth", &db_max_width, FCN_NULL }, 494Srgrimes { "tabstops", &db_tab_stop_width, FCN_NULL }, 504Srgrimes}; 514Srgrimesstruct db_variable *db_evars = db_vars + sizeof(db_vars)/sizeof(db_vars[0]); 524Srgrimes 534Srgrimesint 544Srgrimesdb_find_variable(varp) 554Srgrimes struct db_variable **varp; 564Srgrimes{ 574Srgrimes int t; 584Srgrimes struct db_variable *vp; 594Srgrimes 604Srgrimes t = db_read_token(); 614Srgrimes if (t == tIDENT) { 624Srgrimes for (vp = db_vars; vp < db_evars; vp++) { 634Srgrimes if (!strcmp(db_tok_string, vp->name)) { 644Srgrimes *varp = vp; 654Srgrimes return (1); 664Srgrimes } 674Srgrimes } 684Srgrimes for (vp = db_regs; vp < db_eregs; vp++) { 694Srgrimes if (!strcmp(db_tok_string, vp->name)) { 704Srgrimes *varp = vp; 714Srgrimes return (1); 724Srgrimes } 734Srgrimes } 744Srgrimes } 754Srgrimes db_error("Unknown variable\n"); 764Srgrimes return (0); 774Srgrimes} 784Srgrimes 794Srgrimesint 804Srgrimesdb_get_variable(valuep) 814Srgrimes db_expr_t *valuep; 824Srgrimes{ 834Srgrimes struct db_variable *vp; 844Srgrimes 854Srgrimes if (!db_find_variable(&vp)) 864Srgrimes return (0); 874Srgrimes 884Srgrimes db_read_variable(vp, valuep); 894Srgrimes 904Srgrimes return (1); 914Srgrimes} 924Srgrimes 934Srgrimesint 944Srgrimesdb_set_variable(value) 954Srgrimes db_expr_t value; 964Srgrimes{ 974Srgrimes struct db_variable *vp; 984Srgrimes 994Srgrimes if (!db_find_variable(&vp)) 1004Srgrimes return (0); 1014Srgrimes 1024Srgrimes db_write_variable(vp, &value); 1034Srgrimes 1044Srgrimes return (1); 1054Srgrimes} 1064Srgrimes 1074Srgrimes 108798Swollmanvoid 1094Srgrimesdb_read_variable(vp, valuep) 1104Srgrimes struct db_variable *vp; 1114Srgrimes db_expr_t *valuep; 1124Srgrimes{ 1134Srgrimes int (*func)() = vp->fcn; 1144Srgrimes 1154Srgrimes if (func == FCN_NULL) 1164Srgrimes *valuep = *(vp->valuep); 1174Srgrimes else 1184Srgrimes (*func)(vp, valuep, DB_VAR_GET); 1194Srgrimes} 1204Srgrimes 121798Swollmanstatic void 1224Srgrimesdb_write_variable(vp, valuep) 1234Srgrimes struct db_variable *vp; 1244Srgrimes db_expr_t *valuep; 1254Srgrimes{ 1264Srgrimes int (*func)() = vp->fcn; 1274Srgrimes 1284Srgrimes if (func == FCN_NULL) 1294Srgrimes *(vp->valuep) = *valuep; 1304Srgrimes else 1314Srgrimes (*func)(vp, valuep, DB_VAR_SET); 1324Srgrimes} 1334Srgrimes 1344Srgrimesvoid 135798Swollmandb_set_cmd(db_expr_t dummy1, int dummy2, db_expr_t dummy3, char *dummy4) 1364Srgrimes{ 1374Srgrimes db_expr_t value; 1384Srgrimes int (*func)(); 1394Srgrimes struct db_variable *vp; 1404Srgrimes int t; 1414Srgrimes 1424Srgrimes t = db_read_token(); 1434Srgrimes if (t != tDOLLAR) { 1444Srgrimes db_error("Unknown variable\n"); 1454Srgrimes return; 1464Srgrimes } 1474Srgrimes if (!db_find_variable(&vp)) { 1484Srgrimes db_error("Unknown variable\n"); 1494Srgrimes return; 1504Srgrimes } 1514Srgrimes 1524Srgrimes t = db_read_token(); 1534Srgrimes if (t != tEQ) 1544Srgrimes db_unread_token(t); 1554Srgrimes 1564Srgrimes if (!db_expression(&value)) { 1574Srgrimes db_error("No value\n"); 1584Srgrimes return; 1594Srgrimes } 1604Srgrimes if (db_read_token() != tEOL) { 1614Srgrimes db_error("?\n"); 1624Srgrimes } 1634Srgrimes 1644Srgrimes db_write_variable(vp, &value); 1654Srgrimes} 166