|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1980 Regents of the University of California. ! 3: * All rights reserved. ! 4: * ! 5: * Redistribution and use in source and binary forms are permitted provided ! 6: * that: (1) source distributions retain this entire copyright notice and ! 7: * comment, and (2) distributions including binaries display the following ! 8: * acknowledgement: ``This product includes software developed by the ! 9: * University of California, Berkeley and its contributors'' in the ! 10: * documentation or other materials provided with the distribution and in ! 11: * all advertising materials mentioning features or use of this software. ! 12: * Neither the name of the University nor the names of its contributors may ! 13: * be used to endorse or promote products derived from this software without ! 14: * specific prior written permission. ! 15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED ! 16: * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF ! 17: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 18: */ ! 19: ! 20: #ifndef lint ! 21: static char sccsid[] = "@(#)mkheaders.c 5.6 (Berkeley) 6/1/90"; ! 22: #endif /* not lint */ ! 23: ! 24: /* ! 25: * Make all the .h files for the optional entries ! 26: */ ! 27: ! 28: #include <stdio.h> ! 29: #include <ctype.h> ! 30: #include "config.h" ! 31: #include "y.tab.h" ! 32: ! 33: headers() ! 34: { ! 35: register struct file_list *fl; ! 36: ! 37: for (fl = ftab; fl != 0; fl = fl->f_next) ! 38: if (fl->f_needs != 0) ! 39: do_count(fl->f_needs, fl->f_needs, 1); ! 40: } ! 41: ! 42: /* ! 43: * count all the devices of a certain type and recurse to count ! 44: * whatever the device is connected to ! 45: */ ! 46: do_count(dev, hname, search) ! 47: register char *dev, *hname; ! 48: int search; ! 49: { ! 50: register struct device *dp, *mp; ! 51: register int count; ! 52: ! 53: for (count = 0,dp = dtab; dp != 0; dp = dp->d_next) ! 54: if (dp->d_unit != -1 && eq(dp->d_name, dev)) { ! 55: if (dp->d_type == PSEUDO_DEVICE) { ! 56: count = ! 57: dp->d_slave != UNKNOWN ? dp->d_slave : 1; ! 58: break; ! 59: } ! 60: count++; ! 61: /* ! 62: * Allow holes in unit numbering, ! 63: * assumption is unit numbering starts ! 64: * at zero. ! 65: */ ! 66: if (dp->d_unit + 1 > count) ! 67: count = dp->d_unit + 1; ! 68: if (search) { ! 69: mp = dp->d_conn; ! 70: if (mp != 0 && mp != TO_NEXUS && ! 71: mp->d_conn != 0 && mp->d_conn != TO_NEXUS) { ! 72: do_count(mp->d_name, hname, 0); ! 73: search = 0; ! 74: } ! 75: } ! 76: } ! 77: do_header(dev, hname, count); ! 78: } ! 79: ! 80: do_header(dev, hname, count) ! 81: char *dev, *hname; ! 82: int count; ! 83: { ! 84: char *file, *name, *inw, *toheader(), *tomacro(); ! 85: struct file_list *fl, *fl_head; ! 86: FILE *inf, *outf; ! 87: int inc, oldcount; ! 88: ! 89: file = toheader(hname); ! 90: name = tomacro(dev); ! 91: inf = fopen(file, "r"); ! 92: oldcount = -1; ! 93: if (inf == 0) { ! 94: outf = fopen(file, "w"); ! 95: if (outf == 0) { ! 96: perror(file); ! 97: exit(1); ! 98: } ! 99: fprintf(outf, "#define %s %d\n", name, count); ! 100: (void) fclose(outf); ! 101: return; ! 102: } ! 103: fl_head = 0; ! 104: for (;;) { ! 105: char *cp; ! 106: if ((inw = get_word(inf)) == 0 || inw == (char *)EOF) ! 107: break; ! 108: if ((inw = get_word(inf)) == 0 || inw == (char *)EOF) ! 109: break; ! 110: inw = ns(inw); ! 111: cp = get_word(inf); ! 112: if (cp == 0 || cp == (char *)EOF) ! 113: break; ! 114: inc = atoi(cp); ! 115: if (eq(inw, name)) { ! 116: oldcount = inc; ! 117: inc = count; ! 118: } ! 119: cp = get_word(inf); ! 120: if (cp == (char *)EOF) ! 121: break; ! 122: fl = (struct file_list *) malloc(sizeof *fl); ! 123: fl->f_fn = inw; ! 124: fl->f_type = inc; ! 125: fl->f_next = fl_head; ! 126: fl_head = fl; ! 127: } ! 128: (void) fclose(inf); ! 129: if (count == oldcount) { ! 130: for (fl = fl_head; fl != 0; fl = fl->f_next) ! 131: free((char *)fl); ! 132: return; ! 133: } ! 134: if (oldcount == -1) { ! 135: fl = (struct file_list *) malloc(sizeof *fl); ! 136: fl->f_fn = name; ! 137: fl->f_type = count; ! 138: fl->f_next = fl_head; ! 139: fl_head = fl; ! 140: } ! 141: outf = fopen(file, "w"); ! 142: if (outf == 0) { ! 143: perror(file); ! 144: exit(1); ! 145: } ! 146: for (fl = fl_head; fl != 0; fl = fl->f_next) { ! 147: fprintf(outf, "#define %s %u\n", ! 148: fl->f_fn, count ? fl->f_type : 0); ! 149: free((char *)fl); ! 150: } ! 151: (void) fclose(outf); ! 152: } ! 153: ! 154: /* ! 155: * convert a dev name to a .h file name ! 156: */ ! 157: char * ! 158: toheader(dev) ! 159: char *dev; ! 160: { ! 161: static char hbuf[80]; ! 162: ! 163: (void) strcpy(hbuf, path(dev)); ! 164: (void) strcat(hbuf, ".h"); ! 165: return (hbuf); ! 166: } ! 167: ! 168: /* ! 169: * convert a dev name to a macro name ! 170: */ ! 171: char *tomacro(dev) ! 172: register char *dev; ! 173: { ! 174: static char mbuf[20]; ! 175: register char *cp; ! 176: ! 177: cp = mbuf; ! 178: *cp++ = 'N'; ! 179: while (*dev) ! 180: *cp++ = toupper(*dev++); ! 181: *cp++ = 0; ! 182: return (mbuf); ! 183: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.