1: /*
   2:  * Read the device table into internal structures
   3:  */
   4: 
   5: #include    <stdio.h>
   6: #include    <ctype.h>
   7: #include    <sys/autoconfig.h>
   8: #include    "dtab.h"
   9: #include    "uprobe.h"
  10: 
  11: static int  line;       /* Line number in dtab file */
  12: FILE        *dtab_fp;   /* File pointer to dtab file */
  13: int     guess_ndev = 0; /* Guess as to size of nlist table */
  14: 
  15: otoi(cp)
  16: char *cp;
  17: {
  18:     int res;
  19: 
  20:     sscanf(cp, "%o", &res);
  21:     return res;
  22: }
  23: 
  24: int last_ch;    /* last character read by getword */
  25: 
  26: #define read_while(expr) while ((ch = getc(dtab_fp)) != EOF && (expr))
  27: char *getword()
  28: {
  29:     static char buf[80];
  30:     register int ch;
  31:     register char *cp;
  32: 
  33:     if (feof(dtab_fp))
  34:         return NULL;
  35:     /* First skip any white space */
  36: skip:
  37:     last_ch = EOF;
  38:     read_while(isspace(ch))
  39:         ;
  40:     if (ch == EOF)
  41:         return NULL;
  42: 
  43:     /* If its a comment, skip it too */
  44:     if (ch == '#') {
  45:         read_while(ch != '\n')
  46:             ;
  47:         if (ch == EOF)
  48:             return NULL;
  49:         goto skip;
  50:     }
  51:     cp = buf;
  52:     do {
  53:         *cp++ = ch;
  54:         *cp = '\0';
  55:         if ((ch = getc(dtab_fp)) == EOF)
  56:             return buf;
  57:     } while (!isspace(ch));
  58:     last_ch = ch;
  59:     return buf;
  60: }
  61: 
  62: char *nextword()
  63: {
  64:     register char *cp;
  65: 
  66:     if ((cp = getword()) == NULL) {
  67:         fprintf(stderr, "Syntax error, not enough data on line %d\n", line);
  68:         exit(AC_SINGLE);
  69:     }
  70:     return cp;
  71: }
  72: 
  73: /*
  74:  * Format of lines in the device table are:
  75:  *	DNAME NUM ADDR VEC BR (HANDLER ...) SEMICOLON COMMENT
  76:  * From a '#' to end of line is also considered a comment
  77:  */
  78: 
  79: read_dtab()
  80: {
  81:     char *cp;
  82:     register struct dtab_s *dp, *cdp;
  83:     struct handler_s *sp;
  84:     struct uprobe *up;
  85:     int nhandlers;
  86: 
  87:     line = 0;
  88:     devs = NULL;
  89:     while ((cp = getword()) != NULL) {
  90:         line++;
  91:         dp = malloc(sizeof *dp);
  92:         dp->dt_name = strsave(cp);
  93:         if (*(cp = nextword()) == '?')
  94:             dp->dt_unit = -1;
  95:         else
  96:             dp->dt_unit = atoi(cp);
  97:         dp->dt_addr = otoi(nextword());
  98:         dp->dt_vector = otoi(nextword());
  99:         dp->dt_br = otoi(nextword());
 100:         dp->dt_probe = dp->dt_attach = 0;
 101:         dp->dt_handlers = NULL;
 102:         nhandlers = 0;
 103:         while (strcmp((cp = nextword()), ";")) {
 104:             if (++nhandlers == 4)
 105:                 fprintf(stderr, "Warning, more than three handlers for device %s on line %d.\n", dp->dt_name, line);
 106:             addent(&dp->dt_handlers, strsave(cp));
 107:             guess_ndev++;
 108:         }
 109:         guess_ndev += 2;
 110:         for (up = uprobe; up->up_name; up++) {
 111:             if (!strcmp(dp->dt_name, up->up_name)) {
 112:                 dp->dt_uprobe = up->up_func;
 113:                 break;
 114:             }
 115:         }
 116:         /*
 117: 		 * Skip the rest of the line (comment field).
 118: 		 */
 119:         while (last_ch != '\n' && last_ch != EOF)
 120:             last_ch = getc(dtab_fp);
 121:         dp->dt_next = NULL;
 122:         if (devs == NULL)
 123:             devs = cdp = dp;
 124:         else {
 125:             cdp->dt_next = dp;
 126:             cdp = dp;
 127:         }
 128:     }
 129:     fclose(dtab_fp);
 130: }
 131: 
 132: addent(listp, cp)
 133: struct handler_s **listp;
 134: char *cp;
 135: {
 136:     struct handler_s *el;
 137:     struct handler_s *sp;
 138: 
 139:     el = malloc(sizeof *el);
 140:     el->s_str = cp;
 141:     el->s_next = NULL;
 142:     if (*listp == NULL)
 143:         *listp = el;
 144:     else {
 145:         for (sp = *listp; sp->s_next != NULL; sp = sp->s_next)
 146:             ;
 147:         sp->s_next = el;
 148:     }
 149: }
 150: 
 151: inlist(list, str)
 152: register struct handler_s *list;
 153: register char *str;
 154: {
 155:     for (; list != NULL; list = list->s_next)
 156:         if (strcmp(list->s_str, str) == 0)
 157:             return 1;
 158:     return 0;
 159: }

Defined functions

addent defined in line 132; used 1 times
getword defined in line 27; used 2 times
inlist defined in line 151; never used
nextword defined in line 62; used 5 times
otoi defined in line 15; used 4 times
read_dtab defined in line 79; used 1 times

Defined variables

guess_ndev defined in line 13; used 3 times
last_ch defined in line 24; used 5 times
line defined in line 11; used 4 times

Defined macros

read_while defined in line 26; used 2 times
Last modified: 1983-10-16
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 827
Valid CSS Valid XHTML 1.0 Strict