summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/parselines/parselines.sty
blob: 92970ef9e6561a6f2753fdb2734e1f79d2603bb0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
%%
%% This is file `parselines.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% parselines.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% parselines : 2011/02/19 v1.4 - parselines : catch file between delimiters or tags
%% 
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either
%% version 1.3 of this license or (at your option) any later
%% version. The latest version of this license is in
%%    http://www.latex-project.org/lppl.txt
%% 
%% This work consists of the main source file parselines.dtx
%% and the derived files
%%    parselines.sty, parselines.pdf, parselines.ins
%% 
%% parselines : a simple line parser for TeX
%% Copyright (C) 2010 by Florent Chervet <florent.chervet@free.fr>
%% 
\NeedsTeXFormat{LaTeX2e}% LaTeX 2.09 can't be used (nor non-LaTeX)
   [2005/12/01]% LaTeX must be 2005/12/01 or younger
\ProvidesPackage{parselines}
         [2011/02/19 v1.4 - a simple line parser for TeX]
\ifdefined\globtoks  \globtoks\parselin@tk
\else                \newtoks\parselin@tk
\fi
\newcommand\CollectEnvir{}
\protected\def\CollectEnvir#1{%
   \gdef\parselin@Finish{#1%
      \expandafter{\the\parselin@tk}%
      \global\let\parselin@Finish\@undefined}%
   \ifx\parselin@tk#1\else
      \expandafter\def\expandafter\parselin@Finish
         \expandafter{\parselin@Finish\parselin@tk{}}%
      \if \relax
          \expandafter\expandafter\expandafter\parselin@isatoken
            \expandafter\meaning\expandafter#1\string\toks
          \relax
         \expandafter\gdef\expandafter\parselin@Finish
            \expandafter{\expandafter\expandafter
               \expandafter\def\expandafter\expandafter
               \parselin@Finish}%
   \fi\fi
   \parselin@tk{}\def\parselin@stack{b}\parselin@Collect@Body
}% \CollectEnvir
\long\def\parselin@Collect@Body#1\end#2{%
  \edef\parselin@stack{\parselin@PushBegins#1\begin\end
                     \expandafter\@gobble\parselin@stack}%
  \ifx\parselin@stack\@empty
      \global\parselin@tk\expandafter{\the\parselin@tk#1}%
      \aftergroup\parselin@Finish
      \end{#2}%
  \else
      \parselin@tk\expandafter{\the\parselin@tk#1\end#2}%
      \expandafter\parselin@Collect@Body % recurse
  \fi
}% \parselin@Collect@Body
\long\def\parselin@PushBegins#1\begin#2{%
      \ifx\end#2\else b\expandafter\parselin@PushBegins\fi}
\expandafter\def\expandafter\parselin@isatoken
   \expandafter#\expandafter1\string\toks#2\relax{\detokenize{#2}\relax}%
\newenvironment{parse lines}[2][]
{%
   #1%
   \count@\z@\def\row{\number\count@}%
   \def\parselin@ProcessLine##1{\advance\count@\@ne #2}%
   \parselin@endlinechar{%
      \def~##1~{%
         \ifx\parselin@@@@@@##1\relax
         \else \parselin@ProcessLine{##1}\expandafter~%
         \fi}%
   }%
   \catcode\endlinechar\active
   \CollectEnvir\parselin@tk
}
{%
   \parselin@endlinechar{%
      \parselin@tk\expandafter{\the\parselin@tk\parselin@@@@@@~}%
   }\the\parselin@tk
}%
\long\def\parselin@endlinechar#1{\begingroup
   \lccode`\~\endlinechar  \lowercase{\endgroup#1}%
}% \parselin@endlinechar
\def\parselin@@@@@@{\parselin@@@@@@}
\newread\parselin@read
\protected\def\dofilebyline{\let\parselin@Finish\@empty
   \@ifstar
      \parselin@dobyline
      {\edef\parselin@Finish{\endlinechar\the\endlinechar\relax}%
       \endlinechar\m@ne
       \parselin@dobyline}%
}% \dofilebyline
\protected\def\parselin@dobyline#1{% #1 = file name
   \IfFileExists{#1}
      \parselin@do@byline
      {\PackageError{parselines}
         {No file #1 found !
         \MessageBreak Your command \string\dobyline\space was ignored}\@eha
      }%
}% \parselin@dobyline
\def\parselin@do@byline{%
   \openin\parselin@read=\@filef@und%
   \loop
      \ifeof\parselin@read\else
         \read\parselin@read to\@tempa
         \expandafter\do\expandafter{\@tempa}%
   \repeat
   \parselin@Finish
}% \parselin@do@byline
\endinput
%%
%% End of file `parselines.sty'.