summaryrefslogtreecommitdiff
path: root/support/convert/convert.tex
blob: 54b52da72262530735cf5a26e7b1bceebbe2b997 (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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
%%
%% This is file `convert.tex',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% convert.dtx 
%% 
%% Copyright (C) 1991,1999 by Bernd Raichle.
%% 
%% IMPORTANT NOTICE:
%% 
%% This program can be redistributed and/or modified under the terms
%% of the LaTeX Project Public License Distributed from CTAN
%% archives in directory macros/latex/base/lppl.txt; either
%% version 1 of the License, or any later version.
%% 
%% Error Reports (in case of UNCHANGED versions) should be sent to
%% 
%%   Bernd Raichle <raichle@Informatik.Uni-Stuttgart.DE>
%% 
\def\fileversion{1.0b}
\def\filedate{1991/07/08}
\def\docdate{1991/07/08}

%% \CheckSum{556}
%% \CharacterTable
%%  {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
%%   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
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}
%%
%% TeX utility `convert' to use with plainTeX or LaTeX v2.09
%% Copyright (C) 1991 by Bernd Raichle.
\catcode`@=11
\newwrite\@unused
\def\typeout#1{{\let\protect\string\immediate\write\@unused{#1}}}
\def\@strip#1#2 \@gobble{\def #1{#2}}
\def\@defpar{\par}
\def\@iden#1{#1}
\def\@gobble#1{}
\def\typein[#1]#2{\typeout{#2}\read\sixt@@n to#1%
  \ifx #1\@defpar \def#1{}\else
    \@iden{\expandafter\@strip\expandafter #1#1\@gobble\@gobble} \@gobble
  \fi}
\typeout{TeX Utility `convert' version \fileversion\space <\filedate> (br)}
\typeout{English documentation dated <\docdate> (br)}
\def\endofjob{\csname @@end\endcsname \end}
\everypar{\errhelp{This TeX utility should not produce any dvi output.}%
  \errmessage{Internal Error 1. -- Please fix me!}}
\nullfont
\def\sorry{%
  \typeout{******************************************}
  \typeout{* Sorry, you need TeX 3 for this Utility *}
  \typeout{******************************************}
  \endofjob}
\newif\iftexthree \texthreetrue
\ifx\undefined\inputlineno
  \texthreefalse
\else
  \count@=\inputlineno
  \ifnum\inputlineno<\z@
    \texthreefalse
  \else\ifnum\inputlineno=\count@
    \texthreefalse
  \fi\fi
\fi
\iftexthree \else \expandafter\sorry\fi
\errorcontextlines=\m@ne
\catcode`^=12
\typeout{}
\typeout{********************************************************}
\typeout{ This program converts text-files with 8bit-characters}
\typeout{ into text-files with TeX's ^^xx syntax or TeX macros}
\typeout{ for these characters.}
\typeout{********************************************************}
\typeout{}
\newif\iffehler
\newcount\convtype
\def\getnumber{\afterassignment\gobblerest\count@=}
\def\gobblerest#1\lineend{}
\loop
  \typeout{ Should I convert 8bit characters to...}%
  \typeout{ \space 1) ^^x notation or}%
  \typein[\conversion]%
          { \space 2) macros calls (defined in `convert.tbl')}%
  \getnumber\conversion \space 0 \lineend
  \convtype=\count@
  \fehlertrue
  \ifnum\convtype>\z@ \ifnum\convtype<\thr@@ \fehlerfalse \fi\fi
  \iffehler
    \typeout{ !! Please type 1 or 2 !!}\typeout{}%
\repeat
\typeout{}
\typein[\infilename]{First type the name of your input file:}
\typeout{}
\typein[\outfilename]{Now type the name of your output file:}
\typeout{}
\ifx\infilename\outfilename
  \typeout{}
  \typeout{!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}
  \typeout{! Not possible to read from and write to the same file !}
  \typeout{!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}
  \expandafter\endofjob
\fi
\newwrite\outstream
\ifx\outfilename\empty
  \typeout{Output to \jobname.log and online.}
  \typeout{------------------------------------------------------------}
  \chardef\outstream=\sixt@@n
\else
  \immediate\openout\outstream \outfilename \relax
\fi
\catcode`~=7
\catcode`$=\active
\newtoks\currentline \currentline={}
\newcount\lineno
\ifx\outfilename\empty
  \def\finish@line{\immediate\write\outstream{\the\currentline}%
    \currentline{}\outputpos\z@}
\else
  \def\finish@line{\immediate\write\outstream{\the\currentline}%
    \currentline{}\outputpos\z@\message{\the\lineno}}
\fi
\newcount\outputpos \outputpos=\z@
\begingroup\lccode`$=32
\lowercase{\endgroup
\def\expand@tab{%
  \count@\outputpos
  \loop \ifnum\count@>7 \advance\count@ -8\repeat
  \loop \ifnum\count@<8 \advance\count@\@ne $\repeat
}
} % end of lowercase
\begingroup \catcode`\~~@=\active
\gdef~~@{\currentline\expandafter{\the\currentline ^^@}%
     \advance\outputpos\thr@@}
\endgroup
\def\defoutstring#1#2#3{\ifnum#1=\z@ \else
  \begingroup \lccode`$=#1\relax
  \lowercase{\endgroup\xdef$}%
    {\currentline\noexpand\expandafter{\noexpand\the\currentline #2}%
    \advance\outputpos\noexpand#3}%
  \fi
}
\def\defout#1#2{\lccode`$=#1\relax
  \lowercase{\gdef$}{#2}}
\def\letout#1#2{\lccode`$=#1\relax
  \lowercase{\global\let$}#2}
\def\hexnum#1{\ifcase#1 0\or 1\or 2\or 3\or 4\or 5\or 6\or 7\or
  8\or 9\or a\or b\or c\or d\or e\or f\fi}
\catcode`*=12
\count@=32
\loop
  \lccode`*=\count@
  \ifnum\count@<127
     \lowercase{\defoutstring\count@*{\@ne}}
     \advance\count@\@ne
\repeat
\defoutstring{127}{^^?}\thr@@
\count@=\@ne \count\thr@@=`A
\loop
  \uccode`*=\count\thr@@
  \ifnum\count@<32
     \uppercase{\defoutstring\count@{^^*}}\thr@@
     \advance\count@\@ne \advance\count\thr@@\@ne
\repeat
\count@=128
\count\@ne=8 \count\tw@=0 % hex-counter
\loop
  \ifnum\count@<\@cclvi
     \defoutstring\count@
        {^^\hexnum{\the\count\@ne}\hexnum{\the\count\tw@}}4
     \advance\count@\@ne
     \ifnum\count\tw@>14
       \count\tw@\z@ \advance\count\@ne \@ne
     \else
       \advance\count\tw@ \@ne
     \fi
\repeat
\newcount\length
\def\getlength{\afterassignment\lengthloop\let\next= }
\def\lengthloop{%
  \ifx\next\empty
  \else
    \advance\length\@ne
    \expandafter\getlength
  \fi
}
\def\processline#1 #2\lineend{\length=\z@
  \getlength#2\empty \getnumber#1\space -1 \lineend
  \defoutstring\count@{#2}\length
}
\newif\ifmore \moretrue
\def\readfile{\begingroup
  \count@=\z@
  \loop
    \ifnum\count@<\@cclvi
      \ifnum\catcode\count@<9
        \catcode\count@ 12
      \else\ifnum\catcode\count@=\active
        \catcode\count@ 12
      \fi\fi
      \advance\count@ \@ne
  \repeat
  \loop
    \endlinechar\m@ne
    \read\@ne to \curline
    \endlinechar`~~M
    \ifx\curline\empty % ignore empty lines
    \else
      \expandafter\processline\curline\lineend
    \fi
    \ifeof\@ne \morefalse \fi
    \ifmore
  \repeat
\endgroup}
\ifnum\convtype=\tw@
  \openin\@ne convert.tbl\relax
  \ifeof\@ne
     \typeout{I can't find file `convert.tbl' -- ignored.}%
  \else
    \readfile
    \closein\@ne
  \fi
\fi
\letout{9}\expand@tab
\defout{10}{%
  \typeout{!!--> Found ^J in line \the\lineno--I'll ignore all ^J.}%
  \letout{10}\relax}
\defout{13}{%
  \typeout{!!--> Found ^M in line \the\lineno--I'll ignore all ^M.}%
  \letout{13}\relax}
\def\readfile{%
  \read\@ne to\next
  \ifeof\@ne
  \else
    \advance\lineno\@ne
    \next\relax
    \finish@line
    \expandafter\readfile
  \fi
}
\def\makeactiveandinput{\begingroup
  \count@=\z@
  \loop
    \ifnum\count@<\@cclvi
      \catcode\count@\active
      \advance\count@\@ne
  \repeat
  \endlinechar=-1
  \openin\@ne \infilename\relax
  \ifeof\@ne
    \typeout{No input file \infilename.}%
  \else
    \lineno\z@
    \readfile
    \closein\@ne
  \fi
  \endlinechar=`~~M
  \ifx\outfilename\empty
    \typeout{------------------------------------------------------------}
  \else
    \immediate\closeout\outstream
  \fi
  \endgroup
  \endofjob
}
\makeactiveandinput
\errhelp{This TeX utility should not reach this point.}%
\errmessage{Internal Error 2. -- Please fix me!}
\endinput
%%
%% End of file `convert.tex'.