|
|
1.1 ! root 1: /* ! 2: * mkheaders.c 1.6 81/04/08 ! 3: * Make all the .h files for the optional entries ! 4: */ ! 5: ! 6: #include <stdio.h> ! 7: #include <ctype.h> ! 8: #include "config.h" ! 9: ! 10: /* ! 11: * This macro reads a line of the form ! 12: * #define STRING <number> ! 13: * and assigns STRING to wd and <number> to count ! 14: */ ! 15: #define rdln(f, wd, count) {\ ! 16: register char *iwd;\ ! 17: if ((wd = get_word(f)) != NULL && wd != WEOF)\ ! 18: if ((wd = get_word(f)) != NULL && wd != WEOF) {\ ! 19: iwd = ns(wd);\ ! 20: if ((wd = get_word(f)) != NULL && wd != WEOF) {\ ! 21: count = atoi(wd);\ ! 22: wd = get_word(f);\ ! 23: wd = iwd;\ ! 24: }\ ! 25: }\ ! 26: } ! 27: ! 28: headers() ! 29: { ! 30: register struct file_list *fl; ! 31: ! 32: for (fl = ftab; fl != NULL; fl = fl->f_next) ! 33: if (fl->f_needs != NULL) ! 34: do_count(fl->f_needs, fl->f_needs, TRUE); ! 35: } ! 36: ! 37: /* ! 38: * do_count: ! 39: * Count all the devices of a certain type and recurse to count ! 40: * whatever the device is connected to ! 41: */ ! 42: ! 43: do_count(dev, hname, search) ! 44: register char *dev, *hname; ! 45: bool search; ! 46: { ! 47: register struct device *dp, *mp; ! 48: register int count; ! 49: ! 50: for (count = 0,dp = dtab; dp != NULL; dp = dp->d_next) ! 51: if (dp->d_unit != -1 && eq(dp->d_name, dev)) ! 52: { ! 53: if (dp->d_count) ! 54: count += dp->d_count; ! 55: else ! 56: count++; ! 57: if (search) ! 58: { ! 59: mp = dp->d_conn; ! 60: if (mp != NULL && mp != TO_NEXUS && mp->d_conn != TO_NEXUS) ! 61: { ! 62: do_count(mp->d_name, hname, FALSE); ! 63: search = FALSE; ! 64: } ! 65: } ! 66: } ! 67: do_header(dev, hname, count); ! 68: } ! 69: ! 70: do_header(dev, hname, count) ! 71: char *dev, *hname; ! 72: int count; ! 73: { ! 74: char *file, *name, *inw, *toheader(), *tomacro(); ! 75: struct file_list *fl, *fl_head; ! 76: FILE *inf, *outf; ! 77: int inc, oldcount; ! 78: ! 79: file = toheader(hname); ! 80: name = tomacro(dev); ! 81: inf = fopen(file, "r"); ! 82: oldcount = -1; ! 83: if (inf == NULL) ! 84: { ! 85: outf = fopen(file, "w"); ! 86: if (outf == NULL) { ! 87: perror(file); ! 88: exit(1); ! 89: } ! 90: fprintf(outf, "#define %s %d\n", name, count); ! 91: fclose(outf); ! 92: return; ! 93: } ! 94: fl_head = NULL; ! 95: while(1) ! 96: { ! 97: rdln(inf, inw, inc); ! 98: if (inw == WEOF) ! 99: break; ! 100: if (eq(inw, name)) ! 101: { ! 102: oldcount = inc; ! 103: inc = count; ! 104: } ! 105: fl = (struct file_list *) malloc(sizeof *fl); ! 106: fl->f_fn = inw; ! 107: fl->f_type = inc; ! 108: fl->f_next = fl_head; ! 109: fl_head = fl; ! 110: } ! 111: fclose(inf); ! 112: if (count == oldcount) ! 113: { ! 114: for (fl = fl_head; fl != NULL; fl = fl->f_next) ! 115: free(fl); ! 116: return; ! 117: } ! 118: if (oldcount == -1) ! 119: { ! 120: fl = (struct file_list *) malloc(sizeof *fl); ! 121: fl->f_fn = name; ! 122: fl->f_type = count; ! 123: fl->f_next = fl_head; ! 124: fl_head = fl; ! 125: } ! 126: outf = fopen(file, "w"); ! 127: if (outf == NULL) { ! 128: perror(file); ! 129: exit(1); ! 130: } ! 131: for (fl = fl_head; fl != NULL; fl = fl->f_next) ! 132: { ! 133: fprintf(outf, "#define %s %d\n", fl->f_fn, count ? fl->f_type : 0); ! 134: free(fl); ! 135: } ! 136: fclose(outf); ! 137: } ! 138: ! 139: /* ! 140: * toheader: ! 141: * Convert a dev name to a .h file nae ! 142: */ ! 143: ! 144: char *toheader(dev) ! 145: char *dev; ! 146: { ! 147: static char hbuf[80]; ! 148: ! 149: strcpy(hbuf, LOCAL(dev)); ! 150: strcat(hbuf, ".h"); ! 151: return hbuf; ! 152: } ! 153: ! 154: /* ! 155: * tomacro: ! 156: * Convert a dev name to a macro name ! 157: */ ! 158: ! 159: char *tomacro(dev) ! 160: register char *dev; ! 161: { ! 162: static char mbuf[20]; ! 163: register char *cp; ! 164: ! 165: cp = mbuf; ! 166: *cp++ = 'N'; ! 167: while(*dev) ! 168: *cp++ = toupper(*dev++); ! 169: *cp++ = '\0'; ! 170: return mbuf; ! 171: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.