date and time created 81/02/24 15:51:17 by toy
authorMichael Toy <toy@ucbvax.Berkeley.EDU>
Wed, 25 Feb 1981 07:51:17 +0000 (23:51 -0800)
committerMichael Toy <toy@ucbvax.Berkeley.EDU>
Wed, 25 Feb 1981 07:51:17 +0000 (23:51 -0800)
SCCS-vsn: usr.sbin/config/mkheaders.c 1.1

usr/src/usr.sbin/config/mkheaders.c [new file with mode: 0644]

diff --git a/usr/src/usr.sbin/config/mkheaders.c b/usr/src/usr.sbin/config/mkheaders.c
new file mode 100644 (file)
index 0000000..72d346b
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * mkheaders.c 1.1     81/02/24
+ * Make header files for EVERYTHING
+ */
+
+#include <stdio.h>
+#include <ctype.h>
+#include "config.h"
+#include "y.tab.h"
+
+
+
+headers()
+{
+    register struct device *ip;
+    register struct file_list *tp;
+    register int count;
+
+    for (tp = ftab; tp != NULL; tp = tp->f_next)
+    {
+       if (tp->f_needs == NULL)
+           continue;
+       count = 0;
+       for (ip = dtab; ip != NULL; ip = ip->d_next)
+       {
+           if (eq(tp->f_needs, ip->d_name))
+               count++;
+       }
+       do_header(tp->f_needs, count);
+    }
+}
+
+/*
+ * tomacro
+ *     Convert a two character name to a NXX
+ */
+
+tomacro(nm)
+register char *nm;
+{
+    static char ret[80];
+    register char *cp;
+
+    cp = ret;
+    *cp++ = 'N';
+    while(*nm)
+       *cp++ = toupper(*nm++);
+    *cp++ = '\0';
+    return ret;
+}
+
+/*
+ * do_header:
+ *     See if a header file needs to be changed
+ */
+
+do_header(dev, count)
+char *dev;
+int count;
+{
+    register FILE *f;
+    char file[80];
+    register char *w;
+    register int oldcount;
+
+    strcpy(file, "_unix/");
+    strcat(file, dev);
+    strcat(file, ".h");
+    oldcount = -1;
+    if ((f = fopen(file, "r")) != NULL)
+    {
+       /*
+        * Throw out the #define and the NXX
+        */
+       if ((w = get_word(f)) != EOF && w != NULL)
+           if ((w = get_word(f)) == EOF && w != NULL)
+               oldcount = atoi(get_word(f));
+       fclose(f);
+    }
+    if (oldcount != count)
+    {
+       f = fopen(file, "w");
+       fprintf(f, "#define %s %d\n", tomacro(dev), count);
+       fclose(f);
+    }
+}