/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Copyright (c) 1980 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* we also attempt to match size and font changes, but only the embedded
* kind. These must end in \s0 and \fP resp. Maybe more sophistication
* later but for now think of these restrictions as contributions to
* structured typesetting.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include <locale.h>
static int maxstk;
/*
* The stack on which we remember what we've seen so far.
*/
static struct stkstr {
} *stk;
static int stktop;
/*
* The kinds of opening and closing brackets.
*/
static struct brstr {
char *opbr;
char *clbr;
/* A few bare bones troff commands */
#define SZ 0
"sz", "sz", /* also \s */
"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",
"BD", "DE",
"CD", "DE",
"DS", "DE",
"FS", "FE",
"ID", "DE",
"KF", "KE",
"KS", "KE",
"LD", "DE",
"LG", "NL",
"QS", "QE",
"RS", "RE",
"SM", "NL",
"XA", "XE",
"XS", "XE",
/* The -me package */
"(b", ")b",
"(c", ")c",
"(d", ")d",
"(f", ")f",
"(l", ")l",
"(q", ")q",
"(x", ")x",
"(z", ")z",
/* Things needed by preprocessors */
"EQ", "EN",
"TS", "TE",
/* Refer */
"[", "]",
0, 0
};
/*
* All commands known to nroff, plus macro packages.
* Used so we can complain about unrecognized commands.
*/
"$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
};
static void growstk();
static void usage();
static void complain(int i);
static void prop(int i);
static void checkknown(char *mac);
static void
growstk()
{
stktop++;
maxstk *= 2;
}
}
int
int argc;
char **argv;
{
FILE *f;
int i;
char *cp;
#if !defined(TEXT_DOMAIN)
#endif
(void) textdomain(TEXT_DOMAIN);
maxstk = 100;
/* Figure out how many known commands there are */
ncmds++;
/* -a: add pairs of macros */
case 'a':
if (i % 6 != 0)
usage();
/* look for empty macro slots */
;
/* knows pairs are also known cmds */
i++;
}
break;
/* -c: add known commands */
case 'c':
if (i % 3 != 0)
usage();
usage();
}
break;
/* -f: ignore font changes */
case 'f':
fflag = 1;
break;
/* -s: ignore size changes */
case 's':
sflag = 1;
break;
default:
usage();
}
}
if (nfiles > 0) {
for (i = 1; i < argc; i++) {
if (f == NULL) {
exit(1);
}
else
process(f);
}
} else {
cfilename = "stdin";
}
return (0);
}
static void
usage()
{
checknr [ -fs ] [ -a.xx.yy.xx.yy...] [-c.xx.xx.xx...] [ filename .. ]\n"));
exit(1);
}
static void
{
int i, n;
int pl;
stktop = -1;
if (line[0] == '.') {
/*
*/
mac[1] = 0;
mac[2] = 0;
}
/*
* Is it a known command?
*/
/*
* Should we add it?
*/
}
/*
* At this point we process the line looking
* for \s and \f.
*/
for (i = 0; line[i]; i++)
n = pl - '0';
pl = ' ';
} else
n = 0;
i--;
if (n == 0) {
stktop--;
} else {
(void) printf(
gettext("unmatched \\s0\n"));
}
} else {
growstk();
}
n = line[++i];
if (n == 'P') {
stktop--;
} else {
(void) printf(
gettext("unmatched \\fP\n"));
}
} else {
growstk();
}
}
}
}
/*
* We've hit the end and look at all this stuff that hasn't been
* matched yet! Complain, complain.
*/
for (i = stktop; i >= 0; i--) {
complain(i);
}
}
static void
complain(int i)
{
prop(i);
(void) printf("\n");
}
static void
prop(int i)
{
case SZ:
break;
case FT:
break;
default:
}
}
/* ARGSUSED */
static void
{
int i;
/*
* Check to see if it matches top of stack.
*/
stktop--; /* OK. Pop & forget */
else {
/* No. Maybe it's an opener */
/* Found. Push it. */
growstk();
break;
}
/*
* Maybe it's an unmatched closer.
* NOTE: this depends on the fact
* that none of the closers can be
* openers too.
*/
break;
}
}
}
}
static void
{
int i, j;
/*
* Look for a match further down on stack
* If we find one, it suggests that the stuff in
* between is supposed to match itself.
*/
for (j = stktop; j >= 0; j--)
/* Found. Make a good diagnostic. */
if (j == stktop-2) {
/*
* Check for special case \fx..\fR and don't
* complain.
*/
stktop = j -1;
return;
}
/*
* We have two unmatched frobs. Chances are
* they were intended to match, so we mention
* them together.
*/
prop(j+1);
prop(j+2);
(void) printf("\n");
} else for (i = j+1; i <= stktop; i++) {
complain(i);
}
stktop = j-1;
return;
}
/* Didn't find one. Throw this away. */
}
/* eq: are two strings equal? */
static int
{
}
/* print the first part of an error message, given the line number */
static void
{
if (nfiles > 1)
}
static void
{
return;
return;
return;
}
/*
* We have a .de xx line in "line". Add xx to the list of known commands.
*/
static void
{
char *mac;
/* grab the macro being defined */
mac++;
if (*mac == 0) {
return;
}
mac[2] = 0;
mac[1] = 0;
MAXCMDS);
exit(1);
}
}
/*
* Add mac to the list. We should really have some kind of tree
* structure here but this is a quick-and-dirty job and I just don't
* have time to mess with it. (I wonder if this will come back to haunt
* me someday?) Anyway, I claim that .de is fairly rare in user
* nroff programs, and the loop below is pretty fast.
*/
static void
{
#ifdef DEBUG
#endif
return;
}
/* binsrch sets slot as a side effect */
#ifdef DEBUG
#endif
ncmds++;
#ifdef DEBUG
(void) printf("after: %s %s %s %s %s, %d cmds\n",
#endif
}
/*
* Do a binary search in knowncmds for mac.
* If found, return the index. If not, return -1.
*/
static int
{
char *p; /* pointer to current cmd in list */
int d; /* difference if any */
bot = 0;
d = p[0] - mac[0];
if (d == 0)
if (d == 0)
return (mid);
if (d < 0)
else
}
return (-1);
}