% This is GFTYPE.CHGCMS in text format, as of jul 28, 1985
%  (change file for IBM CMS PASCAL/VS)
%  (written by B. Schulze based on a file from Klaus Thull)
%  (banner line changed to match 2.2; then Tangles and compiles)
%  (but may not work beyond that.  --Alan Spragens 18 June 1986)
%
%line numbers correspond to version 2.1 (of apr 13, 85)
%
%line 65
%
@x
@d banner=='This is GFtype, Version 2.2' {printed when the program starts}
@y
@d banner=='This is GFtype, CMS Version 2.2 (SFB72)'
            {printed when the program starts}
@z
%
%module
%
%line 74
@x
@d othercases == others: {default for cases not listed explicitly}
@y
@d othercases == otherwise {default for cases not listed explicitly}
@f othercases == else
@d term_in == tty_in
@d term_out == tty_out
@z
%
%module
%
%line 84
@x
@d print(#)==write(#)
@d print_ln(#)==write_ln(#)
@d print_nl==write_ln
@y
@d print(#)==write(#)
@d print_ln(#)==write_ln(#)
@d print_nl==write_ln(' ')
@z
%
%module
%
%line 117
@x
@!line_length=79; {\\{xxx} strings will not produce lines longer than this}
@y
@!line_length=79; {\\{xxx} strings will not produce lines longer than this}
@!len_byte_block=1024; {blocksize of gf file}
@z
%
%module
%
%line 181
@x
@d last_text_char=127 {ordinal number of the largest element of |text_char|}
@y
@d last_text_char=255 {ordinal number of the largest element of |text_char|}
@z
%
%module
%
%line 184
@x
@!text_file=packed file of text_char;
@y
@!text_file=text;
@z
%
%module
%
%line 634
@x
@!eight_bits=0..255; {unsigned one-byte quantity}
@!byte_file=packed file of eight_bits; {files that contain binary data}
@y
@!eight_bits= packed 0..255; {unsigned one-byte quantity}
@!byte_block = packed array [0..len_byte_block-1] of eight_bits;
@!byte_file = packed file of byte_block;
@z
%
%module
%
%line 663
@x
@p function get_byte:integer; {returns the next byte, unsigned}
var b:eight_bits;
begin if eof(gf_file) then get_byte:=0
else  begin read(gf_file,b); incr(cur_loc); get_byte:=b;
  end;
end;
@#
function get_two_bytes:integer; {returns the next two bytes, unsigned}
var a,@!b:eight_bits;
begin read(gf_file,a); read(gf_file,b);
cur_loc:=cur_loc+2;
get_two_bytes:=a*256+b;
end;
@#
function get_three_bytes:integer; {returns the next three bytes, unsigned}
var a,@!b,@!c:eight_bits;
begin read(gf_file,a); read(gf_file,b); read(gf_file,c);
cur_loc:=cur_loc+3;
get_three_bytes:=(a*256+b)*256+c;
end;
@#
function signed_quad:integer; {returns the next four bytes, signed}
var a,@!b,@!c,@!d:eight_bits;
begin read(gf_file,a); read(gf_file,b); read(gf_file,c); read(gf_file,d);
cur_loc:=cur_loc+4;
if a<128 then signed_quad:=((a*256+b)*256+c)*256+d
else signed_quad:=(((a-256)*256+b)*256+c)*256+d;
end;
@y
@d eof_gf==((cur_loc mod len_byte_block = 0)
and (eof(gf_file)))
@d get_gf(#)==begin
  if eof_gf then prem_end else
  # := gf_file@@(.cur_loc mod len_byte_block.);
  incr(cur_loc);
  if cur_loc mod len_byte_block = 0
  then get(gf_file)
  end

@p
procedure prem_end; begin bad_gf
('didn''t we read past endfile just now?') end;
@#
function get_byte:integer; {returns the next byte, unsigned}
var b:eight_bits;
begin
get_gf(b); get_byte:=b;
end;
@#
function get_two_bytes:integer; {returns the next two bytes, unsigned}
var a,@!b:eight_bits;
begin get_gf(a); get_gf(b);
get_two_bytes:=a*256+b;
end;
@#
function get_three_bytes:integer; {returns the next three bytes, unsigned}
var a,@!b,@!c:eight_bits;
begin get_gf(a); get_gf(b); get_gf(c);
get_three_bytes:=(a*256+b)*256+c;
end;
@#
function signed_quad:integer; {returns the next four bytes, signed}
var a,@!b,@!c,@!d:eight_bits;
begin get_gf(a); get_gf(b); get_gf(c); get_gf(d);
if a<128 then signed_quad:=((a*256+b)*256+c)*256+d
else signed_quad:=(((a-256)*256+b)*256+c)*256+d;
end;
@z
%
%module
%
%line 734
@x
@d update_terminal == break(term_out) {empty the terminal output buffer}
@y
@d update_terminal == write_ln(term_out)
@z
%
%module
%
%line 745
@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
@p procedure input_ln; {inputs a line from the terminal}
var k:0..terminal_line_length; c: text_char;
begin update_terminal;
if eoln(term_in) then get(term_in);
k:=0;
while (k<terminal_line_length)and not eoln(term_in) do
  begin
  buffer(.k.):=xord(.term_in@@.);
  get (term_in);
   incr(k);
  end;
buffer[k]:=" ";
end;
@z
%
%module
%
%line 770
@x
begin rewrite(term_out); {prepare the terminal for output}
@y
begin @= termout@>(term_out); {prepare the terminal for output}
@= termin@>(term_in); {prepare the terminal for input}
@z
%
%module
%
%line 1027
@x
  if eof(gf_file) then bad_gf('the file ended prematurely')
@y
  if eof_gf then bad_gf('the file ended prematurely');
@z
%
%module
%
%line 1216
@x
while (m=223)and not eof(gf_file) do m:=get_byte;
if not eof(gf_file) then bad_gf('signature in byte ',cur_loc-1:1,
@y
while (m=223)and not eof_gf do m:=get_byte;
if not eof_gf then bad_gf('signature in byte ',cur_loc-1:1,
@z