v07i029: A collection of tools for TeX users, Part02/02

sources-request at mirror.UUCP sources-request at mirror.UUCP
Mon Sep 15 14:41:30 AEST 1986


Submitted by: Kamal Al-Yahya <kamal at hanauma.Stanford.EDU>
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        <stdio.h>
X#include        <sys/ioctl.h>
X#include        <sgtty.h>
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<doclength; i++)
X		printf("%s\n",documentation[i]);
X	exit (0);
X	}

X/* process option flags */
Xxargc = argc;
Xxargv = argv;
Xfor (xargc--,xargv++; xargc; xargc--,xargv++)
X	{
X	cptr = *xargv; 
X	if( *cptr=='-' )
X		{
X		while( *(++cptr))
X			{
X			switch( *cptr )
X				{
X				case 'w':
X					wflag=1;
X					break;
X				default:
X			     		fprintf(stderr,
X					"unknown flag -%c\n",*cptr);
X					break;
X				}
X			}
X		}
X	}

X/* first process pipe input */
Xif(piped_in)
X	{
X	if (wflag != 1)
X		{
X/* need to buffer; can's seek in pipes */
X/* make a temporary and volatile file in /tmp */
X		strcpy(scratch_file,"/tmp/texXXXXXX");
X		mktemp(scratch_file);
X		scr=fopen(scratch_file,"w");
X		scrbuf(stdin,scr);
X		fclose(scr);
X		scr=fopen(scratch_file,"r");
X		unlink(scratch_file);
X		fprintf(stderr,"Checking matching...\n");
X		TeXMatch(scr);
X		fseek(scr,0,0);
X		TeXExpand(scr,big,MAXLEN);
X		fprintf(stderr,"Checking matching done\n\n");
X		fclose(scr);
X		}
X	else
X		TeXExpand(stdin,big,MAXLEN);

X	fprintf(stdout,"%s\n",big);
X	}

X/* then process input line for arguments and assume they are input files */
Xxargc = argc;
Xxargv = argv;
Xfor (xargc--,xargv++; xargc; xargc--,xargv++)
X	{
X	cptr = *xargv; 
X	if((temp=fopen(cptr,"r")) != NULL)
X		{
X		if (wflag != 1)
X			{
X			fprintf(stderr,"Checking matching...\n");
X			fprintf(stderr,"%s:\n",cptr);
X			TeXMatch(temp);
X			fprintf(stderr,"\n");
X			fseek(temp,0,0);
X			}
X		TeXExpand(temp,big,MAXLEN);
X		if (wflag != 1)
X			fprintf(stderr,"Checking matching done\n\n");
X		fprintf(stdout,"%s",big);
X		fclose(temp);
X		}
X	else
X		fprintf(stderr,"texexpand: Cannot open %s\n",cptr);
X	}

X}
@//E*O*F texexpand1.c//
chmod u=rw,g=rw,o=rw $OUT
 
echo x - texexpand2.c
if test -f texexpand2.c ; then
    echo texexpand2.c exists, putting output in $$texexpand2.c
    OUT=$$texexpand2.c
    STATUS=1
else
    OUT=texexpand2.c
fi
sed 's/^X//' > $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        <stdio.h>
X#include        <sys/ioctl.h>
X#include        <sgtty.h>
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<doclength; i++)
X		printf("%s\n",documentation[i]);
X	exit (0);
X	}

Xout_file=stdout;			/* default standard output */

X/* process option flags */
Xxargc = argc;
Xxargv = argv;
Xfor (xargc--,xargv++; xargc; xargc--,xargv++)
X	{
X	cptr = *xargv; 
X	if( *cptr=='-' )
X		{
X		while( *(++cptr))
X			{
X			switch( *cptr )
X				{
X				case 'w':
X					wflag=1;
X					break;
X				default:
X			     		fprintf(stderr,
X					"unknown flag -%c\n",*cptr);
X					break;
X				}
X			}
X		}
X	}

X/* process getpar parameters */
Xxargc = argc;
Xxargv = argv;

Xif(getpar_("out","s",string))
X	{
X	sscanf(string,"%s",filename);
X	if((temp=fopen(filename,"w")) == NULL)
X		fprintf(stderr,"texexpand: Cannot open output file %s\n",filename);
X	else
X		out_file = temp;
X	}


X/* first process pipe input */
Xif(piped_in)
X	{
X	if (wflag != 1)
X		{
X/* need to buffer; can's seek in pipes */
X/* make a temporary and volatile file in /tmp */
X		strcpy(scratch_file,"/tmp/texXXXXXX");
X		mktemp(scratch_file);
X		scr=fopen(scratch_file,"w");
X		scrbuf(stdin,scr);
X		fclose(scr);
X		scr=fopen(scratch_file,"r");
X		unlink(scratch_file);
X		fprintf(stderr,"Checking matching...\n");
X		TeXMatch(scr);
X		fseek(scr,0,0);
X		TeXExpand(scr,big,MAXLEN);
X		fprintf(stderr,"Checking matching done\n\n");
X		fclose(scr);
X		}
X	else
X		TeXExpand(stdin,big,MAXLEN);

X	fprintf(stdout,"%s\n",big);
X	}

X/* next process in=inputfiles */
Xif(getpar_("in","s",string))
X	{
X	sscanf(string,"%s",filename);
X	if((temp=fopen(filename,"r")) != NULL)
X		{
X		if (wflag != 1)
X			{
X			fprintf(stderr,"Checking matching...\n");
X			fprintf(stderr,"%s:\n",cptr);
X			TeXMatch(temp);
X			fprintf(stderr,"\n");
X			fseek(temp,0,0);
X			}
X		TeXExpand(temp,big,MAXLEN);
X		if (wflag != 1)
X			fprintf(stderr,"Checking matching done\n\n");
X		fprintf(stdout,"%s",big);
X		fclose(temp);
X		}
X		else
X			fprintf(stderr,"texexpand: Cannot open %s\n",filename);
X	}

X/* then process input line for arguments and assume they are input files */
Xfor (xargc--,xargv++; xargc; xargc--,xargv++)
X	{
X	cptr = *xargv; 
X	if( *cptr=='-' ) continue;	/* this is a flag */
X	while (*cptr)
X		{
X		if (*cptr == '=')  break; /* this is for getpar */
X		cptr++;
X		}       
X	if (*cptr)  continue;
X	cptr = *xargv;
X	if((temp=fopen(cptr,"r")) != NULL)
X		{
X		if (wflag != 1)
X			{
X			fprintf(stderr,"Checking matching...\n");
X			fprintf(stderr,"%s:\n",cptr);
X			TeXMatch(temp);
X			fprintf(stderr,"\n");
X			fseek(temp,0,0);
X			}
X		TeXExpand(temp,big,MAXLEN);
X		if (wflag != 1)
X			fprintf(stderr,"Checking matching done\n\n");
X		fprintf(stdout,"%s",big);
X		fclose(temp);
X		}
X	else
X		fprintf(stderr,"texexpand: Cannot open %s\n",cptr);
X	}

X}
@//E*O*F texexpand2.c//
chmod u=rw,g=rw,o=rw $OUT
 
echo x - texmatch.1
if test -f texmatch.1 ; then
    echo texmatch.1 exists, putting output in $$texmatch.1
    OUT=$$texmatch.1
    STATUS=1
else
    OUT=texmatch.1
fi
sed 's/^X//' > $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        <stdio.h>
X#include        <sys/ioctl.h>
X#include        <sgtty.h>
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<doclength; i++)
X		printf("%s\n",documentation[i]);
X	exit (0);
X	}

X/* process option flags */
Xxargc = argc;
Xxargv = argv;
Xfor (xargc--,xargv++; xargc; xargc--,xargv++)
X	{
X	cptr = *xargv; 
X	if( *cptr=='-' )
X		{
X		while( *(++cptr))
X			{
X			switch( *cptr )
X				{
X				case 'i':
X					iflag=1;
X					break;
X				default:
X			     		fprintf(stderr,
X					"unknown flag -%c\n",*cptr);
X					break;
X				}
X			}
X		}
X	}

X/* first process pipe input */
Xif(piped_in)
X	{
X	if (iflag != 1)
X		{
X/* need to buffer; can's seek in pipes */
X/* make a temporary and volatile file in /tmp */
X		strcpy(scratch_file,"/tmp/texXXXXXX");
X		mktemp(scratch_file);
X		scr=fopen(scratch_file,"w");
X		scrbuf(stdin,scr);
X		fclose(scr);
X		scr=fopen(scratch_file,"r");
X		unlink(scratch_file);
X		TeXMatch(scr);
X		fseek(scr,0,0);
X		TeXExpand(scr,big,MAXLEN);
X		fclose(scr);
X		}
X	else
X		TeXMatch(stdin);
X	}

X/* then process input line for arguments and assume they are input files */
Xxargc = argc;
Xxargv = argv;
Xfor (xargc--,xargv++; xargc; xargc--,xargv++)
X	{
X	cptr = *xargv; 
X	if( *cptr=='-' ) continue;		/* this is a flag */
X	if((temp=fopen(cptr,"r")) != NULL)
X		{
X		fprintf(stderr,"%s:\n",cptr);
X		TeXMatch(temp);
X		fprintf(stderr,"\n");
X		if (iflag != 1)
X			{
X			fseek(temp,0,0);
X			TeXExpand(temp,big,MAXLEN);
X			}
X		fclose(temp);
X		}
X	else
X		fprintf(stderr,"texmatch: Cannot open %s\n",cptr);
X	}

X}
@//E*O*F texmatch1.c//
chmod u=rw,g=rw,o=rw $OUT
 
echo x - texmatch2.c
if test -f texmatch2.c ; then
    echo texmatch2.c exists, putting output in $$texmatch2.c
    OUT=$$texmatch2.c
    STATUS=1
else
    OUT=texmatch2.c
fi
sed 's/^X//' > $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        <stdio.h>
X#include        <sys/ioctl.h>
X#include        <sgtty.h>
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<doclength; i++)
X		printf("%s\n",documentation[i]);
X	exit (0);
X	}

X/* process option flags */
Xxargc = argc;
Xxargv = argv;
Xfor (xargc--,xargv++; xargc; xargc--,xargv++)
X	{
X	cptr = *xargv; 
X	if( *cptr=='-' )
X		{
X		while( *(++cptr))
X			{
X			switch( *cptr )
X				{
X				case 'i':
X					iflag=1;
X					break;
X				default:
X			     		fprintf(stderr,
X					"unknown flag -%c\n",*cptr);
X					break;
X				}
X			}
X		}
X	}

X/* first process pipe input */
Xxargc = argc;
Xxargv = argv;
Xif(piped_in)
X	{
X	if (iflag != 1)
X		{
X/* need to buffer; can's seek in pipes */
X/* make a temporary and volatile file in /tmp */
X		strcpy(scratch_file,"/tmp/texXXXXXX");
X		mktemp(scratch_file);
X		scr=fopen(scratch_file,"w");
X		scrbuf(stdin,scr);
X		fclose(scr);
X		scr=fopen(scratch_file,"r");
X		unlink(scratch_file);
X		TeXMatch(scr);
X		fseek(scr,0,0);
X		TeXExpand(scr,big,MAXLEN);
X		fclose(scr);
X		}
X	else
X		TeXMatch(stdin);
X	}

X/* next process in=inputfiles */
Xif(getpar_("in","s",string))
X	{
X	sscanf(string,"%s",filename);
X	if((temp=fopen(filename,"r")) != NULL)
X		{
X		fprintf(stderr,"%s:\n",cptr);
X		TeXMatch(temp);
X		fprintf(stderr,"\n");
X		if (iflag != 1)
X			{
X			fseek(temp,0,0);
X			TeXExpand(temp,big,MAXLEN);
X			}
X		fclose(temp);
X		}
X	else
X		fprintf(stderr,"texmatch: Cannot open %s\n",filename);
X	}

X/* then process input line for arguments and assume they are input files */
Xfor (xargc--,xargv++; xargc; xargc--,xargv++)
X	{
X	cptr = *xargv; 
X	if( *cptr=='-' ) continue;		/* this is a flag */
X	while (*cptr)
X		{
X		if (*cptr == '=')  break; /* this is for getpar */
X		cptr++;
X		}       
X	if (*cptr)  continue;
X	cptr = *xargv;
X	if((temp=fopen(cptr,"r")) != NULL)
X		{
X		fprintf(stderr,"%s:\n",cptr);
X		TeXMatch(temp);
X		fprintf(stderr,"\n");
X		if (iflag != 1)
X			{
X			fseek(temp,0,0);
X			TeXExpand(temp,big,MAXLEN);
X			}
X		fclose(temp);
X		}
X	else
X		fprintf(stderr,"texmatch: Cannot open %s\n",cptr);
X	}

X}
@//E*O*F texmatch2.c//
chmod u=rw,g=rw,o=rw $OUT
 
echo x - trmatch.1
if test -f trmatch.1 ; then
    echo trmatch.1 exists, putting output in $$trmatch.1
    OUT=$$trmatch.1
    STATUS=1
else
    OUT=trmatch.1
fi
sed 's/^X//' > $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        <stdio.h>
X#include        <sys/ioctl.h>
X#include        <sgtty.h>

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<doclength; i++)
X			printf("%s\n",documentation[i]);
X		exit (0);
X		}

X	 /* first process pipe input */
X	if(piped_in)
X		{
X		troff_match(stdin);
X		fprintf(stderr,"\n");
X		}

X/* next process input line arguments and assume they are also input files */

X	xargc = argc;
X	xargv = argv;
X	for (xargc--,xargv++; xargc; xargc--,xargv++)
X		{
X		cptr = *xargv; 
X		if((temp=fopen(cptr,"r")) != NULL)
X			{
X			fprintf(stderr,"%s:\n",cptr);
X			troff_match(temp);
X			fprintf(stderr,"\n");
X			fclose(temp);
X			}
X		else
X			fprintf(stderr,"%s: Cannot open %s\n",name,cptr);
X		}

X}

Xtroff_match(fp)			/* check matching */
XFILE *fp;
X{

Xint l=1;			/* line counter */
Xint ld=0;			/* single left dollar signs */
Xint rd=0;			/* single right dollar signs */
Xint eq=0;			/* eq=1 : equation (delimeted by .EQ and .EN) */
Xint lp=0;			/* left parantheses */
Xint rp=0;			/* right parantheses */
Xint lb=0;			/* left brackets */
Xint rb=0;			/* right brackets */
Xint lbr=0;			/* left braces */
Xint rbr=0;			/* right braces */
Xint c=' ';			/* current character */
Xint c1=' ';			/* previous character */
Xint lbrl=1;			/* line number of left braces */
Xint lbl=1;			/* line number of left bracket */
Xint lpl=1;			/* line number of left parentheses */
Xint ldl=1;			/* line number of left single dollar sign */
Xint eql=1;			/* line number at which equation is started */
Xint war=0;			/* warning status */
Xint esc=0;			/* escape status */

Xwhile ((c =getc(fp)) != EOF)
X	{
Xtop:
X	switch(c)
X		{
X		case '\n':
X			l++;		/* increment line counter */
X/* check to see if a single dollar sign is not closed at the same line */
X			if (ld == 1 && war == 0 && c1 != '\\')
X				{
X				fprintf(stderr,"line %d: WARNING: single dollar sign is not closed on the same line\n",l-1);
X				war=1;		/* warning has been given */
X				}
X			esc = 0;		/* escape status */
X			break;
X		case '{':
X			if (esc == 0)
X				{
X				lbr++;
X				if (lbrl == 0) lbrl=l;
X				}
X			esc = 0;		/* escape status */
X			break;
X		case '}':
X			if (esc == 0)	rbr++;
X			if (rbr > 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



More information about the Mod.sources mailing list