Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!columbia!caip!pyrnj!mirror!sources-request From: sources-request@mirror.UUCP Newsgroups: mod.sources Subject: v07i029: A collection of tools for TeX users, Part02/02 Message-ID: <243@mirror.UUCP> Date: Mon, 15-Sep-86 00:41:30 EDT Article-I.D.: mirror.243 Posted: Mon Sep 15 00:41:30 1986 Date-Received: Mon, 15-Sep-86 07:28:50 EDT Sender: rs@mirror.UUCP Organization: Mirror Systems, Cambridge MA Lines: 1112 Approved: mirror!rs Submitted by: Kamal Al-Yahya Mod.sources: Volume 7, Issue 29 Archive-name: textools/Part02 #!/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 "No problems found." # Wrapped by mirror!rs on Mon Sep 15 00:28:18 EDT 1986 # Exit status; set to 1 on "wc" errors or if would overwrite. STATUS=0 # Contents: texexpand1.c texexpand2.c texmatch.1 texmatch1.c # texmatch2.c trmatch.1 trmatch.c MANIFEST echo x - texexpand1.c if test -f texexpand1.c ; then echo texexpand1.c exists, putting output in $$texexpand1.c OUT=$$texexpand1.c STATUS=1 else OUT=texexpand1.c fi sed 's/^X//' > $OUT <<'@//E*O*F texexpand1.c//' X/* texexpand: to expand TeX and LaTeX \input and include files X * to compile: cc texexpand.c -o texexpand X */ Xchar *documentation[] = { X" SYNTAX", X" texexpand [-w] file1 [file2 .....]", X" or texexpand [-w] < file1 [file2 ....]", X"", X" Flags:", X" -w maching is not checked", X"", X"See the manual page for more details.", X"", X}; X/* Author: Kamal Al-Yahya, Stanford University, 11/1/83 */ X/* Modified: 6/30/86 */ Xint doclength = { sizeof documentation/sizeof documentation[0] }; X#include X#include X#include X#define MAXLEN 100000 /* maximum character in a document */ Xstruct sgttyb ttystat; Xextern char *strcpy(), *mktemp(); Xchar scratch_file[100]; Xint wflag; Xint xargc; Xchar **xargv; Xmain(argc,argv) Xint argc; Xchar *argv[]; X{ Xchar big[MAXLEN]; XFILE *temp,*scr; Xregister char *cptr; Xint piped_in; Xint i,w; X/* If no arguments, and not in a pipeline, self document */ Xpiped_in = ioctl ((fileno (stdin)), TIOCGETP, &ttystat); Xif (argc == 1 && !piped_in) X { X for( i=0; i $OUT <<'@//E*O*F texexpand2.c//' X/* texexpand: to expand TeX and LaTeX \input and include files X * to compile: cc texexpand.c -o texexpand X */ Xchar *documentation[] = { X" SYNTAX", X" texexpand [-w] [parameters] [inputfiles]", X"", X" flags:", X" -w does not check matching", X"", X" parameters:", X" in=filename filename is the input file", X" (Default: in=stdin)", X"", X" out=filename filename is the output file", X" (Default: out=stdout)", X"" X}; X/* Author: Kamal Al-Yahya, Stanford University, 11/1/83 */ X/* Modified: 6/30/86 */ Xint doclength = { sizeof documentation/sizeof documentation[0] }; X#include X#include X#include X#define MAXLEN 100000 /* maximum character in a document */ Xchar string[100],filename[100]; Xstruct sgttyb ttystat; Xextern char *strcpy(), *mktemp(); Xchar scratch_file[100]; XFILE *out_file; Xint wflag; Xint xargc; Xchar **xargv; Xmain(argc,argv) Xint argc; Xchar *argv[]; X{ Xchar big[MAXLEN]; XFILE *temp,*scr; Xregister char *cptr; Xint piped_in; Xint i,w; X/* If no arguments, and not in a pipeline, self document */ Xpiped_in = ioctl ((fileno (stdin)), TIOCGETP, &ttystat); Xif (argc == 1 && !piped_in) X { X for( i=0; i $OUT <<'@//E*O*F texmatch.1//' X.TH texmatch 1 7/10/86 X.UC 4 X.SH NAME Xtexmatch \- checks matching in TeX and LaTeX documents. X.SH SYNOPSIS X.B texmatch [-i] X.I filename X.SH DESCRIPTION X.I Texmatch Xgives error messages if it detects unmatched Xbraces, brackets, parentheses, and equations in TeX and LaTeX documents. XError messages are sent Xto the standard error. X.br XEscaped braces, brackets, parentheses, and dollar signs are not Xcounted. It understands TeX's rules of escaping and dollar signs Xpairing as well as LaTeX's \\begin{equation} and \\end{equation}. XIt also checks \\input and \\include files unless the X.B -i Xflag is used. X.br XText and displayed equations are checked separately. X.br XCommented text is not checked. X.SH DIAGNOSTICS XDisplayed equations that are started and ended by user-defined Xcontrol sequences are regarded as text and they are not checked Xseparately. X.br XDoes not check for matching \\begin and \\end in LaTeX environments Xother than equations. X.SH SEE ALSO Xtexexpand(1), texeqn(1). X.SH AUTHOR XKamal Al-Yahya, Stanford University @//E*O*F texmatch.1// chmod u=rw,g=rw,o=rw $OUT echo x - texmatch1.c if test -f texmatch1.c ; then echo texmatch1.c exists, putting output in $$texmatch1.c OUT=$$texmatch1.c STATUS=1 else OUT=texmatch1.c fi sed 's/^X//' > $OUT <<'@//E*O*F texmatch1.c//' X/* X * texmatch: checks matching parantheses, braces, brackets, and dollar signs X * in TeX documents. X * X * to compile: cc texmatch.c -lsep -o texmatch X */ Xchar *documentation[] = { X" SYNTAX", X" texmatch [-i] file1 [file2 .....]", X" or texmatch [-i] < file1 [file2 ....]", X"", X"See the manual page for more details.", X"", X}; X/* Author: Kamal Al-Yahya, Stanford University, 11/1/83 */ X/* Modified: 6/30/86 */ Xint doclength = { sizeof documentation/sizeof documentation[0] }; X#include X#include X#include X#define MAXLEN 100000 /* maximum characters in a document */ Xstruct sgttyb ttystat; Xextern char *strcpy(), *mktemp(); Xchar scratch_file[100]; Xint wflag=0; /* for consistency with other programs */ Xint xargc; Xchar **xargv; Xmain(argc,argv) Xint argc; Xchar *argv[]; X{ Xchar big[MAXLEN]; XFILE *temp,*scr; Xregister char *cptr; Xint piped_in; Xint i,iflag; X/* If no arguments, and not in a pipeline, self document */ Xpiped_in = ioctl ((fileno (stdin)), TIOCGETP, &ttystat); Xif (argc == 1 && !piped_in) X { X for( i=0; i $OUT <<'@//E*O*F texmatch2.c//' X/* X * texmatch: checks matching parantheses, braces, brackets, and dollar signs X * in TeX documents. X * X * to compile: cc texmatch.c -lsep -o texmatch X */ Xchar *documentation[] = { X" SYNTAX", X" texmatch [-i] [parameters] [inputfiles]", X"", X" flags:", X" -i ignores TeX's and LaTeX's \input and \include commands", X"", X" parameters:", X" in=filename filename is the input file", X" (Default: in=stdin)", X"" X}; X/* Author: Kamal Al-Yahya, Stanford University, 11/1/83 */ X/* Modified: 6/30/86 */ Xint doclength = { sizeof documentation/sizeof documentation[0] }; X#include X#include X#include X#define MAXLEN 100000 /* maximum characters in a document */ Xchar string[100],filename[100]; Xstruct sgttyb ttystat; Xextern char *strcpy(), *mktemp(); Xchar scratch_file[100]; Xint wflag=0; /* for consistency with other programs */ Xint xargc; Xchar **xargv; Xmain(argc,argv) Xint argc; Xchar *argv[]; X{ Xchar big[MAXLEN]; XFILE *temp,*scr; Xregister char *cptr; Xint piped_in; Xint i,iflag; X/* If no arguments, and not in a pipeline, self document */ Xpiped_in = ioctl ((fileno (stdin)), TIOCGETP, &ttystat); Xif (argc == 1 && !piped_in) X { X for( i=0; i $OUT <<'@//E*O*F trmatch.1//' X.TH trmatch 1 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 Xcontrol sequences are regarded as text and matching is not checked Xseparately. X.SH SEE ALSO Xtexmatch(1). X.SH AUTHOR XKamal Al-Yahya, Stanford University @//E*O*F trmatch.1// chmod u=rw,g=rw,o=rw $OUT echo x - trmatch.c if test -f trmatch.c ; then echo trmatch.c exists, putting output in $$trmatch.c OUT=$$trmatch.c STATUS=1 else OUT=trmatch.c fi sed 's/^X//' > $OUT <<'@//E*O*F trmatch.c//' X/* X * trmatch: checks matching parantheses, braces, brackets, and dollar signs. X * for troff documents X * non-getpar() version. X * to compile: cc trmatch.c -o trmatch X */ Xchar *documentation[] = { X" SYNTAX", X" trmatch file1 file2 ....", X"", X" See the manula page for more details", X"", X}; X/* Author: Kamal Al-Yahya 7/20/1986 */ Xint doclength = { sizeof documentation/sizeof documentation[0] }; X#include X#include X#include Xstruct sgttyb ttystat; Xstatic char *name="trmatch"; Xextern char *strcpy(), *mktemp(); Xint xargc; Xchar **xargv; Xmain(argc,argv) Xint argc; Xchar *argv[]; X{ X FILE *temp; X register char *cptr; X int piped_in; X int i; 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// chmod u=rw,g=rw,o=rw $OUT echo x - MANIFEST if test -f MANIFEST ; then echo MANIFEST exists, putting output in $$MANIFEST OUT=$$MANIFEST STATUS=1 else OUT=MANIFEST fi sed 's/^X//' > $OUT <<'@//E*O*F MANIFEST//' XMANIFEST 2 XManifest 1 XREADME 1 XTEX 1 XTEX.1 1 XTeXExpand.c 1 XTeXMatch.c 1 Xdetex.1 1 Xdetex1.c 1 Xdetex2.c 1 Xinc_file 1 Xinc_file2.tex 1 Xmakefile 1 Xmakefile.par 1 Xtestfile 1 Xtexeqn.1 1 Xtexeqn1.c 1 Xtexeqn2.c 1 Xtexexpand.1 1 Xtexexpand1.c 2 Xtexexpand2.c 2 Xtexmatch.1 2 Xtexmatch1.c 2 Xtexmatch2.c 2 Xtexspell 1 Xtrmatch.1 2 Xtrmatch.c 2 @//E*O*F MANIFEST// chmod u=rw,g=rw,o=rw $OUT echo Inspecting for damage in transit... temp=/tmp/sharin$$; dtemp=/tmp/sharout$$ trap "rm -f $temp $dtemp; exit" 0 1 2 3 15 cat > $temp <<\!!! 131 319 2656 texexpand1.c 183 431 3878 texexpand2.c 35 158 1028 texmatch.1 124 317 2452 texmatch1.c 156 381 3152 texmatch2.c 27 132 849 trmatch.1 293 1161 7341 trmatch.c 27 54 837 MANIFEST 976 2953 22193 total !!! wc texexpand1.c texexpand2.c texmatch.1 texmatch1.c texmatch2.c trmatch.1 trmatch.c MANIFEST | sed 's=[^ ]*/==' | diff -b $temp - >$dtemp if test -s $dtemp ; then echo "Ouch [diff of wc output]:" cat $dtemp STATUS=1 elif test $STATUS = 0 ; then echo "No problems found." else echo "WARNING -- PROBLEMS WERE FOUND..." fi exit $STATUS