Annotation of Net2/ddb/db_variables.c, revision 1.1.1.2

1.1       root        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  [email protected]
                     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: /*
                     27:  * HISTORY
                     28:  * $Log: db_variables.c,v $
1.1.1.2 ! root       29:  * Revision 1.1.1.1  1993/03/21 09:46:27  cgd
        !            30:  * initial import of 386bsd-0.1 sources
        !            31:  *
1.1       root       32:  * Revision 1.1  1992/03/25  21:45:33  pace
                     33:  * Initial revision
                     34:  *
                     35:  * Revision 2.3  91/02/05  17:07:19  mrt
                     36:  *     Changed to new Mach copyright
                     37:  *     [91/01/31  16:19:46  mrt]
                     38:  * 
                     39:  * Revision 2.2  90/08/27  21:53:24  dbg
                     40:  *     New db_read/write_variable functions.  Should be used instead
                     41:  *     of dereferencing valuep directly, which might not be a true
                     42:  *     pointer if there is an fcn() access function.
                     43:  *     [90/08/20            af]
                     44:  * 
                     45:  *     Fix declarations.
                     46:  *     Check for trailing garbage after last expression on command line.
                     47:  *     [90/08/10  14:34:54  dbg]
                     48:  * 
                     49:  *     Created.
                     50:  *     [90/07/25            dbg]
                     51:  * 
                     52:  */
                     53: /*
                     54:  *     Author: David B. Golub, Carnegie Mellon University
                     55:  *     Date:   7/90
                     56:  */
                     57: 
                     58: #include "param.h"
                     59: #include "proc.h"
                     60: #include <machine/db_machdep.h>
                     61: 
                     62: #include <ddb/db_lex.h>
                     63: #include <ddb/db_variables.h>
                     64: 
                     65: extern unsigned int    db_maxoff;
                     66: 
                     67: extern int     db_radix;
                     68: extern int     db_max_width;
                     69: extern int     db_tab_stop_width;
                     70: 
                     71: struct db_variable db_vars[] = {
                     72:        { "radix",      &db_radix, FCN_NULL },
                     73:        { "maxoff",     (int *)&db_maxoff, FCN_NULL },
                     74:        { "maxwidth",   &db_max_width, FCN_NULL },
                     75:        { "tabstops",   &db_tab_stop_width, FCN_NULL },
                     76: };
                     77: struct db_variable *db_evars = db_vars + sizeof(db_vars)/sizeof(db_vars[0]);
                     78: 
                     79: int
                     80: db_find_variable(varp)
                     81:        struct db_variable      **varp;
                     82: {
                     83:        int     t;
                     84:        struct db_variable *vp;
                     85: 
                     86:        t = db_read_token();
                     87:        if (t == tIDENT) {
                     88:            for (vp = db_vars; vp < db_evars; vp++) {
                     89:                if (!strcmp(db_tok_string, vp->name)) {
                     90:                    *varp = vp;
                     91:                    return (1);
                     92:                }
                     93:            }
                     94:            for (vp = db_regs; vp < db_eregs; vp++) {
                     95:                if (!strcmp(db_tok_string, vp->name)) {
                     96:                    *varp = vp;
                     97:                    return (1);
                     98:                }
                     99:            }
                    100:        }
                    101:        db_error("Unknown variable\n");
                    102:        return (0);
                    103: }
                    104: 
                    105: int
                    106: db_get_variable(valuep)
                    107:        db_expr_t       *valuep;
                    108: {
                    109:        struct db_variable *vp;
                    110: 
                    111:        if (!db_find_variable(&vp))
                    112:            return (0);
                    113: 
                    114:        db_read_variable(vp, valuep);
                    115: 
                    116:        return (1);
                    117: }
                    118: 
                    119: int
                    120: db_set_variable(value)
                    121:        db_expr_t       value;
                    122: {
                    123:        struct db_variable *vp;
                    124: 
                    125:        if (!db_find_variable(&vp))
                    126:            return (0);
                    127: 
                    128:        db_write_variable(vp, &value);
                    129: 
                    130:        return (1);
                    131: }
                    132: 
                    133: 
                    134: db_read_variable(vp, valuep)
                    135:        struct db_variable *vp;
                    136:        db_expr_t       *valuep;
                    137: {
                    138:        int     (*func)() = vp->fcn;
                    139: 
                    140:        if (func == FCN_NULL)
                    141:            *valuep = *(vp->valuep);
                    142:        else
                    143:            (*func)(vp, valuep, DB_VAR_GET);
                    144: }
                    145: 
                    146: db_write_variable(vp, valuep)
                    147:        struct db_variable *vp;
                    148:        db_expr_t       *valuep;
                    149: {
                    150:        int     (*func)() = vp->fcn;
                    151: 
                    152:        if (func == FCN_NULL)
                    153:            *(vp->valuep) = *valuep;
                    154:        else
                    155:            (*func)(vp, valuep, DB_VAR_SET);
                    156: }
                    157: 
                    158: void
                    159: db_set_cmd()
                    160: {
                    161:        db_expr_t       value;
                    162:        int     (*func)();
                    163:        struct db_variable *vp;
                    164:        int     t;
                    165: 
                    166:        t = db_read_token();
                    167:        if (t != tDOLLAR) {
                    168:            db_error("Unknown variable\n");
                    169:            return;
                    170:        }
                    171:        if (!db_find_variable(&vp)) {
                    172:            db_error("Unknown variable\n");
                    173:            return;
                    174:        }
                    175: 
                    176:        t = db_read_token();
                    177:        if (t != tEQ)
                    178:            db_unread_token(t);
                    179: 
                    180:        if (!db_expression(&value)) {
                    181:            db_error("No value\n");
                    182:            return;
                    183:        }
                    184:        if (db_read_token() != tEOL) {
                    185:            db_error("?\n");
                    186:        }
                    187: 
                    188:        db_write_variable(vp, &value);
                    189: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.