home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume8 / textools2 / part02 < prev    next >
Encoding:
Internet Message Format  |  1987-02-12  |  35.5 KB

  1. Subject:  v08i062:  A collection of tools for TeX users, Part02/02
  2. Newsgroups: mod.sources
  3. Approved: mirror!rs
  4.  
  5. Submitted by: Kamal Al-Yahya <kamal@hanauma.STANFORD.EDU>
  6. Mod.sources: Volume 8, Issue 62
  7. Archive-name: tektools2/Part02
  8.  
  9.  
  10. [  Not that the previous posting said to connect this one to the end,
  11.    then unshar them together.  This is really not necessary...  --r$  ]
  12.  
  13. if test -f 'subs.c'
  14. then
  15.     echo shar: will not over-write existing file "'subs.c'"
  16. else
  17. cat << \SHAR_EOF > 'subs.c'
  18. /* COPYRIGHT (C) 1987 Kamal Al-Yahya */
  19.  
  20. /* subroutines used programs in the package */
  21. #include    "setups.h"
  22.  
  23. int
  24. begin_to_end(buffer,environment)
  25. char *buffer;
  26. char *environment;
  27. {
  28. int c,len,i;
  29. char w[MAXWORD];
  30.  
  31. buffer++;    len = 1;
  32. while ((c = *buffer++) != NULL)
  33.     {
  34.     len++;
  35.     if (c == '\\')
  36.         {
  37.         i = get_buf_word(buffer,w);
  38.         buffer += i;    len += i;
  39.         if (strcmp(w,"end") == 0)
  40.             {
  41.             buffer++;    len++;
  42.             i = get_buf_word(buffer,w);
  43.             buffer += i+1;    len += i+1;
  44.             if (strcmp(w,environment) == 0)
  45.                 break;
  46.             }
  47.         }
  48.     }
  49. return(len);
  50. }
  51.  
  52. int
  53. command(inbuf,w)
  54. char *inbuf;
  55. char *w;
  56. {
  57. int c,i,j;
  58. int left_br=0, right_br=0;
  59.  
  60. for (i=0; (c = *inbuf++) != NULL && i < MAXLINE; i++)
  61.     {
  62.     w[i] = (char)c;
  63.     if (c == '{')    left_br++;
  64.     if (c == '}')    right_br++;
  65.     if (left_br == right_br && left_br != 0)    break;
  66.     }
  67. left_br = 0;    right_br = 0;
  68. for (j=i+1; (c = *inbuf++) != NULL && j < MAXLINE; j++)
  69.     {
  70.     w[j] = (char)c;
  71.     if (c == '{')    left_br++;
  72.     if (c == '}')    right_br++;
  73.     if (left_br == right_br && left_br != 0)    break;
  74.     }
  75. w[++j] = NULL;
  76. return(j);
  77. }
  78.  
  79. int
  80. comm_file(fp,line,match)
  81. FILE *fp;
  82. int *line,match;
  83. {
  84. int i=0,lbrl=0;
  85. int c;
  86. int left_br=0, right_br=0;
  87.  
  88. while ((c = getc(fp)) != EOF)
  89.     {
  90.     i++;
  91.     if (c == '\n')    (*line)++;
  92.     if (c == '{')
  93.         {
  94.         left_br++;
  95.         if (lbrl == 0)    lbrl = *line;
  96.         }
  97.     if (c == '}')    right_br++;
  98.     if (right_br > left_br)        break;
  99.     }
  100. if (match == 1 && c == EOF && left_br > right_br)
  101.     {
  102.     fprintf(stderr,"file ends: %d unclosed left braces while reading \\newcommand, first opened at line %d\n",left_br-right_br,lbrl,lbrl);
  103.     return(i);
  104.     }
  105. left_br = 0;    right_br = 0;    lbrl = 0;
  106. while ((c = getc(fp)) != EOF)
  107.     {
  108.     i++;
  109.     if (c == '\n')    (*line)++;
  110.     if (c == '{')
  111.         {
  112.         left_br++;
  113.         if (lbrl == 0)    lbrl = *line;
  114.         }
  115.     if (c == '}')    right_br++;
  116.     if (left_br == right_br && left_br != 0)    break;
  117.     }
  118. if (match == 1 && c == EOF && left_br > right_br)
  119.     fprintf(stderr,"file ends: %d unclosed left braces while reading \\newcommand, first opened at line %d\n",left_br-right_br,lbrl,lbrl);
  120. return(i);
  121. }
  122.  
  123. int
  124. comment(buffer)            /* commented text is ignored */
  125. char *buffer;
  126. {
  127. int c,len=0;
  128.  
  129. while((c = *buffer++) != NULL)
  130.     {
  131.     if (c == '\n')        break;
  132.     len++;
  133.     }
  134. return(len);
  135. }
  136.  
  137. int
  138. def(inbuf,w)
  139. char *inbuf, *w;
  140. {
  141. int c,i;
  142. int left_br=0, right_br=0;
  143.  
  144. for (i=0; (c = *inbuf++) != NULL && i < MAXLINE; i++)
  145.     {
  146.     w[i] = (char)c;
  147.     if (c == '{')    left_br++;
  148.     if (c == '}')    right_br++;
  149.     if (left_br == right_br && left_br != 0)    break;
  150.     }
  151. w[++i] = NULL;
  152. return(i);
  153. }
  154.  
  155. int
  156. def_file(fp,line,match)
  157. FILE *fp;
  158. int *line,match;
  159. {
  160. int i=0, lbrl=0;
  161. int c;
  162. int left_br=0, right_br=0;
  163.  
  164. while ((c = getc(fp)) != EOF)
  165.     {
  166.     i++;
  167.     if (c == '\n')    (*line)++;
  168.     if (c == '{')
  169.         {
  170.         left_br++;
  171.         if (lbrl == 0)    lbrl = *line;
  172.         }
  173.     if (c == '}')    right_br++;
  174.     if (left_br == right_br && left_br != 0)    break;
  175.     }
  176. if (match == 1 && c == EOF && left_br > right_br)
  177.     fprintf(stderr,"file ends: %d unclosed left braces while reading \\def, first opened at line %d\n",left_br-right_br,lbrl);
  178. return(i);
  179. }
  180.  
  181. int
  182. display(buffer)
  183. char *buffer;
  184. {
  185. int c,len=1;
  186.  
  187. while((c = *buffer++) != NULL)
  188.     {
  189.     len++;
  190.     if(c == '\\')
  191.         {
  192.         len++;
  193.         if ((c = *buffer++) == ']')
  194.             break;
  195.         }
  196.     }
  197. return(len);            
  198. }
  199.  
  200. int
  201. dollar(buffer,out_file)
  202. char *buffer;
  203. FILE *out_file;
  204. {
  205. int c,len;
  206.  
  207. c=' ' ;        /* "erase" the dollar sign */
  208. putc (c,out_file);
  209. c = *buffer++;
  210. if(c == '$')        len=two_dollars(buffer,out_file)+1;
  211. else            len=one_dollar(buffer);
  212. return(len);
  213. }
  214.  
  215. int
  216. formula(buffer)
  217. char *buffer;
  218. {
  219. int c,len=1;
  220.  
  221. while((c = *buffer++) != NULL)
  222.     {
  223.     len++;
  224.     if (c == '\\')
  225.         {
  226.         if ((c = *buffer++) == ')')
  227.             break;
  228.         }
  229.     }
  230. return(len);            
  231. }
  232.  
  233. int
  234. get_buf_word(inbuf,w)
  235. char *inbuf;
  236. char *w;
  237. {
  238. int c,i;
  239.  
  240. for (i=0; (c = *inbuf++) != NULL && c != ' ' && c != '\n' && c != '\t'
  241.     && c != '$' && c != '{' && c != '}' && c != '%'
  242.     && c != '\\' && c != '#' && c != '(' && c != ')' && c != '['
  243.     && c != ']' && i < MAXWORD; i++)
  244.         w[i] = (char)c;
  245. if ((c == ' ' || c == '\n' || c == '\t' || c == '$' || c == '{' || c == '}' ||
  246.     c == '%' || c == '\\' && c != '#' || c == '(' || c == ')' || c =='['
  247.     || c == ']') && i == 0)
  248.         w[i++] = (char)c;
  249. w[i] = NULL;
  250. return(i);
  251. }
  252.  
  253. int
  254. getenv_file(fp,line,match)
  255. FILE *fp;
  256. int *line,match;
  257. {
  258. int i=0,lbrl=0;
  259. int c;
  260. int left_br=0, right_br=0;
  261.  
  262. while ((c = getc(fp)) != EOF)
  263.     {
  264.     i++;
  265.     if (c == '\n')    (*line)++;
  266.     if (c == '{')
  267.         {
  268.         left_br++;
  269.         if (lbrl == 0)    lbrl = *line;
  270.         }
  271.     if (c == '}')    right_br++;
  272.     if (right_br > left_br)        break;
  273.     }
  274. if (match == 1 && c == EOF && left_br > right_br)
  275.     {
  276.     fprintf(stderr,"file ends: %d unclosed left braces while reading \\newenvironment, first opened at line %d\n",left_br-right_br,lbrl);
  277.     return(i);
  278.     }
  279. left_br = 0;    right_br = 0;    lbrl = 0;
  280. while ((c = getc(fp)) != EOF)
  281.     {
  282.     i++;
  283.     if (c == '\n')    (*line)++;
  284.     if (c == '{')
  285.         {
  286.         left_br++;
  287.         if (lbrl == 0)    lbrl = *line;
  288.         }
  289.     if (c == '}')    right_br++;
  290.     if (left_br == right_br && left_br != 0)    break;
  291.     }
  292. if (match == 1 && c == EOF && left_br > right_br)
  293.     {
  294.     fprintf(stderr,"file ends: %d unclosed left braces while reading \\newenvironment, first opened at line %d\n",left_br-right_br,lbrl);
  295.     return(i);
  296.     }
  297. left_br = 0;    right_br = 0;    lbrl = 0;
  298. while ((c = getc(fp)) != EOF)
  299.     {
  300.     i++;
  301.     if (c == '\n')    (*line)++;
  302.     if (c == '{')
  303.         {
  304.         left_br++;
  305.         if (lbrl == 0)    lbrl = *line;
  306.         }
  307.     if (c == '}')    right_br++;
  308.     if (left_br == right_br && left_br != 0)    break;
  309.     }
  310. if (match == 1 && c == EOF && left_br > right_br)
  311.     fprintf(stderr,"file ends: %d unclosed left braces while reading \\newenvironment, first opened at line %d\n",left_br-right_br,lbrl);
  312. return(i);
  313. }
  314.  
  315. int
  316. get_file_word(fp,w,line,c)
  317. FILE *fp;
  318. char *w;
  319. int *line, *c;
  320. {
  321. int i;
  322.  
  323. for (i=0; (*c = getc(fp)) != NULL && *c != ' ' && *c != '\n' && *c != '\t'
  324.     && *c != '$' && *c != '{' && *c != '}' && *c != '\\' && *c != '#'
  325.     && *c != '(' && *c != ')' && *c != '[' && *c != ']' && *c != '%'
  326.     && i < MAXWORD; i++)
  327.         w[i] = (char)*c;
  328. if (i == 0 && *c == '\n') (*line)++;
  329. w[i] = NULL;
  330. return(i);
  331. }
  332.  
  333. int
  334. is_new_env(w,env_count)
  335. char *w;
  336. int env_count;
  337. {
  338. int i;
  339.  
  340. for (i=0; i < env_count; i++)
  341.     {
  342.     if (strcmp(env[i].env_name,w) == 0)
  343.         return(i);
  344.     }
  345. return(-1);
  346. }
  347.  
  348. int
  349. one_dollar(buffer)
  350. char *buffer;
  351. /* an in-line equation with one dollar signs as delimeters */
  352. {
  353.  
  354. int c,len=0;
  355.  
  356. while((c = *buffer++) != NULL)
  357.     {
  358.     len++;
  359.     if(c == '$')    break;
  360.     }
  361. return(len+1);
  362. }
  363.  
  364. void
  365. scrbuf(in,out)            /* copy input to output */
  366. FILE *in,*out;
  367. {
  368. int c;
  369. while ((c =getc(in)) != EOF)    putc(c,out);
  370. }
  371.  
  372. void
  373. tmpbuf(in,buffer)
  374. /* copy input to buffer, buffer holds only MAXLEN characters */
  375. FILE *in;
  376. char *buffer;
  377. {
  378. int c;
  379. unsigned int l=0;
  380.  
  381. while (l++ < MAXLEN && (c = getc(in)) != EOF)
  382.     *buffer++ = (char)c;
  383. if (l >= MAXLEN)
  384.     {
  385.     fprintf(stderr,"Sorry: document is too large\n");
  386.     exit(-1);
  387.     }
  388. *buffer = NULL;
  389. }
  390.  
  391. int
  392. two_dollars(buffer,out_file)
  393. char *buffer;
  394. FILE *out_file;
  395. /* displayed equation with two-dollar sign delimeters */
  396. {
  397. int c,len=0;
  398.  
  399. while((c = *buffer++) != NULL)
  400.     {
  401.     len++;
  402.     if(c == '$')
  403.         {
  404.         c = *buffer++;        len++;
  405.         if (c != '$')    putc(c,out_file);
  406.         break;
  407.         }
  408.     }
  409. return(len);
  410. }
  411. SHAR_EOF
  412. fi # end of overwriting check
  413. if test -f 'testfile'
  414. then
  415.     echo shar: will not over-write existing file "'testfile'"
  416. else
  417. cat << \SHAR_EOF > 'testfile'
  418. This is a test file for textools
  419. $\beta$
  420. junk \
  421. (unmatched parentheses))
  422. $dollar sign not closed at the same line
  423. it could be a mistake!$
  424. Input another file
  425. \input inc_file
  426. Try to input a non existing file
  427. \input not_available
  428. $$
  429. {{unclosed braces in equation}
  430. $ this should be a double dollar sign
  431. % commented text is ignored, so unmatching like this (( is ignored.
  432. Insert another file
  433. \include{inc_file2}
  434. but \% this is not a commented text
  435. this \$ is also not a math dollar sign, so it should not give
  436. a matching warning, nor should this \{ escaped left brace.
  437. $$ This is a properly displayed text $$
  438. $((unmatched parentheses)$
  439. LaTeX equation:
  440. \begin{equation}
  441. \alpha + beta =0
  442. \begin{array}
  443.  
  444. \end{array}
  445. \begin{array}
  446.  
  447. \end{equation}
  448.  
  449. \end{equation}
  450. SHAR_EOF
  451. fi # end of overwriting check
  452. if test -f 'texeqn.1'
  453. then
  454.     echo shar: will not over-write existing file "'texeqn.1'"
  455. else
  456. cat << \SHAR_EOF > 'texeqn.1'
  457. .TH texeqn 1 2/2/84
  458. .UC 4
  459. .SH NAME
  460. texeqn \- extracts displayed equations in TeX and LaTeX documents.
  461. .SH SYNOPSIS
  462. .B texeqn [-iw]
  463. .I filename
  464. .SH DESCRIPTION
  465. It is sometimes desirable to check only the equations of a document.
  466. .I Texeqn
  467. strips those patterns that constitute displayed equations, i.e. anything
  468. surrounded by
  469. .I two
  470. dollar signs, \\begin{equation} and \\end{equation},
  471. \\begin{eqnarray} and \\end{eqnarray}, or \\begin{displaymath} and
  472. \\end{displaymath}.
  473. Note that this also includes any text that is displayed
  474. in this fashion even if it is not an equation.
  475. .br
  476. Macros defines by \\def or \\newcommand are also stripped, since
  477. the user is likely to use them in those equations.
  478. Also, \\input and \\include files are inserted unless the
  479. .B -i
  480. flag is used.
  481. .br
  482. Warning is given if suspected unmatching is detected. Use the
  483. .B -w
  484. flag to suppress these warnings.
  485. .br
  486. Text commented by '%' is ignored.
  487. .br
  488. Using 
  489. .I texeqn 
  490. alone does not typest the equations. If you want them typeset use the
  491. .B \-eqn
  492. option with TEX(1).
  493. .SH DIAGNOSTICS
  494. Displayed equations that are started and ended by user-defined
  495. control sequences are nor recognized.
  496. .br
  497. White spaces within LaTeX's \\begin{...} and \\end{...} are not allowed for.
  498. .SH SEE ALSO
  499. TEX(1), detex(1), texexpand(1), texmatch(1)
  500. .SH AUTHOR
  501. Kamal Al-Yahya, Stanford University
  502. SHAR_EOF
  503. fi # end of overwriting check
  504. if test -f 'texeqn1.c'
  505. then
  506.     echo shar: will not over-write existing file "'texeqn1.c'"
  507. else
  508. cat << \SHAR_EOF > 'texeqn1.c'
  509. /* COPYRIGHT (C) 1987 Kamal Al-Yahya */
  510. /* texeqn: TeX equation stripping */
  511.  
  512. char *documentation[] = {
  513. " SYNTAX",
  514. "        texeqn [-iw] file1 [file2 .....]",
  515. "     or texeqn [-iw]  < file1 [file2 ....]",
  516. "",
  517. "        Flags:",
  518. "              -i     ignores TeX's and LaTeX's \input files",
  519. "              -w     matching is not checked",
  520. "",
  521. "See the manual page for more details.",
  522. "",
  523. };
  524.  
  525. /* Author: Kamal Al-Yahya, Stanford University,        11/1/83 */
  526. /* Last modified:                    1/25/87 */
  527.  
  528. int    doclength = { sizeof documentation/sizeof documentation[0] };
  529.  
  530. #include    "setups.h"
  531.  
  532. #ifdef tops20
  533. #define TEMPFILE "texXXXXXX"
  534. #else
  535. #define TEMPFILE "/tmp/texXXXXXX"
  536. #endif
  537.  
  538. #ifdef MSC
  539. #else
  540. struct sgttyb ttystat;
  541. #endif
  542.  
  543. extern char *mktemp();
  544. char scratch_file[MAXWORD];
  545.  
  546. int wflag;
  547. int xargc;
  548. char **xargv;
  549.  
  550. main(argc,argv)
  551. int argc; 
  552. char *argv[];
  553. {
  554. char *buf;
  555. FILE *temp,*scr;
  556. register char *cptr;
  557. int piped_in;
  558. int iflag,i;
  559.  
  560. if (((buf = (char *)malloc(MAXLEN*sizeof(char))) == (char *)NULL))
  561.     {
  562.         fprintf(stderr,"texmatch: Cannot malloc() internal buffer space\n\
  563. Need an array of %d characters\n",MAXLEN);
  564.     exit(-1);
  565.     }
  566.  
  567. /* If no arguments, and not in a pipeline, self document */
  568. #ifdef MSC    /* MS-DOS cannot distinguish piped input from no input */
  569. piped_in = (argc == 1);
  570. #else
  571. piped_in = ioctl ((fileno (stdin)), TIOCGETP, &ttystat);
  572. #endif
  573. if (argc == 1 && !piped_in)
  574.     {
  575.     for( i=0; i<doclength; i++)
  576.         printf("%s\n",documentation[i]);
  577.     exit (0);
  578.     }
  579.  
  580. /* process option flags */
  581. xargc = argc;
  582. xargv = argv;
  583. for (xargc--,xargv++; xargc; xargc--,xargv++)
  584.     {
  585.     cptr = *xargv; 
  586.     if( *cptr=='-' )
  587.         {
  588.         while( *(++cptr))
  589.             {
  590.             switch( *cptr )
  591.                 {
  592.                 case 'i':
  593.                     iflag=1;
  594.                     break;
  595.                 case 'w':
  596.                     wflag=1;
  597.                     break;
  598.                 default:
  599.                          fprintf(stderr,
  600.                         "texeqn: unknown flag -%c\n",*cptr);
  601.                     break;
  602.                 }
  603.             }
  604.         }
  605.     }
  606.  
  607. /* first process pipe input */
  608. if(piped_in)
  609.     {
  610. /* need to buffer; can't seek in pipes */
  611. /* make a temporary and volatile file in /tmp */
  612.     strcpy(scratch_file,TEMPFILE);
  613.     mktemp(scratch_file);
  614.     if ((scr=fopen(scratch_file,"w")) == (FILE *)NULL)
  615.         {
  616.         fprintf(stderr,
  617.         "texeqn: Cannot open scratch file [%s]\n",scratch_file);
  618.         exit(-1);
  619.         }
  620.     scrbuf(stdin,scr);
  621.     fclose(scr);
  622.     scr=fopen(scratch_file,"r");
  623.     unlink(scratch_file);
  624.     if (wflag != 1)
  625.         {
  626.         fprintf(stderr,"Checking matching...\n");
  627.         Match(scr);
  628.         fseek(scr,0,0);
  629.         }
  630. /* either expand or buffer */
  631.     if (iflag != 1)
  632.         { Expand(scr,buf);    fclose(scr); }
  633.     else
  634.         { tmpbuf(scr,buf);    fclose(scr); }
  635.     if (wflag != 1)
  636.         fprintf(stderr,"Checking matching done\n\n");
  637.     Eqn(buf,stdout);
  638.     fclose(scr);
  639.     }
  640.  
  641. /* then process input line for arguments and assume they are input files */
  642. xargc = argc;
  643. xargv = argv;
  644. for (xargc--,xargv++; xargc; xargc--,xargv++)
  645.     {
  646.     cptr = *xargv; 
  647.     if( *cptr=='-' ) continue;        /* this is a flag */
  648.     if((temp=fopen(cptr,"r")) != (FILE *)NULL)
  649.         {
  650.         if (wflag != 1)
  651.             {
  652.             fprintf(stderr,"Checking matching...\n");
  653.             fprintf(stderr,"%s:\n",cptr);
  654.             Match(temp);
  655.             fprintf(stderr,"\n");
  656.             fseek(temp,0,0);
  657.             }
  658. /* either expand or buffer */
  659.         if (iflag != 1)
  660.             { Expand(temp,buf);    fclose(temp); }
  661.         else
  662.             { tmpbuf(temp,buf);    fclose(temp); }
  663.         if (wflag != 1)
  664.             fprintf(stderr,"Checking matching done\n\n");
  665.         Eqn(buf,stdout);
  666.         fclose(temp);
  667.         }
  668.     else
  669.         fprintf(stderr,"texeqn: Cannot open %s\n",cptr);
  670.     }
  671.  
  672. }
  673. SHAR_EOF
  674. fi # end of overwriting check
  675. if test -f 'texeqn2.c'
  676. then
  677.     echo shar: will not over-write existing file "'texeqn2.c'"
  678. else
  679. cat << \SHAR_EOF > 'texeqn2.c'
  680. /* COPYRIGHT (C) 1987 Kamal Al-Yahya */
  681. /* texeqn: TeX equation stripping */
  682.  
  683. char *documentation[] = {
  684. " SYNTAX",
  685. "        texeqn [-iw] [parameters] [inputfiles]",
  686. "",
  687. "        flags:",
  688. "              -i   ignores TeX's and LaTeX's \input and \include commands",
  689. "              -w   does not check matching",
  690. "",
  691. "        parameters:",
  692. "              in=filename       filename is the input file",
  693. "                                (Default: in=stdin)",
  694. "",
  695. "              out=filename      filename is the output file",
  696. "                                (Default: out=stdout)",
  697. ""
  698. };
  699.  
  700. /* Author: Kamal Al-Yahya, Stanford University,        11/1/83 */
  701. /* Last modified:                    1/25/87 */
  702.  
  703. int    doclength = { sizeof documentation/sizeof documentation[0] };
  704.  
  705. #include     "setups.h"
  706.  
  707. #ifdef tops20
  708. #define TEMPFILE "texXXXXXX"
  709. #else
  710. #define TEMPFILE "/tmp/texXXXXXX"
  711. #endif
  712.  
  713. #ifdef MSC
  714. #else
  715. struct sgttyb ttystat;
  716. #endif
  717.  
  718. extern char *mktemp();
  719. char string[MAXWORD], filename[MAXWORD], scratch_file[MAXWORD];
  720. FILE *out_file;
  721. int wflag;
  722. int xargc;
  723. char **xargv;
  724.  
  725. main(argc,argv)
  726. int argc; 
  727. char *argv[];
  728. {
  729. char *buf;
  730. FILE *temp,*scr;
  731. register char *cptr;
  732. int piped_in;
  733. int iflag,i;
  734.  
  735. if (((buf = (char *)malloc(MAXLEN*sizeof(char))) == (char *)NULL))
  736.     {
  737.         fprintf(stderr,"texmatch: Cannot malloc() internal buffer space\n\
  738. Need an arrays of %d characters\n",MAXLEN);
  739.     exit(-1);
  740.     }
  741.  
  742. /* If no arguments, and not in a pipeline, self document */
  743. #ifdef MSC    /* MS-DOS cannot distinguish piped input from no input */
  744. piped_in = (argc == 1);
  745. #else
  746. piped_in = ioctl ((fileno (stdin)), TIOCGETP, &ttystat);
  747. #endif
  748. if (argc == 1 && !piped_in)
  749.     {
  750.     for( i=0; i<doclength; i++)
  751.         printf("%s\n",documentation[i]);
  752.     exit (0);
  753.     }
  754.  
  755. out_file=stdout;            /* default standard output */
  756.  
  757. /* process option flags */
  758. xargc = argc;
  759. xargv = argv;
  760. for (xargc--,xargv++; xargc; xargc--,xargv++)
  761.     {
  762.     cptr = *xargv; 
  763.     if( *cptr=='-' )
  764.         {
  765.         while( *(++cptr))
  766.             {
  767.             switch( *cptr )
  768.                 {
  769.                 case 'i':
  770.                     iflag=1;
  771.                     break;
  772.                 case 'w':
  773.                     wflag=1;
  774.                     break;
  775.                 default:
  776.                          fprintf(stderr,
  777.                         "texeqn: unknown flag -%c\n",*cptr);
  778.                     break;
  779.                 }
  780.             }
  781.         }
  782.     }
  783.  
  784. /* process getpar parameters */
  785. xargc = argc;
  786. xargv = argv;
  787.  
  788. if(getpar_("out","s",string))
  789.     {
  790.     sscanf(string,"%s",filename);
  791.     if((temp=fopen(filename,"w")) == NULL)
  792.         fprintf(stderr,"texeqn: Cannot open output file %s\n",filename);
  793.     else
  794.         out_file = temp;
  795.     }
  796.  
  797. /* first process pipe input */
  798. if(piped_in)
  799.     {
  800. /* need to buffer; can't seek in pipes */
  801. /* make a temporary and volatile file in /tmp */
  802.     strcpy(scratch_file,TEMPFILE);
  803.     mktemp(scratch_file);
  804.     if ((scr=fopen(scratch_file,"w")) == (FILE *)NULL)
  805.         {
  806.         fprintf(stderr,
  807.         "texmatch: Cannot open scratch file [%s]\n",scratch_file);
  808.         exit(-1);
  809.         }
  810.     scrbuf(stdin,scr);
  811.     fclose(scr);
  812.     scr=fopen(scratch_file,"r");
  813.     unlink(scratch_file);
  814.     if (wflag != 1)
  815.         {
  816.         fprintf(stderr,"Checking matching...\n");
  817.         Match(scr);
  818.         fseek(scr,0,0);
  819.         }
  820. /* either expand or buffer */
  821.     if (iflag != 1)
  822.         { Expand(scr,buf);    fclose(scr); }
  823.     else
  824.         { tmpbuf(scr,buf);    fclose(scr); }
  825.     if (wflag != 1)
  826.         fprintf(stderr,"Checking matching done\n");
  827.     Eqn(buf,out_file);
  828.     fclose(scr);
  829.     }
  830.  
  831. /* next process in=inputfiles */
  832. if(getpar_("in","s",string))
  833.     {
  834.     sscanf(string,"%s",filename);
  835.     if((temp=fopen(filename,"r")) != NULL)
  836.         {
  837.         if (wflag != 1)
  838.             {
  839.             fprintf(stderr,"Checking matching...\n");
  840.             fprintf(stderr,"%s:\n",filename);
  841.             Match(temp);
  842.             fprintf(stderr,"\n");
  843.             fseek(temp,0,0);
  844.             }
  845. /* either expand or buffer */
  846.         if (iflag != 1)
  847.             { Expand(temp,buf);    fclose(temp); }
  848.         else
  849.             { tmpbuf(temp,buf);    fclose(temp); }
  850.         if (wflag != 1)
  851.             fprintf(stderr,"Checking matching done\n\n");
  852.         Eqn(buf,out_file);
  853.         fclose(temp);
  854.         }
  855.         else
  856.             fprintf(stderr,"texeqn: Cannot open %s\n",filename);
  857.     }
  858.  
  859. /* then process input line for arguments and assume they are input files */
  860. for (xargc--,xargv++; xargc; xargc--,xargv++)
  861.     {
  862.     cptr = *xargv; 
  863.     if( *cptr=='-' ) continue;        /* this is a flag */
  864.     while (*cptr)
  865.         {
  866.         if (*cptr == '=')  break; /* this is for getpar */
  867.         cptr++;
  868.         }       
  869.     if (*cptr)  continue;
  870.     cptr = *xargv;
  871.     if((temp=fopen(cptr,"r")) != (FILE *)NULL)
  872.         {
  873.         if (wflag != 1)
  874.             {
  875.             fprintf(stderr,"Checking matching...\n");
  876.             fprintf(stderr,"%s:\n",cptr);
  877.             Match(temp);
  878.             fprintf(stderr,"\n");
  879.             fseek(temp,0,0);
  880.             }
  881. /* either expand or buffer */
  882.         if (iflag != 1)
  883.             { Expand(temp,buf);    fclose(temp); }
  884.         else
  885.             { tmpbuf(temp,buf);    fclose(temp); }
  886.         if (wflag != 1)
  887.             fprintf(stderr,"Checking matching done\n\n");
  888.         Eqn(buf,out_file);
  889.         fclose(temp);
  890.         }
  891.     else
  892.         fprintf(stderr,"texeqn: Cannot open %s\n",cptr);
  893.     }
  894.  
  895. }
  896. SHAR_EOF
  897. fi # end of overwriting check
  898. if test -f 'texexpand.1'
  899. then
  900.     echo shar: will not over-write existing file "'texexpand.1'"
  901. else
  902. cat << \SHAR_EOF > 'texexpand.1'
  903. .TH texexpand 1 7/10/86
  904. .UC 4
  905. .SH NAME
  906. texexpand \- expands TeX's \\input and LaTeX's \\input{} and \\include{}.
  907. .SH SYNOPSIS
  908. .B texexpand [-w]
  909. .I filename
  910. .SH DESCRIPTION
  911. A TeX or LaTeX document can have included files.
  912. .I Texexpand
  913. rewrites the document after inserting these files. The name of the
  914. included file has to be correct relative to the current working
  915. directory. If
  916. .I filename
  917. cannot be opened, it will try to open
  918. .I filename.tex.
  919. The character '%' is recognized as a comment indicator and the commented
  920. text is passed to the output without opening inserted files in that line.
  921. .br
  922. Warning is given if suspected unmatching is detected. Use the
  923. .B -w
  924. flag to suppress these warnings.
  925. .SH SEE ALSO
  926. texeqn(1), texmatch(1), detex(1).
  927. .SH DIAGNOSTICS
  928. Nesting of \\input and \\include is allowed but the number of opened files
  929. must not exceed the system's limit on the number of simultaneously opened
  930. files (normally < 20).
  931. .br
  932. LaTeX's \\includeonly is not recognized.
  933. .SH AUTHOR
  934. Kamal Al-Yahya, Stanford University, 7/10/86
  935. SHAR_EOF
  936. fi # end of overwriting check
  937. if test -f 'texexpand1.c'
  938. then
  939.     echo shar: will not over-write existing file "'texexpand1.c'"
  940. else
  941. cat << \SHAR_EOF > 'texexpand1.c'
  942. /* COPYRIGHT (C) 1987 Kamal Al-Yahya */
  943. /* texexpand: to expand TeX and LaTeX \input and include files */
  944.  
  945. char *documentation[] = {
  946. " SYNTAX",
  947. "        texexpand [-w] file1 [file2 .....]",
  948. "     or texexpand [-w] < file1 [file2 ....]",
  949. "",
  950. "        Flags:",
  951. "              -w    maching is not checked",
  952. "",
  953. "See the manual page for more details.",
  954. "",
  955. };
  956.  
  957. /* Author: Kamal Al-Yahya, Stanford University,        11/1/83 */
  958. /* Last modified:                    1/25/87 */
  959.  
  960. int    doclength = { sizeof documentation/sizeof documentation[0] };
  961.  
  962. #include     "setups.h"
  963.  
  964. #ifdef tops20
  965. #define TEMPFILE "texXXXXXX"
  966. #else
  967. #define TEMPFILE "/tmp/texXXXXXX"
  968. #endif
  969.  
  970. #ifdef MSC
  971. #else
  972. struct sgttyb ttystat;
  973. #endif
  974.  
  975. extern char *mktemp();
  976. char scratch_file[MAXWORD];
  977.  
  978. int wflag;
  979. int xargc;
  980. char **xargv;
  981.  
  982. main(argc,argv)
  983. int argc; 
  984. char *argv[];
  985. {
  986. char *buf;
  987. FILE *temp,*scr;
  988. register char *cptr;
  989. int piped_in;
  990. int i;
  991.  
  992. if (((buf = (char *)malloc(MAXLEN*sizeof(char))) == (char *)NULL))
  993.     {
  994.         fprintf(stderr,"texpand: Cannot malloc() internal buffer space\n\
  995. Need an array of %d characters\n",MAXLEN);
  996.     exit(-1);
  997.     }
  998.  
  999. /* If no arguments, and not in a pipeline, self document */
  1000. #ifdef MSC    /* MS-DOS cannot distinguish piped input from no input */
  1001. piped_in = (argc == 1);
  1002. #else
  1003. piped_in = ioctl ((fileno (stdin)), TIOCGETP, &ttystat);
  1004. #endif
  1005. if (argc == 1 && !piped_in)
  1006.     {
  1007.     for( i=0; i<doclength; i++)
  1008.         printf("%s\n",documentation[i]);
  1009.     exit (0);
  1010.     }
  1011.  
  1012. /* process option flags */
  1013. xargc = argc;
  1014. xargv = argv;
  1015. for (xargc--,xargv++; xargc; xargc--,xargv++)
  1016.     {
  1017.     cptr = *xargv; 
  1018.     if( *cptr=='-' )
  1019.         {
  1020.         while( *(++cptr))
  1021.             {
  1022.             switch( *cptr )
  1023.                 {
  1024.                 case 'w':
  1025.                     wflag=1;
  1026.                     break;
  1027.                 default:
  1028.                          fprintf(stderr,
  1029.                     "texexpand: unknown flag -%c\n",*cptr);
  1030.                     break;
  1031.                 }
  1032.             }
  1033.         }
  1034.     }
  1035.  
  1036. /* first process pipe input */
  1037. if(piped_in)
  1038.     {
  1039.     if (wflag != 1)
  1040.         {
  1041. /* need to buffer; can't seek in pipes */
  1042. /* make a temporary and volatile file in /tmp */
  1043.         strcpy(scratch_file,TEMPFILE);
  1044.         mktemp(scratch_file);
  1045.         if ((scr=fopen(scratch_file,"w")) == (FILE *)NULL)
  1046.             {
  1047.             fprintf(stderr,
  1048.             "texexpand: Cannot open scratch file [%s]\n",scratch_file);
  1049.             exit(-1);
  1050.             }
  1051.         scrbuf(stdin,scr);
  1052.         fclose(scr);
  1053.         scr=fopen(scratch_file,"r");
  1054.         unlink(scratch_file);
  1055.         fprintf(stderr,"Checking matching...\n");
  1056.         Match(scr);
  1057.         fseek(scr,0,0);
  1058.         Expand(scr,buf);
  1059.         fprintf(stderr,"Checking matching done\n\n");
  1060.         fclose(scr);
  1061.         }
  1062.     else
  1063.         Expand(stdin,buf);
  1064.     fputs(buf,stdout);
  1065.     }
  1066.  
  1067. /* then process input line for arguments and assume they are input files */
  1068. xargc = argc;
  1069. xargv = argv;
  1070. for (xargc--,xargv++; xargc; xargc--,xargv++)
  1071.     {
  1072.     cptr = *xargv; 
  1073.     if( *cptr=='-' ) continue;        /* this is a flag */
  1074.     if((temp=fopen(cptr,"r")) != (FILE *)NULL)
  1075.         {
  1076.         if (wflag != 1)
  1077.             {
  1078.             fprintf(stderr,"Checking matching...\n");
  1079.             fprintf(stderr,"%s:\n",cptr);
  1080.             Match(temp);
  1081.             fprintf(stderr,"\n");
  1082.             fseek(temp,0,0);
  1083.             }
  1084.         Expand(temp,buf);
  1085.         if (wflag != 1)
  1086.             fprintf(stderr,"Checking matching done\n\n");
  1087.         fputs(buf,stdout);
  1088.         fclose(temp);
  1089.         }
  1090.     else
  1091.         fprintf(stderr,"texexpand: Cannot open %s\n",cptr);
  1092.     }
  1093.  
  1094. }
  1095. SHAR_EOF
  1096. fi # end of overwriting check
  1097. if test -f 'texexpand2.c'
  1098. then
  1099.     echo shar: will not over-write existing file "'texexpand2.c'"
  1100. else
  1101. cat << \SHAR_EOF > 'texexpand2.c'
  1102. /* COPYRIGHT (C) 1987 Kamal Al-Yahya */
  1103. /* texexpand: to expand TeX and LaTeX \input and include files */
  1104.  
  1105. char *documentation[] = {
  1106. " SYNTAX",
  1107. "        texexpand [-w] [parameters] [inputfiles]",
  1108. "",
  1109. "        flags:",
  1110. "              -w   does not check matching",
  1111. "",
  1112. "        parameters:",
  1113. "              in=filename       filename is the input file",
  1114. "                                (Default: in=stdin)",
  1115. "",
  1116. "              out=filename      filename is the output file",
  1117. "                                (Default: out=stdout)",
  1118. ""
  1119. };
  1120.  
  1121. /* Author: Kamal Al-Yahya, Stanford University,        11/1/83 */
  1122. /* Last modified:                    1/25/87 */
  1123.  
  1124. int    doclength = { sizeof documentation/sizeof documentation[0] };
  1125.  
  1126. #include    "setups.h"
  1127.  
  1128. #ifdef tops20
  1129. #define TEMPFILE "texXXXXXX"
  1130. #else
  1131. #define TEMPFILE "/tmp/texXXXXXX"
  1132. #endif
  1133.  
  1134. #ifdef MSC
  1135. #else
  1136. struct sgttyb ttystat;
  1137. #endif
  1138.  
  1139. extern char *mktemp();
  1140. char string[MAXWORD], filename[MAXWORD], scratch_file[MAXWORD];
  1141. FILE *out_file;
  1142.  
  1143. int wflag;
  1144. int xargc;
  1145. char **xargv;
  1146.  
  1147. main(argc,argv)
  1148. int argc; 
  1149. char *argv[];
  1150. {
  1151. char *buf;
  1152. FILE *temp,*scr;
  1153. register char *cptr;
  1154. int piped_in;
  1155. int i;
  1156.  
  1157. if (((buf = (char *)malloc(MAXLEN*sizeof(char))) == (char *)NULL))
  1158.     {
  1159.         fprintf(stderr,"texexpand: Cannot malloc() internal buffer space\n\
  1160. Need an array of %d characters\n",MAXLEN);
  1161.     exit(-1);
  1162.     }
  1163.  
  1164. /* If no arguments, and not in a pipeline, self document */
  1165. #ifdef MSC    /* MS-DOS cannot distinguish piped input from no input */
  1166. piped_in = (argc == 1);
  1167. #else
  1168. piped_in = ioctl ((fileno (stdin)), TIOCGETP, &ttystat);
  1169. #endif
  1170. if (argc == 1 && !piped_in)
  1171.     {
  1172.     for( i=0; i<doclength; i++)
  1173.         printf("%s\n",documentation[i]);
  1174.     exit (0);
  1175.     }
  1176.  
  1177. out_file=stdout;            /* default standard output */
  1178.  
  1179. /* process option flags */
  1180. xargc = argc;
  1181. xargv = argv;
  1182. for (xargc--,xargv++; xargc; xargc--,xargv++)
  1183.     {
  1184.     cptr = *xargv; 
  1185.     if( *cptr=='-' )
  1186.         {
  1187.         while( *(++cptr))
  1188.             {
  1189.             switch( *cptr )
  1190.                 {
  1191.                 case 'w':
  1192.                     wflag=1;
  1193.                     break;
  1194.                 default:
  1195.                          fprintf(stderr,
  1196.                     "texexpand: unknown flag -%c\n",*cptr);
  1197.                     break;
  1198.                 }
  1199.             }
  1200.         }
  1201.     }
  1202.  
  1203. /* process getpar parameters */
  1204. xargc = argc;
  1205. xargv = argv;
  1206.  
  1207. if(getpar_("out","s",string))
  1208.     {
  1209.     sscanf(string,"%s",filename);
  1210.     if((temp=fopen(filename,"w")) == NULL)
  1211.         fprintf(stderr,"texexpand: Cannot open output file %s\n",filename);
  1212.     else
  1213.         out_file = temp;
  1214.     }
  1215.  
  1216.  
  1217. /* first process pipe input */
  1218. if(piped_in)
  1219.     {
  1220.     if (wflag != 1)
  1221.         {
  1222. /* need to buffer; can't seek in pipes */
  1223. /* make a temporary and volatile file in /tmp */
  1224.         strcpy(scratch_file,TEMPFILE);
  1225.         mktemp(scratch_file);
  1226.         if ((scr=fopen(scratch_file,"w")) == (FILE *)NULL)
  1227.             {
  1228.             fprintf(stderr,
  1229.                 "texexpand: Cannot open scratch file [%s]\n",scratch_file);
  1230.             exit(-1);
  1231.             }
  1232.         scrbuf(stdin,scr);
  1233.         fclose(scr);
  1234.         scr=fopen(scratch_file,"r");
  1235.         unlink(scratch_file);
  1236.         fprintf(stderr,"Checking matching...\n");
  1237.         Match(scr);
  1238.         fseek(scr,0,0);
  1239.         Expand(scr,buf);
  1240.         fprintf(stderr,"Checking matching done\n\n");
  1241.         fclose(scr);
  1242.         }
  1243.     else
  1244.         Expand(stdin,buf);
  1245.     fputs(buf,out_file);
  1246.     }
  1247.  
  1248. /* next process in=inputfiles */
  1249. if(getpar_("in","s",string))
  1250.     {
  1251.     sscanf(string,"%s",filename);
  1252.     if((temp=fopen(filename,"r")) != NULL)
  1253.         {
  1254.         if (wflag != 1)
  1255.             {
  1256.             fprintf(stderr,"Checking matching...\n");
  1257.             fprintf(stderr,"%s:\n",filename);
  1258.             Match(temp);
  1259.             fprintf(stderr,"\n");
  1260.             fseek(temp,0,0);
  1261.             }
  1262.         Expand(temp,buf);
  1263.         if (wflag != 1)
  1264.             fprintf(stderr,"Checking matching done\n\n");
  1265.         fputs(buf,out_file);
  1266.         fclose(temp);
  1267.         }
  1268.         else
  1269.             fprintf(stderr,"texexpand: Cannot open %s\n",filename);
  1270.     }
  1271.  
  1272. /* then process input line for arguments and assume they are input files */
  1273. for (xargc--,xargv++; xargc; xargc--,xargv++)
  1274.     {
  1275.     cptr = *xargv; 
  1276.     if( *cptr=='-' ) continue;    /* this is a flag */
  1277.     while (*cptr)
  1278.         {
  1279.         if (*cptr == '=')  break; /* this is for getpar */
  1280.         cptr++;
  1281.         }       
  1282.     if (*cptr)  continue;
  1283.     cptr = *xargv;
  1284.     if((temp=fopen(cptr,"r")) != (FILE *)NULL)
  1285.         {
  1286.         if (wflag != 1)
  1287.             {
  1288.             fprintf(stderr,"Checking matching...\n");
  1289.             fprintf(stderr,"%s:\n",cptr);
  1290.             Match(temp);
  1291.             fprintf(stderr,"\n");
  1292.             fseek(temp,0,0);
  1293.             }
  1294.         Expand(temp,buf);
  1295.         if (wflag != 1)
  1296.             fprintf(stderr,"Checking matching done\n\n");
  1297.         fputs(buf,out_file);
  1298.         fclose(temp);
  1299.         }
  1300.     else
  1301.         fprintf(stderr,"texexpand: Cannot open %s\n",cptr);
  1302.     }
  1303.  
  1304. }
  1305. SHAR_EOF
  1306. fi # end of overwriting check
  1307. if test -f 'texmatch.1'
  1308. then
  1309.     echo shar: will not over-write existing file "'texmatch.1'"
  1310. else
  1311. cat << \SHAR_EOF > 'texmatch.1'
  1312. .TH texmatch 1 7/10/86
  1313. .UC 4
  1314. .SH NAME
  1315. texmatch \- checks matching in TeX and LaTeX documents.
  1316. .SH SYNOPSIS
  1317. .B texmatch [-i]
  1318. .I filename
  1319. .SH DESCRIPTION
  1320. .I Texmatch
  1321. gives error messages if it detects unmatched delimiters.
  1322. Delimiters are
  1323. braces, brackets, parentheses, dollar signs (single and double),
  1324. and LaTeX's \\begin and \\end. 
  1325. Error messages are sent to the standard error.
  1326. .br
  1327. Escaped braces and dollar signs are not counted.
  1328. \\input and \\include files are also checked unless the
  1329. .B -i
  1330. flag is used.
  1331. .br
  1332. Text, displayed equations, and environments are checked independently,
  1333. while commented text is not checked.
  1334. .SH DIAGNOSTICS
  1335. LaTeX environments that are started and ended by user-defined
  1336. control sequences are regarded as ordinary text and they are not checked
  1337. independently.
  1338. .br
  1339. White spaces within LaTeX's \\begin{...} and \\end{...} are not allowed for.
  1340. .SH SEE ALSO
  1341. texexpand(1), texeqn(1).
  1342. .SH AUTHOR
  1343. Kamal Al-Yahya, Stanford University
  1344. SHAR_EOF
  1345. fi # end of overwriting check
  1346. if test -f 'texmatch1.c'
  1347. then
  1348.     echo shar: will not over-write existing file "'texmatch1.c'"
  1349. else
  1350. cat << \SHAR_EOF > 'texmatch1.c'
  1351. /* COPYRIGHT (C) 1987 Kamal Al-Yahya */
  1352. /*
  1353.  * texmatch: checks matching parantheses, braces, brackets, and dollar signs
  1354.  * in TeX documents.
  1355.  */
  1356.  
  1357. char *documentation[] = {
  1358. " SYNTAX",
  1359. "        texmatch [-i] file1 [file2 .....]",
  1360. "     or texmatch [-i]  < file1 [file2 ....]",
  1361. "",
  1362. "See the manual page for more details.",
  1363. "",
  1364. };
  1365.  
  1366. /* Author: Kamal Al-Yahya, Stanford University,        11/1/83 */
  1367. /* Last modified:                    1/25/87 */
  1368.  
  1369. int    doclength = { sizeof documentation/sizeof documentation[0] };
  1370.  
  1371. #include    "setups.h"
  1372.  
  1373. #ifdef tops20
  1374. #define TEMPFILE "texXXXXXX"
  1375. #else
  1376. #define TEMPFILE "/tmp/texXXXXXX"
  1377. #endif
  1378.  
  1379. #ifdef MSC
  1380. #else
  1381. struct sgttyb ttystat;
  1382. #endif
  1383.  
  1384. extern char *mktemp();
  1385. char scratch_file[MAXWORD];
  1386.  
  1387. int wflag=0;        /* for consistency with other programs */
  1388. int xargc;
  1389. char **xargv;
  1390.  
  1391. main(argc,argv)
  1392. int argc; 
  1393. char *argv[];
  1394. {
  1395. char *buf;
  1396. FILE *temp,*scr;
  1397. register char *cptr;
  1398. int piped_in;
  1399. int i,iflag;
  1400.  
  1401. if (((buf = (char *)malloc(MAXLEN*sizeof(char))) == (char *)NULL))
  1402.     {
  1403.         fprintf(stderr,"texmatch: Cannot malloc() internal buffer space\n\
  1404. Need two arrays of %d characters\n",MAXLEN);
  1405.     exit(-1);
  1406.     }
  1407.  
  1408. /* If no arguments, and not in a pipeline, self document */
  1409. #ifdef MSC    /* MS-DOS cannot distinguish piped input from no input */
  1410. piped_in = (argc == 1);
  1411. #else
  1412. piped_in = ioctl ((fileno (stdin)), TIOCGETP, &ttystat);
  1413. #endif
  1414. if (argc == 1 && !piped_in)
  1415.     {
  1416.     for( i=0; i<doclength; i++)
  1417.         printf("%s\n",documentation[i]);
  1418.     exit (0);
  1419.     }
  1420.  
  1421. /* process option flags */
  1422. xargc = argc;
  1423. xargv = argv;
  1424. for (xargc--,xargv++; xargc; xargc--,xargv++)
  1425.     {
  1426.     cptr = *xargv; 
  1427.     if( *cptr=='-' )
  1428.         {
  1429.         while( *(++cptr))
  1430.             {
  1431.             switch( *cptr )
  1432.                 {
  1433.                 case 'i':
  1434.                     iflag=1;
  1435.                     break;
  1436.                 default:
  1437.                          fprintf(stderr,
  1438.                     "texmatch: unknown flag -%c\n",*cptr);
  1439.                     break;
  1440.                 }
  1441.             }
  1442.         }
  1443.     }
  1444.  
  1445. /* first process pipe input */
  1446. if(piped_in)
  1447.     {
  1448.     if (iflag != 1)
  1449.         {
  1450. /* need to buffer; can't seek in pipes */
  1451. /* make a temporary and volatile file in /tmp */
  1452.         strcpy(scratch_file,TEMPFILE);
  1453.         mktemp(scratch_file);
  1454.         if ((scr=fopen(scratch_file,"w")) == (FILE *)NULL)
  1455.             {
  1456.             fprintf(stderr,
  1457.             "texmatch: Cannot open scratch file [%s]\n",scratch_file);
  1458.             exit(-1);
  1459.             }
  1460.         scrbuf(stdin,scr);
  1461.         fclose(scr);
  1462.         scr=fopen(scratch_file,"r");
  1463.         unlink(scratch_file);
  1464.         Match(scr);
  1465.         fseek(scr,0,0);
  1466.         Expand(scr,buf);
  1467.         fclose(scr);
  1468.         }
  1469.     else
  1470.         Match(stdin);
  1471.     }
  1472.  
  1473. /* then process input line for arguments and assume they are input files */
  1474. xargc = argc;
  1475. xargv = argv;
  1476. for (xargc--,xargv++; xargc; xargc--,xargv++)
  1477.     {
  1478.     cptr = *xargv; 
  1479.     if( *cptr=='-' ) continue;        /* this is a flag */
  1480.     if((temp=fopen(cptr,"r")) != (FILE *)NULL)
  1481.         {
  1482.         fprintf(stderr,"%s:\n",cptr);
  1483.         Match(temp);
  1484.         fprintf(stderr,"\n");
  1485.         if (iflag != 1)
  1486.             {
  1487.             fseek(temp,0,0);
  1488.             Expand(temp,buf);
  1489.             }
  1490.         fclose(temp);
  1491.         }
  1492.     else
  1493.         fprintf(stderr,"texmatch: Cannot open %s\n",cptr);
  1494.     }
  1495.  
  1496. }
  1497. SHAR_EOF
  1498. fi # end of overwriting check
  1499. if test -f 'texmatch2.c'
  1500. then
  1501.     echo shar: will not over-write existing file "'texmatch2.c'"
  1502. else
  1503. cat << \SHAR_EOF > 'texmatch2.c'
  1504. /* COPYRIGHT (C) 1987 Kamal Al-Yahya */
  1505. /*
  1506.  * texmatch: checks matching parantheses, braces, brackets, and dollar signs
  1507.  * in TeX documents.
  1508.  */
  1509.  
  1510. char *documentation[] = {
  1511. " SYNTAX",
  1512. "        texmatch [-i] [parameters] [inputfiles]",
  1513. "",
  1514. "        flags:",
  1515. "              -i   ignores TeX's and LaTeX's \input and \include commands",
  1516. "",
  1517. "        parameters:",
  1518. "              in=filename       filename is the input file",
  1519. "                                (Default: in=stdin)",
  1520. ""
  1521. };
  1522.  
  1523. /* Author: Kamal Al-Yahya, Stanford University,        11/1/83 */
  1524. /* Last modified:                    1/25/87 */
  1525.  
  1526. int    doclength = { sizeof documentation/sizeof documentation[0] };
  1527.  
  1528. #include    "setups.h"
  1529.  
  1530. char string[MAXWORD], filename[MAXWORD];
  1531. struct sgttyb ttystat;
  1532. extern char *strcpy(), *mktemp();
  1533. char scratch_file[MAXWORD];
  1534.  
  1535. int wflag=0;        /* for consistency with other programs */
  1536. int xargc;
  1537. char **xargv;
  1538.  
  1539. main(argc,argv)
  1540. int argc; 
  1541. char *argv[];
  1542. {
  1543. char *buf;
  1544. FILE *temp,*scr;
  1545. register char *cptr;
  1546. int piped_in;
  1547. int i,iflag;
  1548.  
  1549. if (((buf = (char *)malloc(MAXLEN*sizeof(char))) == (char *)NULL))
  1550.     {
  1551.         fprintf(stderr,"texmatch: Cannot malloc() internal buffer space\n\
  1552. Need two arrays of %d characters each\n",MAXLEN);
  1553.     exit(-1);
  1554.     }
  1555.  
  1556. /* If no arguments, and not in a pipeline, self document */
  1557. piped_in = ioctl ((fileno (stdin)), TIOCGETP, &ttystat);
  1558. if (argc == 1 && !piped_in)
  1559.     {
  1560.     for( i=0; i<doclength; i++)
  1561.         printf("%s\n",documentation[i]);
  1562.     exit (0);
  1563.     }
  1564.  
  1565. /* process option flags */
  1566. xargc = argc;
  1567. xargv = argv;
  1568. for (xargc--,xargv++; xargc; xargc--,xargv++)
  1569.     {
  1570.     cptr = *xargv; 
  1571.     if( *cptr=='-' )
  1572.         {
  1573.         while( *(++cptr))
  1574.             {
  1575.             switch( *cptr )
  1576.                 {
  1577.                 case 'i':
  1578.                     iflag=1;
  1579.                     break;
  1580.                 default:
  1581.                          fprintf(stderr,
  1582.                     "texmatch: unknown flag -%c\n",*cptr);
  1583.                     break;
  1584.                 }
  1585.             }
  1586.         }
  1587.     }
  1588.  
  1589. /* first process pipe input */
  1590. xargc = argc;
  1591. xargv = argv;
  1592. if(piped_in)
  1593.     {
  1594.     if (iflag != 1)
  1595.         {
  1596. /* need to buffer; can't seek in pipes */
  1597. /* make a temporary and volatile file in /tmp */
  1598.         strcpy(scratch_file,"/tmp/texXXXXXX");
  1599.         mktemp(scratch_file);
  1600.         scr=fopen(scratch_file,"w");
  1601.         scrbuf(stdin,scr);
  1602.         fclose(scr);
  1603.         scr=fopen(scratch_file,"r");
  1604.         unlink(scratch_file);
  1605.         Match(scr);
  1606.         fseek(scr,0,0);
  1607.         Expand(scr,buf);
  1608.         fclose(scr);
  1609.         }
  1610.     else
  1611.         Match(stdin);
  1612.     }
  1613.  
  1614. /* next process in=inputfiles */
  1615. if(getpar_("in","s",string))
  1616.     {
  1617.     sscanf(string,"%s",filename);
  1618.     if((temp=fopen(filename,"r")) != NULL)
  1619.         {
  1620.         fprintf(stderr,"%s:\n",filename);
  1621.         Match(temp);
  1622.         fprintf(stderr,"\n");
  1623.         if (iflag != 1)
  1624.             {
  1625.             fseek(temp,0,0);
  1626.             Expand(temp,buf);
  1627.             }
  1628.         fclose(temp);
  1629.         }
  1630.     else
  1631.         fprintf(stderr,"texmatch: Cannot open %s\n",filename);
  1632.     }
  1633.  
  1634. /* then process input line for arguments and assume they are input files */
  1635. for (xargc--,xargv++; xargc; xargc--,xargv++)
  1636.     {
  1637.     cptr = *xargv; 
  1638.     if( *cptr=='-' ) continue;        /* this is a flag */
  1639.     while (*cptr)
  1640.         {
  1641.         if (*cptr == '=')  break; /* this is for getpar */
  1642.         cptr++;
  1643.         }       
  1644.     if (*cptr)  continue;
  1645.     cptr = *xargv;
  1646.     if((temp=fopen(cptr,"r")) != NULL)
  1647.         {
  1648.         fprintf(stderr,"%s:\n",cptr);
  1649.         Match(temp);
  1650.         fprintf(stderr,"\n");
  1651.         if (iflag != 1)
  1652.             {
  1653.             fseek(temp,0,0);
  1654.             Expand(temp,buf);
  1655.             }
  1656.         fclose(temp);
  1657.         }
  1658.     else
  1659.         fprintf(stderr,"texmatch: Cannot open %s\n",cptr);
  1660.     }
  1661.  
  1662. }
  1663. SHAR_EOF
  1664. fi # end of overwriting check
  1665. if test -f 'texspell'
  1666. then
  1667.     echo shar: will not over-write existing file "'texspell'"
  1668. else
  1669. cat << \SHAR_EOF > 'texspell'
  1670. #! /bin/csh
  1671. # shell for running texspell which is TeX and LaTeX's spell
  1672. # Author: Kamal Al-Yahya 1984
  1673.  
  1674. set flag = ()
  1675. unset file
  1676.  
  1677. if ($#argv == 0) then
  1678.     echo "usage:  texspell [-w -i] file"
  1679.     exit(-1)
  1680. endif
  1681. while ($#argv > 0)
  1682.     switch ($argv[1])
  1683.         case -*:
  1684.             set flag = ($flag $argv[1])
  1685.             breaksw
  1686.         default:
  1687.             set file
  1688.             breaksw
  1689.         endsw
  1690.     if !($?file) then
  1691.         shift argv
  1692.     else
  1693.         break
  1694.     endif
  1695. end
  1696.  
  1697. if ($#argv == 0) then
  1698.     echo "usage:  texspell [-w -i] file"
  1699.     exit(-1)
  1700. endif
  1701. while ($#argv > 0)
  1702.         if -e $argv[1] then
  1703.             detex $flag $argv[1] | spell
  1704.         else
  1705.             echo "Can't open $argv[1]"
  1706.             exit(-1)
  1707.         endif
  1708.         shift argv
  1709. end
  1710. exit(0)
  1711. SHAR_EOF
  1712. chmod +x 'texspell'
  1713. fi # end of overwriting check
  1714. if test -f 'texspell.1'
  1715. then
  1716.     echo shar: will not over-write existing file "'texspell.1'"
  1717. else
  1718. cat << \SHAR_EOF > 'texspell.1'
  1719. .TH texspell 1 2/2/84
  1720. .UC 4
  1721. .SH NAME
  1722. texspell \- finds spelling errors in TeX documents.
  1723. .br
  1724. texproofr \- runs
  1725. .B proofr
  1726. on TeX's documents.
  1727. .SH SYNOPSIS
  1728. .B texspell
  1729. [
  1730. .B -i -w
  1731. ]
  1732. .I filename,
  1733. .br
  1734. .B texproofr
  1735. [
  1736. .B -i -w
  1737. ]
  1738. .I filename,
  1739. .SH DESCRIPTION
  1740. TeX and LaTeX have control characters that
  1741. .B spell
  1742. does not recognize.
  1743. .I texspell
  1744. and
  1745. .I texproofr
  1746. first filter these control characters using
  1747. .I detex
  1748. and then pipe the result to
  1749. .B spell
  1750. or
  1751. .B proofr
  1752. respectively.
  1753. .br
  1754. TeX's and LaTeX's \\input and \\include files are recognized and opened.
  1755. If the
  1756. .B -i
  1757. flag is used, those files are ignored.
  1758. .br
  1759. Unmatching also is checked unless suppressed by the
  1760. .B -w
  1761. flag.
  1762. .SH SEE ALSO
  1763. TEX(1), texeqn(1), detex(1), texmatch(1)
  1764. .SH AUTHOR
  1765. Kamal Al-Yahya
  1766. SHAR_EOF
  1767. fi # end of overwriting check
  1768. #    End of shell archive
  1769. exit 0
  1770.  
  1771.