%  GFtoDVI change file for TOPS-20 by Tomas Rokicki.  Send bug reports
%  to ROKICKI@SU-SCORE.

@x [1] Tell WEAVE to print only the changes:
\pageno=\contentspagenumber \advance\pageno by 1
@y
\pageno=\contentspagenumber \advance\pageno by 1
\let\maybe=\iffalse
\def\ttw{{\mc TOPS-20}}
\def\title{GFtoDVI changes for \ttw}
@z

@x
@d banner=='This is GFtoDVI, Version 1.7' {printed when the program starts}
@y
@d banner=='This is GFtoDVI, TOPS-20 Version 1.7'
     {printed when the program starts}
@z

@x [2]
@d print(#)==write(#)
@d print_ln(#)==write_ln(#)
@d print_nl(#)==begin write_ln; write(#);
  end
@y
@d print(#)==write(TTY,#)
@d print_ln(#)==write_ln(TTY,#)
@d print_nl(#)==begin write_ln(TTY); write(TTY,#);
  end
@z

@x [2] remove output specification
@p program GF_to_DVI(@!output);
@y
@p program GF_to_DVI;
@z

@x
@<Constants...@>=
@!max_labels=2000; {maximum number of labels and dots per character}
@!pool_size=10000; {maximum total length of labels and other strings}
@!max_strings=1100; {maximum number of labels and other strings}
@!terminal_line_length=150; {maximum number of characters input in a single
  line of input from the terminal}
@!file_name_size=50; {a file name shouldn't be longer than this}
@!font_mem_size=1000; {space for font metric data}
@!dvi_buf_size=800; {size of the output buffer; must be a multiple of 8}
@!widest_row=8192; {maximum number of pixels per row}
@y
@<Constants...@>=
@!max_labels=2000; {maximum number of labels and dots per character}
@!pool_size=10000; {maximum total length of labels and other strings}
@!max_strings=1100; {maximum number of labels and other strings}
@!terminal_line_length=150; {maximum number of characters input in a single
  line of input from the terminal}
@!file_name_size=50; {a file name shouldn't be longer than this}
@!font_mem_size=1000; {space for font metric data}
@!dvi_buf_size=800; {size of the output buffer; must be a multiple of 8}
@!widest_row=8192; {maximum number of pixels per row}
@!max_rescan=200; {longest command line}
@z

@x [7]
@d update_terminal == break(output) {empty the terminal output buffer}
@y
@d update_terminal == {the terminal output buffer is always emptied}
@z

@x [7]
@<Glob...@>=
@!buffer:array[0..terminal_line_length] of 0..255;
@!term_in:text_file; {the terminal, considered as an input file}
@y
@d term_in==TTY {the terminal, considered as an input file}

@<Glob...@>=
@!buffer:array[0..terminal_line_length] of 0..255;
@z

@x
begin update_terminal; reset(term_in);
@y
begin update_terminal;
@z

@x [42] fix open procedures
@p procedure open_gf_file; {prepares to read packed bytes in |gf_file|}
begin reset(gf_file,name_of_file);
cur_loc:=0;
end;
@#
procedure open_tfm_file; {prepares to read packed bytes in |tfm_file|}
begin reset(tfm_file,name_of_file);
end;
@#
procedure open_dvi_file; {prepares to write packed bytes in |dvi_file|}
begin rewrite(dvi_file,name_of_file);
end;
@y
@p procedure open_gf_file; {prepares to read packed bytes in |gf_file|}
begin reset(gf_file,name_of_file,'/O/B:8');
cur_loc:=0;
end;
@#
procedure open_tfm_file; {prepares to read packed bytes in |tfm_file|}
begin reset(tfm_file,name_of_file,'/O/B:8');
end;
@#
procedure open_dvi_file; {prepares to write packed bytes in |dvi_file|}
begin rewrite(dvi_file,name_of_file,'/O/B:8');
end;
@z

@x [44] fix min_quarterword addition and subtraction
@d qi(#)==#+min_quarterword
  {to put an |eight_bits| item into a quarterword}
@d qo(#)==#-min_quarterword
  {to take an |eight_bits| item out of a quarterword}
@y
@d qi(#)==#  {to put an |eight_bits| item into a quarterword}
@d qo(#)==#  {to take an |eight_bits| item out of a quarterword}
@z

@x
bad_tfm: print_nl('Bad TFM file for');
@y
bad_tfm: print_nl('Tried to open ',name_of_file);
print_nl('Bad TFM file for');
@z

@x [60] we allow the command line to be fetched
@p procedure start_gf;
label found,done;
begin loop@+begin print_nl('GF file name: '); input_ln;
@.GF file name@>
@y
@p procedure start_gf;
label found,done;
var i,j:integer;
    startup:boolean;
begin startup:=true;
@<Get rescan line@>;
loop@+begin if not startup then begin
  print_nl('GF file name: '); input_ln;
end ;
startup := false ;
@.GF file name@>
@z

@x
@* System-dependent changes.
This section should be replaced, if necessary, by changes to the program
that are necessary to make \.{GFtoDVI} work at a particular installation.
It is usually best to design your change file so that all changes to
previous sections preserve the section numbering; then everybody's version
will be consistent with the printed program. More extensive changes,
which introduce new sections, can be inserted here; then only the index
itself will get a new section number.
@^system dependencies@>
@y
@* System-dependent changes.
This section should be replaced, if necessary, by changes to the program
that are necessary to make \.{GFtoDVI} work at a particular installation.
It is usually best to design your change file so that all changes to
previous sections preserve the section numbering; then everybody's version
will be consistent with the printed program. More extensive changes,
which introduce new sections, can be inserted here; then only the index
itself will get a new section number.
@^system dependencies@>

We call a system procedure to put the command line into the input buffer.
We then read it in, skipping over the program name to the first blank.

@d RSCAN=@'500 {ReSCAN buffer JSYS}

@<Get rescan line@>=
jsys(RSCAN,1,i;0;j); {get the command line}
if (i<>2) or (j<=0) then startup := false
else begin
  if eoln(term_in) then read_ln(term_in); {for some TOPS-20's}
  read(term_in,rescan_buffer:rescan_len); {read in rescan buffer}
  if rescan_len>max_rescan then abort('command line too long!');
  read_ln(term_in);
  if rescan_len=j-2 then startup := false
  else begin
    i:=1; while rescan_buffer[i]>' 'do incr(i); {skip invocation}
    while(i<=rescan_len) and (rescan_buffer[i]=' ')do incr(i); {skip spaces}
    if i>rescan_len then startup := false
    else begin
      buf_ptr := 0 ;
      while ( i <= rescan_len ) and ( buf_ptr < terminal_line_length ) do begin
        buffer[buf_ptr] := xord[rescan_buffer[i]] ;
        incr(buf_ptr) ; incr(i) ;
      end ;
      line_length := buf_ptr ;
      buf_ptr := 0 ;
    end ;
  end ;
end

@ @<Glob...@>=
@!rescan_buffer:packed array[1..max_rescan] of char;
@!rescan_len:integer;

@z