1: /*
   2:  * Copyright (c) 1986 Regents of the University of California.
   3:  * All rights reserved.  The Berkeley software License Agreement
   4:  * specifies the terms and conditions for redistribution.
   5:  *
   6:  *	@(#)read_dtab.c	2.1 (2.11BSD GTE) 1/10/94
   7:  */
   8: 
   9: #include <machine/autoconfig.h>
  10: #include <sys/types.h>
  11: #include <stdio.h>
  12: #include <ctype.h>
  13: #include "dtab.h"
  14: #include "uprobe.h"
  15: 
  16: extern UPROBE   uprobe[];
  17: 
  18: int guess_ndev = 0;     /* Guess as to size of nlist table */
  19: #define STRSAVE(str)    (strcpy(malloc((u_int)(strlen(str) + 1)),str))
  20: 
  21: /*
  22:  * read the device table (/etc/dtab) into internal structures
  23:  * format of lines in the device table are:
  24:  *	device_name unit_number address vector br handler[0-3]	; comment
  25:  *								# comment
  26:  */
  27: read_dtab()
  28: {
  29:     register DTAB   *dp,
  30:             *cdp;
  31:     UPROBE  *up;
  32:     HAND    *sp;
  33:     FILE    *fp;
  34:     int nhandlers,  /* number of handlers per line */
  35:         line;       /* line number in dtab file */
  36:     short   cnt;        /* general counter */
  37:     char    *cp,        /* traveling char pointer */
  38:         *save,      /* save string position */
  39:         buf[500],   /* line buffer */
  40:         name[20],   /* device name */
  41:         unit[5],    /* unit number */
  42:         *index(), *malloc(), *strcpy(), *fgets();
  43: 
  44:     if (!(fp = fopen(dtab_name,"r"))) {
  45:         perror(dtab_name);
  46:         exit(AC_SETUP);
  47:     }
  48:     for (line = 1,devs = NULL;fgets(buf, sizeof(buf), fp);++line) {
  49:         if (cp = index(buf, '\n'))
  50:             *cp = EOS;
  51:         else {
  52:             fprintf(stderr,"%s: line %d too long.\n",myname,line);
  53:             exit(AC_SINGLE);
  54:         }
  55:         for (cp = buf;isspace(*cp);++cp);
  56:         if (!*cp || cp == ';' || *cp == '#')
  57:             continue;
  58:         dp = (DTAB *)malloc(sizeof(DTAB));
  59:         if (sscanf(buf," %s %s %o %o %o ",name,unit,&dp->dt_addr,&dp->dt_vector,&dp->dt_br) != 5) {
  60:             fprintf(stderr,"%s: missing information on line %d.\n",myname,line);
  61:             exit(AC_SINGLE);
  62:         }
  63:         dp->dt_name = STRSAVE(name);
  64:         dp->dt_unit = *unit == '?' ? -1 : atoi(unit);
  65:         for (cnt = 0;cnt < 5;++cnt) {
  66:             for (;!isspace(*cp);++cp);
  67:             for (;isspace(*cp);++cp);
  68:         }
  69:         dp->dt_probe = dp->dt_attach = (NLIST *)0;
  70:         dp->dt_handlers = (HAND *)0;
  71:         for (nhandlers = 0;;nhandlers) {
  72:             if (!*cp || *cp == ';' || *cp == '#')
  73:                 break;
  74:             if (++nhandlers == 4)
  75:                 fprintf(stderr,"%s: warning: more than three handlers for device %s on line %d.\n",myname,dp->dt_name,line);
  76:             for (save = cp;!isspace(*cp);++cp);
  77:             *cp = EOS;
  78:             addent(&dp->dt_handlers,STRSAVE(save));
  79:             for (++cp;isspace(*cp);++cp);
  80:         }
  81:         guess_ndev += nhandlers;
  82: /*
  83:  * In addition to the "handler" symbols for a device we need 3 more
  84:  * symbols: 'xxVec', 'xxprobe', and 'xxattach'.
  85:  *
  86:  * N.B.  If more symbols are added (to the 'DTAB' structure) the following
  87:  *       line may need to be modified.
  88: */
  89:         guess_ndev += 3;
  90:         for (up = uprobe;up->up_name;++up)
  91:             if (!strcmp(dp->dt_name,up->up_name)) {
  92:                 dp->dt_uprobe = up->up_func;
  93:                 break;
  94:             }
  95:         dp->dt_next = NULL;
  96:         if (!devs)
  97:             devs = cdp = dp;
  98:         else {
  99:             cdp->dt_next = dp;
 100:             cdp = dp;
 101:         }
 102:     }
 103: }
 104: 
 105: static
 106: addent(listp, cp)
 107: HAND    **listp;
 108: char    *cp;
 109: {
 110:     HAND    *el,
 111:         *sp;
 112:     char    *malloc();
 113: 
 114:     el = (HAND *)malloc(sizeof(HAND));
 115:     el->s_str = cp;
 116:     el->s_next = NULL;
 117:     if (!*listp)
 118:         *listp = el;
 119:     else {
 120:         for (sp = *listp;sp->s_next; sp = sp->s_next);
 121:         sp->s_next = el;
 122:     }
 123: }

Defined functions

addent defined in line 105; used 1 times
  • in line 78
read_dtab defined in line 27; used 1 times

Defined variables

guess_ndev defined in line 18; used 3 times

Defined macros

STRSAVE defined in line 19; used 2 times
Last modified: 1994-01-11
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2998
Valid CSS Valid XHTML 1.0 Strict