summaryrefslogtreecommitdiff
path: root/systems/unix/tex-gpc/gftype.ch
blob: c44b95395425b7f4b78d6ab44c46c09f09d5d494 (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
% This is a change file of GFType for GPC, Wolfgang Helbig, Nov. 2007
To be used with the GNU Pascal Compiler Version 2.1
Sep 2008: command line and exit code.

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

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

\def\name{\tt GFtype}

\N0\*. About \namegpc.\fi

This is an adaption of Donald~E. Knuth's \.{GFtype}, version 3.1
from March 1991, to Unix. It is based on GNU~Pascal, version 2.1.

This program expects the input file (\.{.gf}) 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 GFtype, Version 3.1' {printed when the program starts}
@y
@d banner=='This is GFtype-GPC' {printed when the program starts}
@z

[2] default case branch
@x
@d othercases == others: {default for cases not listed explicitly}
@y
@d othercases == @+else {default for cases not listed explicitly, like Modula 2}
@z

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

[3] file names from command line.
@x
@p program GF_type(@!gf_file,@!output);
@y
@p program GF_type(term_in,term_out);
@z

[3] print banner to typ_file after opening typ_file
@x
  begin print_ln(banner);@/
  @<Set initial values@>@/
@y
  begin @<Set initial values@>@/
  print_ln(banner);@/
@z

[6] 
@x
@d negate(#) == #:=-# {change the sign of a variable}
@y
@d negate(#) == #:=-# {change the sign of a variable}
@d do_nothing == 
@z

[7] set history
@x
@d abort(#)==begin print(' ',#); jump_out;
    end
@y
@d abort(#)==begin print_ln(' ',#); history := 1; jump_out;
             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

[11] command line
@x
|xchr| array properly, without needing any system-dependent changes.

@<Set init...@>=
@y
|xchr| array properly, without needing any system-dependent changes.

@d gpc_length == length
@d gpc_param_str == paramstr
@d gpc_param_count == param_count

@<Set init...@>=

if gpc_param_count <> 2 then begin
   write_ln('! Usage: gftype gf_file text_file'); history := 1; goto final_end;
   end;
@z

[20] 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

[21] declare typ_file
@x
@!gf_file:byte_file; {the stuff we are \.{GF}typing}
@y
@!gf_file:byte_file; {the stuff we are \.{GF}typing}
@!typ_file:text; {the outfile}
@z

[22] open GF file with name from command line
@x
begin reset(gf_file);
@y
begin reset(gf_file, gpc_param_str(1));
@z

[26] rewrite out file
@x
wants_mnemonics:=true; wants_pixels:=true;
@y
wants_mnemonics:=true; wants_pixels:=true;
rewrite(typ_file, gpc_param_str(2));
@z


[27] term_in und term_out are input and 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

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

[29]
@x
@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
This is changed here: |term_in| is standard input and is not supposed
to be opened. There is never a end of line mark 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

[31] don't rewrite term_out, don't write banner here.
@x
begin rewrite(term_out); {prepare the terminal for output}
write_ln(term_out,banner);@/
@y
begin
@z

[66] write banner to term_out before opening the other files
@x
@p begin initialize; {get all variables initialized}
@y
@p begin write_ln(term_out, banner);
initialize; {get all variables initialized}
@z

[66] print end of line at end of line
@x
print(' altogether.');
@.The file had n characters...@>
final_end:end.
@y
print_ln(' altogether.');
@.The file had n characters...@>
final_end: halt(history) end.
@z

[73] 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