date and time created 81/02/24 15:51:17 by toy
[unix-history] / usr / src / usr.sbin / config / mkheaders.c
CommitLineData
900ae8f5
MT
1/*
2 * mkheaders.c 1.1 81/02/24
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
13headers()
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
38tomacro(nm)
39register 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
57do_header(dev, count)
58char *dev;
59int 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}