|
|
1.1 ! root 1: /* ! 2: * master devices file: ! 3: * name tag [stuff] ! 4: */ ! 5: ! 6: #include <fio.h> ! 7: #include <libc.h> ! 8: #include <ctype.h> ! 9: #include "mkconf.h" ! 10: ! 11: #define BIGARGS 30 ! 12: ! 13: readdevs(f) ! 14: char *f; ! 15: { ! 16: int fd; ! 17: register char *p; ! 18: char *args[BIGARGS]; ! 19: register int n; ! 20: register Mdev *mp; ! 21: register int i; ! 22: ! 23: if ((fd = open(f, 0)) < 0) { ! 24: perror(f); ! 25: exit(1); ! 26: } ! 27: while ((p = Frdline(fd)) != NULL) { ! 28: while (isspace(*p)) ! 29: p++; ! 30: if (*p == '#' || *p == 0) ! 31: continue; ! 32: if ((n = crack(p, args, BIGARGS)) < 2) { ! 33: fprint(STDERR, "%s: bad line ignored: %s\n", f, p); ! 34: errs++; ! 35: continue; ! 36: } ! 37: if ((mp = (Mdev *)ealloc(sizeof(Mdev))) == NULL) { ! 38: fprint(STDERR, "out of memory\n"); ! 39: exit(1); ! 40: } ! 41: mp->name = estrdup(args[0]); ! 42: mp->tag = estrdup(args[1]); ! 43: mp->atype = ANONE; ! 44: mp->adptype = ANONE; ! 45: mp->nvec = 1; ! 46: mp->rept = 1; ! 47: mp->flags = 0; ! 48: for (i = 0; i < NSTR; i++) { ! 49: mp->strs[i] = 0; ! 50: mp->fstrs[i] = 0; ! 51: } ! 52: mdflags(mp, &args[2], n - 2); ! 53: if (badmdev(mp)) { ! 54: free((char *)mp); ! 55: errs++; ! 56: continue; ! 57: } ! 58: mp->next = mlist; ! 59: mlist = mp; ! 60: } ! 61: close(fd); ! 62: } ! 63: ! 64: badmdev(mp) ! 65: register Mdev *mp; ! 66: { ! 67: /* various consistency checks here */ ! 68: return (0); ! 69: } ! 70: ! 71: mdflags(mp, a, n) ! 72: register Mdev *mp; ! 73: register char **a; ! 74: register int n; ! 75: { ! 76: register int i; ! 77: ! 78: for (; --n >= 0; a++) { ! 79: /* ! 80: * address types: mine or the bus i control ! 81: */ ! 82: if (strcmp(*a, "sbi") == 0) ! 83: mp->atype = ASBI; ! 84: else if (strcmp(*a, "sbia") == 0) ! 85: mp->adptype = ASBI; ! 86: else if (strcmp(*a, "vaxbi") == 0) ! 87: mp->atype = AVBI; ! 88: else if (strcmp(*a, "vaxbia") == 0) ! 89: mp->adptype = AVBI; ! 90: else if (strcmp(*a, "mb") == 0) ! 91: mp->atype = AMBA; ! 92: else if (strcmp(*a, "mba") == 0) ! 93: mp->adptype = AMBA; ! 94: else if (strcmp(*a, "ub") == 0) ! 95: mp->atype = AUBA; ! 96: else if (strcmp(*a, "uba") == 0) ! 97: mp->adptype = AUBA; ! 98: else if (strcmp(*a, "sub") == 0) ! 99: mp->atype = ASUB; ! 100: else if (strcmp(*a, "count") == 0) ! 101: mp->atype = ACNT; ! 102: else if (strcmp(*a, "param") == 0) ! 103: mp->atype = APARAM; ! 104: else if (strcmp(*a, "mscp") == 0) ! 105: mp->atype = AMSCP; ! 106: else if (strcmp(*a, "mscpa") == 0) ! 107: mp->adptype = AMSCP; ! 108: else if (strcmp(*a, "nobus") == 0) ! 109: mp->atype = ANOBUS; ! 110: /* ! 111: * hacks ! 112: */ ! 113: else if (strcmp(*a, "vec") == 0) { ! 114: if (--n < 0) { ! 115: fprint(STDERR, "%s: vec what?\n", mp->name); ! 116: errs++; ! 117: continue; ! 118: } ! 119: mp->nvec = atoi(*++a); ! 120: } else if (strcmp(*a, "rep") == 0) { ! 121: if (--n < 0) { ! 122: fprint(STDERR, "%s: rep what?\n", mp->name); ! 123: errs++; ! 124: continue; ! 125: } ! 126: mp->rept = atoi(*++a); ! 127: } else if (strcmp(*a, "dupok") == 0) ! 128: mp->flags |= FDUPOK; ! 129: else if (strcmp(*a, "rawvec") == 0) ! 130: mp->flags |= FRAWVEC; ! 131: /* ! 132: * structures, includes ! 133: */ ! 134: else if (strcmp(*a, "data") == 0) { ! 135: i = mddata(mp, a, n); ! 136: a += i; ! 137: n -= i; ! 138: } else if (strcmp(*a, "inc") == 0) { ! 139: i = mdincl(mp, a, n); ! 140: a += i; ! 141: n -= i; ! 142: } else { ! 143: fprint(STDERR, "%s: unknown arg %s\n", mp->name, *a); ! 144: errs++; ! 145: } ! 146: } ! 147: } ! 148: ! 149: int ! 150: mddata(mp, a, n) ! 151: register Mdev *mp; ! 152: register char **a; ! 153: int n; ! 154: { ! 155: register int i; ! 156: char buf[80]; ! 157: register char *p, *q; ! 158: register int xn; ! 159: int c; ! 160: ! 161: i = 0; ! 162: xn = n - 1; ! 163: ++a; /* skip "data" */ ! 164: while (xn >= 0) { ! 165: q = buf; ! 166: do { ! 167: p = *a++; ! 168: while ((*q++ = *p++) != 0) ! 169: ; ! 170: q[-1] = ' '; ! 171: } while (--xn >= 0 && q[-2] != ';' && q[-2] != ','); ! 172: *--q = 0; /* smash last blank */ ! 173: c = q[-1]; ! 174: if (c == ';' || c == ',') ! 175: *--q = 0; ! 176: if (i < NSTR-1) ! 177: mp->strs[i++] = estrdup(buf); ! 178: else { ! 179: fprint(STDERR, "%s: too much data\n", mp->name); ! 180: errs++; ! 181: } ! 182: if (c == ';') ! 183: break; ! 184: } ! 185: return (n - xn - 1); ! 186: } ! 187: ! 188: Include *inclist; ! 189: ! 190: int ! 191: mdincl(mp, a, n) ! 192: Mdev *mp; ! 193: register char **a; ! 194: int n; ! 195: { ! 196: register int xn; ! 197: register Include *ip, *jp; ! 198: register char *p; ! 199: Include *bjp; ! 200: char *s; ! 201: int last; ! 202: ! 203: xn = n; ! 204: a++; /* skip "inc" */ ! 205: last = 0; ! 206: while (last == 0 && --xn >= 0) { ! 207: s = *a++; ! 208: for (p = s; *p; p++) ! 209: ; ! 210: if (*--p == ';') { ! 211: *p = 0; ! 212: last = 1; ! 213: } ! 214: bjp = NULL; ! 215: for (jp = inclist; jp; bjp = jp, jp = jp->next) ! 216: if (strcmp(jp->incl, s) == 0) ! 217: break; ! 218: ip = (Include *)ealloc(sizeof(Include)); ! 219: ip->inuse = 0; ! 220: ip->dev = mp; ! 221: if (jp) ! 222: ip->incl = jp->incl; ! 223: else ! 224: ip->incl = estrdup(s); ! 225: if (bjp) { ! 226: ip->next = bjp->next; ! 227: bjp->next = ip; ! 228: } ! 229: else { ! 230: ip->next = inclist; ! 231: inclist = ip; ! 232: } ! 233: } ! 234: return (n - xn); ! 235: } ! 236: ! 237: incfix(dp) ! 238: Dev *dp; ! 239: { ! 240: register Mdev *mp; ! 241: register Include *ip; ! 242: ! 243: mp = dp->mdev; ! 244: for (ip = inclist; ip; ip = ip->next) ! 245: if (ip->dev == mp) ! 246: ip->inuse = 1; ! 247: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.