Commit | Line | Data |
---|---|---|
900ae8f5 | 1 | /* |
9455553e | 2 | * mkheaders.c 1.2 81/02/24 |
900ae8f5 MT |
3 | * Make header files for EVERYTHING |
4 | */ | |
5 | ||
6 | #include <stdio.h> | |
7 | #include <ctype.h> | |
8 | #include "config.h" | |
9 | #include "y.tab.h" | |
10 | ||
11 | ||
12 | ||
13 | headers() | |
14 | { | |
15 | register struct device *ip; | |
16 | register struct file_list *tp; | |
17 | register int count; | |
18 | ||
19 | for (tp = ftab; tp != NULL; tp = tp->f_next) | |
20 | { | |
21 | if (tp->f_needs == NULL) | |
22 | continue; | |
23 | count = 0; | |
24 | for (ip = dtab; ip != NULL; ip = ip->d_next) | |
25 | { | |
26 | if (eq(tp->f_needs, ip->d_name)) | |
27 | count++; | |
28 | } | |
29 | do_header(tp->f_needs, count); | |
30 | } | |
31 | } | |
32 | ||
33 | /* | |
34 | * tomacro | |
35 | * Convert a two character name to a NXX | |
36 | */ | |
37 | ||
38 | tomacro(nm) | |
39 | register char *nm; | |
40 | { | |
41 | static char ret[80]; | |
42 | register char *cp; | |
43 | ||
44 | cp = ret; | |
45 | *cp++ = 'N'; | |
46 | while(*nm) | |
47 | *cp++ = toupper(*nm++); | |
48 | *cp++ = '\0'; | |
49 | return ret; | |
50 | } | |
51 | ||
52 | /* | |
53 | * do_header: | |
54 | * See if a header file needs to be changed | |
55 | */ | |
56 | ||
57 | do_header(dev, count) | |
58 | char *dev; | |
59 | int count; | |
60 | { | |
61 | register FILE *f; | |
62 | char file[80]; | |
63 | register char *w; | |
64 | register int oldcount; | |
65 | ||
66 | strcpy(file, "_unix/"); | |
67 | strcat(file, dev); | |
68 | strcat(file, ".h"); | |
69 | oldcount = -1; | |
70 | if ((f = fopen(file, "r")) != NULL) | |
71 | { | |
72 | /* | |
73 | * Throw out the #define and the NXX | |
74 | */ | |
75 | if ((w = get_word(f)) != EOF && w != NULL) | |
76 | if ((w = get_word(f)) == EOF && w != NULL) | |
77 | oldcount = atoi(get_word(f)); | |
78 | fclose(f); | |
79 | } | |
80 | if (oldcount != count) | |
81 | { | |
82 | f = fopen(file, "w"); | |
83 | fprintf(f, "#define %s %d\n", tomacro(dev), count); | |
84 | fclose(f); | |
85 | } | |
86 | } |