Annotation of 43BSDTahoe/etc/config/mkheaders.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.