summaryrefslogtreecommitdiff
path: root/systems/unix/tex-gpc/dvitype.ch
blob: 38997eb736cbc289ef7801a89c959e45099b1575 (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
% This is a change file of DVIType for GPC, Wolfgang Helbig, Nov. 2007
To be used with the GNU Pascal Compiler

[0] About DVItype-GPC
@x
\pageno=\contentspagenumber \advance\pageno by 1
@y
\pageno=\contentspagenumber \advance\pageno by 1
\input webmac-gpc

\let\maybe=\iffalse % print changed modules only.

\def\name{\tt DVItype}

\N0\*. About \namegpc.\fi

This is an adaption of Donald~E. Knuth's \.{DVItype}, version 3.6
from December 1995, to Unix. It is based on GNU~Pascal, version 2.1.

This program expects the input file (\.{.dvi}) and the output file,
which is a text file, on the command line.  To support shell
scripting, \namegpc\ sets the exit code to one when something was
wrong with the input file.

\hint

Comments and questions are welcome!

\bigskip
\address
@z
[1] Change the banner line
@x
@d banner=='This is DVItype, Version 3.6' {printed when the program starts}
@y
@d banner=='This is DVItype-GPC'
   {printed when the program starts}
@z

[2] default case branch / no random_reading
@x
@d random_reading==true {should we skip around in the file?}
@d othercases == others: {default for cases not listed explicitly}
@y
@d random_reading==false {should we skip around in the file?}
@d othercases == @+else {default for cases not listed explicitly}
@z

[3] don't use output for output, but out_file
@x
@d print(#)==write(#)
@d print_ln(#)==write_ln(#)
@y
@d print(#)==write(out_file, #)
@d print_ln(#)==write_ln(out_file, #)
@z

[3] suppress io error messages
@x
@p program DVI_type(@!dvi_file,@!output);
@y
@p program DVI_type(term_in,term_out);
@z

[3] write banner on terminal and on outfile only when opened!
@x
  begin print_ln(banner);@/
@y
  begin write_ln(banner);@/
@z

[7] end output line
@x
@d abort(#)==begin print(' ',#); jump_out;
@y
@d abort(#)==begin write_ln(' ', #); print_ln(' ', #);
history := 1; goto final_end;
@z

[9] the type of text_files is text in ISO Pascal
@x
@!text_file=packed file of text_char;
@y
@!text_file=text;
@z

[21] use GPC extension for packing subranges.
@x
@!eight_bits=0..255; {unsigned one-byte quantity}
@y
@!eight_bits=packed 0..255; {unsigned one-byte quantity}
@z

[22] declare out_file
@x
@!tfm_file:byte_file; {a font metric file}
@y
@!tfm_file:byte_file; {a font metric file}
@!out_file:text; {the outfile}
@z

[23] open file whose name is not known at compile time
@x
begin reset(dvi_file);
@y
begin reset(dvi_file, param_str(1));
@z

@x
begin reset(tfm_file,cur_name);
@y
begin reset(tfm_file,trim(cur_name)); {ignore leading and trailing blanks}
@z

[28] no random access
@x;
begin set_pos(dvi_file,-1); dvi_length:=cur_pos(dvi_file);
end;
@#
procedure move_to_byte(n:integer);
begin set_pos(dvi_file,n); cur_loc:=n;
end;
@y;
begin dvi_length := 0
end;
@#
procedure move_to_byte(n:integer);
begin do_nothing;
end;
@z

[43] out_file muss geoeffnet werden!
@x
out_mode:=the_works; max_pages:=1000000; start_vals:=0; start_there[0]:=false;
@y
out_mode:=the_works; max_pages:=1000000; start_vals:=0; start_there[0]:=false;
if param_count <> 2 then
begin write_ln('Usage: dvitype dvi_file text_file'); halt(1);
end;
rewrite(out_file, param_str(2)); print_ln(banner);
@z

[45] term_in und term_out sind input und output
@x
and |term_out| for terminal output.
@^system dependencies@>

@y
and |term_out| for terminal output.
@^system dependencies@>

@d term_in == input
@d term_out == output
@z

@x
@!term_in:text_file; {the terminal, considered as an input file}
@!term_out:text_file; {the terminal, considered as an output file}
@y
@z

[46]
@x
@d update_terminal == break(term_out) {empty the terminal output buffer}
@y
@d update_terminal == do_nothing {empty the terminal output buffer}
@z

[47]
@x
is always at least one blank space in |buffer|.
@^system dependencies@>

@p procedure input_ln; {inputs a line from the terminal}
var k:0..terminal_line_length;
begin update_terminal; reset(term_in);
if eoln(term_in) then read_ln(term_in);
k:=0;
while (k<terminal_line_length)and not eoln(term_in) do
  begin buffer[k]:=xord[term_in^]; incr(k); get(term_in);
  end;
buffer[k]:=" ";
end;
@y
is always at least one blank space in |buffer|.
This is changed here: |term_in| is standard input and is not supposed
to be opened. There is never an end-of-line marker at the beginning of
a line but always at the end of a line.
@^system dependencies@>

@p procedure input_ln; {inputs a line from the terminal}
var k:0..terminal_line_length;
begin update_terminal;
k:=0;
while (k<terminal_line_length)and not eoln(term_in) do
  begin buffer[k]:=xord[term_in^]; incr(k); get(term_in);
  end;
read_ln(term_in);
buffer[k]:=" ";
end;
@z

[50] don't rewrite output file, write the banner while initializing
@x
begin rewrite(term_out); {prepare the terminal for output}
write_ln(term_out,banner);
@y
begin
@z

[64]
@x
@d default_directory_name=='TeXfonts:' {change this to the correct name}
@y
@d default_directory_name=='TeXfonts/' {change this to the correct name}
@z

[66] lowercase filename
@x
  if (names[k]>="a")and(names[k]<="z") then
      cur_name[r]:=xchr[names[k]-@'40]
  else cur_name[r]:=xchr[names[k]];
  end;
cur_name[r+1]:='.'; cur_name[r+2]:='T'; cur_name[r+3]:='F'; cur_name[r+4]:='M'
@y
  cur_name[r]:=xchr[names[k]]
  end;
cur_name[r+1]:='.'; cur_name[r+2]:='t'; cur_name[r+3]:='f'; cur_name[r+4]:='m'
@z

[107] set exit code
@x
final_end:end.
@y
final_end:halt(history) end.
@z

[112] declare and initialize history
@x
itself will get a new section number.
@^system dependencies@>
@y
itself will get a new section number.
@^system dependencies@>

@<Globals...@>=
history : integer;

@
@<Set init...@>=
history := 0;
@z