Annotation of 43BSD/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.  The Berkeley software License Agreement
                      4:  * specifies the terms and conditions for redistribution.
                      5:  */
                      6: 
                      7: #ifndef lint
                      8: static char sccsid[] = "@(#)mkheaders.c        5.1 (Berkeley) 5/8/85";
                      9: #endif not lint
                     10: 
                     11: /*
                     12:  * Make all the .h files for the optional entries
                     13:  */
                     14: 
                     15: #include <stdio.h>
                     16: #include <ctype.h>
                     17: #include "config.h"
                     18: #include "y.tab.h"
                     19: 
                     20: headers()
                     21: {
                     22:        register struct file_list *fl;
                     23: 
                     24:        for (fl = ftab; fl != 0; fl = fl->f_next)
                     25:                if (fl->f_needs != 0)
                     26:                        do_count(fl->f_needs, fl->f_needs, 1);
                     27: }
                     28: 
                     29: /*
                     30:  * count all the devices of a certain type and recurse to count
                     31:  * whatever the device is connected to
                     32:  */
                     33: do_count(dev, hname, search)
                     34:        register char *dev, *hname;
                     35:        int search;
                     36: {
                     37:        register struct device *dp, *mp;
                     38:        register int count;
                     39: 
                     40:        for (count = 0,dp = dtab; dp != 0; dp = dp->d_next)
                     41:                if (dp->d_unit != -1 && eq(dp->d_name, dev)) {
                     42:                        if (dp->d_type == PSEUDO_DEVICE) {
                     43:                                count =
                     44:                                    dp->d_slave != UNKNOWN ? dp->d_slave : 1;
                     45:                                break;
                     46:                        }
                     47:                        count++;
                     48:                        /*
                     49:                         * Allow holes in unit numbering,
                     50:                         * assumption is unit numbering starts
                     51:                         * at zero.
                     52:                         */
                     53:                        if (dp->d_unit + 1 > count)
                     54:                                count = dp->d_unit + 1;
                     55:                        if (search) {
                     56:                                mp = dp->d_conn;
                     57:                                if (mp != 0 && mp != (struct device *)-1 &&
                     58:                                    mp->d_conn != (struct device *)-1) {
                     59:                                        do_count(mp->d_name, hname, 0);
                     60:                                        search = 0;
                     61:                                }
                     62:                        }
                     63:                }
                     64:        do_header(dev, hname, count);
                     65: }
                     66: 
                     67: do_header(dev, hname, count)
                     68:        char *dev, *hname;
                     69:        int count;
                     70: {
                     71:        char *file, *name, *inw, *toheader(), *tomacro();
                     72:        struct file_list *fl, *fl_head;
                     73:        FILE *inf, *outf;
                     74:        int inc, oldcount;
                     75: 
                     76:        file = toheader(hname);
                     77:        name = tomacro(dev);
                     78:        inf = fopen(file, "r");
                     79:        oldcount = -1;
                     80:        if (inf == 0) {
                     81:                outf = fopen(file, "w");
                     82:                if (outf == 0) {
                     83:                        perror(file);
                     84:                        exit(1);
                     85:                }
                     86:                fprintf(outf, "#define %s %d\n", name, count);
                     87:                (void) fclose(outf);
                     88:                return;
                     89:        }
                     90:        fl_head = 0;
                     91:        for (;;) {
                     92:                char *cp;
                     93:                if ((inw = get_word(inf)) == 0 || inw == (char *)EOF)
                     94:                        break;
                     95:                if ((inw = get_word(inf)) == 0 || inw == (char *)EOF)
                     96:                        break;
                     97:                inw = ns(inw);
                     98:                cp = get_word(inf);
                     99:                if (cp == 0 || cp == (char *)EOF)
                    100:                        break;
                    101:                inc = atoi(cp);
                    102:                if (eq(inw, name)) {
                    103:                        oldcount = inc;
                    104:                        inc = count;
                    105:                }
                    106:                cp = get_word(inf);
                    107:                if (cp == (char *)EOF)
                    108:                        break;
                    109:                fl = (struct file_list *) malloc(sizeof *fl);
                    110:                fl->f_fn = inw;
                    111:                fl->f_type = inc;
                    112:                fl->f_next = fl_head;
                    113:                fl_head = fl;
                    114:        }
                    115:        (void) fclose(inf);
                    116:        if (count == oldcount) {
                    117:                for (fl = fl_head; fl != 0; fl = fl->f_next)
                    118:                        free((char *)fl);
                    119:                return;
                    120:        }
                    121:        if (oldcount == -1) {
                    122:                fl = (struct file_list *) malloc(sizeof *fl);
                    123:                fl->f_fn = name;
                    124:                fl->f_type = count;
                    125:                fl->f_next = fl_head;
                    126:                fl_head = fl;
                    127:        }
                    128:        outf = fopen(file, "w");
                    129:        if (outf == 0) {
                    130:                perror(file);
                    131:                exit(1);
                    132:        }
                    133:        for (fl = fl_head; fl != 0; fl = fl->f_next) {
                    134:                fprintf(outf, "#define %s %d\n",
                    135:                    fl->f_fn, count ? fl->f_type : 0);
                    136:                free((char *)fl);
                    137:        }
                    138:        (void) fclose(outf);
                    139: }
                    140: 
                    141: /*
                    142:  * convert a dev name to a .h file name
                    143:  */
                    144: char *
                    145: toheader(dev)
                    146:        char *dev;
                    147: {
                    148:        static char hbuf[80];
                    149: 
                    150:        (void) strcpy(hbuf, path(dev));
                    151:        (void) strcat(hbuf, ".h");
                    152:        return (hbuf);
                    153: }
                    154: 
                    155: /*
                    156:  * convert a dev name to a macro name
                    157:  */
                    158: char *tomacro(dev)
                    159:        register char *dev;
                    160: {
                    161:        static char mbuf[20];
                    162:        register char *cp;
                    163: 
                    164:        cp = mbuf;
                    165:        *cp++ = 'N';
                    166:        while (*dev)
                    167:                *cp++ = toupper(*dev++);
                    168:        *cp++ = 0;
                    169:        return (mbuf);
                    170: }

unix.superglobalmegacorp.com

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