xref: /freebsd/sys/ddb/db_variables.c (revision 5ccbc3cc5aa70fee35bc061ab0e4fadcf67ad335)
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  *
265ccbc3ccSBruce Evans  *	$Id: db_variables.c,v 1.10 1995/12/07 12:45:04 davidg 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>
365b81b6b3SRodney W. Grimes 
375ccbc3ccSBruce Evans #include <ddb/ddb.h>
385b81b6b3SRodney W. Grimes #include <ddb/db_lex.h>
395b81b6b3SRodney W. Grimes #include <ddb/db_variables.h>
405b81b6b3SRodney W. Grimes 
41f73a856dSPoul-Henning Kamp static int	db_find_variable __P((struct db_variable **varp));
42058284fcSBruce Evans static void	db_write_variable __P((struct db_variable *, db_expr_t *));
435b81b6b3SRodney W. Grimes 
44f73a856dSPoul-Henning Kamp #ifdef notused
45f73a856dSPoul-Henning Kamp static int	db_set_variable __P((db_expr_t value));
46f73a856dSPoul-Henning Kamp #endif
47f73a856dSPoul-Henning Kamp 
48f73a856dSPoul-Henning Kamp static struct db_variable db_vars[] = {
495b81b6b3SRodney W. Grimes 	{ "radix",	&db_radix, FCN_NULL },
505b81b6b3SRodney W. Grimes 	{ "maxoff",	(int *)&db_maxoff, FCN_NULL },
515b81b6b3SRodney W. Grimes 	{ "maxwidth",	&db_max_width, FCN_NULL },
525b81b6b3SRodney W. Grimes 	{ "tabstops",	&db_tab_stop_width, FCN_NULL },
535b81b6b3SRodney W. Grimes };
54f73a856dSPoul-Henning Kamp static struct db_variable *db_evars =
55f73a856dSPoul-Henning Kamp 		db_vars + sizeof(db_vars)/sizeof(db_vars[0]);
565b81b6b3SRodney W. Grimes 
57f73a856dSPoul-Henning Kamp static int
585b81b6b3SRodney W. Grimes db_find_variable(varp)
595b81b6b3SRodney W. Grimes 	struct db_variable	**varp;
605b81b6b3SRodney W. Grimes {
615b81b6b3SRodney W. Grimes 	int	t;
625b81b6b3SRodney W. Grimes 	struct db_variable *vp;
635b81b6b3SRodney W. Grimes 
645b81b6b3SRodney W. Grimes 	t = db_read_token();
655b81b6b3SRodney W. Grimes 	if (t == tIDENT) {
665b81b6b3SRodney W. Grimes 	    for (vp = db_vars; vp < db_evars; vp++) {
675b81b6b3SRodney W. Grimes 		if (!strcmp(db_tok_string, vp->name)) {
685b81b6b3SRodney W. Grimes 		    *varp = vp;
695b81b6b3SRodney W. Grimes 		    return (1);
705b81b6b3SRodney W. Grimes 		}
715b81b6b3SRodney W. Grimes 	    }
725b81b6b3SRodney W. Grimes 	    for (vp = db_regs; vp < db_eregs; vp++) {
735b81b6b3SRodney W. Grimes 		if (!strcmp(db_tok_string, vp->name)) {
745b81b6b3SRodney W. Grimes 		    *varp = vp;
755b81b6b3SRodney W. Grimes 		    return (1);
765b81b6b3SRodney W. Grimes 		}
775b81b6b3SRodney W. Grimes 	    }
785b81b6b3SRodney W. Grimes 	}
795b81b6b3SRodney W. Grimes 	db_error("Unknown variable\n");
805b81b6b3SRodney W. Grimes 	return (0);
815b81b6b3SRodney W. Grimes }
825b81b6b3SRodney W. Grimes 
835b81b6b3SRodney W. Grimes int
845b81b6b3SRodney W. Grimes db_get_variable(valuep)
855b81b6b3SRodney W. Grimes 	db_expr_t	*valuep;
865b81b6b3SRodney W. Grimes {
875b81b6b3SRodney W. Grimes 	struct db_variable *vp;
885b81b6b3SRodney W. Grimes 
895b81b6b3SRodney W. Grimes 	if (!db_find_variable(&vp))
905b81b6b3SRodney W. Grimes 	    return (0);
915b81b6b3SRodney W. Grimes 
925b81b6b3SRodney W. Grimes 	db_read_variable(vp, valuep);
935b81b6b3SRodney W. Grimes 
945b81b6b3SRodney W. Grimes 	return (1);
955b81b6b3SRodney W. Grimes }
965b81b6b3SRodney W. Grimes 
97f73a856dSPoul-Henning Kamp #ifdef notused
98f73a856dSPoul-Henning Kamp static int
995b81b6b3SRodney W. Grimes db_set_variable(value)
1005b81b6b3SRodney W. Grimes 	db_expr_t	value;
1015b81b6b3SRodney W. Grimes {
1025b81b6b3SRodney W. Grimes 	struct db_variable *vp;
1035b81b6b3SRodney W. Grimes 
1045b81b6b3SRodney W. Grimes 	if (!db_find_variable(&vp))
1055b81b6b3SRodney W. Grimes 	    return (0);
1065b81b6b3SRodney W. Grimes 
1075b81b6b3SRodney W. Grimes 	db_write_variable(vp, &value);
1085b81b6b3SRodney W. Grimes 
1095b81b6b3SRodney W. Grimes 	return (1);
1105b81b6b3SRodney W. Grimes }
111f73a856dSPoul-Henning Kamp #endif
1125b81b6b3SRodney W. Grimes 
113381fe1aaSGarrett Wollman void
1145b81b6b3SRodney W. Grimes db_read_variable(vp, valuep)
1155b81b6b3SRodney W. Grimes 	struct db_variable *vp;
1165b81b6b3SRodney W. Grimes 	db_expr_t	*valuep;
1175b81b6b3SRodney W. Grimes {
118058284fcSBruce Evans 	db_varfcn_t	*func = vp->fcn;
1195b81b6b3SRodney W. Grimes 
1205b81b6b3SRodney W. Grimes 	if (func == FCN_NULL)
1215b81b6b3SRodney W. Grimes 	    *valuep = *(vp->valuep);
1225b81b6b3SRodney W. Grimes 	else
1235b81b6b3SRodney W. Grimes 	    (*func)(vp, valuep, DB_VAR_GET);
1245b81b6b3SRodney W. Grimes }
1255b81b6b3SRodney W. Grimes 
126381fe1aaSGarrett Wollman static void
1275b81b6b3SRodney W. Grimes db_write_variable(vp, valuep)
1285b81b6b3SRodney W. Grimes 	struct db_variable *vp;
1295b81b6b3SRodney W. Grimes 	db_expr_t	*valuep;
1305b81b6b3SRodney W. Grimes {
131058284fcSBruce Evans 	db_varfcn_t	*func = vp->fcn;
1325b81b6b3SRodney W. Grimes 
1335b81b6b3SRodney W. Grimes 	if (func == FCN_NULL)
1345b81b6b3SRodney W. Grimes 	    *(vp->valuep) = *valuep;
1355b81b6b3SRodney W. Grimes 	else
1365b81b6b3SRodney W. Grimes 	    (*func)(vp, valuep, DB_VAR_SET);
1375b81b6b3SRodney W. Grimes }
1385b81b6b3SRodney W. Grimes 
1395b81b6b3SRodney W. Grimes void
140058284fcSBruce Evans db_set_cmd(dummy1, dummy2, dummy3, dummy4)
141058284fcSBruce Evans 	db_expr_t	dummy1;
142058284fcSBruce Evans 	boolean_t	dummy2;
143058284fcSBruce Evans 	db_expr_t	dummy3;
144058284fcSBruce Evans 	char *		dummy4;
1455b81b6b3SRodney W. Grimes {
1465b81b6b3SRodney W. Grimes 	db_expr_t	value;
1475b81b6b3SRodney W. Grimes 	struct db_variable *vp;
1485b81b6b3SRodney W. Grimes 	int	t;
1495b81b6b3SRodney W. Grimes 
1505b81b6b3SRodney W. Grimes 	t = db_read_token();
1515b81b6b3SRodney W. Grimes 	if (t != tDOLLAR) {
1525b81b6b3SRodney W. Grimes 	    db_error("Unknown variable\n");
1535b81b6b3SRodney W. Grimes 	    return;
1545b81b6b3SRodney W. Grimes 	}
1555b81b6b3SRodney W. Grimes 	if (!db_find_variable(&vp)) {
1565b81b6b3SRodney W. Grimes 	    db_error("Unknown variable\n");
1575b81b6b3SRodney W. Grimes 	    return;
1585b81b6b3SRodney W. Grimes 	}
1595b81b6b3SRodney W. Grimes 
1605b81b6b3SRodney W. Grimes 	t = db_read_token();
1615b81b6b3SRodney W. Grimes 	if (t != tEQ)
1625b81b6b3SRodney W. Grimes 	    db_unread_token(t);
1635b81b6b3SRodney W. Grimes 
1645b81b6b3SRodney W. Grimes 	if (!db_expression(&value)) {
1655b81b6b3SRodney W. Grimes 	    db_error("No value\n");
1665b81b6b3SRodney W. Grimes 	    return;
1675b81b6b3SRodney W. Grimes 	}
1685b81b6b3SRodney W. Grimes 	if (db_read_token() != tEOL) {
1695b81b6b3SRodney W. Grimes 	    db_error("?\n");
1705b81b6b3SRodney W. Grimes 	}
1715b81b6b3SRodney W. Grimes 
1725b81b6b3SRodney W. Grimes 	db_write_variable(vp, &value);
1735b81b6b3SRodney W. Grimes }
174