home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Tex / lgrind.zoo / docstrip.tex < prev    next >
Text File  |  1992-09-28  |  15KB  |  544 lines

  1. % $Id: docstrip.tex,v 1.1 91/09/08 03:53:12 gvr Exp $
  2. %
  3. %% This is file `docstrip.tex' generated
  4. %% on <1991/2/1> with the docstrip utility (v1.1l test). 
  5. %% 
  6. %% The original source file was `docstrip.doc'.
  7. %% Included modules: `stats'.
  8. %% 
  9. %% IMPORTANT NOTICE:
  10. %% You are not allowed to distribute this file.
  11. %% For distribution of the original source see 
  12. %% the copyright notice in the file `docstrip.doc'. 
  13. %% 
  14. \def\filename{docstrip}
  15. \def\fileversion{v1.1l test}
  16. \def\filedate{90/12/10}
  17. \def\docdate {90/06/15}
  18.  
  19. %% \CheckSum{835}
  20. %% \CharacterTable
  21. %%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
  22. %%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
  23. %%   Digits        \0\1\2\3\4\5\6\7\8\9
  24. %%   Exclamation   \!     Double quote  \"     Hash (number) \#
  25. %%   Dollar        \$     Percent       \%     Ampersand     \&
  26. %%   Acute accent  \'     Left paren    \(     Right paren   \)
  27. %%   Asterisk      \*     Plus          \+     Comma         \,
  28. %%   Minus         \-     Point         \.     Solidus       \/
  29. %%   Colon         \:     Semicolon     \;     Less than     \<
  30. %%   Equals        \=     Greater than  \>     Question mark \?
  31. %%   Commercial at \@     Left bracket  \[     Backslash     \\
  32. %%   Right bracket \]     Circumflex    \^     Underscore    \_
  33. %%   Grave accent  \`     Left brace    \{     Vertical bar  \|
  34. %%   Right brace   \}     Tilde         \~}
  35. %%
  36. \nofiles
  37.  
  38. \makeatletter
  39.  
  40.  
  41. %% correcting a LaTeX bug first...
  42. \def\@xtypein[#1]#2{\typeout{#2}\read\sixt@@n to#1\ifx #1\@defpar
  43.   \def#1{}\else
  44.    \@iden{\expandafter\@strip\expandafter
  45.    #1#1\@gobble\@gobble} \@gobble\fi\@typein}
  46.  
  47. \typeout{LaTeX utility: `docstrip'
  48.    \fileversion\space <\filedate> (FMi)}
  49. \typeout{English documentation
  50.  \@spaces\@spaces\space\space <\docdate> (FMi)}
  51. \typeout{}
  52. \typeout{**********************************************************}
  53. \typeout{* This program converts documented macro-files into fast *}
  54. \typeout{* loadable files by stripping of (nearly) all comments!
  55.                                                             \space*}
  56. \typeout{**********************************************************}
  57. \typeout{}
  58.  
  59. \def\test@batchfile{%
  60.   \ifx\undefined\batchfile
  61.     \let\batchfile\default@batchfile
  62.     \@okaytrue \else \@okayfalse \fi
  63.   \openin\batch@stream \batchfile\relax
  64.   \ifeof\batch@stream
  65.     \if@okay \else
  66.       \typeout{*************************************************}
  67.       \typeout{* Could not find your \string\batchfile=\batchfile}
  68.       \typeout{* Try to continue without it}
  69.       \typeout{*************************************************}
  70.     \fi
  71.   \else
  72.     \if@okay
  73.       \typeout{*************************************************}
  74.       \typeout{* Batch file docstrip.cmd found. Use it ? (y/n) *}
  75.       \typein[\answer]
  76.               {*************************************************}
  77.       \def\@tempa{y}%
  78.     \else \let\answer\@tempa \fi
  79.     \ifx\@tempa\answer \process@batchfile \fi
  80.   \fi}
  81.  
  82. \def\ask@questions{%
  83.    \typeout{}
  84.    \typeout{***************************************************}
  85.    \typeout{* First type the extension of your input file(s): *}
  86.    \typein[\infileext]
  87.            {***************************************************}
  88.    \typeout{}
  89.    \typeout{**************************************************}
  90.    \typeout{* Now type the extension of your output file(s): *}
  91.    \typein[\outfileext]
  92.            {**************************************************}
  93.    \typeout{}
  94.    \typeout{**************************************************}
  95.    \typeout{* Now give the name(s) of module(s) to include: \space *}
  96.    \typein[\includelist]
  97.            {**************************************************}
  98.    \typeout{}
  99.    \typeout{**************************************************}
  100.    \typeout{* Finally give the list of input file(s) without *}
  101.    \typeout{* extension separated by commas if necessary:\@spaces*}
  102.    \typein[\filelist]
  103.            {**************************************************}}
  104.  
  105. \newif\if@okay
  106. \newread\@infile
  107. \newread\@outfile
  108.  
  109. \def^^L{ }
  110.  
  111. \def\set@filenames{%
  112.     \edef\in@filename{\main@filename.\infileext}%
  113.     \edef\out@filename{\main@filename.\outfileext}}
  114.  
  115. \def\check@filenames{%
  116.   \ifx\infileext\outfilext
  117.     \typeout{}
  118.     \typeout{!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}
  119.     \typeout{! Not possible to read from and write to the same file !}
  120.     \typeout{!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}
  121.     \@okayfalse
  122.   \else
  123.     \@okaytrue
  124.     \immediate\openin\@infile \in@filename \relax
  125.     \ifeof \@infile
  126.       \@okayfalse
  127.       \typeout{}
  128.       \typeout{!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}
  129.       \typeout{! Input file `\in@filename' not found !}
  130.       \typeout{!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}
  131.     \else
  132.       \check@outfile
  133.     \fi
  134.     \immediate\closein\@infile
  135.   \fi}
  136.  
  137. \def\check@outfile{%
  138.    \immediate\openin\@outfile \out@filename \relax
  139.    \ifeof \@outfile \@okaytrue
  140.    \else
  141.      \@okayfalse
  142.      \typeout{}
  143.      \typeout{!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}
  144.      \typeout{! Output file `\out@filename' already exists.}
  145.      \typeout{! Do you want to overwrite it? (yes/no)}
  146.      \typein[\answer]{!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}
  147.      \def\@tempa{yes}%
  148.      \ifx\answer\@tempa \@okaytrue \fi
  149.     \fi
  150.     \immediate\closein\@outfile}
  151.  
  152. \def\write@postamble{%
  153.     \owrite{\string\endinput}%
  154.     \owrite{\double@percent}%
  155.     \owrite{\double@percent End of file `\out@filename'.}%
  156.     \immediate\closeout\@outfile}
  157.  
  158.   \newcount\numberof@files
  159.   \newcount\meta@comment
  160.   \newcount\normal@comment
  161.   \newcount\code@line
  162.   \newcount\processed@line
  163.   \newcount\summeta@comment
  164.   \newcount\sumnormal@comment
  165.   \newcount\sumcode@line
  166.   \newcount\sumprocessed@line
  167.  
  168. \def\process@line{%
  169.   \advance\processed@line\@ne
  170.     \futurelet\next\process@@line}
  171.  
  172. \begingroup
  173. \catcode`\*=12
  174. \lccode`\*=`\%
  175. \lowercase{%
  176. \gdef\double@percent{** }
  177. \gdef\percent@{*}
  178. \gdef\process@@line{%
  179.     \if*\next
  180.       \expandafter\check@second
  181.     \else
  182.   \advance\code@line\@ne
  183.   \endlast@module
  184.            \expandafter\put@line
  185.     \fi}
  186. \gdef\check@@second{%
  187.   \if*\next
  188.  \advance\meta@comment\@ne
  189.  \endlast@module
  190.           \let\next\put@line
  191.    \else
  192.     \if<\next
  193.       \let\next\check@module
  194.     \else
  195.  \advance\normal@comment\@ne
  196.  \endlast@module
  197.       \let\next\remove@line
  198.     \fi
  199.   \fi
  200.   \next}
  201. }
  202.  
  203. \endgroup
  204.  
  205. \gdef\check@second#1{\futurelet\next\check@@second}
  206.  
  207. \def\check@module<{\futurelet\next\check@@module}
  208.  
  209. \def\check@@module{%
  210.     \if+\next
  211.      \let\next\plus@module
  212.     \else
  213.       \if-\next
  214.         \let\next\minus@module
  215.       \else
  216.         \if*\next
  217.           \let\next\star@module
  218.         \else
  219.           \if/\next
  220.             \let\next\slash@module
  221.          \else
  222.             \advance\normal@comment\@ne
  223.             \endlast@module
  224.             \let\next\remove@line
  225.           \fi
  226.         \fi
  227.       \fi
  228.     \fi
  229.     \next}
  230.  
  231. \def\module@included#1#2{%
  232.    \ifin@line@module
  233.      \def\@tempa{#1#2}%
  234.      \ifx\@tempa\curr@module \else
  235.      \maybe@message{>}\in@line@modulefalse \module@included#1{#2}\fi
  236.    \else
  237.      \in@line@moduletrue
  238.      \def\curr@module{#1#2}%
  239.      \maybe@message{<#1#2}%
  240.       \inclcurr@modulefalse
  241.       \@for\@tempa:=#2\do
  242.       {\edef\@tempb{\noexpand\in@{\@tempa,}{\includelist,}}%
  243.       \@tempb \ifin@ \inclcurr@moduletrue \fi}%
  244.     \fi
  245. }
  246.  
  247. \def\endlast@module{%
  248.    \ifin@line@module
  249.      \maybe@message{>}\in@line@modulefalse \fi}
  250.  
  251.  \newif\ifin@line@module
  252. \newif\ifinclcurr@module
  253.  
  254. \def\plus@module+#1>{%
  255.   \module@included+{#1}%
  256.   \ifinclcurr@module
  257.  \advance\code@line\@ne
  258.           \expandafter\put@module
  259.   \else
  260.  \advance\normal@comment\@ne
  261.           \expandafter\remove@line
  262.   \fi}
  263.  
  264. \newif\ifoutput@block \output@blocktrue
  265. \newif\ifin@block
  266.  
  267. \def\star@module*#1>{%
  268.  \ifin@block
  269.   \errmessage{Already in block <\block@type>}%
  270.  \else
  271.   \in@blocktrue
  272.   \def\block@type{*#1}%
  273.   \module@included*{#1}%
  274.   \in@line@modulefalse
  275.   \ifinclcurr@module
  276.     \output@blocktrue
  277.   \else
  278.     \output@blockfalse
  279.   \fi
  280.  \fi
  281.  \advance\normal@comment\@ne
  282.  \remove@line
  283. }
  284.  
  285. \def\slash@module/#1>{%
  286.  \ifin@block
  287.   \in@blockfalse
  288.   \output@blocktrue
  289.  \maybe@message{\percent@}%
  290.  \maybe@message{>}%
  291.   \def\@tempa{*#1}%
  292.   \ifx\@tempa\block@type
  293.   \else
  294.     \errmessage{Block <\block@type> ended by </#1>}%
  295.   \fi
  296.  \else
  297.   \errmessage{There was no start block for </#1>}%
  298.  \fi
  299.  \advance\normal@comment\@ne
  300.  \remove@line
  301. }
  302.  
  303. \def\minus@module-#1>{%
  304.   \module@included-{#1}%
  305.   \ifinclcurr@module
  306.  \advance\normal@comment\@ne
  307.           \expandafter\remove@line
  308.   \else
  309.  \advance\code@line\@ne
  310.           \expandafter\put@module
  311.   \fi}
  312.  
  313. \def\in@#1#2{%
  314.   \def\in@@##1#1##2##3\in@@{%
  315.     \ifx\in@##2\in@false\else\in@true\fi}%
  316.   \in@@#2#1\in@\in@@}
  317.  
  318. \newif\ifin@
  319.  
  320. \def\include#1{\def\includelist{#1}}
  321.  
  322. \include{}
  323.  
  324. \def\owrite{%
  325.  \maybe@message{.}%
  326.   \immediate\write\@outfile}
  327.  
  328. \let\end@inline\relax
  329.  
  330. \def\put@module#1\end@inline{\owrite{#1}}
  331.  
  332. \def\put@line#1\end@inline{%
  333.   \ifoutput@block
  334.      \owrite{\in@line}%
  335.  \else
  336.    \maybe@message{\percent@}%
  337.   \fi
  338. }
  339.  
  340. \def\remove@line#1\end@inline{%
  341.  \maybe@message{\percent@}%
  342. }
  343.  
  344. \def\setup@reading{%
  345.        \immediate\openin\@infile \in@filename \relax
  346.        \@sanitize
  347.        \@makeother\{%
  348.        \@makeother\}%
  349.        \endlinechar\m@ne
  350.        \par@cnt\z@}
  351.  
  352. \edef\end@input{\expandafter\@gobble\string\\endinput}
  353.  
  354. \newcount\par@cnt
  355.  
  356. \def\process@file{%
  357.   \typeout{}%
  358.   \typeout{Processing \in@filename\space
  359.            \ifx\includelist\@empty \else
  360.             (\includelist) \fi
  361.             -> \out@filename}%
  362.   \typeout{}%
  363.   \begingroup
  364.   \setup@reading
  365.   \loop
  366.     \read\@infile to\in@line
  367.     \ifx\end@input\in@line
  368.       \typeout{File \in@filename\space
  369.                ended by \string\endinput.}%
  370.       \@tempswafalse                      % end the loop
  371.     \else
  372.       \ifx\@empty\in@line
  373.         \advance\par@cnt\@ne
  374.       \else
  375.         \par@cnt\z@
  376.       \fi
  377.       \ifnum \par@cnt<2
  378.         \expandafter\process@line\in@line\end@inline
  379.       \else
  380.         \maybe@message{/}%
  381.       \fi
  382.       \ifeof\@infile \@tempswafalse \else \@tempswatrue \fi
  383.     \fi
  384.   \if@tempswa
  385.   \repeat
  386.   \immediate\closein\@infile
  387.     \typeout{Lines \space processed: \the\processed@line}
  388.     \typeout{Comments removed: \the\normal@comment}
  389.     \typeout{Comments \space passed: \the\meta@comment}
  390.     \typeout{Codelines passed: \the\code@line}
  391.     \global\advance\sumprocessed@line\processed@line
  392.     \global\advance\sumnormal@comment\normal@comment
  393.     \global\advance\summeta@comment\meta@comment
  394.     \global\advance\sumcode@line\code@line
  395.     \global\advance\numberof@files\@ne
  396.  \endgroup}
  397.  
  398. \def\generatefile#1#2#3{%
  399.  \def\out@filename{#1}%
  400.  \typeout{}%
  401.  \typeout{Generating \out@filename:}%
  402.  \typeout{}%
  403.  \if#2t\check@outfile\else\@okaytrue\fi
  404.  \if@okay
  405.    \def\from##1##2{\owrite{\double@percent ##1
  406.                    \if!##2!\else \space
  407.                     (with modules: `##2')\fi}}%
  408.    \edef\reference@lines{\owrite{\double@percent }%
  409.        \owrite{\double@percent The original source files were:}%
  410.        \owrite{\double@percent }%
  411.        #3}%
  412.     \def\from##1##2{\def\in@filename{##1}%
  413.                     \def\includelist{##2}%
  414.                     \process@file}%
  415.     \write@preamble#3\write@postamble
  416.     \let\reference@lines\original@refs
  417.  \fi}
  418.  
  419. \def\processfile#1#2#3#4{%
  420.    \def\main@filename{#1}%
  421.    \def\infileext{#2}%
  422.    \def\outfileext{#3}%
  423.    \set@filenames
  424.    \if #4t\check@filenames\fi
  425.    \if@okay
  426.      \write@preamble
  427.      \process@file
  428.      \write@postamble
  429.    \else \@okaytrue \fi}
  430.  
  431. \def\write@preamble{%
  432.   \immediate\openout\@outfile \out@filename \relax
  433.   \owrite{\double@percent This is file `\out@filename' generated}%
  434.   \owrite{\double@percent on <\the\year/\the\month/\the\day> with
  435.                           the docstrip utility (\fileversion). }%
  436.   \reference@lines
  437.   \owrite{\double@percent }}
  438.  
  439. \def\original@refs{%
  440.   \owrite{\double@percent }%
  441.   \owrite{\double@percent The original source file was `\in@filename'.}%
  442.   \ifx\includelist\@empty\else
  443.     \owrite{\double@percent Included modules: `\includelist'.}\fi
  444.   \owrite{\double@percent }}
  445.  
  446. \let\reference@lines\original@refs
  447.  
  448. \def\default@batchfile{docstrip.cmd}
  449.  
  450.  
  451. \def\showprogress{\let\maybe@message\message}
  452. \def\keepsilent{\let\maybe@message\@gobble}
  453.  
  454. \def\preamble{\begingroup
  455.   \let\reference@lines\relax
  456.   \let\out@filename\relax
  457.   \let\in@filename\relax
  458.   \@tempswatrue
  459.   \def\@tempa{\endpreamble}%
  460.   \def\@tempb{\par}%
  461.   \gdef\write@preamble{%
  462.      \immediate\openout\@outfile \out@filename \relax
  463.      \owrite{\double@percent }%
  464.      \owrite{\double@percent This is file `\out@filename' generated}%
  465.      \owrite{\double@percent on <\the\year/\the\month/\the\day> with
  466.                              the docstrip utility (\fileversion). }%
  467.      \reference@lines}%
  468.   \loop
  469.      \read\batch@stream to \batch@line   % get stuff for preamble
  470.      \ifx\batch@line\@tempa \@tempswafalse \else
  471.         \xdef\write@preamble{\write@preamble\owrite
  472.                {\double@percent
  473.                 \ifx\batch@line\@tempb\else\batch@line\fi}}\fi
  474.   \if@tempswa
  475.   \repeat\endgroup}
  476.  
  477. \def\postamble{\begingroup
  478.   \@tempswatrue
  479.   \def\@tempa{\endpostamble}%
  480.   \def\@tempb{\par}%
  481.   \gdef\write@postamble{}%
  482.   \loop
  483.      \read\batch@stream to \batch@line   % get stuff for postamble
  484.      \ifx\batch@line\@tempa \@tempswafalse \else
  485.         \xdef\write@postamble{\write@postamble\owrite
  486.                {\double@percent
  487.                 \ifx\batch@line\@tempb\else\batch@line\fi}}\fi
  488.   \if@tempswa
  489.   \repeat\endgroup
  490.   \xdef\write@postamble{\write@postamble
  491.                  \immediate\closeout\@outfile}}
  492.  
  493. \newif\ifmore@files \more@filestrue
  494.  
  495. \newread\batch@stream
  496.  
  497. \def\process@batchfile{%
  498.   \@okaytrue
  499.   \let\endinput\@okayfalse
  500.   \loop
  501.   \ifeof\batch@stream \@okayfalse \else
  502.     \read\batch@stream to \batch@line         % get input line
  503.     \batch@line
  504.   \fi
  505.   \if@okay
  506.   \repeat
  507.   \more@filesfalse}
  508.  
  509.  
  510. \showprogress
  511.  
  512. \test@batchfile
  513.  
  514.   \@whilesw\ifmore@files\fi
  515.     {\ask@questions
  516.      \@for\main@filename:=\filelist \do
  517.        {\set@filenames
  518.         \check@filenames
  519.         \if@okay
  520.            \write@preamble
  521.            \process@file
  522.            \write@postamble
  523.         \fi}%
  524.      \typein[\answer]{More files to process? (yes/no)}
  525.      \def\@tempa{yes}%
  526.      \ifx\answer\@tempa \else \more@filesfalse \fi}
  527.  
  528.   \typeout{}
  529.   \ifnum\numberof@files>\@ne
  530.     \typeout{Overall statistics:}
  531.     \typeout{Files \space processed: \the\numberof@files}
  532.     \typeout{Lines \space processed: \the\sumprocessed@line}
  533.     \typeout{Comments removed: \the\sumnormal@comment}
  534.     \typeout{Comments \space passed: \the\summeta@comment}
  535.     \typeout{Codelines passed: \the\sumcode@line}
  536.   \fi
  537.  
  538. \@@end
  539.  
  540.  
  541. \endinput
  542. %% 
  543. %% End of file `docstrip.tex'.
  544.