The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/ddb/db_variables.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    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@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 /*
   27  *      Author: David B. Golub, Carnegie Mellon University
   28  *      Date:   7/90
   29  */
   30 
   31 #include <sys/cdefs.h>
   32 __FBSDID("$FreeBSD: releng/6.2/sys/ddb/db_variables.c 139747 2005-01-06 01:34:41Z imp $");
   33 
   34 #include <sys/param.h>
   35 #include <sys/systm.h>
   36 
   37 #include <ddb/ddb.h>
   38 #include <ddb/db_lex.h>
   39 #include <ddb/db_variables.h>
   40 
   41 static int      db_find_variable(struct db_variable **varp);
   42 
   43 static struct db_variable db_vars[] = {
   44         { "radix",      &db_radix, FCN_NULL },
   45         { "maxoff",     &db_maxoff, FCN_NULL },
   46         { "maxwidth",   &db_max_width, FCN_NULL },
   47         { "tabstops",   &db_tab_stop_width, FCN_NULL },
   48         { "lines",      &db_lines_per_page, FCN_NULL },
   49 };
   50 static struct db_variable *db_evars =
   51         db_vars + sizeof(db_vars)/sizeof(db_vars[0]);
   52 
   53 static int
   54 db_find_variable(struct db_variable **varp)
   55 {
   56         struct db_variable *vp;
   57         int t;
   58 
   59         t = db_read_token();
   60         if (t == tIDENT) {
   61                 for (vp = db_vars; vp < db_evars; vp++) {
   62                         if (!strcmp(db_tok_string, vp->name)) {
   63                                 *varp = vp;
   64                                 return (1);
   65                         }
   66                 }
   67                 for (vp = db_regs; vp < db_eregs; vp++) {
   68                         if (!strcmp(db_tok_string, vp->name)) {
   69                                 *varp = vp;
   70                                 return (1);
   71                         }
   72                 }
   73         }
   74         db_error("Unknown variable\n");
   75         return (0);
   76 }
   77 
   78 int
   79 db_get_variable(db_expr_t *valuep)
   80 {
   81         struct db_variable *vp;
   82 
   83         if (!db_find_variable(&vp))
   84                 return (0);
   85 
   86         return (db_read_variable(vp, valuep));
   87 }
   88 
   89 int
   90 db_set_variable(db_expr_t value)
   91 {
   92         struct db_variable *vp;
   93 
   94         if (!db_find_variable(&vp))
   95                 return (0);
   96 
   97         return (db_write_variable(vp, value));
   98 }
   99 
  100 int
  101 db_read_variable(struct db_variable *vp, db_expr_t *valuep)
  102 {
  103         db_varfcn_t *func = vp->fcn;
  104 
  105         if (func == FCN_NULL) {
  106                 *valuep = *(vp->valuep);
  107                 return (1);
  108         }
  109         return ((*func)(vp, valuep, DB_VAR_GET));
  110 }
  111 
  112 int
  113 db_write_variable(struct db_variable *vp, db_expr_t value)
  114 {
  115         db_varfcn_t *func = vp->fcn;
  116 
  117         if (func == FCN_NULL) {
  118                 *(vp->valuep) = value;
  119                 return (1);
  120         }
  121         return ((*func)(vp, &value, DB_VAR_SET));
  122 }
  123 
  124 void
  125 db_set_cmd(db_expr_t dummy1, boolean_t dummy2, db_expr_t dummy3, char *dummy4)
  126 {
  127         struct db_variable *vp;
  128         db_expr_t value;
  129         int t;
  130 
  131         t = db_read_token();
  132         if (t != tDOLLAR) {
  133                 db_error("Unknown variable\n");
  134                 return;
  135         }
  136         if (!db_find_variable(&vp)) {
  137                 db_error("Unknown variable\n");
  138                 return;
  139         }
  140 
  141         t = db_read_token();
  142         if (t != tEQ)
  143                 db_unread_token(t);
  144 
  145         if (!db_expression(&value)) {
  146                 db_error("No value\n");
  147                 return;
  148         }
  149         if (db_read_token() != tEOL)
  150                 db_error("?\n");
  151 
  152         db_write_variable(vp, value);
  153 }

Cache object: 0ee099d52d96a7c8c3f8dc8c1bf132fe


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.