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

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

unix.superglobalmegacorp.com

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