Home | History | Annotate | Line # | Download | only in ddb
db_variables.c revision 1.5
      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 (at) 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 1993/12/18 04:46:42 mycroft Exp $
     27  */
     28 
     29 #include <sys/param.h>
     30 #include <sys/proc.h>
     31 
     32 #include <machine/db_machdep.h>
     33 
     34 #include <ddb/db_lex.h>
     35 #include <ddb/db_variables.h>
     36 
     37 extern unsigned int	db_maxoff;
     38 
     39 extern int	db_radix;
     40 extern int	db_max_width;
     41 extern int	db_tab_stop_width;
     42 extern int	db_max_line;
     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 	{ "lines",	&db_max_line, FCN_NULL },
     50 };
     51 struct db_variable *db_evars = db_vars + sizeof(db_vars)/sizeof(db_vars[0]);
     52 
     53 int
     54 db_find_variable(varp)
     55 	struct db_variable	**varp;
     56 {
     57 	int	t;
     58 	struct db_variable *vp;
     59 
     60 	t = db_read_token();
     61 	if (t == tIDENT) {
     62 	    for (vp = db_vars; vp < db_evars; vp++) {
     63 		if (!strcmp(db_tok_string, vp->name)) {
     64 		    *varp = vp;
     65 		    return (1);
     66 		}
     67 	    }
     68 	    for (vp = db_regs; vp < db_eregs; vp++) {
     69 		if (!strcmp(db_tok_string, vp->name)) {
     70 		    *varp = vp;
     71 		    return (1);
     72 		}
     73 	    }
     74 	}
     75 	db_error("Unknown variable\n");
     76 	return (0);
     77 }
     78 
     79 int
     80 db_get_variable(valuep)
     81 	db_expr_t	*valuep;
     82 {
     83 	struct db_variable *vp;
     84 
     85 	if (!db_find_variable(&vp))
     86 	    return (0);
     87 
     88 	db_read_variable(vp, valuep);
     89 
     90 	return (1);
     91 }
     92 
     93 int
     94 db_set_variable(value)
     95 	db_expr_t	value;
     96 {
     97 	struct db_variable *vp;
     98 
     99 	if (!db_find_variable(&vp))
    100 	    return (0);
    101 
    102 	db_write_variable(vp, &value);
    103 
    104 	return (1);
    105 }
    106 
    107 
    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 db_write_variable(vp, valuep)
    121 	struct db_variable *vp;
    122 	db_expr_t	*valuep;
    123 {
    124 	int	(*func)() = vp->fcn;
    125 
    126 	if (func == FCN_NULL)
    127 	    *(vp->valuep) = *valuep;
    128 	else
    129 	    (*func)(vp, valuep, DB_VAR_SET);
    130 }
    131 
    132 void
    133 db_set_cmd()
    134 {
    135 	db_expr_t	value;
    136 	int	(*func)();
    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