summaryrefslogtreecommitdiff
path: root/support/kamal
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /support/kamal
Initial commit
Diffstat (limited to 'support/kamal')
-rw-r--r--support/kamal/DeTeX.c67
-rw-r--r--support/kamal/Eqn.c113
-rw-r--r--support/kamal/Expand.c165
-rw-r--r--support/kamal/Match.c315
-rw-r--r--support/kamal/README74
-rw-r--r--support/kamal/TEX227
-rw-r--r--support/kamal/TEX.1104
-rw-r--r--support/kamal/detex.158
-rw-r--r--support/kamal/detex1.c165
-rw-r--r--support/kamal/detex2.c221
-rw-r--r--support/kamal/inc_file4
-rw-r--r--support/kamal/inc_file2.tex1
-rw-r--r--support/kamal/makefile30
-rw-r--r--support/kamal/makefile.msc44
-rw-r--r--support/kamal/makefile.par34
-rw-r--r--support/kamal/setups.h68
-rw-r--r--support/kamal/setups.h-68
-rw-r--r--support/kamal/subs.c393
-rw-r--r--support/kamal/testfile32
-rw-r--r--support/kamal/texeqn.145
-rw-r--r--support/kamal/texeqn1.c164
-rw-r--r--support/kamal/texeqn2.c216
-rw-r--r--support/kamal/texexpand.132
-rw-r--r--support/kamal/texexpand1.c153
-rw-r--r--support/kamal/texexpand2.c203
-rw-r--r--support/kamal/texmatch.132
-rw-r--r--support/kamal/texmatch1.c146
-rw-r--r--support/kamal/texmatch2.c159
-rw-r--r--support/kamal/texspell41
-rw-r--r--support/kamal/texspell.147
30 files changed, 3421 insertions, 0 deletions
diff --git a/support/kamal/DeTeX.c b/support/kamal/DeTeX.c
new file mode 100644
index 0000000000..804c3172c9
--- /dev/null
+++ b/support/kamal/DeTeX.c
@@ -0,0 +1,67 @@
+/* COPYRIGHT (C) 1987 Kamal Al-Yahya */
+#include "setups.h"
+DeTeX(buffer,out_file) /* stripping TEX commands */
+
+char *buffer;
+FILE *out_file;
+{
+int c,cc;
+char w[MAXWORD];
+
+while ((c = *buffer++) != NULL)
+ {
+ switch (c)
+ {
+/* detect TeX commands (backslash) */
+ case '\\':
+ c=' ' ; /* "erase" the backslash */
+ putc(c,out_file);
+ cc = *buffer++;
+ if (cc == '\n') putc(cc,out_file);
+ else if (cc == '[') buffer += display(buffer);
+ else if (cc == '(') buffer += formula(buffer);
+ else if (cc == '$' || cc == '%')
+ break;
+/* check for LaTeX \begin{equation}, \begin{eqnarray}, and \begin{displaymath} */
+ else
+ {
+ buffer--;
+ buffer += get_buf_word(buffer,w);
+ if (strcmp(w,"begin") == 0)
+ {
+ buffer++;
+ buffer += get_buf_word(buffer,w);
+ if (strcmp(w,"equation") == 0 ||
+ strcmp(w,"eqnarray") == 0 ||
+ strcmp(w,"displaymath") == 0)
+ buffer += begin_to_end(buffer,w);
+ }
+ }
+ break;
+
+ case '$':
+ buffer += dollar(buffer,out_file);
+ break;
+ case '%':
+ buffer += comment(buffer);
+ break;
+/* erase these character */
+ case '{':
+ c=' ';
+ case '}':
+ c=' ';
+ case '_':
+ c=' ';
+ case '^':
+ c=' ';
+ case '&':
+ c=' ';
+ case '#':
+ c=' ';
+/* default is doing nothing: pass the character to the output */
+ default:
+ putc(c,out_file);
+ break;
+ }
+ }
+}
diff --git a/support/kamal/Eqn.c b/support/kamal/Eqn.c
new file mode 100644
index 0000000000..9809c91808
--- /dev/null
+++ b/support/kamal/Eqn.c
@@ -0,0 +1,113 @@
+/* COPYRIGHT (C) 1987 Kamal Al-Yahya */
+#include "setups.h"
+Eqn(buffer,out_file) /* srips TEX equations */
+
+FILE *out_file;
+char *buffer;
+{
+int c,d;
+int i;
+char w[MAXLINE], ww[MAXWORD];
+while ((c = *buffer++) != NULL)
+ {
+ if(c == '%')
+ {
+ while ((c = *buffer++) != NULL)
+ if (c == '\n') break;
+ }
+ else if(c == '$')
+ {
+ if ((d = *buffer++) == '$')
+ {
+ putc(c,out_file); putc(d,out_file);
+ while ((c = *buffer++) != NULL)
+ {
+ if(c != '$') putc(c,out_file);
+ else
+ {
+ buffer++;
+ fprintf(out_file,"$$ \n");
+ break;
+ }
+ }
+ }
+ }
+/* check for LaTeX \begin{equation}, \begin{eqnarray}, and \begin{displaymath} */
+ else if(c == '\\')
+ {
+ c = *buffer++;
+ if (c == '[')
+ {
+ putc('\\',out_file); putc(c,out_file);
+ while((c = *buffer++) != NULL)
+ {
+ if(c == '\\')
+ {
+ c = *buffer++;
+ fprintf(out_file,"\\%c",c);
+ if (c == ']')
+ {
+ putc('\n',out_file);
+ break;
+ }
+ }
+ else
+ putc(c,out_file);
+ }
+ continue;
+ }
+ buffer--;
+ buffer += get_buf_word(buffer,w);
+ if (strcmp(w,"begin") == 0)
+ {
+ buffer++;
+ i = get_buf_word(buffer,w);
+ buffer += i;
+ if (strcmp(w,"equation") == 0 || strcmp(w,"eqnarray")
+ == 0 || strcmp(w,"displaymath") == 0)
+ {
+ fprintf(out_file,"\\begin{%s}",w);
+ buffer++;
+ while ((c = *buffer++) != NULL)
+ {
+ putc(c,out_file);
+ if (c == '\\')
+ {
+ i = get_buf_word(buffer,ww);
+ buffer += i;
+ fprintf(out_file,"%s",ww);
+ if (strcmp(ww,"end") == 0)
+ {
+ buffer++;
+ i = get_buf_word(buffer,ww);
+ buffer += i;
+ fprintf(out_file,
+ "{%s}\n",ww);
+ buffer++;
+ if (strcmp(ww,"equation")
+ == 0 ||
+ strcmp(ww,"eqnarray")
+ == 0 ||
+ strcmp(ww,"displaymath")
+ == 0)
+ break;
+ }
+ }
+ }
+ }
+ }
+ else if (strcmp(w,"def") == 0)
+ {
+ i = def(buffer,w);
+ buffer += i;
+ fprintf(out_file,"\\def%s\n",w);
+ }
+ else if (strcmp(w,"newcommand") == 0)
+ {
+ i = command(buffer,w);
+ buffer += i;
+ fprintf(out_file,"\\newcommand%s\n",w);
+ }
+ }
+ }
+}
diff --git a/support/kamal/Expand.c b/support/kamal/Expand.c
new file mode 100644
index 0000000000..5cca17d37b
--- /dev/null
+++ b/support/kamal/Expand.c
@@ -0,0 +1,165 @@
+/* COPYRIGHT (C) 1987 Kamal Al-Yahya */
+
+#include "setups.h"
+unsigned int len=0; /* length of document */
+
+Expand(fp,buf) /* expand TeX and LaTeX's \input and \include */
+
+FILE *fp;
+char *buf;
+{
+char *buf2;
+FILE *fpp;
+int c;
+int c1=' '; /* previous character */
+char w[MAXWORD];
+int i,j;
+extern wflag;
+
+if (((buf2 = (char *)malloc(MAXLEN*sizeof(char))) == (char *)NULL))
+ {
+ fprintf(stderr,"Expand: Cannot malloc() internal buffer space\n\
+Need an arrays of %d characters\n",MAXLEN);
+ exit(-1);
+ }
+
+while ((c = getc(fp)) != EOF)
+ {
+ if (++len >= MAXLEN)
+ {
+ fprintf(stderr,"Document is too large\n");
+ exit(-1);
+ }
+ if (c == '%' || c1 == '%')
+ {
+ *buf++ = c;
+ while ((c =getc(fp)) != EOF)
+ {
+ if (++len >= MAXLEN)
+ {
+ fprintf(stderr,"Sorry: document is too large\n");
+ exit(-1);
+ }
+ *buf++=c;
+ if (c == '\n') break;
+ }
+ c1=c;
+ continue;
+ }
+ if (c != '\\')
+ *buf++ = c;
+ else /* detect TeX commands (backslash) */
+ {
+ /* see if \input or \include is the control sequence */
+ i=0;
+ c1=c; /* update last character */
+ while ((c = getc(fp)) != EOF && i < MAXWORD)
+ {
+ if (++len >= MAXLEN)
+ {
+ fprintf(stderr,"Document is too large\n");
+ exit(-1);
+ }
+ if (c == ' ' || c=='\n' || c=='$' || c=='#' || c=='%'
+ || c=='{' || c=='(' || c==')' || c == '\\')
+ break;
+ w[i++] = (char)c;
+ }
+ if (strncmp(w,"input",5) == 0 || (strncmp(w,"include",7) == 0
+ && strcmp(w,"includeonly") !=0))
+ {
+/* if it is \input or \include , get the file name */
+ i=0;
+ while ((c=getc(fp)) != EOF && i < MAXWORD)
+ {
+ if (c == ' ' || c == '\n'
+ || c == '\t' || c == '}' || c == '%')
+ break;
+ w[i++] = (char)c;
+ }
+ w[i] = NULL;
+ fpp=fopen(w, "r"); /* open the new file */
+ if( fpp == NULL )
+ {
+/* if file is not found, try file.tex */
+ strcat(w,".tex");
+ fpp=fopen(w, "r");
+ if( fpp == NULL )
+ {
+ fprintf(stderr,
+ "TeXExpand: Cannot open %s\n",w);
+ buf2[0] = NULL;
+ }
+ else
+ {
+ if (wflag != 1)
+ {
+ fprintf(stderr,"%s:\n",w);
+ Match(fpp);
+ fprintf(stderr,"\n");
+ fseek(fpp,0,0);
+ }
+ Expand(fpp,buf2);
+ fclose(fpp);
+ }
+ }
+ else
+ {
+ if (wflag != 1)
+ {
+ fprintf(stderr,"%s:\n",w);
+ Match(fpp);
+ fprintf(stderr,"\n");
+ fseek(fpp,0,0);
+ }
+ Expand(fpp,buf2);
+ fclose(fpp);
+ }
+ strcat(buf,buf2);
+ buf += strlen(buf2);
+ w[0] = NULL;
+ }
+ else
+/* if the control sequence is not \input or \include write it out */
+ {
+/* if it is \def, \newcommand, or \newenvironment, write the full command */
+ if (strncmp(w,"def",3) == 0)
+ {
+ i = def_file(fp,&j,0);
+ fseek(fp,-i,1);
+ strcat(buf,"\\def\\");
+ buf += 5;
+ for (j=0; j < i; j++)
+ *buf++=getc(fp);
+ }
+ else if (strncmp(w,"newcommand",10) == 0)
+ {
+ i = comm_file(fp,&j,0);
+ fseek(fp,-i,1);
+ strcat(buf,"\\newcommand{");
+ buf += 12;
+ for (j=0; j < i; j++)
+ *buf++=getc(fp);
+ }
+ else if (strncmp(w,"newenvironment",14)==0)
+ {
+ i = getenv_file(fp,&j,0);
+ fseek(fp,-i,1);
+ strcat(buf,"\\newenvironment{");
+ buf += 16;
+ for (j=0; j < i; j++)
+ *buf++=getc(fp);
+ }
+ else
+ {
+ *buf++='\\';
+ for (j=0; j < i; j++)
+ *buf++ = w[j];
+ *buf++ = c;
+ }
+ }
+ }
+ c1 = c; /* update last character */
+ }
+*buf = NULL; /* terminate it with a null */
+}
diff --git a/support/kamal/Match.c b/support/kamal/Match.c
new file mode 100644
index 0000000000..0498f84aef
--- /dev/null
+++ b/support/kamal/Match.c
@@ -0,0 +1,315 @@
+/* COPYRIGHT (C) 1987 Kamal Al-Yahya */
+#define IN_TM
+#include "setups.h"
+
+Match(fp) /* check matching */
+FILE *fp;
+{
+
+int line=1; /* line counter */
+int ld=0; /* single left dollar signs */
+int rd=0; /* single right dollar signs */
+int ldd=0; /* left double dollar signs */
+int rdd=0; /* right double dollar signs */
+int disp=0; /* \[ \] */
+int disp_line=1; /* line number of \[ */
+int form=0; /* \( \) */
+int lform=1; /* line number of \( */
+int lp=0; /* left parenthesis */
+int rp=0; /* right parenthesis */
+int lb=0; /* left brackets */
+int rb=0; /* right brackets */
+int lbr=0; /* left braces */
+int rbr=0; /* right braces */
+int c=' '; /* current character */
+int c1=' '; /* previous character */
+int lbrl=0; /* line number of left braces */
+int lbl=0; /* line number of left bracket */
+int lpl=0; /* line number of left parenthesis */
+int ldl=1; /* line number of left single dollar sign */
+int lddl=1; /* line number of left double dollar sign */
+int warn=0; /* warning status */
+int env_count = 0; /* environment counter */
+int i=0, j=0;
+char w[MAXWORD];
+char *p;
+int cc;
+extern char *malloc();
+
+while ((c =getc(fp)) != EOF)
+ {
+ if (ldd == 1 && ld == 1 && c != '$')
+ {
+ fprintf(stderr,"line %d: a double dollar sign is closed by a single dollar sign\n",line);
+ ld=0.; ldd=0.; /* reset dollar signs */
+/* Give warning about unclosed openings */
+ if ((lbr-rbr) > 0)
+ fprintf(stderr,"line %d: %d unclosed braces in equation\n",lddl,lbr-rbr);
+ if ((lb-rb) > 0)
+ fprintf(stderr,"line %d: %d unclosed brackets in equation\n",lddl,lb-rb);
+ if ((lp-rp) > 0)
+ fprintf(stderr,"line %d: %d unclosed parentheses in equation\n",lddl,lp-rp);
+/* clear registers */
+ lp=0; lb=0; lbr=0;
+ rp=0; rb=0; rbr=0;
+ lpl=0; lbrl=0; lbl=0;
+ }
+ switch(c)
+ {
+ case '\n':
+ line++; /* increment line counter */
+/* check to see if a single dollar sign is not closed at the same line */
+ if (ld == 1 && warn == 0)
+ {
+ fprintf(stderr,"line %d: single dollar sign is not closed on the same line\n",line-1);
+ warn=1; /* warning has been given */
+ }
+ break;
+ case '%': /* ignore commented text */
+ while ((c =getc(fp)) != EOF)
+ if (c == '\n') {line++; break;}
+ break;
+ case '{':
+ if (lbrl == 0) lbrl=line;
+ lbr++;
+ break;
+ case '}':
+ rbr++;
+ if (rbr > lbr)
+ {
+ fprintf(stderr,"line %d: unmatched brace\n",line);
+ rbr--; /* reset counter */
+ }
+ if (lbr == rbr) lbrl=0;
+ break;
+ case '[':
+ if (lbl == 0) lbl=line;
+ lb++;
+ break;
+ case ']':
+ rb++;
+ if (rb > lb)
+ {
+ fprintf(stderr,"line %d: unmatched bracket\n",line);
+ rb--; /* reset counter */
+ }
+ if (lb == rb) lbl=0;
+ break;
+ case '(':
+ if (lpl == 0) lpl=line;
+ lp++;
+ break;
+ case ')':
+ rp++;
+ if (rp > lp)
+ {
+ fprintf(stderr,"line %d: unmatched parenthesis\n",line);
+ rp--; /* reset counter */
+ }
+ if (lp == rp) lpl=0;
+ break;
+ case '$':
+ if (c1 == '$') /* double dollar sign */
+ {
+ if (ld == 0)
+ {
+ fprintf(stderr,"line %d: single dollar sign is closed by a duble dollar sign\n",line);
+ c=' '; /* reset the dollar sign */
+ break;
+ }
+ if (ldd == 1)
+ {
+ rdd=1; /* right double dollar sign */
+/* Give warning about unclosed openings */
+ if ((lbr-rbr) > 0)
+ fprintf(stderr,"line %d: %d unclosed braces in equation\n",lddl,lbr-rbr);
+ if ((lb-rb) > 0)
+ fprintf(stderr,"line %d: %d unclosed brackets in equation\n",lddl,lb-rb);
+ if ((lp-rp) > 0)
+ fprintf(stderr,"line %d: %d unclosed parentheses in equation\n",lddl,lp-rp);
+/* clear registers */
+ lp=0; lb=0; lbr=0;
+ rp=0; rb=0; rbr=0;
+ lpl=0; lbrl=0; lbl=0;
+ }
+ else
+ {
+ ldd=1; /* left double dollar sign */
+ lddl=line; /* line number */
+/* Give warning about unclosed openings */
+ if ((lbr-rbr) > 0)
+ fprintf(stderr,"line %d: %d unclosed braces before equation, first opened at line %d\n",lddl,lbr-rbr,lbrl);
+ if ((lb-rb) > 0)
+ fprintf(stderr,"line %d: %d unclosed brackets before equation, first opened at line %d\n",lddl,lb-rb,lbl);
+ if ((lp-rp) > 0)
+ fprintf(stderr,"line %d: %d unclosed parentheses before equation, first opened at line %d\n",lddl,lp-rp,lpl);
+/* clear registers */
+ lp=0; lb=0; lbr=0;
+ rp=0; rb=0; rbr=0;
+ lpl=0; lbrl=0; lbl=0;
+ }
+ }
+ if (ld == 1) rd=1; /* right dollar sign */
+ else
+ {
+ ld=1; /* left dollar sign */
+ ldl=line; /* line number */
+ warn=0; /* no warning has been given */
+ }
+ break;
+ case '\\':
+/* check for \begin{...} and \end{...} */
+ i = get_file_word(fp,w,&line,&cc);
+ if (i == 0 && cc == '[')
+ {
+ if (disp == 1)
+ fprintf(stderr,"line %d: displayed equation starts, previous one at line %d not closed\n",line,disp_line);
+ disp=1; /* left \] */
+ disp_line=line;
+/* Give warning about unclosed openings */
+ if ((lbr-rbr) > 0)
+ fprintf(stderr,"line %d: %d unclosed braces before equation\n",line,lbr-rbr);
+ if ((lb-rb) > 0)
+ fprintf(stderr,"line %d: %d unclosed brackets before equation\n",line,lb-rb);
+ if ((lp-rp) > 0)
+ fprintf(stderr,"line %d: %d unclosed parentheses before equation\n",line,lp-rp);
+/* clear registers */
+ lp=0; lb=0; lbr=0;
+ rp=0; rb=0; rbr=0;
+ lpl=0; lbrl=0; lbl=0;
+ }
+ else if (i == 0 && cc == ']')
+ {
+ if (disp == 0)
+ fprintf(stderr,"line %d: displayed equation ends but no beginning\n",line);
+ disp=0; /* right \] */
+/* Give warning about unclosed openings */
+ if ((lbr-rbr) > 0)
+ fprintf(stderr,"line %d: %d unclosed braces in equation\n",line,lbr-rbr);
+ if ((lb-rb) > 0)
+ fprintf(stderr,"line %d: %d unclosed brackets in equation\n",line,lb-rb);
+ if ((lp-rp) > 0)
+ fprintf(stderr,"line %d: %d unclosed parentheses in equation\n",line,lp-rp);
+/* clear registers */
+ lp=0; lb=0; lbr=0;
+ rp=0; rb=0; rbr=0;
+ lpl=0; lbrl=0; lbl=0;
+ }
+ else if (i == 0 && cc == '(')
+ {
+ if (form == 1)
+ fprintf(stderr,"line %d: formula starts but previous one not closed\n",line);
+ form=1; /* left \( */
+ lform=line; /* line of \( */
+ }
+ else if (i == 0 && cc == ')')
+ {
+ if (form == 0)
+ fprintf(stderr,"line %d: formula ends but no beginning\n",line);
+ form=0; /* right \) */
+ }
+ else if (strcmp(w,"begin") == 0)
+ {
+ int ii=0;
+
+ ii=get_file_word(fp,w,&line,&cc);
+ if ((j=is_new_env(w,env_count)) < 0)
+ {
+ j = env_count;
+ env[j].env_beg = 0;
+ env[j].env_end = 0;
+ p = (char *) malloc((unsigned)(ii*sizeof(char)+1));
+ strcpy(p,w);
+ env[env_count++].env_name = p;
+ }
+ env[j].beg_line = line;
+ env[j].env_beg++;
+/* Give warning about unclosed openings before these environments */
+ if (strcmp(env[j].env_name,"equation") == 0 ||
+ strcmp(env[j].env_name,"eqnarray") == 0 ||
+ strcmp(env[j].env_name,"eqnarray*") == 0 ||
+ strcmp(env[j].env_name,"displaymath") == 0)
+ {
+ if ((lbr-rbr) > 0)
+ fprintf(stderr,"line %d: %d unclosed braces before environment ``%s'', first opened at line %d\n",line,lbr-rbr,env[j].env_name,lbrl);
+ if ((lb-rb) > 0)
+ fprintf(stderr,"line %d: %d unclosed brackets before environment ``%s'', first opened at line %d\n",line,lb-rb,env[j].env_name,lbl);
+ if ((lp-rp) > 0)
+ fprintf(stderr,"line %d: %d unclosed parentheses before environment ``%s'', first opened at line %d\n",line,lp-rp,env[j].env_name,lpl);
+/* clear registers */
+ lp=0; lb=0; lbr=0;
+ rp=0; rb=0; rbr=0;
+ lpl=0; lbrl=0; lbl=0;
+ }
+ }
+ else if (strcmp(w,"end") == 0)
+ {
+ (void) get_file_word(fp,w,&line,&cc);
+ if ((j=is_new_env(w,env_count)) < 0)
+ fprintf(stderr,"line %d: unmatched end for environment ``%s''\n",line,w);
+ else
+ {
+ env[j].env_end++;
+ if (env[j].env_end > env[j].env_beg)
+ {
+ fprintf(stderr,"line %d: unmatched end for environment ``%s''\n",line,
+ env[j].env_name);
+ env[j].env_end--; /* reset */
+ }
+/* Give warning about unclosed openings in these environments */
+ if (strcmp(env[j].env_name,"equation") == 0 ||
+ strcmp(env[j].env_name,"eqnarray") == 0 ||
+ strcmp(env[j].env_name,"eqnarray*") == 0 ||
+ strcmp(env[j].env_name,"displaymath") == 0)
+ {
+ if ((lbr-rbr) > 0)
+ fprintf(stderr,"line %d: %d unclosed braces in environment ``%s''\n",
+line,lbr-rbr,env[j].env_name);
+ if ((lb-rb) > 0)
+ fprintf(stderr,"line %d: %d unclosed brackets in environment ``%s''\n",
+line,lb-rb,env[j].env_name);
+ if ((lp-rp) > 0)
+ fprintf(stderr,"line %d: %d unclosed parentheses in environment ``%s''\n",
+line,lp-rp,env[j].env_name);
+/* clear registers */
+ lp=0; lb=0; lbr=0;
+ rp=0; rb=0; rbr=0;
+ lpl=0; lbrl=0; lbl=0;
+ }
+ }
+ }
+ else if (strcmp(w,"def") == 0)
+ (void) def_file(fp,&line,1);
+ else if (strcmp(w,"newcommand") == 0)
+ (void) comm_file(fp,&line,1);
+ else if (strcmp(w,"newenvironment") == 0)
+ (void) getenv_file(fp,&line,1);
+ else if (i > 0) fseek(fp,-1,1);
+ break;
+ default:
+ break;
+ }
+ c1=c; /* update previous character */
+ if (ld == 1 && rd == 1)
+ {ld=0.; rd=0.;} /* matched dollar signs */
+ if (ldd == 1 && rdd == 1)
+ {ldd=0.; rdd=0.;} /* matched double dollar signs */
+ }
+if ((lbr-rbr) > 0)
+ fprintf(stderr,"file ends: %d unclosed left braces, first opened at line %d \n",lbr-rbr,lbrl);
+if ((lb-rb) > 0)
+ fprintf(stderr,"file ends: %d unclosed left brackets, first opened at line %d\n",lb-rb,lbl);
+if ((lp-rp) > 0)
+ fprintf(stderr,"file ends: %d unclosed left parentheses, first opened at line %d\n",lp-rp,lpl);
+if (ld == 1)
+ fprintf(stderr,"file ends: single dollar sign opened at line %d unclosed\n",ldl);
+if (ldd == 1)
+ fprintf(stderr,"file ends: double dollar sign opened at line %d unclosed\n",lddl);
+if (disp == 1)
+ fprintf(stderr,"file ends: displayed equation opened at line %d unclosed\n",disp_line);
+if (form == 1)
+ fprintf(stderr,"file ends: formula opened at line %d unclosed\n",lform);
+for (i=0; i<env_count; i++)
+ if (env[i].env_beg > env[i].env_end)
+ fprintf(stderr,"file ends: environment ``%s'' begun at line %d not ended\n",env[i].env_name,env[i].beg_line);
+}
diff --git a/support/kamal/README b/support/kamal/README
new file mode 100644
index 0000000000..e9de51b781
--- /dev/null
+++ b/support/kamal/README
@@ -0,0 +1,74 @@
+TeXTools Version 1.0
+Date: 1/25/87
+
+Copyright (C) 1987 by Kamal Al-Yahya
+
+This directory contains some filters that were developed at the
+Stanford Exploration Project (SEP), Geophysics Department, by Kamal Al-Yahya.
+Copying them to any other machine is permitted without prior permission
+provided that copyright messages are kept, no profit is made by copying
+the files, and modifications are clearly documented and noted in the
+edit history below.
+
+--------------------------------------------------------------------------
+EDIT HISTORY:
+
+--------------------------------------------------------------------------
+
+Acknowledgment:
+Many users at the SEP gave valuable feedbacks that improved the programs.
+
+The main programs have names that end with either 1 or 2 (e.g. detex1.c,
+detex2.c). Those ending with 2 are used in makefile.par and can
+be used only by those who have getpar(). This enables them to use
+in= and out= for input and output files specifications in addition
+to what can be done in files ending with 1.
+
+The maximum number of characters in a document is set by MAXLEN
+(in setups.h) to be 65535. If the limit of unsigned integers in
+your machine is lower than this, change this number accordingly.
+
+To install:
+ - modify MAXLEN in setups.h if necessary.
+ - choose either makefile or makefile.par (as explained above).
+ - type 'make'.
+ - test the programs on the testfile provided.
+ - move the executables to a common path (like /usr/local/bin).
+ - type 'make clean'.
+
+The following files should be in this directory:
+
+README this file
+setups.h an include file used by all programs.
+testfile a file that demonstrates how these programs work
+inc_file an include file that is opened by testfile
+inc_file2.tex another include file
+makefile what else but a makefile
+makefile.par a makefile that assumes you have access to getpar()
+detex1.c strips TeX's commands from the document
+detex2.c same as detex1.c but assumes you have access to getpar()
+texeqn1.c picks displayed equations from a document
+texeqn2.c same as texeqn1.c but assumes you have access to getpar()
+texexpand1.c expands the document by opening \input and \include files
+texexpand2.c same as texexpand1.c but assumes you have access to getpar()
+texmatch1.c checks for matching braces, brackets, parentheses, and dollar signs
+texmatch2.c same as texmatch1.c but assumes you have access to getpar()
+DeTeX.c subroutine to strip TeX's commands from the document
+Eqn.c subroutine to extracts equations
+Expand.c subroutine to expand the document
+Match.c subroutine that checks the matching
+subs.c subroutines used by the programs
+TEX a shell that can be used to run all TeX processing
+texspell shell that runs spell on TeX documnets
+detex.1 manual page for detex
+texeqn.1 manual page for texeqn
+texexpand.1 manual page for texexpand
+texmatch.1 manual page for texmatch
+texspell.1 manual page for texspell
+TEX.1 manual page for TEX
+
+
+Feedbacks are welcome. E-mail: try any of these
+
+ kamal@hanauma.stanford.edu
+ kamal%hanauma@score.stanford.edu
diff --git a/support/kamal/TEX b/support/kamal/TEX
new file mode 100644
index 0000000000..149b69bf68
--- /dev/null
+++ b/support/kamal/TEX
@@ -0,0 +1,227 @@
+#! /bin/csh -f
+#
+# Usage: TEX [-flags ...] filename
+#
+# The various flags are described below, but only one filename should
+# be given; stdin is not used. File types are indicated by the filename
+# suffix. Input files may have one of the following suffixes:
+# .tex -- a file with tex commands, equations.
+# .dvi -- device independent format.
+# .ver -- output of verser1 (for the varian or AED)
+# .imp -- output of dvi-imagen (or dviimp)
+# Anything else is assumed to be in .tex format.
+# If TEX sees a .dvi, .ver, or .imp suffix, it will skip ahead to the right
+# point in the processing sequence. Specifically,
+# texeqn accepts .tex, outputs .tex
+# tex accepts .tex, outputs .dvi and .log
+# latex accepts .tex, outputs .dvi and .log
+# verser1 accepts .dvi, outputs .ver (for the varian or AED, not on hanuma).
+# lpr accepts .ver, outputs raster
+# ipr accepts .imp, outputs raster
+#
+# Flags:
+# -latex uses LaTeX.
+# -log saves a log file from the tex run in filename.log.
+# -d quits once the .dvi file has been made.
+# -x makes two passes on the (latex) input, so cross-references
+# are resolved.
+# -v output device is the varian (imagen is the default)
+# -q quits once the .imp file has been made if the imagen is the target printer
+# or after the .ver file (i.e. after verser1 stage) if the AED or the varian
+# is the target printer.
+# -eqn strips out the equations with texeqn and typeset them.
+#
+# Authors: Kamal Al-Yahya, Jeff Thorson, and Chuck Sword, Stanfor University
+#
+umask 0
+onintr removal
+set name=() host=()
+set destdir = /usr/local
+set tmp = TEX$$
+set device = imagen
+set st = 0
+unset latex x d q eqn log
+
+if ($#argv == 0) then
+ echo "usage: TEX [-latex] [-eqn] [-log] [-d] [-q] [-x] filename"
+ exit(-1)
+endif
+
+while ($#argv > 0 && !($?inf))
+ switch ($argv[1])
+ case -latex:
+ set latex
+ breaksw
+
+ case -x:
+ set x
+ breaksw
+
+ case -q:
+ set q
+ breaksw
+
+ case -d:
+ set d
+ breaksw
+
+ case -v:
+ set device = varian
+ breaksw
+
+ case -eqn:
+ set eqn
+ breaksw
+
+ case -log:
+ set log
+ breaksw
+
+ case -*:
+ echo unknown flag $argv[1], ignored
+ breaksw
+ default:
+ set inf = $argv[1]
+ if !(-e $inf) then
+
+# filename not found, try with .tex ending
+
+ if !(-e $inf.tex) then
+ echo $0 'cannot find file' $inf.
+ exit(-1)
+ else
+ set inf = ($inf.tex)
+ endif
+ endif
+ breaksw
+ endsw
+ shift argv
+end
+
+set name = $inf:t
+set sname = $name:r
+set name = $cwd/$name
+set suffix = $name:e
+
+if ($suffix == dvi) then
+ echo TEX: starting with .dvi file
+ set name = $name:r
+ set dvifile = $inf
+ goto dvi
+endif
+
+if ($suffix == ver) then
+ echo TEX: starting with .ver file
+ set name = $name:r
+ set verfile = $inf
+ goto ver
+endif
+
+if ($suffix == imp) then
+ echo TEX: starting with .imp file
+ set name = $name:r
+ set impfile = $inf
+ goto imp
+endif
+
+if ($suffix == tex || $suffix == eqn) then
+ set name = $name:r
+endif
+
+echo "\batchmode" > $tmp.tex
+
+if ($?eqn) then
+ $destdir/texeqn < $inf >> $tmp.tex
+else
+ cat $inf >> $tmp.tex
+endif
+
+echo "\bye" >> $tmp.tex
+
+# Choose tex or latex
+
+if ($?latex) then
+ if (-e $name.aux) then
+ cp $name.aux $tmp.aux
+ endif
+ $destdir/latex $tmp:t
+ if ($status != 0) then
+ goto oops
+ else
+ if (-e $tmp.aux) then
+ cp $tmp.aux $name.aux
+ endif
+ endif
+
+ if ($?x) then
+ echo "Starting second pass"
+ $destdir/latex $tmp
+ if ($status != 0) then
+ goto oops
+ endif
+ if (-e $tmp.aux) then
+ cp $tmp.aux $name.aux
+ endif
+ endif
+
+else $destdir/tex $tmp
+ if ($status != 0) then
+oops:
+ echo TEX could not process your file.
+ echo Error messages are in $name.log
+ mv -f $tmp.log $name.log
+ set st = -1
+ goto removal
+ endif
+endif
+
+if ($?log) then
+ mv -f $tmp.log $name.log
+ if (-e $tmp.aux) then
+ mv -f $tmp.aux $name.aux
+ endif
+endif
+
+set dvifile = $tmp.dvi
+
+if ($?d) then
+ mv -f $dvifile $name.dvi
+ goto removal
+endif
+
+dvi:
+
+if($device == imagen) then
+ $destdir/dvi-imagen -s $dvifile > $tmp.imp
+ if ($?q) then
+ mv -f $tmp.imp $name.imp
+ goto removal
+ endif
+ set impfile = $tmp.imp
+imp:
+ (echo -n \@document\(owner \"$user\", site \"$host\", spooldate \
+ \"`date`\", language \"imPress\", jobheader off, \
+ jamresistance on\) ; cat $impfile ) | $destdir/ipr
+ goto removal
+endif
+
+if($device == varian) then
+ $destdir/verser1 < $dvifile > $tmp.ver
+ if ($status != 0) then
+ echo TEX bombed out on verser1.
+ set st = -1
+ goto removal
+ endif
+ set verfile = $tmp.ver
+
+ if ($?q) then
+ mv -f $verfile $name.ver
+ goto removal
+ endif
+ver:
+ lpr -d -s -Pvarian $tmp.ver
+endif
+
+removal:
+/bin/rm -f $tmp.tex $tmp.log $tmp.dvi $tmp.ver $tmp.imp $tmp.aux
+exit($st)
diff --git a/support/kamal/TEX.1 b/support/kamal/TEX.1
new file mode 100644
index 0000000000..de37b3a716
--- /dev/null
+++ b/support/kamal/TEX.1
@@ -0,0 +1,104 @@
+.TH TEX 1 2/2/84
+.UC 4
+.SH NAME
+TEX \-
+.I TeX
+and
+.I LaTeX
+typesetter and printer.
+.SH SYNOPSIS
+.B TEX
+[
+options
+]
+.I filename
+.SH DESCRIPTION
+.I TEX
+processes a file
+and sends it to a printer. The default is the Imagen; other devices
+can be used if available at the site.
+.PP
+The input to
+.I TEX
+does not have to be the raw manuscript.
+.I TEX
+can be given a
+.I .dvi
+file (which results from using the
+.B -d
+option),
+or
+.I .imp
+and
+.I .ver
+files (which result from using the
+.B -q
+option), and it will proceed from and end at the appropriate stage.
+.br
+The file name does not have to end with
+.I
+tex.
+.sp 2
+OPTIONS :
+.br
+.TP
+.B \-latex
+uses LaTeX. See the LaTeX manual.
+.TP
+.B \-x
+makes two passes on the
+.I LaTeX
+input to resolve cross-references.
+.TP
+.B \-eqn
+uses
+.B
+texeqn
+to extract the equations.
+.TP
+.B \-log
+saves messages from the
+.B tex
+run in
+.I filename
+.B .log
+and saves messages from LaTeX run in
+.I filename
+.B .aux
+.TP
+.B \-d
+quits once the
+.I dvi
+file is produced without producing a hardcopy.
+.TP
+.B \-q
+(for quiescent) intermediate output is not spooled
+to the printing device.
+.TP
+.B \-v
+output device is the varian (default is the imagen).
+.fi
+.SH SEE ALSO
+tex(1), texeqn(1), texmatch(1), detex(1)
+.SH FILES
+file.aux the auxiliary file used by LaTeX for labeling figures.
+.br
+The default is to remove the following files at the end of the run:
+.br
+TE????.dvi the device independent file.
+.br
+TE????.log the log file.
+.br
+TE????.imp the impress file; can be printed by
+.B ipr
+file.
+.SH BUGS
+Only one file can be processed at a time.
+.br
+Drivers flags are not incorporated. Add the ones you need.
+.SH AUTHOR
+Kamal Al-Yahya
+.br
+Jeff Thorson
+.br
+Chuck Sword
diff --git a/support/kamal/detex.1 b/support/kamal/detex.1
new file mode 100644
index 0000000000..dc27bdde5b
--- /dev/null
+++ b/support/kamal/detex.1
@@ -0,0 +1,58 @@
+.TH detex 1 2/27/86
+.UC 4
+.SH NAME
+detex \- a filter to strip TeX and LaTeX's commands from a file.
+.SH SYNOPSIS
+.B detex [-iw]
+.I file1 [file2 ......]
+.br
+or
+.B detex [-iw]
+.I < file
+.br
+.SH DESCRIPTION
+TeX and LaTeX have control characters that
+.B spell
+and other
+.I troff
+-dependent
+processors (like diction) do not recognize.
+.I Detex
+works as a preprocessor by
+filtering those control characters. The output can then be piped to the next
+process. The output can be saved by redirecting the standard output.
+.I Detex
+does not break the document into individual words. It merely
+.I erases
+the control sequences.
+.br
+In-line or displayed equation are not passed to the output. Also,
+the character '%' is recognized as a comment indicator and the commented
+text is not passed to the output.
+.br
+.I Detex
+recognizes and opens files called by TeX's and LaTeX's \\input
+and \\include commands. The
+.B -i
+flag makes
+.I detex
+ignore these commands.
+The file name has to be correct relative to the current working directory.
+If it cannot open the file nor file_name.tex, it will give a non-fatal
+error message and proceed.
+.br
+Warning is given if suspected unmatching is detected. Use the
+.B -w
+flag to suppress these warnings.
+.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
+Displayed material is regarded as mathematical equations and is ignored.
+.br
+White spaces withing LaTeX's \\begin{...} or \\end{...} are not allowed for.
+.SH SEE ALSO
+texexpand(1), texeqn(1), texmatch(1).
+.SH AUTHOR
+Kamal Al-Yahya, Stanford University
diff --git a/support/kamal/detex1.c b/support/kamal/detex1.c
new file mode 100644
index 0000000000..8a390d87a6
--- /dev/null
+++ b/support/kamal/detex1.c
@@ -0,0 +1,165 @@
+/* COPYRIGHT (C) 1987 Kamal Al-Yahya */
+/* detex: strips TeX's and LaTeX's commands */
+
+char *documentation[] = {
+" SYNTAX",
+" detex [-i] file1 [file2 .....]",
+" or detex [-i] < file1 [file2 ....]",
+"",
+"See the manual page for more details.",
+"",
+" Flag:",
+" -i: ignores TeX's and LaTeX's \input and \include commands",
+" -w: matching is not checked",
+"",
+};
+
+/* 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,"detex: 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,
+ "detex: 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,
+ "detex: 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");
+ DeTeX(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");
+ DeTeX(buf,stdout);
+ fclose(temp);
+ }
+ else
+ fprintf(stderr,"detex: Cannot open %s\n",cptr);
+ }
+
+}
diff --git a/support/kamal/detex2.c b/support/kamal/detex2.c
new file mode 100644
index 0000000000..c0ad4eb7a3
--- /dev/null
+++ b/support/kamal/detex2.c
@@ -0,0 +1,221 @@
+/* COPYRIGHT (C) 1987 Kamal Al-Yahya */
+/* detex: strips TeX's and LaTeX's commands */
+
+
+char *documentation[] = {
+" SYNTAX",
+" detex [-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
+
+char string[MAXWORD], filename[MAXWORD], scratch_file[MAXWORD];
+FILE *out_file;
+extern char *mktemp();
+
+#ifdef MSC
+#else
+struct sgttyb ttystat;
+#endif
+
+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,"detex: 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 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,
+ "detex: 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,"detex: 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,
+ "detex: 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");
+ DeTeX(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");
+ DeTeX(buf,out_file);
+ fclose(temp);
+ }
+ else
+ fprintf(stderr,"detex: Cannot open %s\n",filename);
+ }
+
+/* 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 */
+ 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");
+ DeTeX(buf,out_file);
+ fclose(temp);
+ }
+ else
+ fprintf(stderr,"detex: Cannot open %s\n",cptr);
+ }
+
+}
diff --git a/support/kamal/inc_file b/support/kamal/inc_file
new file mode 100644
index 0000000000..5abb90ca7e
--- /dev/null
+++ b/support/kamal/inc_file
@@ -0,0 +1,4 @@
+This is an included file.
+when texexpand is run on testfile, this file should be inserted.
+(unmatching in inc_file))
+END OF INSERTED FILE.
diff --git a/support/kamal/inc_file2.tex b/support/kamal/inc_file2.tex
new file mode 100644
index 0000000000..c8d90b9ef8
--- /dev/null
+++ b/support/kamal/inc_file2.tex
@@ -0,0 +1 @@
+This is another included file
diff --git a/support/kamal/makefile b/support/kamal/makefile
new file mode 100644
index 0000000000..ad0c4eb16a
--- /dev/null
+++ b/support/kamal/makefile
@@ -0,0 +1,30 @@
+CFLAGS = -O
+LINTFLAGS = -abchnpux
+CSUBS = Expand.c Match.c subs.c
+OSUBS = Expand.o Match.o subs.o
+B =
+
+default: all
+
+all: texexpand detex texeqn texmatch
+
+texexpand: texexpand1.o $(OSUBS)
+ cc $(CFLAGS) -o $(B)texexpand texexpand1.o $(OSUBS)
+
+detex: detex1.o DeTeX.o $(OSUBS)
+ cc $(CFLAGS) -o $(B)detex detex1.o DeTeX.o $(OSUBS)
+
+texeqn: texeqn1.o Eqn.o $(OSUBS)
+ cc $(CFLAGS) -o $(B)texeqn texeqn1.o Eqn.o $(OSUBS)
+
+texmatch: texmatch1.o $(OSUBS)
+ cc $(CFLAGS) -o $(B)texmatch texmatch1.o $(OSUBS)
+
+lint:
+ lint $(LINTFLAGS) texexpand1.c $(CSUBS) > texexpand.lnt
+ lint $(LINTFLAGS) detex1.c DeTeX.c $(CSUBS) > detex.lnt
+ lint $(LINTFLAGS) texeqn1.c Eqn.c $(CSUBS) > texeqn.lnt
+ lint $(LINTFLAGS) texmatch1.c $(CSUBS) > texmatch.lnt
+
+clean:
+ /bin/rm -f *.o texexpand detex texeqn texmatch core *junk*
diff --git a/support/kamal/makefile.msc b/support/kamal/makefile.msc
new file mode 100644
index 0000000000..dec2b879c8
--- /dev/null
+++ b/support/kamal/makefile.msc
@@ -0,0 +1,44 @@
+#-----------------------------------------------------------------------
+# Makefile for textools
+# Make targets:
+# (none) same as all
+# all produces all executables
+# lint run lint on sources
+# clean remove object files
+# share make ../textools.sh for mailing
+#
+
+CFLAGS = -O
+LINTFLAGS = -abchnpux
+CSUBS = Expand.c Match.c subs.c
+OSUBS = Expand.o Match.o subs.o
+B =
+
+default: all
+
+all: texexpand detex texeqn texmatch
+
+texexpand: texexpand1.o $(OSUBS)
+ cc $(CFLAGS) -o $(B)texexpand texexpand1.o $(OSUBS)
+
+detex: detex1.o DeTeX.o $(OSUBS)
+ cc $(CFLAGS) -o $(B)detex detex1.o DeTeX.o $(OSUBS)
+
+texeqn: texeqn1.o Eqn.o $(OSUBS)
+ cc $(CFLAGS) -o $(B)texeqn texeqn1.o Eqn.o $(OSUBS)
+
+texmatch: texmatch1.o $(OSUBS)
+ cc $(CFLAGS) -o $(B)texmatch texmatch1.o $(OSUBS)
+
+share:
+ make clean
+ makescript ../textools.sh *
+
+lint:
+ lint $(LINTFLAGS) texexpand1.c $(CSUBS) > texexpand.lnt
+ lint $(LINTFLAGS) detex1.c DeTeX.c $(CSUBS) > detex.lnt
+ lint $(LINTFLAGS) texeqn1.c Eqn.c $(CSUBS) > texeqn.lnt
+ lint $(LINTFLAGS) texmatch1.c $(CSUBS) > texmatch.lnt
+
+clean:
+ \rm -f *.o core *junk* lint.lst
diff --git a/support/kamal/makefile.par b/support/kamal/makefile.par
new file mode 100644
index 0000000000..6df81ec819
--- /dev/null
+++ b/support/kamal/makefile.par
@@ -0,0 +1,34 @@
+# Use this makefile if you have access to getpar(). You then
+# need to link with the library that provides it (e.g. -lsep below).
+# If you don't use the other makefile (./makefiile).
+
+CFLAGS = -O
+LINTFLAGS = -abchnpux
+CSUBS = Expand.c Match.c subs.c
+OSUBS = Expand.o Match.o subs.o
+B =
+
+default: all
+
+all: texexpand detex texeqn texmatch
+
+texexpand: texexpand2.o $(OSUBS)
+ cc $(CFLAGS) -o $(B)texexpand texexpand2.o $(OSUBS) -lsep
+
+detex: detex2.o DeTeX.o $(OSUBS)
+ cc $(CFLAGS) -o $(B)detex detex2.o DeTeX.o $(OSUBS) -lsep
+
+texeqn: texeqn2.o Eqn.o $(OSUBS)
+ cc $(CFLAGS) -o $(B)texeqn texeqn2.o Eqn.o $(OSUBS) -lsep
+
+texmatch: texmatch2.o $(OSUBS)
+ cc $(CFLAGS) -o $(B)texmatch texmatch2.o $(OSUBS) -lsep
+
+lint:
+ lint $(LINTFLAGS) texexpand2.c $(CSUBS) > texexpand.lnt
+ lint $(LINTFLAGS) detex2.c DeTeX.c $(CSUBS) > detex.lnt
+ lint $(LINTFLAGS) texeqn2.c Eqn.c $(CSUBS) > texeqn.lnt
+ lint $(LINTFLAGS) texmatch2.c $(CSUBS) > texmatch.lnt
+
+clean:
+ /bin/rm -f *.o core *junk* lint.lst
diff --git a/support/kamal/setups.h b/support/kamal/setups.h
new file mode 100644
index 0000000000..c0509e3663
--- /dev/null
+++ b/support/kamal/setups.h
@@ -0,0 +1,68 @@
+/* setup file */
+
+#include <stdio.h>
+#ifdef MSC
+#include <string.h>
+#include <stdlib.h> /* for type declarations */
+#include <io.h> /* for type declarations */
+#else
+#include <strings.h>
+#include <sys/ioctl.h>
+#include <sgtty.h>
+#endif
+
+#define MAXLEN 1048576 /* maximum number of chars in a document */
+#define MAXWORD 100 /* maximum word length */
+#define MAXLINE 250 /* maximum line length */
+#define MAXENV 50 /* maximum number of environments */
+
+extern char *malloc();
+
+#ifdef IN_TM /* can only declare globals once */
+#else
+extern
+#endif
+struct environment {
+ char *env_name; /* name of environment */
+ int env_beg; /* counter for \begin{environment} */
+ int env_end; /* counter for \end{environment} */
+ int beg_line; /* line number for \beging{environment} */
+ } env[MAXENV];
+
+#ifdef ANSI
+int begin_to_end(char*,char*);
+int command(char*,char*);
+int comm_file(FILE*,int*);
+int comment(char*);
+int def(char*,char*);
+int def_file(FILE*,int*);
+int display(char*);
+int dollar(char*,FILE*);
+int formula(char*);
+int get_buf_word(char*,char*);
+int getenv_file(FILE*,int*);
+int get_file_word(FILE*,char*,int*,int*);
+int is_new_env(char*,int);
+int one_dollar(char*);
+void scrbuf(FILE*,FILE*);
+void tmpbuf(FILE*,char*);
+int two_dollars(char*,FILE*);
+#else
+int begin_to_end();
+int command();
+int comm_file();
+int comment();
+int def();
+int def_file();
+int display();
+int dollar();
+int formula();
+int get_buf_word();
+int getenv_file();
+int get_file_word();
+int is_new_env();
+int one_dollar();
+void scrbuf();
+void tmpbuf();
+int two_dollars();
+#endif
diff --git a/support/kamal/setups.h- b/support/kamal/setups.h-
new file mode 100644
index 0000000000..1d46c2b39c
--- /dev/null
+++ b/support/kamal/setups.h-
@@ -0,0 +1,68 @@
+/* setup file */
+
+#include <stdio.h>
+#ifdef MSC
+#include <string.h>
+#include <stdlib.h> /* for type declarations */
+#include <io.h> /* for type declarations */
+#else
+#include <strings.h>
+#include <sys/ioctl.h>
+#include <sgtty.h>
+#endif
+
+#define MAXLEN 65535 /* maximum number of chars in a document */
+#define MAXWORD 100 /* maximum word length */
+#define MAXLINE 250 /* maximum line length */
+#define MAXENV 50 /* maximum number of environments */
+
+extern char *malloc();
+
+#ifdef IN_TM /* can only declare globals once */
+#else
+extern
+#endif
+struct environment {
+ char *env_name; /* name of environment */
+ int env_beg; /* counter for \begin{environment} */
+ int env_end; /* counter for \end{environment} */
+ int beg_line; /* line number for \beging{environment} */
+ } env[MAXENV];
+
+#ifdef ANSI
+int begin_to_end(char*,char*);
+int command(char*,char*);
+int comm_file(FILE*,int*);
+int comment(char*);
+int def(char*,char*);
+int def_file(FILE*,int*);
+int display(char*);
+int dollar(char*,FILE*);
+int formula(char*);
+int get_buf_word(char*,char*);
+int getenv_file(FILE*,int*);
+int get_file_word(FILE*,char*,int*,int*);
+int is_new_env(char*,int);
+int one_dollar(char*);
+void scrbuf(FILE*,FILE*);
+void tmpbuf(FILE*,char*);
+int two_dollars(char*,FILE*);
+#else
+int begin_to_end();
+int command();
+int comm_file();
+int comment();
+int def();
+int def_file();
+int display();
+int dollar();
+int formula();
+int get_buf_word();
+int getenv_file();
+int get_file_word();
+int is_new_env();
+int one_dollar();
+void scrbuf();
+void tmpbuf();
+int two_dollars();
+#endif
diff --git a/support/kamal/subs.c b/support/kamal/subs.c
new file mode 100644
index 0000000000..cff940694d
--- /dev/null
+++ b/support/kamal/subs.c
@@ -0,0 +1,393 @@
+/* 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);
+}
diff --git a/support/kamal/testfile b/support/kamal/testfile
new file mode 100644
index 0000000000..9bcd101935
--- /dev/null
+++ b/support/kamal/testfile
@@ -0,0 +1,32 @@
+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}
diff --git a/support/kamal/texeqn.1 b/support/kamal/texeqn.1
new file mode 100644
index 0000000000..022c2f8c4a
--- /dev/null
+++ b/support/kamal/texeqn.1
@@ -0,0 +1,45 @@
+.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
diff --git a/support/kamal/texeqn1.c b/support/kamal/texeqn1.c
new file mode 100644
index 0000000000..d051eb8f8b
--- /dev/null
+++ b/support/kamal/texeqn1.c
@@ -0,0 +1,164 @@
+/* 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);
+ }
+
+}
diff --git a/support/kamal/texeqn2.c b/support/kamal/texeqn2.c
new file mode 100644
index 0000000000..79c6d82552
--- /dev/null
+++ b/support/kamal/texeqn2.c
@@ -0,0 +1,216 @@
+/* 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);
+ }
+
+}
diff --git a/support/kamal/texexpand.1 b/support/kamal/texexpand.1
new file mode 100644
index 0000000000..4bf1130bc4
--- /dev/null
+++ b/support/kamal/texexpand.1
@@ -0,0 +1,32 @@
+.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
diff --git a/support/kamal/texexpand1.c b/support/kamal/texexpand1.c
new file mode 100644
index 0000000000..8db44d932d
--- /dev/null
+++ b/support/kamal/texexpand1.c
@@ -0,0 +1,153 @@
+/* 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);
+ }
+
+}
diff --git a/support/kamal/texexpand2.c b/support/kamal/texexpand2.c
new file mode 100644
index 0000000000..467dfd3cff
--- /dev/null
+++ b/support/kamal/texexpand2.c
@@ -0,0 +1,203 @@
+/* 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);
+ }
+
+}
diff --git a/support/kamal/texmatch.1 b/support/kamal/texmatch.1
new file mode 100644
index 0000000000..5b5ec0fb38
--- /dev/null
+++ b/support/kamal/texmatch.1
@@ -0,0 +1,32 @@
+.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
diff --git a/support/kamal/texmatch1.c b/support/kamal/texmatch1.c
new file mode 100644
index 0000000000..ab75dd3186
--- /dev/null
+++ b/support/kamal/texmatch1.c
@@ -0,0 +1,146 @@
+/* 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);
+ }
+
+}
diff --git a/support/kamal/texmatch2.c b/support/kamal/texmatch2.c
new file mode 100644
index 0000000000..74487d8c89
--- /dev/null
+++ b/support/kamal/texmatch2.c
@@ -0,0 +1,159 @@
+/* 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);
+ }
+
+}
diff --git a/support/kamal/texspell b/support/kamal/texspell
new file mode 100644
index 0000000000..13dca97217
--- /dev/null
+++ b/support/kamal/texspell
@@ -0,0 +1,41 @@
+#! /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)
diff --git a/support/kamal/texspell.1 b/support/kamal/texspell.1
new file mode 100644
index 0000000000..ac1afaf1ae
--- /dev/null
+++ b/support/kamal/texspell.1
@@ -0,0 +1,47 @@
+.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