| 1 |
% omtrans.ch: Characters sets for input and output |
| 2 |
% |
| 3 |
% This file is part of the Omega project, which |
| 4 |
% is based on the web2c distribution of TeX. |
| 5 |
% |
| 6 |
% Copyright (c) 1994--2000 John Plaice and Yannis Haralambous |
| 7 |
% |
| 8 |
% This library is free software; you can redistribute it and/or |
| 9 |
% modify it under the terms of the GNU Library General Public |
| 10 |
% License as published by the Free Software Foundation; either |
| 11 |
% version 2 of the License, or (at your option) any later version. |
| 12 |
% |
| 13 |
% This library is distributed in the hope that it will be useful, |
| 14 |
% but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 |
% Library General Public License for more details. |
| 17 |
% |
| 18 |
% You should have received a copy of the GNU Library General Public |
| 19 |
% License along with this library; if not, write to the Free Software |
| 20 |
% Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 21 |
% |
| 22 |
%--------------------------------------- |
| 23 |
@x [3] m.25 l.767 - Omega Translation |
| 24 |
initialization. We shall define a word file later; but it will be possible |
| 25 |
for us to specify simple operations on word files before they are defined. |
| 26 |
@y |
| 27 |
initialization. We shall define a word file later; but it will be possible |
| 28 |
for us to specify simple operations on word files before they are defined. |
| 29 |
|
| 30 |
@d no_mode=0 |
| 31 |
@d onebyte_mode=1 |
| 32 |
@d ebcdic_mode=2 |
| 33 |
@d twobyte_mode=3 |
| 34 |
@d twobyteLE_mode=4 |
| 35 |
|
| 36 |
@d trans_input=0 |
| 37 |
@d trans_output=1 |
| 38 |
@d trans_default_input=2 |
| 39 |
@d trans_default_output=3 |
| 40 |
@d trans_no_input=4 |
| 41 |
@d trans_no_output=5 |
| 42 |
@d trans_no_default_input=6 |
| 43 |
@d trans_no_default_output=7 |
| 44 |
|
| 45 |
@d mode_input=0 |
| 46 |
@d mode_output=1 |
| 47 |
@d mode_default_input=2 |
| 48 |
@d mode_default_output=3 |
| 49 |
@d mode_no_input=4 |
| 50 |
@d mode_no_output=5 |
| 51 |
@d mode_no_default_input=6 |
| 52 |
@d mode_no_default_output=7 |
| 53 |
@z |
| 54 |
%--------------------------------------- |
| 55 |
@x [3] m.30 l.890 - Omega Translation |
| 56 |
@!max_buf_stack:0..buf_size; {largest index used in |buffer|} |
| 57 |
@y |
| 58 |
@!max_buf_stack:0..buf_size; {largest index used in |buffer|} |
| 59 |
@!term_in_mode:halfword; |
| 60 |
@!term_in_translation:halfword; |
| 61 |
@z |
| 62 |
%--------------------------------------- |
| 63 |
@x [3] m.37 l.1065 - Omega Translation |
| 64 |
if not input_ln(term_in,true) then {this shouldn't happen} |
| 65 |
@y |
| 66 |
if not new_input_ln(term_in,term_in_mode,term_in_translation,true) |
| 67 |
then {this shouldn't happen} |
| 68 |
@z |
| 69 |
%--------------------------------------- |
| 70 |
@x [5] m.54 l. - Omega Translation |
| 71 |
@!log_file : alpha_file; {transcript of \TeX\ session} |
| 72 |
@y |
| 73 |
@!log_file : alpha_file; {transcript of \TeX\ session} |
| 74 |
@!term_out_mode:halfword; |
| 75 |
@!term_out_translation:halfword; |
| 76 |
@z |
| 77 |
%--------------------------------------- |
| 78 |
@x [5] m.59 l. - Omega Translation |
| 79 |
@<Basic printing...@>= |
| 80 |
procedure print_char(@!s:ASCII_code); {prints a single character} |
| 81 |
label exit; |
| 82 |
begin if @<Character |s| is the current new-line character@> then |
| 83 |
if selector<pseudo then |
| 84 |
begin print_ln; return; |
| 85 |
end; |
| 86 |
case selector of |
| 87 |
term_and_log: begin wterm(xchr[s]); wlog(xchr[s]); |
| 88 |
incr(term_offset); incr(file_offset); |
| 89 |
if term_offset=max_print_line then |
| 90 |
begin wterm_cr; term_offset:=0; |
| 91 |
end; |
| 92 |
if file_offset=max_print_line then |
| 93 |
begin wlog_cr; file_offset:=0; |
| 94 |
end; |
| 95 |
end; |
| 96 |
log_only: begin wlog(xchr[s]); incr(file_offset); |
| 97 |
if file_offset=max_print_line then print_ln; |
| 98 |
end; |
| 99 |
term_only: begin wterm(xchr[s]); incr(term_offset); |
| 100 |
if term_offset=max_print_line then print_ln; |
| 101 |
end; |
| 102 |
no_print: do_nothing; |
| 103 |
pseudo: if tally<trick_count then trick_buf[tally mod error_line]:=s; |
| 104 |
new_string: begin if pool_ptr<pool_size then append_char(s); |
| 105 |
end; {we drop characters if the string space is full} |
| 106 |
othercases write(write_file[selector],xchr[s]) |
| 107 |
endcases;@/ |
| 108 |
incr(tally); |
| 109 |
exit:end; |
| 110 |
@y |
| 111 |
@d omega_write(#)==case term_out_mode of |
| 112 |
no_mode: write(#,xchr[s]); |
| 113 |
onebyte_mode,ebcdic_mode: write(#,xchr[s]); |
| 114 |
twobyte_mode: begin write(#,xchr[s div @"100]); |
| 115 |
write(#,xchr[s mod @"100]); |
| 116 |
end; |
| 117 |
twobyteLE_mode: begin write(#,xchr[s mod @"100]); |
| 118 |
write(#,xchr[s div @"100]); |
| 119 |
end; |
| 120 |
end |
| 121 |
|
| 122 |
@d omega_file_write(#)==case write_file_mode[#] of |
| 123 |
no_mode: write(write_file[#],xchr[s]); |
| 124 |
onebyte_mode,ebcdic_mode: write(write_file[#],xchr[s]); |
| 125 |
twobyte_mode: begin write(write_file[#],xchr[s div @"100]); |
| 126 |
write(write_file[#],xchr[s mod @"100]); |
| 127 |
end; |
| 128 |
twobyteLE_mode: begin write(write_file[#],xchr[s mod @"100]); |
| 129 |
write(write_file[#],xchr[s div @"100]); |
| 130 |
end; |
| 131 |
end |
| 132 |
|
| 133 |
@<Basic printing...@>= |
| 134 |
procedure print_char(@!s:ASCII_code); {prints a single character} |
| 135 |
label exit; |
| 136 |
begin if @<Character |s| is the current new-line character@> then |
| 137 |
if selector<pseudo then |
| 138 |
begin print_ln; return; |
| 139 |
end; |
| 140 |
case selector of |
| 141 |
term_and_log: begin omega_write(term_out); omega_write(log_file); |
| 142 |
incr(term_offset); incr(file_offset); |
| 143 |
if term_offset=max_print_line then |
| 144 |
begin wterm_cr; term_offset:=0; |
| 145 |
end; |
| 146 |
if file_offset=max_print_line then |
| 147 |
begin wlog_cr; file_offset:=0; |
| 148 |
end; |
| 149 |
end; |
| 150 |
log_only: begin omega_write(log_file); incr(file_offset); |
| 151 |
if file_offset=max_print_line then print_ln; |
| 152 |
end; |
| 153 |
term_only: begin omega_write(term_out); incr(term_offset); |
| 154 |
if term_offset=max_print_line then print_ln; |
| 155 |
end; |
| 156 |
no_print: do_nothing; |
| 157 |
pseudo: if tally<trick_count then trick_buf[tally mod error_line]:=s; |
| 158 |
new_string: begin if pool_ptr<pool_size then append_char(s); |
| 159 |
end; {we drop characters if the string space is full} |
| 160 |
othercases omega_file_write(selector) |
| 161 |
endcases;@/ |
| 162 |
incr(tally); |
| 163 |
exit:end; |
| 164 |
@z |
| 165 |
%--------------------------------------- |
| 166 |
@x [5] m.59 l. - Omega Translation |
| 167 |
procedure print(@!s:integer); {prints string |s|} |
| 168 |
label exit; |
| 169 |
var j:pool_pointer; {current character code position} |
| 170 |
@!nl:integer; {new-line character to restore} |
| 171 |
@!l:integer; {for printing 16-bit characters} |
| 172 |
begin if s>=str_ptr then s:="???" {this can't happen} |
| 173 |
@.???@> |
| 174 |
else if s<biggest_char then |
| 175 |
if s<0 then s:="???" {can't happen} |
| 176 |
else begin if selector>pseudo then |
| 177 |
begin print_char(s); return; {internal strings are not expanded} |
| 178 |
end; |
| 179 |
if (@<Character |s| is the current new-line character@>) then |
| 180 |
if selector<pseudo then |
| 181 |
begin print_ln; return; |
| 182 |
end; |
| 183 |
nl:=new_line_char; |
| 184 |
@<Set newline character to -1@>; |
| 185 |
if s<@"20 then begin |
| 186 |
print_char(@"5E); print_char(@"5E); print_char(s+@'100); |
| 187 |
end |
| 188 |
else if s<@"7F then |
| 189 |
print_char(s) |
| 190 |
else if s=@"7F then begin |
| 191 |
print_char(@"5E); print_char(@"5E); print_char(s-@'100); |
| 192 |
end |
| 193 |
else if s<@"100 then begin |
| 194 |
print_char(@"5E); print_char(@"5E); |
| 195 |
print_lc_hex((s mod @"100) div @"10); print_lc_hex(s mod @"10); |
| 196 |
end |
| 197 |
else begin {Here is where we generate the strings on the fly.} |
| 198 |
print_char(@"5E); print_char(@"5E); |
| 199 |
print_char(@"5E); print_char(@"5E); |
| 200 |
print_lc_hex(s div @"1000); print_lc_hex((s mod @"1000) div @"100); |
| 201 |
print_lc_hex((s mod @"100) div @"10); print_lc_hex(s mod @"10); |
| 202 |
end; |
| 203 |
@<Set newline character to nl@>; |
| 204 |
return; |
| 205 |
end; |
| 206 |
j:=str_start(s); |
| 207 |
while j<str_start(s+1) do |
| 208 |
begin print_char(so(str_pool[j])); incr(j); |
| 209 |
end; |
| 210 |
exit:end; |
| 211 |
|
| 212 |
@ Control sequence names, file names, and strings constructed with |
| 213 |
\.{\\string} might contain |ASCII_code| values that can't |
| 214 |
be printed using |print_char|. Therefore we use |slow_print| for them: |
| 215 |
|
| 216 |
@<Basic print...@>= |
| 217 |
procedure slow_print(@!s:integer); {prints string |s|} |
| 218 |
var j:pool_pointer; {current character code position} |
| 219 |
begin if (s>=str_ptr) or (s<=biggest_char) then print(s) |
| 220 |
else begin j:=str_start(s); |
| 221 |
while j<str_start(s+1) do |
| 222 |
begin print(so(str_pool[j])); incr(j); |
| 223 |
end; |
| 224 |
end; |
| 225 |
end; |
| 226 |
@y |
| 227 |
procedure print(@!s:integer); {prints string |s|} |
| 228 |
label exit; |
| 229 |
var j:pool_pointer; {current character code position} |
| 230 |
@!nl:integer; {new-line character to restore} |
| 231 |
@!l:integer; {for printing 16-bit characters} |
| 232 |
begin if s>=str_ptr then s:="???" {this can't happen} |
| 233 |
@.???@> |
| 234 |
else if s<biggest_char then |
| 235 |
if s<0 then s:="???" {can't happen} |
| 236 |
else begin if selector>pseudo then |
| 237 |
begin print_char(s); return; {internal strings are not expanded} |
| 238 |
end; |
| 239 |
if (@<Character |s| is the current new-line character@>) then |
| 240 |
if selector<pseudo then |
| 241 |
begin print_ln; return; |
| 242 |
end; |
| 243 |
nl:=new_line_char; |
| 244 |
@<Set newline character to -1@>; |
| 245 |
if s<@"20 then begin |
| 246 |
print_char(@"5E); print_char(@"5E); print_char(s+@'100); |
| 247 |
end |
| 248 |
else if s<@"7F then |
| 249 |
print_char(s) |
| 250 |
else if s=@"7F then begin |
| 251 |
print_char(@"5E); print_char(@"5E); print_char(s-@'100); |
| 252 |
end |
| 253 |
else if s<@"100 then begin |
| 254 |
print_char(@"5E); print_char(@"5E); |
| 255 |
print_lc_hex((s mod @"100) div @"10); print_lc_hex(s mod @"10); |
| 256 |
end |
| 257 |
else begin {Here is where we generate the strings on the fly.} |
| 258 |
print_char(@"5E); print_char(@"5E); |
| 259 |
print_char(@"5E); print_char(@"5E); |
| 260 |
print_lc_hex(s div @"1000); print_lc_hex((s mod @"1000) div @"100); |
| 261 |
print_lc_hex((s mod @"100) div @"10); print_lc_hex(s mod @"10); |
| 262 |
end; |
| 263 |
@<Set newline character to nl@>; |
| 264 |
return; |
| 265 |
end; |
| 266 |
j:=str_start(s); |
| 267 |
while j<str_start(s+1) do |
| 268 |
begin print_char(so(str_pool[j])); incr(j); |
| 269 |
end; |
| 270 |
exit:end; |
| 271 |
|
| 272 |
procedure print_nl(@!s:str_number); {prints string |s| at beginning of line} |
| 273 |
begin if ((term_offset>0)and(odd(selector)))or@| |
| 274 |
((file_offset>0)and(selector>=log_only)) then print_ln; |
| 275 |
print(s); |
| 276 |
end; |
| 277 |
|
| 278 |
procedure overflow_ocp_buf_size; forward; |
| 279 |
procedure overflow_ocp_stack_size; forward; |
| 280 |
|
| 281 |
procedure omega_print(s:str_number); |
| 282 |
var new_s:str_number; |
| 283 |
om_mode,om_translation:integer; |
| 284 |
j:integer; |
| 285 |
begin |
| 286 |
om_mode:=no_mode; |
| 287 |
om_translation:=0; |
| 288 |
case selector of |
| 289 |
term_and_log,log_only,term_only: begin |
| 290 |
om_mode:=term_out_mode; |
| 291 |
if om_mode<>no_mode then om_translation:=term_out_translation; |
| 292 |
end; |
| 293 |
no_print,pseudo,new_string: do_nothing; |
| 294 |
othercases begin |
| 295 |
om_mode:=write_file_mode[selector]; |
| 296 |
if om_mode<>no_mode then om_translation:=write_file_translation[selector]; |
| 297 |
end |
| 298 |
endcases; |
| 299 |
|
| 300 |
if (om_mode=no_mode) or |
| 301 |
((om_mode=onebyte_mode) and (om_translation=0)) then |
| 302 |
begin |
| 303 |
j:=str_start(s); |
| 304 |
while j<str_start(s+1) do begin |
| 305 |
new_s:=so(str_pool[j]); |
| 306 |
if (new_s=new_line_char)and(selector<pseudo) then |
| 307 |
print_ln {added, to be more compatible with TeX} |
| 308 |
else if new_s<@"20 then begin |
| 309 |
print_char(@"5E); print_char(@"5E); print_char(new_s+@'100); |
| 310 |
end |
| 311 |
else if new_s<@"7F then |
| 312 |
print_char(new_s) |
| 313 |
else if new_s=@"7F then begin |
| 314 |
print_char(@"5E); print_char(@"5E); print_char(new_s-@'100); |
| 315 |
end |
| 316 |
else if new_s<@"100 then begin |
| 317 |
print_char(@"5E); print_char(@"5E); |
| 318 |
print_lc_hex((new_s mod @"100) div @"10); print_lc_hex(new_s mod @"10); |
| 319 |
end |
| 320 |
else begin {Here is where we generate the strings on the fly.} |
| 321 |
print_char(@"5E); print_char(@"5E); |
| 322 |
print_char(@"5E); print_char(@"5E); |
| 323 |
print_lc_hex(new_s div @"1000); |
| 324 |
print_lc_hex((new_s mod @"1000) div @"100); |
| 325 |
print_lc_hex((new_s mod @"100) div @"10); |
| 326 |
print_lc_hex(new_s mod @"10); |
| 327 |
end; |
| 328 |
incr(j); |
| 329 |
end; |
| 330 |
end |
| 331 |
else begin |
| 332 |
if om_translation=0 then begin |
| 333 |
j:=str_start(s); |
| 334 |
otp_counter:=1; |
| 335 |
while j<str_start(s+1) do begin |
| 336 |
otp_output_buf[otp_counter]:=so(str_pool[j]); |
| 337 |
incr(otp_counter); |
| 338 |
incr(j); |
| 339 |
end; |
| 340 |
otp_output_end:=otp_counter; |
| 341 |
end |
| 342 |
else begin |
| 343 |
otp_input_start:=0; |
| 344 |
otp_input_last:=0; |
| 345 |
otp_stack_used:=0; |
| 346 |
otp_stack_last:=0; |
| 347 |
otp_stack_new:=0; |
| 348 |
otp_output_end:=0; |
| 349 |
otp_pc:=0; |
| 350 |
otp_finished:=false; |
| 351 |
otp_calc_ptr:=0; |
| 352 |
otp_calcs[otp_calc_ptr]:=0; |
| 353 |
otp_state_ptr:=0; |
| 354 |
otp_states[otp_state_ptr]:=0; |
| 355 |
otp_input_ocp:=om_translation; |
| 356 |
j:=str_start(s); |
| 357 |
otp_counter:=1; |
| 358 |
while j<str_start(s+1) do begin |
| 359 |
otp_input_buf[otp_counter]:=so(str_pool[j]); |
| 360 |
incr(otp_counter); |
| 361 |
incr(j); |
| 362 |
end; |
| 363 |
otp_input_end:=otp_counter; |
| 364 |
while not otp_finished do |
| 365 |
@<Run the OTP program@>; |
| 366 |
end; |
| 367 |
for otp_counter:=1 to (otp_output_end-1) do begin |
| 368 |
new_s:=otp_output_buf[otp_counter]; |
| 369 |
if (om_mode<twobyte_mode) and (new_s>255) then |
| 370 |
begin |
| 371 |
print_char(@"5E); print_char(@"5E); |
| 372 |
print_char(@"5E); print_char(@"5E); |
| 373 |
print_lc_hex(new_s div @"1000); |
| 374 |
print_lc_hex((new_s mod @"1000) div @"100); |
| 375 |
print_lc_hex((new_s mod @"100) div @"10); |
| 376 |
print_lc_hex(new_s mod @"10); |
| 377 |
end |
| 378 |
else |
| 379 |
print_char(new_s); |
| 380 |
end; |
| 381 |
end; |
| 382 |
end; |
| 383 |
|
| 384 |
@ Control sequence names, file names, and strings constructed with |
| 385 |
\.{\\string} might contain |ASCII_code| values that can't |
| 386 |
be printed using |print_char|. Therefore we use |slow_print| for them: |
| 387 |
|
| 388 |
@<Basic print...@>= |
| 389 |
procedure slow_print(@!s:integer); {prints string |s|} |
| 390 |
begin if (s>=str_ptr) or (s<=biggest_char) then print(s) |
| 391 |
else omega_print(s); |
| 392 |
end; |
| 393 |
@z |
| 394 |
%--------------------------------------- |
| 395 |
@x [5] - Omega Translation |
| 396 |
procedure print_nl(@!s:str_number); {prints string |s| at beginning of line} |
| 397 |
begin if ((term_offset>0)and(odd(selector)))or@| |
| 398 |
((file_offset>0)and(selector>=log_only)) then print_ln; |
| 399 |
print(s); |
| 400 |
end; |
| 401 |
@y |
| 402 |
@z |
| 403 |
%--------------------------------------- |
| 404 |
@x [5] m.71 l.1694 - Omega Translation |
| 405 |
if not input_ln(term_in,true) then fatal_error("End of file on the terminal!"); |
| 406 |
@y |
| 407 |
if not new_input_ln(term_in,term_in_mode,term_in_translation,true) |
| 408 |
then fatal_error("End of file on the terminal!"); |
| 409 |
@z |
| 410 |
%--------------------------------------- |
| 411 |
@x [15] m.209 l.4170 - Omega Translation |
| 412 |
@d max_command=ocp_trace_level |
| 413 |
{the largest command code seen at |big_switch|} |
| 414 |
@y |
| 415 |
@d char_trans=ocp_trace_level+1 |
| 416 |
@d char_mode=char_trans+1 |
| 417 |
@d max_command=char_mode |
| 418 |
{the largest command code seen at |big_switch|} |
| 419 |
@z |
| 420 |
%--------------------------------------- |
| 421 |
@x [17] m.230 l.4722 - Omega Translation |
| 422 |
@d toks_base=ocp_active_base+max_active_ocp_lists |
| 423 |
{table of |number_regs| token list registers} |
| 424 |
@y |
| 425 |
@d ocp_input_mode_base=ocp_active_base+max_active_ocp_lists |
| 426 |
@d ocp_input_onebyte_translation_base =ocp_input_mode_base+ 1 |
| 427 |
@d ocp_input_ebcdic_translation_base =ocp_input_mode_base+ 2 |
| 428 |
@d ocp_input_twobyte_translation_base =ocp_input_mode_base+ 3 |
| 429 |
@d ocp_input_twobyteLE_translation_base =ocp_input_mode_base+ 4 |
| 430 |
|
| 431 |
@d ocp_output_mode_base =ocp_input_mode_base+ 5 |
| 432 |
@d ocp_output_onebyte_translation_base =ocp_input_mode_base+ 6 |
| 433 |
@d ocp_output_ebcdic_translation_base =ocp_input_mode_base+ 7 |
| 434 |
@d ocp_output_twobyte_translation_base =ocp_input_mode_base+ 8 |
| 435 |
@d ocp_output_twobyteLE_translation_base =ocp_input_mode_base+ 9 |
| 436 |
|
| 437 |
@d toks_base =ocp_input_mode_base+10 |
| 438 |
@z |
| 439 |
%--------------------------------------- |
| 440 |
@x [22] m.304 l.6535 - Omega Translation |
| 441 |
@!input_file : array[1..max_in_open] of alpha_file; |
| 442 |
@y |
| 443 |
@!input_file : array[1..max_in_open] of alpha_file; |
| 444 |
@!input_file_mode : array[1..max_in_open] of halfword; |
| 445 |
@!input_file_translation : array[1..max_in_open] of halfword; |
| 446 |
@z |
| 447 |
%--------------------------------------- |
| 448 |
@x [23] m.331 l.7066 - Omega Translation |
| 449 |
param_ptr:=0; max_param_stack:=0; |
| 450 |
@y |
| 451 |
param_ptr:=0; max_param_stack:=0; |
| 452 |
geq_define(ocp_input_mode_base,data,1); |
| 453 |
term_in_mode:=equiv(ocp_input_mode_base); |
| 454 |
term_out_mode:=equiv(ocp_input_mode_base); |
| 455 |
if term_in_mode>0 |
| 456 |
then term_in_translation:= |
| 457 |
equiv(ocp_input_onebyte_translation_base+term_in_mode-1); |
| 458 |
if term_out_mode>0 |
| 459 |
then term_out_translation:= |
| 460 |
equiv(ocp_output_onebyte_translation_base+term_in_mode-1); |
| 461 |
@z |
| 462 |
%--------------------------------------- |
| 463 |
@x [24] m.362 l.7066 - Omega Translation |
| 464 |
begin if input_ln(cur_file,true) then {not end of file} |
| 465 |
@y |
| 466 |
begin if new_input_ln(cur_file,input_file_mode[index], |
| 467 |
input_file_translation[index],true) then {not end of file} |
| 468 |
@z |
| 469 |
%--------------------------------------- |
| 470 |
@x [27] m.480 l.9411 - Omega Translation |
| 471 |
@!read_file:array[0..15] of alpha_file; {used for \.{\\read}} |
| 472 |
@y |
| 473 |
@!read_file:array[0..15] of alpha_file; {used for \.{\\read}} |
| 474 |
@!read_file_mode:array[0..15] of halfword; |
| 475 |
@!read_file_translation:array[0..15] of halfword; |
| 476 |
@z |
| 477 |
%--------------------------------------- |
| 478 |
@x [27] m.485 l.9475 - Omega Translation |
| 479 |
@<Input the first line of |read_file[m]|@>= |
| 480 |
if input_ln(read_file[m],false) then read_open[m]:=normal |
| 481 |
else begin a_close(read_file[m]); read_open[m]:=closed; |
| 482 |
end |
| 483 |
@y |
| 484 |
@<Input the first line of |read_file[m]|@>= |
| 485 |
begin read_file_mode[m]:= |
| 486 |
get_file_mode(read_file[m], equiv(ocp_input_mode_base)); |
| 487 |
if read_file_mode[m]>0 |
| 488 |
then read_file_translation[m]:= |
| 489 |
equiv(ocp_input_onebyte_translation_base+read_file_mode[m]-1); |
| 490 |
if new_input_ln(read_file[m],read_file_mode[m], |
| 491 |
read_file_translation[m],false) then read_open[m]:=normal |
| 492 |
else begin a_close(read_file[m]); read_open[m]:=closed; |
| 493 |
end |
| 494 |
end |
| 495 |
@z |
| 496 |
%--------------------------------------- |
| 497 |
@x [27] m.486 l.9484 - Omega Translation |
| 498 |
begin if not input_ln(read_file[m],true) then |
| 499 |
begin a_close(read_file[m]); read_open[m]:=closed; |
| 500 |
@y |
| 501 |
begin if not new_input_ln(read_file[m], |
| 502 |
read_file_mode[m],read_file_translation[m],true) then |
| 503 |
begin a_close(read_file[m]); read_open[m]:=closed; |
| 504 |
@z |
| 505 |
%--------------------------------------- |
| 506 |
@x [29] m.538 l.10371 - Omega Translation |
| 507 |
begin line:=1; |
| 508 |
if input_ln(cur_file,false) then do_nothing; |
| 509 |
@y |
| 510 |
begin line:=1; |
| 511 |
input_file_mode[index]:= |
| 512 |
get_file_mode(cur_file, equiv(ocp_input_mode_base)); |
| 513 |
if input_file_mode[index]>0 |
| 514 |
then input_file_translation[index]:= |
| 515 |
equiv(ocp_input_onebyte_translation_base+input_file_mode[index]-1); |
| 516 |
if new_input_ln(cur_file,input_file_mode[index], |
| 517 |
input_file_translation[index],false) then do_nothing; |
| 518 |
@z |
| 519 |
%--------------------------------------- |
| 520 |
@x [49] m.1210 l.22629 - Omega Translation |
| 521 |
any_mode(ocp_trace_level) : prefixed_command; |
| 522 |
@y |
| 523 |
any_mode(ocp_trace_level) : prefixed_command; |
| 524 |
any_mode(char_mode) : do_char_mode; |
| 525 |
any_mode(char_trans) : do_char_translation; |
| 526 |
@z |
| 527 |
%--------------------------------------- |
| 528 |
@x [49] m.1343 l.24928 - Omega Translation |
| 529 |
@!write_file:array[0..15] of alpha_file; |
| 530 |
@y |
| 531 |
@!write_file:array[0..15] of alpha_file; |
| 532 |
@!write_file_mode:array[0..15] of halfword; |
| 533 |
@!write_file_translation:array[0..15] of halfword; |
| 534 |
@z |
| 535 |
%--------------------------------------- |
| 536 |
@x |
| 537 |
@* \[54] $\Omega$ changes. |
| 538 |
|
| 539 |
@y |
| 540 |
@* \[54] $\Omega$ changes. |
| 541 |
|
| 542 |
@ Here we do the main work required for reading and interpreting |
| 543 |
$\Omega$ Input Translation Processes. |
| 544 |
|
| 545 |
@ @<Put each...@>= |
| 546 |
primitive("InputTranslation", char_trans, trans_input); |
| 547 |
primitive("OutputTranslation", char_trans, trans_output); |
| 548 |
primitive("DefaultInputTranslation", char_trans, trans_default_input); |
| 549 |
primitive("DefaultOutputTranslation", char_trans, trans_default_output); |
| 550 |
primitive("noInputTranslation", char_trans, trans_no_input); |
| 551 |
primitive("noOutputTranslation", char_trans, trans_no_output); |
| 552 |
primitive("noDefaultInputTranslation", char_trans, trans_no_default_input); |
| 553 |
primitive("noDefaultOutputTranslation", char_trans, trans_no_default_output); |
| 554 |
primitive("InputMode", char_mode, mode_input); |
| 555 |
primitive("OutputMode", char_mode, mode_output); |
| 556 |
primitive("DefaultInputMode", char_mode, mode_default_input); |
| 557 |
primitive("DefaultOutputMode", char_mode, mode_default_output); |
| 558 |
primitive("noInputMode", char_mode, mode_no_input); |
| 559 |
primitive("noOutputMode", char_mode, mode_no_output); |
| 560 |
primitive("noDefaultInputMode", char_mode, mode_no_default_input); |
| 561 |
primitive("noDefaultOutputMode", char_mode, mode_no_default_output); |
| 562 |
|
| 563 |
geq_define(ocp_input_onebyte_translation_base, data, 0); |
| 564 |
geq_define(ocp_input_ebcdic_translation_base, data, 0); |
| 565 |
geq_define(ocp_input_twobyte_translation_base, data, 0); |
| 566 |
geq_define(ocp_input_twobyteLE_translation_base, data, 0); |
| 567 |
geq_define(ocp_input_mode_base, data, 0); |
| 568 |
|
| 569 |
geq_define(ocp_output_onebyte_translation_base, data, 0); |
| 570 |
geq_define(ocp_output_ebcdic_translation_base, data, 0); |
| 571 |
geq_define(ocp_output_twobyte_translation_base, data, 0); |
| 572 |
geq_define(ocp_output_twobyteLE_translation_base, data, 0); |
| 573 |
geq_define(ocp_output_mode_base, data, 0); |
| 574 |
|
| 575 |
@ @<Cases of |print_cmd_chr|...@>= |
| 576 |
char_trans: |
| 577 |
case chr_code of |
| 578 |
trans_input: print_esc("InputTranslation"); |
| 579 |
trans_output: print_esc("OutputTranslation"); |
| 580 |
trans_default_input: print_esc("DefaultInputTranslation"); |
| 581 |
trans_default_output: print_esc("DefaultOutputTranslation"); |
| 582 |
trans_no_input: print_esc("noInputTranslation"); |
| 583 |
trans_no_output: print_esc("noOutputTranslation"); |
| 584 |
trans_no_default_input: print_esc("noDefaultInputTranslation"); |
| 585 |
trans_no_default_output: print_esc("noDefaultOutputTranslation"); |
| 586 |
end; |
| 587 |
char_mode: |
| 588 |
case chr_code of |
| 589 |
mode_input: print_esc("InputMode"); |
| 590 |
mode_output: print_esc("OutputMode"); |
| 591 |
mode_default_input: print_esc("DefaultInputMode"); |
| 592 |
mode_default_output: print_esc("DefaultOutputMode"); |
| 593 |
mode_no_input: print_esc("noInputMode"); |
| 594 |
mode_no_output: print_esc("noOutputMode"); |
| 595 |
mode_no_default_input: print_esc("noDefaultInputMode"); |
| 596 |
mode_no_default_output: print_esc("noDefaultOutputMode"); |
| 597 |
end; |
| 598 |
|
| 599 |
@ @<Declare subprocedures for |prefixed_command|@>= |
| 600 |
procedure scan_file_referrent; |
| 601 |
begin |
| 602 |
if scan_keyword("currentfile") then cur_val:=max_halfword |
| 603 |
else scan_int; |
| 604 |
end; |
| 605 |
|
| 606 |
procedure scan_mode; |
| 607 |
begin |
| 608 |
if scan_keyword("onebyte") then cur_val:=onebyte_mode |
| 609 |
else if scan_keyword("ebcdic") then cur_val:=ebcdic_mode |
| 610 |
else if scan_keyword("twobyte") then cur_val:=twobyte_mode |
| 611 |
else if scan_keyword("twobyteLE") then cur_val:=twobyteLE_mode |
| 612 |
else begin print_err("Invalid input mode"); cur_val:=0; end; |
| 613 |
end; |
| 614 |
|
| 615 |
procedure do_char_translation; |
| 616 |
var kind:halfword; |
| 617 |
fileref:halfword; |
| 618 |
moderef:halfword; |
| 619 |
ocpref:halfword; |
| 620 |
begin |
| 621 |
fileref:=0; |
| 622 |
moderef:=0; |
| 623 |
ocpref:=0; |
| 624 |
kind:=cur_chr; |
| 625 |
if (kind mod 4) <= 1 then begin |
| 626 |
scan_file_referrent; |
| 627 |
fileref:=cur_val; |
| 628 |
end |
| 629 |
else begin |
| 630 |
scan_mode; |
| 631 |
moderef:=cur_val; |
| 632 |
end; |
| 633 |
if kind < 4 then begin |
| 634 |
scan_ocp_ident; |
| 635 |
ocpref:=cur_val; |
| 636 |
end; |
| 637 |
case (kind mod 4) of |
| 638 |
trans_input: begin |
| 639 |
if (fileref>=0) and (fileref<=15) then begin |
| 640 |
read_file_translation[fileref]:=ocpref; |
| 641 |
end |
| 642 |
else if fileref<>max_halfword then begin |
| 643 |
term_in_translation:=ocpref; |
| 644 |
end |
| 645 |
else begin |
| 646 |
base_ptr:=input_ptr; input_stack[base_ptr]:=cur_input; |
| 647 |
while state = token_list do |
| 648 |
begin |
| 649 |
decr(base_ptr); |
| 650 |
cur_input:=input_stack[base_ptr]; |
| 651 |
end; |
| 652 |
if name>17 then input_file_translation[index]:=ocpref; |
| 653 |
cur_input:=input_stack[input_ptr]; |
| 654 |
end; |
| 655 |
end; |
| 656 |
trans_output: begin |
| 657 |
if (fileref>=0) and (fileref<=15) then begin |
| 658 |
write_file_translation[fileref]:=ocpref; |
| 659 |
end |
| 660 |
else begin |
| 661 |
term_out_translation:=ocpref; |
| 662 |
end; |
| 663 |
end; |
| 664 |
trans_default_input: begin |
| 665 |
geq_define(ocp_input_mode_base+moderef,data,ocpref); |
| 666 |
end; |
| 667 |
trans_default_output: begin |
| 668 |
geq_define(ocp_output_mode_base+moderef,data,ocpref); |
| 669 |
end; |
| 670 |
end; |
| 671 |
end; |
| 672 |
|
| 673 |
procedure do_char_mode; |
| 674 |
var kind:halfword; |
| 675 |
fileref:halfword; |
| 676 |
moderef:halfword; |
| 677 |
begin |
| 678 |
fileref:=0; |
| 679 |
moderef:=0; |
| 680 |
kind:=cur_chr; |
| 681 |
if (kind mod 4) <= 1 then begin |
| 682 |
scan_file_referrent; |
| 683 |
fileref:=cur_val; |
| 684 |
end; |
| 685 |
if kind < 4 then begin |
| 686 |
scan_mode; |
| 687 |
moderef:=cur_val; |
| 688 |
end; |
| 689 |
case (kind mod 4) of |
| 690 |
trans_input: begin |
| 691 |
if (fileref>=0) and (fileref<=15) then begin |
| 692 |
read_file_mode[fileref]:=moderef; |
| 693 |
end |
| 694 |
else if fileref<>max_halfword then begin |
| 695 |
term_in_mode:=moderef; |
| 696 |
end |
| 697 |
else begin |
| 698 |
base_ptr:=input_ptr; input_stack[base_ptr]:=cur_input; |
| 699 |
while state = token_list do |
| 700 |
begin |
| 701 |
decr(base_ptr); |
| 702 |
cur_input:=input_stack[base_ptr]; |
| 703 |
end; |
| 704 |
if name>17 then input_file_mode[index]:=moderef; |
| 705 |
cur_input:=input_stack[input_ptr]; |
| 706 |
end; |
| 707 |
end; |
| 708 |
trans_output: begin |
| 709 |
if (fileref>=0) and (fileref<=15) then begin |
| 710 |
write_file_mode[fileref]:=moderef; |
| 711 |
end |
| 712 |
else begin |
| 713 |
term_out_mode:=moderef; |
| 714 |
end; |
| 715 |
end; |
| 716 |
trans_default_input: begin |
| 717 |
geq_define(ocp_input_mode_base,data,moderef); |
| 718 |
end; |
| 719 |
trans_default_output: begin |
| 720 |
geq_define(ocp_output_mode_base,data,moderef); |
| 721 |
end; |
| 722 |
end; |
| 723 |
end; |
| 724 |
|
| 725 |
function p_new_input_ln(f:alpha_file; |
| 726 |
the_mode,translation:halfword; |
| 727 |
bypass_eoln:boolean):boolean; |
| 728 |
begin |
| 729 |
if (the_mode=no_mode) or ((the_mode=onebyte_mode) and (translation=0)) |
| 730 |
then p_new_input_ln:=input_ln(f,bypass_eoln) |
| 731 |
else if not newinputline(f,the_mode,bypass_eoln) |
| 732 |
then p_new_input_ln:=false |
| 733 |
else if translation=0 then |
| 734 |
begin |
| 735 |
if (first+otp_input_end)>=buf_size then overflow("buffer size", buf_size); |
| 736 |
state:=new_line; |
| 737 |
start:=first; |
| 738 |
last:=start; |
| 739 |
loc:=start; |
| 740 |
for otp_counter:=1 to otp_input_end do |
| 741 |
begin |
| 742 |
buffer[last]:=otp_input_buf[otp_counter]; |
| 743 |
incr(last); |
| 744 |
end; |
| 745 |
while buffer[last-1]=' ' do decr(last); |
| 746 |
limit:=last-1; |
| 747 |
p_new_input_ln:=true |
| 748 |
end |
| 749 |
else |
| 750 |
begin |
| 751 |
otp_input_start:=0; |
| 752 |
otp_input_last:=0; |
| 753 |
otp_stack_used:=0; |
| 754 |
otp_stack_last:=0; |
| 755 |
otp_stack_new:=0; |
| 756 |
otp_output_end:=0; |
| 757 |
otp_pc:=0; |
| 758 |
otp_finished:=false; |
| 759 |
otp_calc_ptr:=0; |
| 760 |
otp_calcs[otp_calc_ptr]:=0; |
| 761 |
otp_state_ptr:=0; |
| 762 |
otp_states[otp_state_ptr]:=0; |
| 763 |
otp_input_ocp:=translation; |
| 764 |
while not otp_finished do |
| 765 |
@<Run the OTP program@>; |
| 766 |
if (first+otp_output_end)>=buf_size then overflow("buffer size", buf_size); |
| 767 |
state:=new_line; |
| 768 |
start:=first; |
| 769 |
last:=start; |
| 770 |
loc:=start; |
| 771 |
for otp_counter:=1 to otp_output_end do |
| 772 |
begin |
| 773 |
buffer[last]:=otp_output_buf[otp_counter]; |
| 774 |
incr(last); |
| 775 |
end; |
| 776 |
while buffer[last-1]=' ' do decr(last); |
| 777 |
limit:=last-1; |
| 778 |
p_new_input_ln:=true |
| 779 |
end |
| 780 |
end; |
| 781 |
|
| 782 |
|
| 783 |
@z |
| 784 |
%--------------------------------------- |