summaryrefslogtreecommitdiff
path: root/systems/unix/tex-fpc/mp/dvitomp.ch
blob: 5f4d7d6bd033702256e313bb1ad8c5616c53d25e (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
% This is a change file of DVItoMP-FPC, Wolfgang Helbig, Aug. 2008
To be used with the GNU Pascal Compiler Version 2.1

[0] About DVItoMP-FPC
@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 DVItoMP}

\N0\*. About \namegpc.\fi

This is an adaption of John Hobby's \name, version 0.64, to Unix
and GNU~Pascal, version 2.1.

This program expects the input file (\.{.dvi}) and the output file,
(\.{mpx}) 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=='% Written by DVItoMP, Version 0.64'
@y
@d banner=='% Written by DVItoMP-FPC, 2nd ed.'
@z

[3] only stdio files in program header.
@x
@p program DVI_to_MP(@!dvi_file,@!mpx_file,@!output);
@y
@p
@{@&$I-@} {no I/O checking}
program DVI_to_MP(input, output);
@z

[9] check command line arguments
@x
history:=spotless;
@y
history:=spotless;
if param_count <> 2 then
  begin write_ln('Usage: dvitomp dvi_file mpx_file'); halt(1);
  end;
@z

[12] Pascal's type of text_files is text
@x
@!text_file=packed file of text_char;
@y
@!text_file=text;
@z

[14] get file name from command line
@x
begin rewrite(mpx_file);
@y
begin
rewrite(mpx_file, param_str(2));
@z

[17] use FPC 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

[19] open file whose name is not known at compile time
@x
has acted, these routines assume that no file named |s| is accessible.
@y
has acted, these routines assume that no file named |s| is accessible.
@d io_ok==io_result=0
@d clear_io_result==@+if io_result=0 then
@z

@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

@x
begin reset(vf_file,cur_name);
open_vf_file:=(not eof(vf_file));
@y
begin clear_io_result; reset(vf_file,trim(cur_name));
 open_vf_file:=io_ok;
@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 do_nothing;
	end;
	@#
	procedure move_to_byte(n:integer);
	begin do_nothing;
	end;
	@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

[61]
@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

[63] lowercase filename
@x
  if (names[k]>="a")and(names[k]<="z") then
      cur_name[l]:=xchr[names[k]-@'40]
  else cur_name[l]:=xchr[names[k]];
  end;
cur_name[l+1]:='.'; cur_name[l+2]:='V'; cur_name[l+3]:='F'
@y
  cur_name[l]:=xchr[names[k]]
  end;
cur_name[l+1]:='.'; cur_name[l+2]:='v'; cur_name[l+3]:='f'
@z

[64] lowercase filename
@x
cur_name[l+2]:='T'; cur_name[l+3]:='F'; cur_name[l+4]:='M'
@y
cur_name[l+2]:='t'; cur_name[l+3]:='f'; cur_name[l+4]:='m'
@z

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