v08INF3: Repost of textool2, part 2
sources-request at mirror.UUCP
sources-request at mirror.UUCP
Wed Feb 18 03:51:14 AEST 1987
Submitted by: Rich Salz <rs at mirror.TMC.COM>
Mod.sources: Volume 8, Info 3
Archive-name: /dev/null
There were two problems with last week's publication of the TeX tools
sources. First, the second part seemed to have never made it out
of mirror. Second, the archive name, tektools2, is an error, not a
joke: it should have been textools2. Sorry.
/r$
-----------------------------------------------------------------------
Subject: v08i062: A collection of tools for TeX users, Part02/02
Newsgroups: mod.sources
Approved: mirror!rs
Submitted by: Kamal Al-Yahya <kamal at hanauma.STANFORD.EDU>
Mod.sources: Volume 8, Issue 62
Archive-name: tektools2/Part02
[ Not that the previous posting said to connect this one to the end,
then unshar them together. This is really not necessary... --r$ ]
if test -f 'subs.c'
then
echo shar: will not over-write existing file "'subs.c'"
else
cat << \SHAR_EOF > 'subs.c'
/* COPYRIGHT (C) 1987 Kamal Al-Yahya */
/* subroutines used programs in the package */
#include "setups.h"
int
begin_to_end(buffer,environment)
char *buffer;
char *environment;
{
int c,len,i;
char w[MAXWORD];
buffer++; len = 1;
while ((c = *buffer++) != NULL)
{
len++;
if (c == '\\')
{
i = get_buf_word(buffer,w);
buffer += i; len += i;
if (strcmp(w,"end") == 0)
{
buffer++; len++;
i = get_buf_word(buffer,w);
buffer += i+1; len += i+1;
if (strcmp(w,environment) == 0)
break;
}
}
}
return(len);
}
int
command(inbuf,w)
char *inbuf;
char *w;
{
int c,i,j;
int left_br=0, right_br=0;
for (i=0; (c = *inbuf++) != NULL && i < MAXLINE; i++)
{
w[i] = (char)c;
if (c == '{') left_br++;
if (c == '}') right_br++;
if (left_br == right_br && left_br != 0) break;
}
left_br = 0; right_br = 0;
for (j=i+1; (c = *inbuf++) != NULL && j < MAXLINE; j++)
{
w[j] = (char)c;
if (c == '{') left_br++;
if (c == '}') right_br++;
if (left_br == right_br && left_br != 0) break;
}
w[++j] = NULL;
return(j);
}
int
comm_file(fp,line,match)
FILE *fp;
int *line,match;
{
int i=0,lbrl=0;
int c;
int left_br=0, right_br=0;
while ((c = getc(fp)) != EOF)
{
i++;
if (c == '\n') (*line)++;
if (c == '{')
{
left_br++;
if (lbrl == 0) lbrl = *line;
}
if (c == '}') right_br++;
if (right_br > left_br) break;
}
if (match == 1 && c == EOF && left_br > right_br)
{
fprintf(stderr,"file ends: %d unclosed left braces while reading \\newcommand, first opened at line %d\n",left_br-right_br,lbrl,lbrl);
return(i);
}
left_br = 0; right_br = 0; lbrl = 0;
while ((c = getc(fp)) != EOF)
{
i++;
if (c == '\n') (*line)++;
if (c == '{')
{
left_br++;
if (lbrl == 0) lbrl = *line;
}
if (c == '}') right_br++;
if (left_br == right_br && left_br != 0) break;
}
if (match == 1 && c == EOF && left_br > right_br)
fprintf(stderr,"file ends: %d unclosed left braces while reading \\newcommand, first opened at line %d\n",left_br-right_br,lbrl,lbrl);
return(i);
}
int
comment(buffer) /* commented text is ignored */
char *buffer;
{
int c,len=0;
while((c = *buffer++) != NULL)
{
if (c == '\n') break;
len++;
}
return(len);
}
int
def(inbuf,w)
char *inbuf, *w;
{
int c,i;
int left_br=0, right_br=0;
for (i=0; (c = *inbuf++) != NULL && i < MAXLINE; i++)
{
w[i] = (char)c;
if (c == '{') left_br++;
if (c == '}') right_br++;
if (left_br == right_br && left_br != 0) break;
}
w[++i] = NULL;
return(i);
}
int
def_file(fp,line,match)
FILE *fp;
int *line,match;
{
int i=0, lbrl=0;
int c;
int left_br=0, right_br=0;
while ((c = getc(fp)) != EOF)
{
i++;
if (c == '\n') (*line)++;
if (c == '{')
{
left_br++;
if (lbrl == 0) lbrl = *line;
}
if (c == '}') right_br++;
if (left_br == right_br && left_br != 0) break;
}
if (match == 1 && c == EOF && left_br > right_br)
fprintf(stderr,"file ends: %d unclosed left braces while reading \\def, first opened at line %d\n",left_br-right_br,lbrl);
return(i);
}
int
display(buffer)
char *buffer;
{
int c,len=1;
while((c = *buffer++) != NULL)
{
len++;
if(c == '\\')
{
len++;
if ((c = *buffer++) == ']')
break;
}
}
return(len);
}
int
dollar(buffer,out_file)
char *buffer;
FILE *out_file;
{
int c,len;
c=' ' ; /* "erase" the dollar sign */
putc (c,out_file);
c = *buffer++;
if(c == '$') len=two_dollars(buffer,out_file)+1;
else len=one_dollar(buffer);
return(len);
}
int
formula(buffer)
char *buffer;
{
int c,len=1;
while((c = *buffer++) != NULL)
{
len++;
if (c == '\\')
{
if ((c = *buffer++) == ')')
break;
}
}
return(len);
}
int
get_buf_word(inbuf,w)
char *inbuf;
char *w;
{
int c,i;
for (i=0; (c = *inbuf++) != NULL && c != ' ' && c != '\n' && c != '\t'
&& c != '$' && c != '{' && c != '}' && c != '%'
&& c != '\\' && c != '#' && c != '(' && c != ')' && c != '['
&& c != ']' && i < MAXWORD; i++)
w[i] = (char)c;
if ((c == ' ' || c == '\n' || c == '\t' || c == '$' || c == '{' || c == '}' ||
c == '%' || c == '\\' && c != '#' || c == '(' || c == ')' || c =='['
|| c == ']') && i == 0)
w[i++] = (char)c;
w[i] = NULL;
return(i);
}
int
getenv_file(fp,line,match)
FILE *fp;
int *line,match;
{
int i=0,lbrl=0;
int c;
int left_br=0, right_br=0;
while ((c = getc(fp)) != EOF)
{
i++;
if (c == '\n') (*line)++;
if (c == '{')
{
left_br++;
if (lbrl == 0) lbrl = *line;
}
if (c == '}') right_br++;
if (right_br > left_br) break;
}
if (match == 1 && c == EOF && left_br > right_br)
{
fprintf(stderr,"file ends: %d unclosed left braces while reading \\newenvironment, first opened at line %d\n",left_br-right_br,lbrl);
return(i);
}
left_br = 0; right_br = 0; lbrl = 0;
while ((c = getc(fp)) != EOF)
{
i++;
if (c == '\n') (*line)++;
if (c == '{')
{
left_br++;
if (lbrl == 0) lbrl = *line;
}
if (c == '}') right_br++;
if (left_br == right_br && left_br != 0) break;
}
if (match == 1 && c == EOF && left_br > right_br)
{
fprintf(stderr,"file ends: %d unclosed left braces while reading \\newenvironment, first opened at line %d\n",left_br-right_br,lbrl);
return(i);
}
left_br = 0; right_br = 0; lbrl = 0;
while ((c = getc(fp)) != EOF)
{
i++;
if (c == '\n') (*line)++;
if (c == '{')
{
left_br++;
if (lbrl == 0) lbrl = *line;
}
if (c == '}') right_br++;
if (left_br == right_br && left_br != 0) break;
}
if (match == 1 && c == EOF && left_br > right_br)
fprintf(stderr,"file ends: %d unclosed left braces while reading \\newenvironment, first opened at line %d\n",left_br-right_br,lbrl);
return(i);
}
int
get_file_word(fp,w,line,c)
FILE *fp;
char *w;
int *line, *c;
{
int i;
for (i=0; (*c = getc(fp)) != NULL && *c != ' ' && *c != '\n' && *c != '\t'
&& *c != '$' && *c != '{' && *c != '}' && *c != '\\' && *c != '#'
&& *c != '(' && *c != ')' && *c != '[' && *c != ']' && *c != '%'
&& i < MAXWORD; i++)
w[i] = (char)*c;
if (i == 0 && *c == '\n') (*line)++;
w[i] = NULL;
return(i);
}
int
is_new_env(w,env_count)
char *w;
int env_count;
{
int i;
for (i=0; i < env_count; i++)
{
if (strcmp(env[i].env_name,w) == 0)
return(i);
}
return(-1);
}
int
one_dollar(buffer)
char *buffer;
/* an in-line equation with one dollar signs as delimeters */
{
int c,len=0;
while((c = *buffer++) != NULL)
{
len++;
if(c == '$') break;
}
return(len+1);
}
void
scrbuf(in,out) /* copy input to output */
FILE *in,*out;
{
int c;
while ((c =getc(in)) != EOF) putc(c,out);
}
void
tmpbuf(in,buffer)
/* copy input to buffer, buffer holds only MAXLEN characters */
FILE *in;
char *buffer;
{
int c;
unsigned int l=0;
while (l++ < MAXLEN && (c = getc(in)) != EOF)
*buffer++ = (char)c;
if (l >= MAXLEN)
{
fprintf(stderr,"Sorry: document is too large\n");
exit(-1);
}
*buffer = NULL;
}
int
two_dollars(buffer,out_file)
char *buffer;
FILE *out_file;
/* displayed equation with two-dollar sign delimeters */
{
int c,len=0;
while((c = *buffer++) != NULL)
{
len++;
if(c == '$')
{
c = *buffer++; len++;
if (c != '$') putc(c,out_file);
break;
}
}
return(len);
}
SHAR_EOF
fi # end of overwriting check
if test -f 'testfile'
then
echo shar: will not over-write existing file "'testfile'"
else
cat << \SHAR_EOF > 'testfile'
This is a test file for textools
$\beta$
junk \
(unmatched parentheses))
$dollar sign not closed at the same line
it could be a mistake!$
Input another file
\input inc_file
Try to input a non existing file
\input not_available
$$
{{unclosed braces in equation}
$ this should be a double dollar sign
% commented text is ignored, so unmatching like this (( is ignored.
Insert another file
\include{inc_file2}
but \% this is not a commented text
this \$ is also not a math dollar sign, so it should not give
a matching warning, nor should this \{ escaped left brace.
$$ This is a properly displayed text $$
$((unmatched parentheses)$
LaTeX equation:
\begin{equation}
\alpha + beta =0
\begin{array}
\end{array}
\begin{array}
\end{equation}
\end{equation}
SHAR_EOF
fi # end of overwriting check
if test -f 'texeqn.1'
then
echo shar: will not over-write existing file "'texeqn.1'"
else
cat << \SHAR_EOF > 'texeqn.1'
.TH texeqn 1 2/2/84
.UC 4
.SH NAME
texeqn \- extracts displayed equations in TeX and LaTeX documents.
.SH SYNOPSIS
.B texeqn [-iw]
.I filename
.SH DESCRIPTION
It is sometimes desirable to check only the equations of a document.
.I Texeqn
strips those patterns that constitute displayed equations, i.e. anything
surrounded by
.I two
dollar signs, \\begin{equation} and \\end{equation},
\\begin{eqnarray} and \\end{eqnarray}, or \\begin{displaymath} and
\\end{displaymath}.
Note that this also includes any text that is displayed
in this fashion even if it is not an equation.
.br
Macros defines by \\def or \\newcommand are also stripped, since
the user is likely to use them in those equations.
Also, \\input and \\include files are inserted unless the
.B -i
flag is used.
.br
Warning is given if suspected unmatching is detected. Use the
.B -w
flag to suppress these warnings.
.br
Text commented by '%' is ignored.
.br
Using
.I texeqn
alone does not typest the equations. If you want them typeset use the
.B \-eqn
option with TEX(1).
.SH DIAGNOSTICS
Displayed equations that are started and ended by user-defined
control sequences are nor recognized.
.br
White spaces within LaTeX's \\begin{...} and \\end{...} are not allowed for.
.SH SEE ALSO
TEX(1), detex(1), texexpand(1), texmatch(1)
.SH AUTHOR
Kamal Al-Yahya, Stanford University
SHAR_EOF
fi # end of overwriting check
if test -f 'texeqn1.c'
then
echo shar: will not over-write existing file "'texeqn1.c'"
else
cat << \SHAR_EOF > 'texeqn1.c'
/* COPYRIGHT (C) 1987 Kamal Al-Yahya */
/* texeqn: TeX equation stripping */
char *documentation[] = {
" SYNTAX",
" texeqn [-iw] file1 [file2 .....]",
" or texeqn [-iw] < file1 [file2 ....]",
"",
" Flags:",
" -i ignores TeX's and LaTeX's \input files",
" -w matching is not checked",
"",
"See the manual page for more details.",
"",
};
/* Author: Kamal Al-Yahya, Stanford University, 11/1/83 */
/* Last modified: 1/25/87 */
int doclength = { sizeof documentation/sizeof documentation[0] };
#include "setups.h"
#ifdef tops20
#define TEMPFILE "texXXXXXX"
#else
#define TEMPFILE "/tmp/texXXXXXX"
#endif
#ifdef MSC
#else
struct sgttyb ttystat;
#endif
extern char *mktemp();
char scratch_file[MAXWORD];
int wflag;
int xargc;
char **xargv;
main(argc,argv)
int argc;
char *argv[];
{
char *buf;
FILE *temp,*scr;
register char *cptr;
int piped_in;
int iflag,i;
if (((buf = (char *)malloc(MAXLEN*sizeof(char))) == (char *)NULL))
{
fprintf(stderr,"texmatch: Cannot malloc() internal buffer space\n\
Need an array of %d characters\n",MAXLEN);
exit(-1);
}
/* If no arguments, and not in a pipeline, self document */
#ifdef MSC /* MS-DOS cannot distinguish piped input from no input */
piped_in = (argc == 1);
#else
piped_in = ioctl ((fileno (stdin)), TIOCGETP, &ttystat);
#endif
if (argc == 1 && !piped_in)
{
for( i=0; i<doclength; i++)
printf("%s\n",documentation[i]);
exit (0);
}
/* process option flags */
xargc = argc;
xargv = argv;
for (xargc--,xargv++; xargc; xargc--,xargv++)
{
cptr = *xargv;
if( *cptr=='-' )
{
while( *(++cptr))
{
switch( *cptr )
{
case 'i':
iflag=1;
break;
case 'w':
wflag=1;
break;
default:
fprintf(stderr,
"texeqn: unknown flag -%c\n",*cptr);
break;
}
}
}
}
/* first process pipe input */
if(piped_in)
{
/* need to buffer; can't seek in pipes */
/* make a temporary and volatile file in /tmp */
strcpy(scratch_file,TEMPFILE);
mktemp(scratch_file);
if ((scr=fopen(scratch_file,"w")) == (FILE *)NULL)
{
fprintf(stderr,
"texeqn: Cannot open scratch file [%s]\n",scratch_file);
exit(-1);
}
scrbuf(stdin,scr);
fclose(scr);
scr=fopen(scratch_file,"r");
unlink(scratch_file);
if (wflag != 1)
{
fprintf(stderr,"Checking matching...\n");
Match(scr);
fseek(scr,0,0);
}
/* either expand or buffer */
if (iflag != 1)
{ Expand(scr,buf); fclose(scr); }
else
{ tmpbuf(scr,buf); fclose(scr); }
if (wflag != 1)
fprintf(stderr,"Checking matching done\n\n");
Eqn(buf,stdout);
fclose(scr);
}
/* then process input line for arguments and assume they are input files */
xargc = argc;
xargv = argv;
for (xargc--,xargv++; xargc; xargc--,xargv++)
{
cptr = *xargv;
if( *cptr=='-' ) continue; /* this is a flag */
if((temp=fopen(cptr,"r")) != (FILE *)NULL)
{
if (wflag != 1)
{
fprintf(stderr,"Checking matching...\n");
fprintf(stderr,"%s:\n",cptr);
Match(temp);
fprintf(stderr,"\n");
fseek(temp,0,0);
}
/* either expand or buffer */
if (iflag != 1)
{ Expand(temp,buf); fclose(temp); }
else
{ tmpbuf(temp,buf); fclose(temp); }
if (wflag != 1)
fprintf(stderr,"Checking matching done\n\n");
Eqn(buf,stdout);
fclose(temp);
}
else
fprintf(stderr,"texeqn: Cannot open %s\n",cptr);
}
}
SHAR_EOF
fi # end of overwriting check
if test -f 'texeqn2.c'
then
echo shar: will not over-write existing file "'texeqn2.c'"
else
cat << \SHAR_EOF > 'texeqn2.c'
/* COPYRIGHT (C) 1987 Kamal Al-Yahya */
/* texeqn: TeX equation stripping */
char *documentation[] = {
" SYNTAX",
" texeqn [-iw] [parameters] [inputfiles]",
"",
" flags:",
" -i ignores TeX's and LaTeX's \input and \include commands",
" -w does not check matching",
"",
" parameters:",
" in=filename filename is the input file",
" (Default: in=stdin)",
"",
" out=filename filename is the output file",
" (Default: out=stdout)",
""
};
/* Author: Kamal Al-Yahya, Stanford University, 11/1/83 */
/* Last modified: 1/25/87 */
int doclength = { sizeof documentation/sizeof documentation[0] };
#include "setups.h"
#ifdef tops20
#define TEMPFILE "texXXXXXX"
#else
#define TEMPFILE "/tmp/texXXXXXX"
#endif
#ifdef MSC
#else
struct sgttyb ttystat;
#endif
extern char *mktemp();
char string[MAXWORD], filename[MAXWORD], scratch_file[MAXWORD];
FILE *out_file;
int wflag;
int xargc;
char **xargv;
main(argc,argv)
int argc;
char *argv[];
{
char *buf;
FILE *temp,*scr;
register char *cptr;
int piped_in;
int iflag,i;
if (((buf = (char *)malloc(MAXLEN*sizeof(char))) == (char *)NULL))
{
fprintf(stderr,"texmatch: Cannot malloc() internal buffer space\n\
Need an arrays of %d characters\n",MAXLEN);
exit(-1);
}
/* If no arguments, and not in a pipeline, self document */
#ifdef MSC /* MS-DOS cannot distinguish piped input from no input */
piped_in = (argc == 1);
#else
piped_in = ioctl ((fileno (stdin)), TIOCGETP, &ttystat);
#endif
if (argc == 1 && !piped_in)
{
for( i=0; i<doclength; i++)
printf("%s\n",documentation[i]);
exit (0);
}
out_file=stdout; /* default standard output */
/* process option flags */
xargc = argc;
xargv = argv;
for (xargc--,xargv++; xargc; xargc--,xargv++)
{
cptr = *xargv;
if( *cptr=='-' )
{
while( *(++cptr))
{
switch( *cptr )
{
case 'i':
iflag=1;
break;
case 'w':
wflag=1;
break;
default:
fprintf(stderr,
"texeqn: unknown flag -%c\n",*cptr);
break;
}
}
}
}
/* process getpar parameters */
xargc = argc;
xargv = argv;
if(getpar_("out","s",string))
{
sscanf(string,"%s",filename);
if((temp=fopen(filename,"w")) == NULL)
fprintf(stderr,"texeqn: Cannot open output file %s\n",filename);
else
out_file = temp;
}
/* first process pipe input */
if(piped_in)
{
/* need to buffer; can't seek in pipes */
/* make a temporary and volatile file in /tmp */
strcpy(scratch_file,TEMPFILE);
mktemp(scratch_file);
if ((scr=fopen(scratch_file,"w")) == (FILE *)NULL)
{
fprintf(stderr,
"texmatch: Cannot open scratch file [%s]\n",scratch_file);
exit(-1);
}
scrbuf(stdin,scr);
fclose(scr);
scr=fopen(scratch_file,"r");
unlink(scratch_file);
if (wflag != 1)
{
fprintf(stderr,"Checking matching...\n");
Match(scr);
fseek(scr,0,0);
}
/* either expand or buffer */
if (iflag != 1)
{ Expand(scr,buf); fclose(scr); }
else
{ tmpbuf(scr,buf); fclose(scr); }
if (wflag != 1)
fprintf(stderr,"Checking matching done\n");
Eqn(buf,out_file);
fclose(scr);
}
/* next process in=inputfiles */
if(getpar_("in","s",string))
{
sscanf(string,"%s",filename);
if((temp=fopen(filename,"r")) != NULL)
{
if (wflag != 1)
{
fprintf(stderr,"Checking matching...\n");
fprintf(stderr,"%s:\n",filename);
Match(temp);
fprintf(stderr,"\n");
fseek(temp,0,0);
}
/* either expand or buffer */
if (iflag != 1)
{ Expand(temp,buf); fclose(temp); }
else
{ tmpbuf(temp,buf); fclose(temp); }
if (wflag != 1)
fprintf(stderr,"Checking matching done\n\n");
Eqn(buf,out_file);
fclose(temp);
}
else
fprintf(stderr,"texeqn: Cannot open %s\n",filename);
}
/* then process input line for arguments and assume they are input files */
for (xargc--,xargv++; xargc; xargc--,xargv++)
{
cptr = *xargv;
if( *cptr=='-' ) continue; /* this is a flag */
while (*cptr)
{
if (*cptr == '=') break; /* this is for getpar */
cptr++;
}
if (*cptr) continue;
cptr = *xargv;
if((temp=fopen(cptr,"r")) != (FILE *)NULL)
{
if (wflag != 1)
{
fprintf(stderr,"Checking matching...\n");
fprintf(stderr,"%s:\n",cptr);
Match(temp);
fprintf(stderr,"\n");
fseek(temp,0,0);
}
/* either expand or buffer */
if (iflag != 1)
{ Expand(temp,buf); fclose(temp); }
else
{ tmpbuf(temp,buf); fclose(temp); }
if (wflag != 1)
fprintf(stderr,"Checking matching done\n\n");
Eqn(buf,out_file);
fclose(temp);
}
else
fprintf(stderr,"texeqn: Cannot open %s\n",cptr);
}
}
SHAR_EOF
fi # end of overwriting check
if test -f 'texexpand.1'
then
echo shar: will not over-write existing file "'texexpand.1'"
else
cat << \SHAR_EOF > 'texexpand.1'
.TH texexpand 1 7/10/86
.UC 4
.SH NAME
texexpand \- expands TeX's \\input and LaTeX's \\input{} and \\include{}.
.SH SYNOPSIS
.B texexpand [-w]
.I filename
.SH DESCRIPTION
A TeX or LaTeX document can have included files.
.I Texexpand
rewrites the document after inserting these files. The name of the
included file has to be correct relative to the current working
directory. If
.I filename
cannot be opened, it will try to open
.I filename.tex.
The character '%' is recognized as a comment indicator and the commented
text is passed to the output without opening inserted files in that line.
.br
Warning is given if suspected unmatching is detected. Use the
.B -w
flag to suppress these warnings.
.SH SEE ALSO
texeqn(1), texmatch(1), detex(1).
.SH DIAGNOSTICS
Nesting of \\input and \\include is allowed but the number of opened files
must not exceed the system's limit on the number of simultaneously opened
files (normally < 20).
.br
LaTeX's \\includeonly is not recognized.
.SH AUTHOR
Kamal Al-Yahya, Stanford University, 7/10/86
SHAR_EOF
fi # end of overwriting check
if test -f 'texexpand1.c'
then
echo shar: will not over-write existing file "'texexpand1.c'"
else
cat << \SHAR_EOF > 'texexpand1.c'
/* COPYRIGHT (C) 1987 Kamal Al-Yahya */
/* texexpand: to expand TeX and LaTeX \input and include files */
char *documentation[] = {
" SYNTAX",
" texexpand [-w] file1 [file2 .....]",
" or texexpand [-w] < file1 [file2 ....]",
"",
" Flags:",
" -w maching is not checked",
"",
"See the manual page for more details.",
"",
};
/* Author: Kamal Al-Yahya, Stanford University, 11/1/83 */
/* Last modified: 1/25/87 */
int doclength = { sizeof documentation/sizeof documentation[0] };
#include "setups.h"
#ifdef tops20
#define TEMPFILE "texXXXXXX"
#else
#define TEMPFILE "/tmp/texXXXXXX"
#endif
#ifdef MSC
#else
struct sgttyb ttystat;
#endif
extern char *mktemp();
char scratch_file[MAXWORD];
int wflag;
int xargc;
char **xargv;
main(argc,argv)
int argc;
char *argv[];
{
char *buf;
FILE *temp,*scr;
register char *cptr;
int piped_in;
int i;
if (((buf = (char *)malloc(MAXLEN*sizeof(char))) == (char *)NULL))
{
fprintf(stderr,"texpand: Cannot malloc() internal buffer space\n\
Need an array of %d characters\n",MAXLEN);
exit(-1);
}
/* If no arguments, and not in a pipeline, self document */
#ifdef MSC /* MS-DOS cannot distinguish piped input from no input */
piped_in = (argc == 1);
#else
piped_in = ioctl ((fileno (stdin)), TIOCGETP, &ttystat);
#endif
if (argc == 1 && !piped_in)
{
for( i=0; i<doclength; i++)
printf("%s\n",documentation[i]);
exit (0);
}
/* process option flags */
xargc = argc;
xargv = argv;
for (xargc--,xargv++; xargc; xargc--,xargv++)
{
cptr = *xargv;
if( *cptr=='-' )
{
while( *(++cptr))
{
switch( *cptr )
{
case 'w':
wflag=1;
break;
default:
fprintf(stderr,
"texexpand: unknown flag -%c\n",*cptr);
break;
}
}
}
}
/* first process pipe input */
if(piped_in)
{
if (wflag != 1)
{
/* need to buffer; can't seek in pipes */
/* make a temporary and volatile file in /tmp */
strcpy(scratch_file,TEMPFILE);
mktemp(scratch_file);
if ((scr=fopen(scratch_file,"w")) == (FILE *)NULL)
{
fprintf(stderr,
"texexpand: Cannot open scratch file [%s]\n",scratch_file);
exit(-1);
}
scrbuf(stdin,scr);
fclose(scr);
scr=fopen(scratch_file,"r");
unlink(scratch_file);
fprintf(stderr,"Checking matching...\n");
Match(scr);
fseek(scr,0,0);
Expand(scr,buf);
fprintf(stderr,"Checking matching done\n\n");
fclose(scr);
}
else
Expand(stdin,buf);
fputs(buf,stdout);
}
/* then process input line for arguments and assume they are input files */
xargc = argc;
xargv = argv;
for (xargc--,xargv++; xargc; xargc--,xargv++)
{
cptr = *xargv;
if( *cptr=='-' ) continue; /* this is a flag */
if((temp=fopen(cptr,"r")) != (FILE *)NULL)
{
if (wflag != 1)
{
fprintf(stderr,"Checking matching...\n");
fprintf(stderr,"%s:\n",cptr);
Match(temp);
fprintf(stderr,"\n");
fseek(temp,0,0);
}
Expand(temp,buf);
if (wflag != 1)
fprintf(stderr,"Checking matching done\n\n");
fputs(buf,stdout);
fclose(temp);
}
else
fprintf(stderr,"texexpand: Cannot open %s\n",cptr);
}
}
SHAR_EOF
fi # end of overwriting check
if test -f 'texexpand2.c'
then
echo shar: will not over-write existing file "'texexpand2.c'"
else
cat << \SHAR_EOF > 'texexpand2.c'
/* COPYRIGHT (C) 1987 Kamal Al-Yahya */
/* texexpand: to expand TeX and LaTeX \input and include files */
char *documentation[] = {
" SYNTAX",
" texexpand [-w] [parameters] [inputfiles]",
"",
" flags:",
" -w does not check matching",
"",
" parameters:",
" in=filename filename is the input file",
" (Default: in=stdin)",
"",
" out=filename filename is the output file",
" (Default: out=stdout)",
""
};
/* Author: Kamal Al-Yahya, Stanford University, 11/1/83 */
/* Last modified: 1/25/87 */
int doclength = { sizeof documentation/sizeof documentation[0] };
#include "setups.h"
#ifdef tops20
#define TEMPFILE "texXXXXXX"
#else
#define TEMPFILE "/tmp/texXXXXXX"
#endif
#ifdef MSC
#else
struct sgttyb ttystat;
#endif
extern char *mktemp();
char string[MAXWORD], filename[MAXWORD], scratch_file[MAXWORD];
FILE *out_file;
int wflag;
int xargc;
char **xargv;
main(argc,argv)
int argc;
char *argv[];
{
char *buf;
FILE *temp,*scr;
register char *cptr;
int piped_in;
int i;
if (((buf = (char *)malloc(MAXLEN*sizeof(char))) == (char *)NULL))
{
fprintf(stderr,"texexpand: Cannot malloc() internal buffer space\n\
Need an array of %d characters\n",MAXLEN);
exit(-1);
}
/* If no arguments, and not in a pipeline, self document */
#ifdef MSC /* MS-DOS cannot distinguish piped input from no input */
piped_in = (argc == 1);
#else
piped_in = ioctl ((fileno (stdin)), TIOCGETP, &ttystat);
#endif
if (argc == 1 && !piped_in)
{
for( i=0; i<doclength; i++)
printf("%s\n",documentation[i]);
exit (0);
}
out_file=stdout; /* default standard output */
/* process option flags */
xargc = argc;
xargv = argv;
for (xargc--,xargv++; xargc; xargc--,xargv++)
{
cptr = *xargv;
if( *cptr=='-' )
{
while( *(++cptr))
{
switch( *cptr )
{
case 'w':
wflag=1;
break;
default:
fprintf(stderr,
"texexpand: unknown flag -%c\n",*cptr);
break;
}
}
}
}
/* process getpar parameters */
xargc = argc;
xargv = argv;
if(getpar_("out","s",string))
{
sscanf(string,"%s",filename);
if((temp=fopen(filename,"w")) == NULL)
fprintf(stderr,"texexpand: Cannot open output file %s\n",filename);
else
out_file = temp;
}
/* first process pipe input */
if(piped_in)
{
if (wflag != 1)
{
/* need to buffer; can't seek in pipes */
/* make a temporary and volatile file in /tmp */
strcpy(scratch_file,TEMPFILE);
mktemp(scratch_file);
if ((scr=fopen(scratch_file,"w")) == (FILE *)NULL)
{
fprintf(stderr,
"texexpand: Cannot open scratch file [%s]\n",scratch_file);
exit(-1);
}
scrbuf(stdin,scr);
fclose(scr);
scr=fopen(scratch_file,"r");
unlink(scratch_file);
fprintf(stderr,"Checking matching...\n");
Match(scr);
fseek(scr,0,0);
Expand(scr,buf);
fprintf(stderr,"Checking matching done\n\n");
fclose(scr);
}
else
Expand(stdin,buf);
fputs(buf,out_file);
}
/* next process in=inputfiles */
if(getpar_("in","s",string))
{
sscanf(string,"%s",filename);
if((temp=fopen(filename,"r")) != NULL)
{
if (wflag != 1)
{
fprintf(stderr,"Checking matching...\n");
fprintf(stderr,"%s:\n",filename);
Match(temp);
fprintf(stderr,"\n");
fseek(temp,0,0);
}
Expand(temp,buf);
if (wflag != 1)
fprintf(stderr,"Checking matching done\n\n");
fputs(buf,out_file);
fclose(temp);
}
else
fprintf(stderr,"texexpand: Cannot open %s\n",filename);
}
/* then process input line for arguments and assume they are input files */
for (xargc--,xargv++; xargc; xargc--,xargv++)
{
cptr = *xargv;
if( *cptr=='-' ) continue; /* this is a flag */
while (*cptr)
{
if (*cptr == '=') break; /* this is for getpar */
cptr++;
}
if (*cptr) continue;
cptr = *xargv;
if((temp=fopen(cptr,"r")) != (FILE *)NULL)
{
if (wflag != 1)
{
fprintf(stderr,"Checking matching...\n");
fprintf(stderr,"%s:\n",cptr);
Match(temp);
fprintf(stderr,"\n");
fseek(temp,0,0);
}
Expand(temp,buf);
if (wflag != 1)
fprintf(stderr,"Checking matching done\n\n");
fputs(buf,out_file);
fclose(temp);
}
else
fprintf(stderr,"texexpand: Cannot open %s\n",cptr);
}
}
SHAR_EOF
fi # end of overwriting check
if test -f 'texmatch.1'
then
echo shar: will not over-write existing file "'texmatch.1'"
else
cat << \SHAR_EOF > 'texmatch.1'
.TH texmatch 1 7/10/86
.UC 4
.SH NAME
texmatch \- checks matching in TeX and LaTeX documents.
.SH SYNOPSIS
.B texmatch [-i]
.I filename
.SH DESCRIPTION
.I Texmatch
gives error messages if it detects unmatched delimiters.
Delimiters are
braces, brackets, parentheses, dollar signs (single and double),
and LaTeX's \\begin and \\end.
Error messages are sent to the standard error.
.br
Escaped braces and dollar signs are not counted.
\\input and \\include files are also checked unless the
.B -i
flag is used.
.br
Text, displayed equations, and environments are checked independently,
while commented text is not checked.
.SH DIAGNOSTICS
LaTeX environments that are started and ended by user-defined
control sequences are regarded as ordinary text and they are not checked
independently.
.br
White spaces within LaTeX's \\begin{...} and \\end{...} are not allowed for.
.SH SEE ALSO
texexpand(1), texeqn(1).
.SH AUTHOR
Kamal Al-Yahya, Stanford University
SHAR_EOF
fi # end of overwriting check
if test -f 'texmatch1.c'
then
echo shar: will not over-write existing file "'texmatch1.c'"
else
cat << \SHAR_EOF > 'texmatch1.c'
/* COPYRIGHT (C) 1987 Kamal Al-Yahya */
/*
* texmatch: checks matching parantheses, braces, brackets, and dollar signs
* in TeX documents.
*/
char *documentation[] = {
" SYNTAX",
" texmatch [-i] file1 [file2 .....]",
" or texmatch [-i] < file1 [file2 ....]",
"",
"See the manual page for more details.",
"",
};
/* Author: Kamal Al-Yahya, Stanford University, 11/1/83 */
/* Last modified: 1/25/87 */
int doclength = { sizeof documentation/sizeof documentation[0] };
#include "setups.h"
#ifdef tops20
#define TEMPFILE "texXXXXXX"
#else
#define TEMPFILE "/tmp/texXXXXXX"
#endif
#ifdef MSC
#else
struct sgttyb ttystat;
#endif
extern char *mktemp();
char scratch_file[MAXWORD];
int wflag=0; /* for consistency with other programs */
int xargc;
char **xargv;
main(argc,argv)
int argc;
char *argv[];
{
char *buf;
FILE *temp,*scr;
register char *cptr;
int piped_in;
int i,iflag;
if (((buf = (char *)malloc(MAXLEN*sizeof(char))) == (char *)NULL))
{
fprintf(stderr,"texmatch: Cannot malloc() internal buffer space\n\
Need two arrays of %d characters\n",MAXLEN);
exit(-1);
}
/* If no arguments, and not in a pipeline, self document */
#ifdef MSC /* MS-DOS cannot distinguish piped input from no input */
piped_in = (argc == 1);
#else
piped_in = ioctl ((fileno (stdin)), TIOCGETP, &ttystat);
#endif
if (argc == 1 && !piped_in)
{
for( i=0; i<doclength; i++)
printf("%s\n",documentation[i]);
exit (0);
}
/* process option flags */
xargc = argc;
xargv = argv;
for (xargc--,xargv++; xargc; xargc--,xargv++)
{
cptr = *xargv;
if( *cptr=='-' )
{
while( *(++cptr))
{
switch( *cptr )
{
case 'i':
iflag=1;
break;
default:
fprintf(stderr,
"texmatch: unknown flag -%c\n",*cptr);
break;
}
}
}
}
/* first process pipe input */
if(piped_in)
{
if (iflag != 1)
{
/* need to buffer; can't seek in pipes */
/* make a temporary and volatile file in /tmp */
strcpy(scratch_file,TEMPFILE);
mktemp(scratch_file);
if ((scr=fopen(scratch_file,"w")) == (FILE *)NULL)
{
fprintf(stderr,
"texmatch: Cannot open scratch file [%s]\n",scratch_file);
exit(-1);
}
scrbuf(stdin,scr);
fclose(scr);
scr=fopen(scratch_file,"r");
unlink(scratch_file);
Match(scr);
fseek(scr,0,0);
Expand(scr,buf);
fclose(scr);
}
else
Match(stdin);
}
/* then process input line for arguments and assume they are input files */
xargc = argc;
xargv = argv;
for (xargc--,xargv++; xargc; xargc--,xargv++)
{
cptr = *xargv;
if( *cptr=='-' ) continue; /* this is a flag */
if((temp=fopen(cptr,"r")) != (FILE *)NULL)
{
fprintf(stderr,"%s:\n",cptr);
Match(temp);
fprintf(stderr,"\n");
if (iflag != 1)
{
fseek(temp,0,0);
Expand(temp,buf);
}
fclose(temp);
}
else
fprintf(stderr,"texmatch: Cannot open %s\n",cptr);
}
}
SHAR_EOF
fi # end of overwriting check
if test -f 'texmatch2.c'
then
echo shar: will not over-write existing file "'texmatch2.c'"
else
cat << \SHAR_EOF > 'texmatch2.c'
/* COPYRIGHT (C) 1987 Kamal Al-Yahya */
/*
* texmatch: checks matching parantheses, braces, brackets, and dollar signs
* in TeX documents.
*/
char *documentation[] = {
" SYNTAX",
" texmatch [-i] [parameters] [inputfiles]",
"",
" flags:",
" -i ignores TeX's and LaTeX's \input and \include commands",
"",
" parameters:",
" in=filename filename is the input file",
" (Default: in=stdin)",
""
};
/* Author: Kamal Al-Yahya, Stanford University, 11/1/83 */
/* Last modified: 1/25/87 */
int doclength = { sizeof documentation/sizeof documentation[0] };
#include "setups.h"
char string[MAXWORD], filename[MAXWORD];
struct sgttyb ttystat;
extern char *strcpy(), *mktemp();
char scratch_file[MAXWORD];
int wflag=0; /* for consistency with other programs */
int xargc;
char **xargv;
main(argc,argv)
int argc;
char *argv[];
{
char *buf;
FILE *temp,*scr;
register char *cptr;
int piped_in;
int i,iflag;
if (((buf = (char *)malloc(MAXLEN*sizeof(char))) == (char *)NULL))
{
fprintf(stderr,"texmatch: Cannot malloc() internal buffer space\n\
Need two arrays of %d characters each\n",MAXLEN);
exit(-1);
}
/* If no arguments, and not in a pipeline, self document */
piped_in = ioctl ((fileno (stdin)), TIOCGETP, &ttystat);
if (argc == 1 && !piped_in)
{
for( i=0; i<doclength; i++)
printf("%s\n",documentation[i]);
exit (0);
}
/* process option flags */
xargc = argc;
xargv = argv;
for (xargc--,xargv++; xargc; xargc--,xargv++)
{
cptr = *xargv;
if( *cptr=='-' )
{
while( *(++cptr))
{
switch( *cptr )
{
case 'i':
iflag=1;
break;
default:
fprintf(stderr,
"texmatch: unknown flag -%c\n",*cptr);
break;
}
}
}
}
/* first process pipe input */
xargc = argc;
xargv = argv;
if(piped_in)
{
if (iflag != 1)
{
/* need to buffer; can't seek in pipes */
/* make a temporary and volatile file in /tmp */
strcpy(scratch_file,"/tmp/texXXXXXX");
mktemp(scratch_file);
scr=fopen(scratch_file,"w");
scrbuf(stdin,scr);
fclose(scr);
scr=fopen(scratch_file,"r");
unlink(scratch_file);
Match(scr);
fseek(scr,0,0);
Expand(scr,buf);
fclose(scr);
}
else
Match(stdin);
}
/* next process in=inputfiles */
if(getpar_("in","s",string))
{
sscanf(string,"%s",filename);
if((temp=fopen(filename,"r")) != NULL)
{
fprintf(stderr,"%s:\n",filename);
Match(temp);
fprintf(stderr,"\n");
if (iflag != 1)
{
fseek(temp,0,0);
Expand(temp,buf);
}
fclose(temp);
}
else
fprintf(stderr,"texmatch: Cannot open %s\n",filename);
}
/* then process input line for arguments and assume they are input files */
for (xargc--,xargv++; xargc; xargc--,xargv++)
{
cptr = *xargv;
if( *cptr=='-' ) continue; /* this is a flag */
while (*cptr)
{
if (*cptr == '=') break; /* this is for getpar */
cptr++;
}
if (*cptr) continue;
cptr = *xargv;
if((temp=fopen(cptr,"r")) != NULL)
{
fprintf(stderr,"%s:\n",cptr);
Match(temp);
fprintf(stderr,"\n");
if (iflag != 1)
{
fseek(temp,0,0);
Expand(temp,buf);
}
fclose(temp);
}
else
fprintf(stderr,"texmatch: Cannot open %s\n",cptr);
}
}
SHAR_EOF
fi # end of overwriting check
if test -f 'texspell'
then
echo shar: will not over-write existing file "'texspell'"
else
cat << \SHAR_EOF > 'texspell'
#! /bin/csh
# shell for running texspell which is TeX and LaTeX's spell
# Author: Kamal Al-Yahya 1984
set flag = ()
unset file
if ($#argv == 0) then
echo "usage: texspell [-w -i] file"
exit(-1)
endif
while ($#argv > 0)
switch ($argv[1])
case -*:
set flag = ($flag $argv[1])
breaksw
default:
set file
breaksw
endsw
if !($?file) then
shift argv
else
break
endif
end
if ($#argv == 0) then
echo "usage: texspell [-w -i] file"
exit(-1)
endif
while ($#argv > 0)
if -e $argv[1] then
detex $flag $argv[1] | spell
else
echo "Can't open $argv[1]"
exit(-1)
endif
shift argv
end
exit(0)
SHAR_EOF
chmod +x 'texspell'
fi # end of overwriting check
if test -f 'texspell.1'
then
echo shar: will not over-write existing file "'texspell.1'"
else
cat << \SHAR_EOF > 'texspell.1'
.TH texspell 1 2/2/84
.UC 4
.SH NAME
texspell \- finds spelling errors in TeX documents.
.br
texproofr \- runs
.B proofr
on TeX's documents.
.SH SYNOPSIS
.B texspell
[
.B -i -w
]
.I filename,
.br
.B texproofr
[
.B -i -w
]
.I filename,
.SH DESCRIPTION
TeX and LaTeX have control characters that
.B spell
does not recognize.
.I texspell
and
.I texproofr
first filter these control characters using
.I detex
and then pipe the result to
.B spell
or
.B proofr
respectively.
.br
TeX's and LaTeX's \\input and \\include files are recognized and opened.
If the
.B -i
flag is used, those files are ignored.
.br
Unmatching also is checked unless suppressed by the
.B -w
flag.
.SH SEE ALSO
TEX(1), texeqn(1), detex(1), texmatch(1)
.SH AUTHOR
Kamal Al-Yahya
SHAR_EOF
fi # end of overwriting check
# End of shell archive
exit 0
More information about the Mod.sources
mailing list