BSD 4_3_Net_2 release
[unix-history] / usr / src / usr.bin / checknr / checknr.c
index fa81f94..84d4086 100644 (file)
@@ -1,4 +1,46 @@
-static char *sccsid = "@(#)checknr.c   4.2 (Berkeley) %G%";
+/*
+ * Copyright (c) 1980 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+char copyright[] =
+"@(#) Copyright (c) 1980 The Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif /* not lint */
+
+#ifndef lint
+static char sccsid[] = "@(#)checknr.c  5.4 (Berkeley) 6/1/90";
+#endif /* not lint */
+
 /*
  * checknr: check an nroff/troff input file for matching macro calls.
  * we also attempt to match size and font changes, but only the embedded
 /*
  * checknr: check an nroff/troff input file for matching macro calls.
  * we also attempt to match size and font changes, but only the embedded
@@ -36,72 +78,88 @@ struct brstr {
        "sz",   "sz",   /* also \s */
 #define FT     1
        "ft",   "ft",   /* also \f */
        "sz",   "sz",   /* also \s */
 #define FT     1
        "ft",   "ft",   /* also \f */
+       /* the -mm package */
+       "AL",   "LE",
+       "AS",   "AE",
+       "BL",   "LE",
+       "BS",   "BE",
+       "DF",   "DE",
+       "DL",   "LE",
+       "DS",   "DE",
+       "FS",   "FE",
+       "ML",   "LE",
+       "NS",   "NE",
+       "RL",   "LE",
+       "VL",   "LE",
        /* the -ms package */
        "AB",   "AE",
        /* the -ms package */
        "AB",   "AE",
-       "RS",   "RE",
-       "LG",   "NL",
-       "SM",   "NL",
-       "FS",   "FE",
-       "DS",   "DE",
+       "BD",   "DE",
        "CD",   "DE",
        "CD",   "DE",
-       "LD",   "DE",
+       "DS",   "DE",
+       "FS",   "FE",
        "ID",   "DE",
        "ID",   "DE",
-       "KS",   "KE",
        "KF",   "KE",
        "KF",   "KE",
+       "KS",   "KE",
+       "LD",   "DE",
+       "LG",   "NL",
        "QS",   "QE",
        "QS",   "QE",
-       /* Things needed by preprocessors */
-       "TS",   "TE",
-       "EQ",   "EN",
+       "RS",   "RE",
+       "SM",   "NL",
+       "XA",   "XE",
+       "XS",   "XE",
        /* The -me package */
        /* The -me package */
-       "(l",   ")l",
-       "(q",   ")q",
        "(b",   ")b",
        "(b",   ")b",
-       "(z",   ")z",
        "(c",   ")c",
        "(d",   ")d",
        "(f",   ")f",
        "(c",   ")c",
        "(d",   ")d",
        "(f",   ")f",
+       "(l",   ")l",
+       "(q",   ")q",
        "(x",   ")x",
        "(x",   ")x",
+       "(z",   ")z",
+       /* Things needed by preprocessors */
+       "EQ",   "EN",
+       "TS",   "TE",
+       /* Refer */
+       "[",    "]",
        0,      0
 };
 
 /*
        0,      0
 };
 
 /*
- * All commands known to nroff, plus ms and me.
+ * All commands known to nroff, plus macro packages.
  * Used so we can complain about unrecognized commands.
  */
 char *knowncmds[MAXCMDS] = {
  * Used so we can complain about unrecognized commands.
  */
 char *knowncmds[MAXCMDS] = {
-"$c", "$f", "$h", "$p", "$s", "(b", "(c", "(d", "(f", "(l",
-"(q", "(t", "(x", "(z", ")b", ")c", ")d", ")f", ")l", ")q",
-")t", ")x", ")z", "++", "+c", "1C", "1c", "2C", "2c", "@(",
-"@)", "@C", "@D", "@F", "@I", "@M", "@c", "@e", "@f", "@h",
-"@m", "@n", "@o", "@p", "@r", "@t", "@z", "AB", "AB", "AE",
-"AE", "AI", "AI", "AT", "AU", "AU", "AX", "B",  "B1", "B2",
-"BD", "BG", "BT", "BX", "C1", "C2", "CD", "CM", "CT", "D", 
-"DA", "DE", "DF", "DS", "EG", "EM", "EN", "EQ", "EQ", "FA",
-"FE", "FJ", "FK", "FL", "FN", "FO", "FQ", "FS", "FV", "FX",
-"HO", "I",  "ID", "IE", "IH", "IM", "IP", "IZ", "KD", "KE",
-"KF", "KQ", "KS", "LB", "LD", "LG", "LP", "MC", "ME", "MF",
-"MH", "MR", "ND", "NH", "NL", "NP", "OK", "PP", "PT", "PY",
-"QE", "QP", "QS", "R",  "RA", "RC", "RE", "RP", "RQ", "RS",
-"RT", "S0", "S2", "S3", "SG", "SH", "SM", "SY", "TA", "TC",
-"TD", "TE", "TH", "TL", "TL", "TM", "TQ", "TR", "TS", "TS",
-"TX", "UL", "US", "UX", "WH", "XD", "XF", "XK", "XP", "[-",
-"[0", "[1", "[2", "[3", "[4", "[5", "[<", "[>", "[]", "]-",
-"]<", "]>", "][", "ab", "ac", "ad", "af", "am", "ar", "as",
-"b",  "ba", "bc", "bd", "bi", "bl", "bp", "bp", "br", "bx",
-"c.", "c2", "cc", "ce", "cf", "ch", "cs", "ct", "cu", "da",
-"de", "di", "dl", "dn", "ds", "dt", "dw", "dy", "ec", "ef",
-"eh", "el", "em", "eo", "ep", "ev", "ex", "fc", "fi", "fl",
-"fo", "fp", "ft", "fz", "hc", "he", "hl", "hp", "ht", "hw",
-"hx", "hy", "i",  "ie", "if", "ig", "in", "ip", "it", "ix",
-"lc", "lg", "li", "ll", "ll", "ln", "lo", "lp", "ls", "lt",
-"m1", "m2", "m3", "m4", "mc", "mk", "mo", "n1", "n2", "na",
-"ne", "nf", "nh", "nl", "nm", "nn", "np", "nr", "ns", "nx",
-"of", "oh", "os", "pa", "pc", "pi", "pl", "pm", "pn", "po",
-"po", "pp", "ps", "q",  "r",  "rb", "rd", "re", "re", "rm",
-"rn", "ro", "rr", "rs", "rt", "sb", "sc", "sh", "sk", "so",
-"sp", "ss", "st", "sv", "sz", "ta", "tc", "th", "ti", "tl",
-"tm", "tp", "tr", "u",  "uf", "uh", "ul", "vs", "wh", "yr",
-0
+"$c", "$f", "$h", "$p", "$s", "(b", "(c", "(d", "(f", "(l", "(q", "(t",
+"(x", "(z", ")b", ")c", ")d", ")f", ")l", ")q", ")t", ")x", ")z", "++",
+"+c", "1C", "1c", "2C", "2c", "@(", "@)", "@C", "@D", "@F", "@I", "@M",
+"@c", "@e", "@f", "@h", "@m", "@n", "@o", "@p", "@r", "@t", "@z", "AB",
+"AE", "AF", "AI", "AL", "AM", "AS", "AT", "AU", "AX", "B",  "B1", "B2",
+"BD", "BE", "BG", "BL", "BS", "BT", "BX", "C1", "C2", "CD", "CM", "CT",
+"D",  "DA", "DE", "DF", "DL", "DS", "DT", "EC", "EF", "EG", "EH", "EM",
+"EN", "EQ", "EX", "FA", "FD", "FE", "FG", "FJ", "FK", "FL", "FN", "FO",
+"FQ", "FS", "FV", "FX", "H",  "HC", "HD", "HM", "HO", "HU", "I",  "ID",
+"IE", "IH", "IM", "IP", "IX", "IZ", "KD", "KE", "KF", "KQ", "KS", "LB",
+"LC", "LD", "LE", "LG", "LI", "LP", "MC", "ME", "MF", "MH", "ML", "MR",
+"MT", "ND", "NE", "NH", "NL", "NP", "NS", "OF", "OH", "OK", "OP", "P",
+"P1", "PF", "PH", "PP", "PT", "PX", "PY", "QE", "QP", "QS", "R",  "RA",
+"RC", "RE", "RL", "RP", "RQ", "RS", "RT", "S",  "S0", "S2", "S3", "SA",
+"SG", "SH", "SK", "SM", "SP", "SY", "T&", "TA", "TB", "TC", "TD", "TE",
+"TH", "TL", "TM", "TP", "TQ", "TR", "TS", "TX", "UL", "US", "UX", "VL",
+"WC", "WH", "XA", "XD", "XE", "XF", "XK", "XP", "XS", "[",  "[-", "[0",
+"[1", "[2", "[3", "[4", "[5", "[<", "[>", "[]", "]",  "]-", "]<", "]>",
+"][", "ab", "ac", "ad", "af", "am", "ar", "as", "b",  "ba", "bc", "bd",
+"bi", "bl", "bp", "br", "bx", "c.", "c2", "cc", "ce", "cf", "ch", "cs",
+"ct", "cu", "da", "de", "di", "dl", "dn", "ds", "dt", "dw", "dy", "ec",
+"ef", "eh", "el", "em", "eo", "ep", "ev", "ex", "fc", "fi", "fl", "fo",
+"fp", "ft", "fz", "hc", "he", "hl", "hp", "ht", "hw", "hx", "hy", "i",
+"ie", "if", "ig", "in", "ip", "it", "ix", "lc", "lg", "li", "ll", "ln",
+"lo", "lp", "ls", "lt", "m1", "m2", "m3", "m4", "mc", "mk", "mo", "n1",
+"n2", "na", "ne", "nf", "nh", "nl", "nm", "nn", "np", "nr", "ns", "nx",
+"of", "oh", "os", "pa", "pc", "pi", "pl", "pm", "pn", "po", "pp", "ps",
+"q",  "r",  "rb", "rd", "re", "rm", "rn", "ro", "rr", "rs", "rt", "sb",
+"sc", "sh", "sk", "so", "sp", "ss", "st", "sv", "sz", "ta", "tc", "th",
+"ti", "tl", "tm", "tp", "tr", "u",  "uf", "uh", "ul", "vs", "wh", "xp",
+"yr", 0
 };
 
 int    lineno;         /* current line number in input file */
 };
 
 int    lineno;         /* current line number in input file */
@@ -124,8 +182,6 @@ char **argv;
        char *cp;
        char b1[4];
 
        char *cp;
        char b1[4];
 
-       if (argc <= 1)
-               usage();
        /* Figure out how many known commands there are */
        while (knowncmds[ncmds])
                ncmds++;
        /* Figure out how many known commands there are */
        while (knowncmds[ncmds])
                ncmds++;
@@ -224,7 +280,7 @@ FILE *f;
                                mac[1] = 0;
                        } else if (isspace(mac[2])) {
                                mac[2] = 0;
                                mac[1] = 0;
                        } else if (isspace(mac[2])) {
                                mac[2] = 0;
-                       } else if (mac[2] != '\\' || mac[3] != '\"') {
+                       } else if (mac[0] != '\\' || mac[1] != '\"') {
                                pe(lineno);
                                printf("Command too long\n");
                        }
                                pe(lineno);
                                printf("Command too long\n");
                        }
@@ -429,6 +485,8 @@ char *mac;
                return;
        if (binsrch(mac) >= 0)
                return;
                return;
        if (binsrch(mac) >= 0)
                return;
+       if (mac[0] == '\\' && mac[1] == '"')    /* comments */
+               return;
 
        pe(lineno);
        printf("Unknown command: .%s\n", mac);
 
        pe(lineno);
        printf("Unknown command: .%s\n", mac);
@@ -473,7 +531,12 @@ char *mac;
 {
        register char **src, **dest, **loc;
 
 {
        register char **src, **dest, **loc;
 
-       binsrch(mac);   /* it's OK to redefine something */
+       if (binsrch(mac) >= 0){ /* it's OK to redefine something */
+#ifdef DEBUG
+               printf("binsrch(%s) -> already in table\n", mac);
+#endif DEBUG
+               return;
+       }
        /* binsrch sets slot as a side effect */
 #ifdef DEBUG
 printf("binsrch(%s) -> %d\n", mac, slot);
        /* binsrch sets slot as a side effect */
 #ifdef DEBUG
 printf("binsrch(%s) -> %d\n", mac, slot);