home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / useful / text / tex / pastex / macros / latex2e / inputs / textmerg.sty (.txt) < prev    next >
LaTeX Document  |  1994-06-09  |  5KB  |  176 lines

  1. %% This is file `textmerg.sty', generated 
  2. %% on <1994/6/9> with the docstrip utility (2.2h).
  3. %% The original source files were:
  4. %% textmerg.dtx  (with options: `textmerg')
  5. %% Copyright (C) 1992,1994 Mike Piff, University of Sheffield, England 
  6. %% You are not allowed to change this file. 
  7. %% You are NOT ALLOWED to distribute this file alone. You are NOT 
  8. %% ALLOWED to take money for the distribution or use of this 
  9. %% file except for a nominal charge for copying etc. 
  10. %% Please address any problems to: 
  11. %% M.Piff@shef.ac.uk 
  12. %% For updates, contact your nearest CTAN site. 
  13. \def\fileversion{2.0}
  14. \def\filedate{1994/03/30}
  15. \def\filename{textmerg.dtx}
  16. \def\Copyright{Copyright (C) 1992,1994 Mike Piff, University of Sheffield, England}
  17. \NeedsTeXFormat{LaTeX2e}[1994/01/01]
  18. \ProvidesPackage{TextMerg}[\filedate]
  19. \typeout{Package `TextMerg' <\filedate>.}
  20. \typeout{\Copyright}
  21. \def\glet{\global\let}
  22. \newread\MergeFile
  23. \def\InputFile#1{%
  24.    \openin\MergeFile=#1
  25.    \ifeof\MergeFile
  26.    \errmessage{Empty merge file}%
  27.    \closein\MergeFile
  28.    \long\def\MakeTemplate##1{%
  29.       \def\Template{}}%
  30.    \else\GetInput\fi}
  31. \def\GetInput{{\endlinechar=-1
  32.    \global\read\MergeFile to\InputBuffer}}
  33. \def\SeeIfEof{%
  34.    \let\NextLook\relax
  35.    \ifeof\MergeFile
  36.    \else
  37.       \ifx\InputBuffer\empty
  38.          \LookAgain
  39.       \fi
  40.    \fi
  41.    \NextLook}
  42. \def\LookAgain{\GetInput
  43.    \let\NextLook\SeeIfEof}
  44. \newif\ifNonBlank \NonBlankfalse
  45. \def\AllowBlank{\global\NonBlankfalse}
  46. \def\DontAllowBlank{\global\NonBlanktrue}
  47. \def\ReadIn#1{%
  48.    \ifNonBlank\SeeIfEof\fi
  49.    \ifeof\MergeFile
  50.       \gdef#1{??}\MissingField
  51.    \else
  52.       \glet#1\InputBuffer
  53.       \GetInput
  54.    \fi}
  55. \def\MissingField{%
  56.    \message{Missing field in file}}
  57. \newtoks\GlobalFields
  58. \def\Fields#1{\GlobalFields{#1}}
  59. \def\ParseFields#1{%
  60.    \ifx#1\EndParseFields
  61.       \let\NextParse\relax
  62.    \else
  63.       \let\NextParse\ParseFields
  64.       \ifx#1+\DontAllowBlank
  65.       \else
  66.          \ifx#1-\AllowBlank
  67.          \else\ReadIn#1
  68.          \fi
  69.       \fi
  70.    \fi\NextParse}
  71. \let\EndParseFields\ParseFields
  72. \def\ReadFields#1{\expandafter\ParseFields
  73.    \the#1\EndParseFields
  74.    \AllowBlank}
  75. \long\def\Merge#1#2{\begingroup%
  76.    \InputFile{#1}%
  77.    \def\Fields##1{%
  78.       \ParseFields##1\EndParseFields}%
  79.    \MakeTemplate{#2}\Iterate}
  80. \long\def\MakeTemplate#1{\def\Template{#1}}
  81. \countdef\Iteratecounter=2
  82. \Iteratecounter=0
  83. \def\Iterate{%
  84.    \global\advance\Iteratecounter by1
  85.    \ReadFields\GlobalFields
  86.    \Template
  87.    \SeeIfEof
  88.    \ifeof\MergeFile
  89.       \def\NextIteration{%
  90.          \endgroup\closein\MergeFile}%
  91.    \else
  92.       \let\NextIteration\Iterate
  93.    \fi
  94.    \NextIteration}
  95. \newcount\MultiCount \newcount\MaxCount
  96. \newif\ifStartOfList
  97. \def\MultiRead#1{%
  98.    \ifnum#1>0
  99.       \SelectCR
  100.       \MakeEmpty{#1}%
  101.       \global\StartOfListtrue
  102.       \glet\NextRead\MRead
  103.       \AllowBlank
  104.       \global\MaxCount=#1
  105.       \NextRead
  106.    \fi}
  107. \newcount\Emptyctr
  108. \def\MakeEmpty#1{\Emptyctr=0
  109.    \loop
  110.       \advance\Emptyctr by1
  111.       \expandafter\ifx\csname
  112.          pr\the\Emptyctr\endcsname\relax
  113.          \expandafter\glet\csname
  114.             pr\the\Emptyctr\endcsname\empty
  115.       \fi
  116.       \ifnum\Emptyctr<#1
  117.    \repeat}
  118. \def\Process#1#2{%
  119.    \expandafter\def\csname
  120.       pr#1\endcsname##1{#2{##1}}}
  121. \def\MarkEnd#1{\gdef\EndMarker{#1}}
  122. \MarkEnd{}
  123. \newtoks\NextLine \newtoks\NextField
  124. \def\AppendNextField{%
  125.    \global\advance\MultiCount1
  126.    \NextField=\expandafter{\TempField}%
  127.    \edef\Append{\NextLine=
  128.       {\the\NextLine&\csname
  129.          pr\the\MultiCount\endcsname
  130.          {\the\NextField}}}%
  131.    \Append}
  132. \def\SelectCR{\glet\EndLine\\}%
  133. \def\FinishLine{%
  134.    \ifStartOfList
  135.       \global\StartOfListfalse
  136.    \else\EndLine\fi}
  137. \def\StopProcessing{%
  138.    \global\MultiCount\MaxCount
  139.    \glet\NextRead\AllowBlank}
  140. \def\MRead{%
  141.    \global\MultiCount=1
  142.    \ReadIn\TempField
  143.    \ifx\TempField\EndMarker
  144.       \StopProcessing
  145.    \else
  146.       \FinishLine
  147.       \NextField=\expandafter{\TempField}%
  148.       \edef\StartLine{\NextLine={\csname
  149.          pr1\endcsname{\the\NextField}}}%
  150.       \StartLine
  151.       \ConstructNextRow
  152.    \fi
  153.    \NextRead}
  154. \def\ConstructNextRow{%
  155.    \ifnum\MultiCount<\MaxCount
  156.       \loop
  157.          \ReadIn\TempField
  158.          \ifx\TempField\EndMarker
  159.             \glet\TempField\empty
  160.             \StopProcessing
  161.             \MissingField
  162.          \else
  163.             \ifeof\MergeFile
  164.                \glet\TempField\empty
  165.                \StopProcessing
  166.                \MissingField
  167.             \fi
  168.          \fi
  169.          \AppendNextField
  170.          \ifnum\MultiCount<\MaxCount
  171.       \repeat
  172.     \fi
  173.    \the\NextLine}
  174. \endinput
  175. %% End of file `textmerg.sty'.
  176.