Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!ima!mirror!sources-request From: sources-request@mirror.UUCP Newsgroups: mod.sources Subject: v08i063: Syntax-checker for *roff Message-ID: <1733@mirror.TMC.COM> Date: Fri, 13-Feb-87 18:21:44 EST Article-I.D.: mirror.1733 Posted: Fri Feb 13 18:21:44 1987 Date-Received: Sat, 14-Feb-87 04:42:33 EST Sender: rs@mirror.TMC.COM Lines: 406 Approved: mirror!rs Submitted by: Kamal Al-Yahya Mod.sources: Volume 8, Issue 63 Archive-name: trmatch #! /bin/sh # This is a shell archive. Remove anything before this line, # then unpack it by saving it in a file and typing "sh file". # If all goes well, you will see the message "End of shell archive." # Contents: Makefile trmatch.1 trmatch.c PATH=/bin:/usr/bin:/usr/ucb; export PATH echo shar: extracting "'Makefile'" '(84 characters)' if test -f 'Makefile' ; then echo shar: will not over-write existing file "'Makefile'" else sed 's/^X//' >Makefile <<'@//E*O*F Makefile//' X# Makefile for trmatch. X XCFLAGS = -O Xtrmatch: X $(CC) $(CFLAGS) -o trmatch trmatch.c @//E*O*F Makefile// if test 84 -ne "`wc -c <'Makefile'`"; then echo shar: error transmitting "'Makefile'" '(should have been 84 characters)' fi fi # end of overwriting check echo shar: extracting "'trmatch.1'" '(841 characters)' if test -f 'trmatch.1' ; then echo shar: will not over-write existing file "'trmatch.1'" else sed 's/^X//' >trmatch.1 <<'@//E*O*F trmatch.1//' X.TH trmatch L 7/10/86 X.UC 4 X.SH NAME Xtrmatch \- checks matching in troff documents. X.SH SYNOPSIS X.B trmatch X.I filename X.SH DESCRIPTION X.I Trmatch Xgives error messages if it detects unmatched Xbraces, brackets, parentheses, equations, and Xdollar signs in troff documents. XError messages are sent to the standard error. X.br XEscaped braces, brackets, parentheses, and dollar signs are not counted. XText and equations are checked separately. XIt takes equations to be delimited by .EQ and .EN. XIf a ``define'' occurs in the equation, the line containing Xthe ``define'' is not checked (since it is bound to have unmatches). X.SH DIAGNOSTICS XDisplayed equations that are started and ended by user-defined Xcommands are regarded as text and matching is not checked Xseparately. X.SH SEE ALSO Xtexmatch(L). X.SH AUTHOR XKamal Al-Yahya, Stanford University X @//E*O*F trmatch.1// if test 841 -ne "`wc -c <'trmatch.1'`"; then echo shar: error transmitting "'trmatch.1'" '(should have been 841 characters)' fi fi # end of overwriting check echo shar: extracting "'trmatch.c'" '(8152 characters)' if test -f 'trmatch.c' ; then echo shar: will not over-write existing file "'trmatch.c'" else sed 's/^X//' >trmatch.c <<'@//E*O*F trmatch.c//' X/* X * trmatch: checks matching parantheses, braces, brackets, and dollar signs. X * for troff documents X * X * to compile: cc trmatch.c -lsep -o trmatch X */ X Xchar *documentation[] = { X" NAME", X" trmatch", X"", X" SYNTAX", X" trmatch [parameters] [inputfiles]", X"", X" parameters:", X" in=filename filename is the input file", X" (Default: in=stdin)", X"", X}; X X/* Author: Kamal Al-Yahya 7/20/1986 */ X Xint doclength = { sizeof documentation/sizeof documentation[0] }; X X#include X#include X#include X Xchar string[80],filename[80]; Xstruct sgttyb ttystat; Xstatic char *name="trmatch"; Xextern char *strcpy(), *mktemp(); X X/* for getpar */ Xint xargc; Xchar **xargv; X Xmain(argc,argv) Xint argc; Xchar *argv[]; X{ X FILE *temp; X register char *cptr; X int piped_in; X int i; X X /* If no arguments, and not in a pipeline, self document */ X piped_in = ioctl ((fileno (stdin)), TIOCGETP, &ttystat); X if (argc == 1 && !piped_in) X { X for( i=0; i lbr) X { X fprintf(stderr,"line %d: unmatched braces\n",l); X rbr--; /* reset the count */ X } X if (lbr == rbr) lbrl=0; X esc = 0; /* escape status */ X break; X case '[': X if (esc == 0) X { X lb++; X if (lbl == 0) lbl=l; X } X esc = 0; /* escape status */ X break; X case ']': X if (esc == 0) rb++; X else esc = 0; /* escape status */ X if (rb > lb) X { X fprintf(stderr,"line %d: unmatched brackets\n",l); X rb--; /* reset the count */ X } X if (lb == rb) lbl=0; X esc = 0; /* escape status */ X break; X case '(': X if (esc == 0) X { X lp++; X if (lpl == 0) lpl=l; X } X esc = 0; /* escape status */ X break; X case ')': X if (esc == 0) rp++; X if (rp > lp) X { X fprintf(stderr,"line %d: unmatched parentheses\n",l); X rp--; /* reset the count */ X } X if (lp == rp) lpl=0; X esc = 0; /* escape status */ X break; X case '$': X if (esc == 1) /* escaped dollar sign */ X { X c=' '; /* reset the dollar sign */ X esc = 0; /* escape status */ X break; X } X if (ld == 1) rd=1; /* right dollar sign */ X else X { X ld=1; /* left dollar sign */ X ldl=l; /* line number */ X war=0; /* no warning hs been given */ X } X esc = 0; /* escape status */ X break; X case '.': X if (c1 == '\n' || l == 1) /* troff command */ X { X /* see if it is .EQ */ X c1=getc(fp); X if (c1 == '\n') X { X esc=0; X l++; X break; X } X c=getc(fp); X if (c == '\n') X { X esc=0; X l++; X break; X } X if (c1 == 'E' && c == 'Q') X { X if (eq == 1) X fprintf(stderr,"line %d: equation started while equation at line %d is still open\n",l,eql); X eq=1; /* beginning of equation */ X eql=l; /* line number */ X/* Give warning about unclosed openings */ X if ((lbr-rbr) > 0) X fprintf(stderr,"line %d: %d unclosed braces before equation, first brace opened at line %d\n",eql,lbr-rbr,lbrl); X if ((lb-rb) > 0) X fprintf(stderr,"line %d: %d unclosed brackets before equation, first bracket opened at line %d\n",eql,lb-rb,lbl); X if ((lp-rp) > 0) X fprintf(stderr,"line %d: %d unclosed parentheses before equation, first parenthesis opened at line %d\n",eql,lp-rp,lpl); X/* clear registers */ X lp=0; lb=0; lbr=0; X rp=0; rb=0; rbr=0; X lpl=0; lbrl=0; lbl=0; X } X else if (c1 == 'E' && c == 'N') X { X if (eq == 0) X fprintf(stderr,"line %d: equation ends but no equation beginning\n",l); X/* Give warning about unclosed openings */ X if ((lbr-rbr) > 0) X fprintf(stderr,"line %d: %d unclosed braces in equation\n",eql,lbr-rbr); X if ((lb-rb) > 0) X fprintf(stderr,"line %d: %d unclosed brackets in equation\n",eql,lb-rb); X if ((lp-rp) > 0) X fprintf(stderr,"line %d: %d unclosed parentheses in equation\n",eql,lp-rp); X/* clear registers */ X lp=0; lb=0; lbr=0; X rp=0; rb=0; rbr=0; X lpl=0; lbrl=0; lbl=0; X eq=0; /* end of equation */ X } X else X while ((c = getc(fp)) != EOF) X if (c == '\n') X { X l++; X break; X } X } X esc = 0; /* escape status */ X break; X case 'd': X/* check for possible define; ignore define lines */ X esc = 0; X if (eq == 1 && c1 == '\n') X { X if ((c = getc(fp)) == 'e') X if ((c = getc(fp)) == 'f') X if ((c = getc(fp)) == 'i') X if ((c = getc(fp)) == 'n') X if ((c = getc(fp)) == 'e') X while ((c = getc(fp)) != EOF) X if (c == '\n') break; X if (c == '\n') l++; X } X/* if we grapped a character not in the word "define", go to switch X to parse the rest of the line */ X if (!(c=='d'||c=='e'||c=='f'||c=='i'||c=='n'||c=='\n')) X goto top; X c1 = ' '; X esc = 0; /* escape status */ X break; X case '\\': X/* check escape status */ X if (c1 == '\\' && esc == 1) esc = 0; X else esc = 1; X break; X default: X esc = 0; /* escape status */ X break; X } X c1=c; /* update previous character */ X if (ld == 1 && rd == 1) X {ld=0.; rd=0.;} /* matched dollar signs */ X } Xif ((lbr-rbr) > 0) X fprintf(stderr,"file ends: %d unclosed left braces, first opened at line %d \n",lbr-rbr,lbrl); Xif ((lb-rb) > 0) X fprintf(stderr,"file ends: %d unclosed left brackets, first opened at line %d \n",lb-rb,lbl); Xif ((lp-rp) > 0) X fprintf(stderr,"file ends: %d unclosed left parentheses, first opened at line %d \n",lp-rp,lpl); Xif (ld == 1) X fprintf(stderr,"file ends: single dollar sign opened at line %d unclosed\n",ldl); Xif (eq == 1) X fprintf(stderr,"file ends: equation started at line %d not closed\n",eql); X} @//E*O*F trmatch.c// if test 8152 -ne "`wc -c <'trmatch.c'`"; then echo shar: error transmitting "'trmatch.c'" '(should have been 8152 characters)' fi fi # end of overwriting check echo shar: "End of shell archive." exit 0