BSD 4_3_Tahoe release
[unix-history] / usr / src / sys / tahoe / inline / main.c
index aa2aba5..25dffd1 100644 (file)
@@ -8,11 +8,11 @@
 char copyright[] =
 "@(#) Copyright (c) 1984 Regents of the University of California.\n\
  All rights reserved.\n";
 char copyright[] =
 "@(#) Copyright (c) 1984 Regents of the University of California.\n\
  All rights reserved.\n";
-#endif not lint
+#endif
 
 #ifndef lint
 
 #ifndef lint
-static char sccsid[] = "@(#)main.c     1.8 (Berkeley) 6/8/85";
-#endif not lint
+static char sccsid[] = "@(#)main.c     1.3 (Berkeley) 2/24/86";
+#endif
 
 #include <stdio.h>
 #include <ctype.h>
 
 #include <stdio.h>
 #include <ctype.h>
@@ -37,7 +37,12 @@ struct stats {
        int     lostmodified;   /* mergers inhibited by intervening mod */
        int     savedpush;      /* successful push/pop merger */
 } stats;
        int     lostmodified;   /* mergers inhibited by intervening mod */
        int     savedpush;      /* successful push/pop merger */
 } stats;
-int dflag;
+
+extern char *strcpy();
+
+char   *whoami;
+int    lineno = 0;
+int    dflag;
 
 main(argc, argv)
        int argc;
 
 main(argc, argv)
        int argc;
@@ -51,6 +56,7 @@ main(argc, argv)
        int size;
        extern char *index();
 
        int size;
        extern char *index();
 
+       whoami = argv[0];
        if (argc > 1 && bcmp(argv[1], "-d", 3) == 0)
                dflag++, argc--, argv++;
        if (argc > 1)
        if (argc > 1 && bcmp(argv[1], "-d", 3) == 0)
                dflag++, argc--, argv++;
        if (argc > 1)
@@ -83,6 +89,7 @@ main(argc, argv)
        buftail = bufhead = 0;
        bufp = line[0];
        while (fgets(bufp, MAXLINELEN, stdin)) {
        buftail = bufhead = 0;
        bufp = line[0];
        while (fgets(bufp, MAXLINELEN, stdin)) {
+               lineno++;
                lp = index(bufp, LABELCHAR);
                if (lp != NULL) {
                        for (cp = bufp; cp < lp; cp++)
                lp = index(bufp, LABELCHAR);
                if (lp != NULL) {
                        for (cp = bufp; cp < lp; cp++)
@@ -94,7 +101,7 @@ main(argc, argv)
                                        emptyqueue();
                                        continue;
                                }
                                        emptyqueue();
                                        continue;
                                }
-                               strcpy(bufp, lp);
+                               (void) strcpy(bufp, lp);
                                *lp++ = '\n';
                                *lp = '\0';
                                emptyqueue();
                                *lp++ = '\n';
                                *lp = '\0';
                                emptyqueue();
@@ -108,6 +115,11 @@ main(argc, argv)
                }
                for (pp = patshdr[hash(cp, &size)]; pp; pp = pp->next) {
                        if (pp->size == size && bcmp(pp->name, cp, size) == 0) {
                }
                for (pp = patshdr[hash(cp, &size)]; pp; pp = pp->next) {
                        if (pp->size == size && bcmp(pp->name, cp, size) == 0) {
+                               if (argcounterr(pp->args, countargs(bufp),
+                                   pp->name)) {
+                                       pp = NULL;
+                                       break;
+                               }
                                expand(pp->replace);
                                bufp = line[bufhead];
                                break;
                                expand(pp->replace);
                                bufp = line[bufhead];
                                break;
@@ -120,7 +132,8 @@ main(argc, argv)
        }
        emptyqueue();
        if (dflag)
        }
        emptyqueue();
        if (dflag)
-               fprintf(stderr, "inline: %s %d, %s %d, %s %d, %s %d\n",
+               fprintf(stderr, "%s: %s %d, %s %d, %s %d, %s %d\n",
+                       whoami,
                        "attempts", stats.attempted,
                        "finished", stats.finished,
                        "inhibited", stats.lostmodified,
                        "attempts", stats.attempted,
                        "finished", stats.finished,
                        "inhibited", stats.lostmodified,
@@ -250,6 +263,37 @@ copyline(from, to)
        return (from);
 }
 
        return (from);
 }
 
+/*
+ * Check for a disparity between the number of arguments a function
+ * is called with and the number which we expect to see.
+ * If the error is unrecoverable, return 1, otherwise 0.
+ */
+argcounterr(args, callargs, name)
+       int args, callargs;
+       char *name;
+{
+       register char *cp;
+       char namebuf[MAXLINELEN];
+
+       if (args == callargs)
+               return (0);
+       cp = strcpy(namebuf, name);
+       while (*cp != '\0' && *cp != '\n')
+               ++cp;
+       if (*cp == '\n')
+               *cp = '\0';
+       if (callargs >= 0) {
+               fprintf(stderr,
+               "%s: error: arg count mismatch, %d != %d for '%s' at line %d\n",
+                       whoami, callargs, args, namebuf, lineno);
+               return (1);
+       }
+       fprintf(stderr,
+               "%s: warning: can't verify arg count for '%s' at line %d\n",
+               whoami, namebuf, lineno);
+       return (0);
+}
+
 /*
  * open space for next line in the queue
  */
 /*
  * open space for next line in the queue
  */