blob: bd7a1c899e05b0c2d20a1045045e0ecc5392df8b (
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
%%
%% This is file `newfile.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% newfile.dtx (with options: `outin')
%%
%% -----------------------------------------------------------------
%% Author: Peter Wilson (CUA) now at peter.r.wilson@boeing.com until June 2004
%% (or at: pandgwilson at earthlink dot net)
%% Copyright 2002 --- 2004 Peter R. Wilson
%%
%% 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 the license is in
%% http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of
%% LaTeX version 2003/06/01 or later.
%%
%% This work has the LPPL maintenance status "author-maintained".
%%
%% This work consists of the files listed in the README file.
%% -----------------------------------------------------------------
%%
\NeedsTeXFormat{LaTeX2e}[1996/06/01]
\ProvidesPackage{newfile}[2002/06/21 v1.0 Output and input files]
\RequirePackage{verbatim}
\newcommand{\newoutputstream}[1]{%
\@ifundefined{#1outstre@m}%
{\expandafter\newwrite\csname #1outstre@m\endcsname
\csname newif\expandafter\endcsname
\csname ifstre@m#1open\endcsname
\global\csname stre@m#1openfalse\endcsname
\expandafter\ifx\csname atstreamopen#1\endcsname\relax
\global\@namedef{atstreamopen#1}{}%
\fi
\expandafter\ifx\csname atstreamclose#1\endcsname\relax
\global\@namedef{atstreamclose#1}{}%
\fi
}%
{\PackageError{newfile}{Output stream #1 is already defined}{\@ehc}}}
\newcommand{\newinputstream}[1]{%
\@ifundefined{#1instre@m}%
{\expandafter\newread\csname #1instre@m\endcsname
\csname newif\expandafter\endcsname
\csname ifstre@m#1open\endcsname
\global\csname stre@m#1openfalse\endcsname
\expandafter\ifx\csname atstreamopen#1\endcsname\relax
\global\@namedef{atstreamopen#1}{}%
\fi
\expandafter\ifx\csname atstreamclose#1\endcsname\relax
\global\@namedef{atstreamclose#1}{}%
\fi
}%
{\PackageError{newfile}{Input stream #1 is already defined}{\@ehc}}}
\newcommand{\@ifstre@mopen}[3]{%
\csname ifstre@m#1open\endcsname#2\else#3\fi}
\newcommand{\instre@mandopen}[2]{%
\@ifundefined{#1instre@m}{%
\PackageError{newfile}{#1\space is not an input stream}{\@ehc}}%
{\@ifstre@mopen{#1}{#2}{%
\PackageError{newfile}{Input stream #1\space is not open}{\@ehc}}}}
\newcommand{\instre@mandclosed}[2]{%
\@ifundefined{#1instre@m}{%
\PackageError{newfile}{#1\space is not an input stream}{\@ehc}}%
{\@ifstre@mopen{#1}{%
\PackageError{newfile}{Input stream #1\space is open}{\@ehc}}{#2}}}
\newcommand{\outstre@mandopen}[2]{%
\@ifundefined{#1outstre@m}{%
\PackageError{newfile}{#1\space is not an output stream}{\@ehc}}%
{\@ifstre@mopen{#1}{#2}{%
\PackageError{newfile}{Output stream #1\space is not open}{\@ehc}}}}
\newcommand{\outstre@mandclosed}[2]{%
\@ifundefined{#1outstre@m}{%
\PackageError{newfile}{#1\space is not an output stream}{\@ehc}}%
{\@ifstre@mopen{#1}{%
\PackageError{newfile}{Output stream #1\space is open}{\@ehc}}{#2}}}
\newcommand{\openoutputfile}[2]{%
\outstre@mandclosed{#2}{%
\global\@namedef{#1@filename}{#1}%
\if@filesw
\immediate\openout\@nameuse{#2outstre@m}=\@nameuse{#1@filename}%
\fi
\global\csname stre@m#2opentrue\endcsname%
\@nameuse{atstreamopen#2}%
}%
}
\newcommand{\closeoutputstream}[1]{%
\outstre@mandopen{#1}{%
\@nameuse{atstreamclose#1}%
\immediate\closeout\@nameuse{#1outstre@m}%
\global\csname stre@m#1openfalse\endcsname}%
}
\newcommand{\openinputfile}[2]{%
\IfFileExists{#1}{% file exists
\instre@mandclosed{#2}{%
\@addtofilelist{#1}%
\global\@namedef{#1@filename}{#1}%
\immediate\openin\@nameuse{#2instre@m}=\@nameuse{#1@filename}%
\global\csname stre@m#2opentrue\endcsname%
\@nameuse{atstreamopen#2}}}%
{% file not found
\PackageError{newfile}{Can't find file #1}{\@ehc}%
}%
}
\newcommand{\closeinputstream}[1]{%
\instre@mandopen{#1}{%
\@nameuse{atstreamclose#1}%
\immediate\closein\@nameuse{#1instre@m}%
\global\csname stre@m#1openfalse\endcsname}%
}
\def\writeverbatim#1{%
\@bsphack
\let\do\@makeother\dospecials
\catcode`\^^M\active
\verbatim@startline
\verbatim@addtoline
\verbatim@finish
\def\verbatim@processline{%
\immediate\write\@nameuse{#1outstre@m}{\the\verbatim@line}}%
\verbatim@start}
\def\endwriteverbatim{\@esphack}
\newcommand{\addtostream}[2]{%
\@bsphack
\outstre@mandopen{#1}{%
{\let\protect\string
\immediate\write\@nameuse{#1outstre@m}{#2}%
}}%
\@esphack
}
\newif\ifstre@mnoteof
\newcommand{\checkstre@meof}[1]{%
\stre@mnoteoftrue\ifeof\@nameuse{#1instre@m}\stre@mnoteoffalse\fi}
\def\readstream#1{
\instre@mandopen{#1}{%
\loop \checkstre@meof{#1} \ifstre@mnoteof
\read\@nameuse{#1instre@m} to\temptokstre@m
\temptokstre@m
\repeat
}%
}
\def\readaline#1{
\instre@mandopen{#1}{%
\ifeof\@nameuse{#1instre@m}
\PackageWarning{newfile}{No more to read from stream #1}
\else
\read\@nameuse{#1instre@m} to\temptokstre@m
\temptokstre@m
\fi
}%
}
\def\readverbatim{\begingroup
\@ifstar{\stre@mverbatim@input\relax}%
{\stre@mverbatim@input{\frenchspacing\@vobeyspaces}}}
\def\stre@mverbatim@input#1#2{%
\@ifstre@mopen{#2}%
{\@verbatim #1\relax
\def\verbatim@in@stream{\@nameuse{#2instre@m}}
\verbatim@readstre@m{#2}\endtrivlist\endgroup\@doendpe}%
{\PackageError{newfile}{Stream #2 is not open}{\@ehc}\endgroup}%
}
\def\verbatim@readstre@m#1{%
\verbatim@startline
\expandafter\endlinechar\expandafter\m@ne
\expandafter\verbatim@read@file
\expandafter\endlinechar\the\endlinechar\relax
\verbatim@finish
}
\newcommand{\plainvstream}{%
\def\verbatim@processline{\the\verbatim@line\par}%
}
\newcounter{streamvline}
\newcommand{\streamvnumfont}[1]{\def\stre@mvnfont{#1}}
\streamvnumfont{\footnotesize}
\newcommand{\verbatimfont}[1]{%
\def\verbatim@font{#1%
\hyphenchar\font\m@ne
\let\do\do@noligs
\verbatim@nolig@list}}
\verbatimfont{\normalfont\ttfamily}
\newcommand{\numbervstream}{%
\setcounter{streamvline}{0}%
\def\verbatim@processline{%
\addtocounter{streamvline}{1}%
\leavevmode
{\stre@mvnfont \thestreamvline}\space
\the\verbatim@line\par}%
}
\newcommand{\marginnumbervstream}{%
\setcounter{streamvline}{0}%
\def\verbatim@processline{%
\addtocounter{streamvline}{1}%
\leavevmode
\llap{{\stre@mvnfont \thestreamvline} \hskip\@totalleftmargin}
\the\verbatim@line\par}%
}
\endinput
%%
%% End of file `newfile.sty'.
|