xref: /freebsd/sys/ddb/db_variables.c (revision f73a856d2385c41dae0d1bacc12bda6b031f47e7)
15b81b6b3SRodney W. Grimes /*
25b81b6b3SRodney W. Grimes  * Mach Operating System
35b81b6b3SRodney W. Grimes  * Copyright (c) 1991,1990 Carnegie Mellon University
45b81b6b3SRodney W. Grimes  * All Rights Reserved.
55b81b6b3SRodney W. Grimes  *
65b81b6b3SRodney W. Grimes  * Permission to use, copy, modify and distribute this software and its
75b81b6b3SRodney W. Grimes  * documentation is hereby granted, provided that both the copyright
85b81b6b3SRodney W. Grimes  * notice and this permission notice appear in all copies of the
95b81b6b3SRodney W. Grimes  * software, derivative works or modified versions, and any portions
105b81b6b3SRodney W. Grimes  * thereof, and that both notices appear in supporting documentation.
115b81b6b3SRodney W. Grimes  *
125b81b6b3SRodney W. Grimes  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
135b81b6b3SRodney W. Grimes  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
145b81b6b3SRodney W. Grimes  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
155b81b6b3SRodney W. Grimes  *
165b81b6b3SRodney W. Grimes  * Carnegie Mellon requests users of this software to return to
175b81b6b3SRodney W. Grimes  *
185b81b6b3SRodney W. Grimes  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
195b81b6b3SRodney W. Grimes  *  School of Computer Science
205b81b6b3SRodney W. Grimes  *  Carnegie Mellon University
215b81b6b3SRodney W. Grimes  *  Pittsburgh PA 15213-3890
225b81b6b3SRodney W. Grimes  *
235b81b6b3SRodney W. Grimes  * any improvements or extensions that they make and grant Carnegie the
245b81b6b3SRodney W. Grimes  * rights to redistribute these changes.
250edf66ecSRodney W. Grimes  *
26f73a856dSPoul-Henning Kamp  *	$Id: db_variables.c,v 1.8 1995/11/24 14:13:41 bde Exp $
275b81b6b3SRodney W. Grimes  */
280edf66ecSRodney W. Grimes 
295b81b6b3SRodney W. Grimes /*
305b81b6b3SRodney W. Grimes  * 	Author: David B. Golub, Carnegie Mellon University
315b81b6b3SRodney W. Grimes  *	Date:	7/90
325b81b6b3SRodney W. Grimes  */
335b81b6b3SRodney W. Grimes 
34f540b106SGarrett Wollman #include <sys/param.h>
35f540b106SGarrett Wollman #include <sys/systm.h>
36f540b106SGarrett Wollman #include <sys/proc.h>
37f540b106SGarrett Wollman #include <ddb/ddb.h>
385b81b6b3SRodney W. Grimes 
395b81b6b3SRodney W. Grimes #include <ddb/db_lex.h>
405b81b6b3SRodney W. Grimes #include <ddb/db_variables.h>
415b81b6b3SRodney W. Grimes 
42f73a856dSPoul-Henning Kamp static int	db_find_variable __P((struct db_variable **varp));
43058284fcSBruce Evans static void	db_write_variable __P((struct db_variable *, db_expr_t *));
445b81b6b3SRodney W. Grimes 
45f73a856dSPoul-Henning Kamp #ifdef notused
46f73a856dSPoul-Henning Kamp static int	db_set_variable __P((db_expr_t value));
47f73a856dSPoul-Henning Kamp #endif
48f73a856dSPoul-Henning Kamp 
49f73a856dSPoul-Henning Kamp static struct db_variable db_vars[] = {
505b81b6b3SRodney W. Grimes 	{ "radix",	&db_radix, FCN_NULL },
515b81b6b3SRodney W. Grimes 	{ "maxoff",	(int *)&db_maxoff, FCN_NULL },
525b81b6b3SRodney W. Grimes 	{ "maxwidth",	&db_max_width, FCN_NULL },
535b81b6b3SRodney W. Grimes 	{ "tabstops",	&db_tab_stop_width, FCN_NULL },
545b81b6b3SRodney W. Grimes };
55f73a856dSPoul-Henning Kamp static struct db_variable *db_evars =
56f73a856dSPoul-Henning Kamp 		db_vars + sizeof(db_vars)/sizeof(db_vars[0]);
575b81b6b3SRodney W. Grimes 
58f73a856dSPoul-Henning Kamp static int
595b81b6b3SRodney W. Grimes db_find_variable(varp)
605b81b6b3SRodney W. Grimes 	struct db_variable	**varp;
615b81b6b3SRodney W. Grimes {
625b81b6b3SRodney W. Grimes 	int	t;
635b81b6b3SRodney W. Grimes 	struct db_variable *vp;
645b81b6b3SRodney W. Grimes 
655b81b6b3SRodney W. Grimes 	t = db_read_token();
665b81b6b3SRodney W. Grimes 	if (t == tIDENT) {
675b81b6b3SRodney W. Grimes 	    for (vp = db_vars; vp < db_evars; vp++) {
685b81b6b3SRodney W. Grimes 		if (!strcmp(db_tok_string, vp->name)) {
695b81b6b3SRodney W. Grimes 		    *varp = vp;
705b81b6b3SRodney W. Grimes 		    return (1);
715b81b6b3SRodney W. Grimes 		}
725b81b6b3SRodney W. Grimes 	    }
735b81b6b3SRodney W. Grimes 	    for (vp = db_regs; vp < db_eregs; vp++) {
745b81b6b3SRodney W. Grimes 		if (!strcmp(db_tok_string, vp->name)) {
755b81b6b3SRodney W. Grimes 		    *varp = vp;
765b81b6b3SRodney W. Grimes 		    return (1);
775b81b6b3SRodney W. Grimes 		}
785b81b6b3SRodney W. Grimes 	    }
795b81b6b3SRodney W. Grimes 	}
805b81b6b3SRodney W. Grimes 	db_error("Unknown variable\n");
815b81b6b3SRodney W. Grimes 	return (0);
825b81b6b3SRodney W. Grimes }
835b81b6b3SRodney W. Grimes 
845b81b6b3SRodney W. Grimes int
855b81b6b3SRodney W. Grimes db_get_variable(valuep)
865b81b6b3SRodney W. Grimes 	db_expr_t	*valuep;
875b81b6b3SRodney W. Grimes {
885b81b6b3SRodney W. Grimes 	struct db_variable *vp;
895b81b6b3SRodney W. Grimes 
905b81b6b3SRodney W. Grimes 	if (!db_find_variable(&vp))
915b81b6b3SRodney W. Grimes 	    return (0);
925b81b6b3SRodney W. Grimes 
935b81b6b3SRodney W. Grimes 	db_read_variable(vp, valuep);
945b81b6b3SRodney W. Grimes 
955b81b6b3SRodney W. Grimes 	return (1);
965b81b6b3SRodney W. Grimes }
975b81b6b3SRodney W. Grimes 
98f73a856dSPoul-Henning Kamp #ifdef notused
99f73a856dSPoul-Henning Kamp static int
1005b81b6b3SRodney W. Grimes db_set_variable(value)
1015b81b6b3SRodney W. Grimes 	db_expr_t	value;
1025b81b6b3SRodney W. Grimes {
1035b81b6b3SRodney W. Grimes 	struct db_variable *vp;
1045b81b6b3SRodney W. Grimes 
1055b81b6b3SRodney W. Grimes 	if (!db_find_variable(&vp))
1065b81b6b3SRodney W. Grimes 	    return (0);
1075b81b6b3SRodney W. Grimes 
1085b81b6b3SRodney W. Grimes 	db_write_variable(vp, &value);
1095b81b6b3SRodney W. Grimes 
1105b81b6b3SRodney W. Grimes 	return (1);
1115b81b6b3SRodney W. Grimes }
112f73a856dSPoul-Henning Kamp #endif
1135b81b6b3SRodney W. Grimes 
114381fe1aaSGarrett Wollman void
1155b81b6b3SRodney W. Grimes db_read_variable(vp, valuep)
1165b81b6b3SRodney W. Grimes 	struct db_variable *vp;
1175b81b6b3SRodney W. Grimes 	db_expr_t	*valuep;
1185b81b6b3SRodney W. Grimes {
119058284fcSBruce Evans 	db_varfcn_t	*func = vp->fcn;
1205b81b6b3SRodney W. Grimes 
1215b81b6b3SRodney W. Grimes 	if (func == FCN_NULL)
1225b81b6b3SRodney W. Grimes 	    *valuep = *(vp->valuep);
1235b81b6b3SRodney W. Grimes 	else
1245b81b6b3SRodney W. Grimes 	    (*func)(vp, valuep, DB_VAR_GET);
1255b81b6b3SRodney W. Grimes }
1265b81b6b3SRodney W. Grimes 
127381fe1aaSGarrett Wollman static void
1285b81b6b3SRodney W. Grimes db_write_variable(vp, valuep)
1295b81b6b3SRodney W. Grimes 	struct db_variable *vp;
1305b81b6b3SRodney W. Grimes 	db_expr_t	*valuep;
1315b81b6b3SRodney W. Grimes {
132058284fcSBruce Evans 	db_varfcn_t	*func = vp->fcn;
1335b81b6b3SRodney W. Grimes 
1345b81b6b3SRodney W. Grimes 	if (func == FCN_NULL)
1355b81b6b3SRodney W. Grimes 	    *(vp->valuep) = *valuep;
1365b81b6b3SRodney W. Grimes 	else
1375b81b6b3SRodney W. Grimes 	    (*func)(vp, valuep, DB_VAR_SET);
1385b81b6b3SRodney W. Grimes }
1395b81b6b3SRodney W. Grimes 
1405b81b6b3SRodney W. Grimes void
141058284fcSBruce Evans db_set_cmd(dummy1, dummy2, dummy3, dummy4)
142058284fcSBruce Evans 	db_expr_t	dummy1;
143058284fcSBruce Evans 	boolean_t	dummy2;
144058284fcSBruce Evans 	db_expr_t	dummy3;
145058284fcSBruce Evans 	char *		dummy4;
1465b81b6b3SRodney W. Grimes {
1475b81b6b3SRodney W. Grimes 	db_expr_t	value;
1485b81b6b3SRodney W. Grimes 	struct db_variable *vp;
1495b81b6b3SRodney W. Grimes 	int	t;
1505b81b6b3SRodney W. Grimes 
1515b81b6b3SRodney W. Grimes 	t = db_read_token();
1525b81b6b3SRodney W. Grimes 	if (t != tDOLLAR) {
1535b81b6b3SRodney W. Grimes 	    db_error("Unknown variable\n");
1545b81b6b3SRodney W. Grimes 	    return;
1555b81b6b3SRodney W. Grimes 	}
1565b81b6b3SRodney W. Grimes 	if (!db_find_variable(&vp)) {
1575b81b6b3SRodney W. Grimes 	    db_error("Unknown variable\n");
1585b81b6b3SRodney W. Grimes 	    return;
1595b81b6b3SRodney W. Grimes 	}
1605b81b6b3SRodney W. Grimes 
1615b81b6b3SRodney W. Grimes 	t = db_read_token();
1625b81b6b3SRodney W. Grimes 	if (t != tEQ)
1635b81b6b3SRodney W. Grimes 	    db_unread_token(t);
1645b81b6b3SRodney W. Grimes 
1655b81b6b3SRodney W. Grimes 	if (!db_expression(&value)) {
1665b81b6b3SRodney W. Grimes 	    db_error("No value\n");
1675b81b6b3SRodney W. Grimes 	    return;
1685b81b6b3SRodney W. Grimes 	}
1695b81b6b3SRodney W. Grimes 	if (db_read_token() != tEOL) {
1705b81b6b3SRodney W. Grimes 	    db_error("?\n");
1715b81b6b3SRodney W. Grimes 	}
1725b81b6b3SRodney W. Grimes 
1735b81b6b3SRodney W. Grimes 	db_write_variable(vp, &value);
1745b81b6b3SRodney W. Grimes }
175