%  TOPS-20 Change file for GFread 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{GFread changes for \ttw}
@z

@x
@d banner=='This is GFread, Version 1.1' {printed when the program starts}
@y
@d banner=='This is GFread, TOPS-20 Version 1.1' {printed at startup}
@z

@x
@d debug==@{
@d gubed==@t@>@}@/
@y
@d debug==@{
@d gubed==@t@>@}
@z

@x
@d eebug==@{
@d gubee==@t@>@}@/
@y
@d eebug==@{
@d gubee==@t@>@}
@z

@x
@d print(#)==write(#)
@d print_ln(#)==write_ln(#)
@d print_nl==write_ln
@y
@d print(#)==write(tty,#)
@d print_ln(#)==write_ln(tty,#)
@d print_nl==write_ln(tty)
@z

@x
@p program GFread(@!gf_file,@!pxl_file,@!output);
@y
@p program GFread;
@z

@x
@<Constants...@>=
@!line_length=79; {bracketed lines of output will be at most this long}
@!terminal_line_length=150; {maximum number of characters input in a single
  line of input from the terminal}
@!mem_max=4000; {largest index in the main |mem| array}
@y
@<Constants...@>=
@!line_length=79; {bracketed lines of output will be at most this long}
@!terminal_line_length=150; {maximum number of characters input in a single
  line of input from the terminal}
@!mem_max=4000; {largest index in the main |mem| array}
@!name_length=80; {longest name}
@!max_rescan=200; {longest command line}
@z

@x
begin reset(gf_file);
@y
begin reset(gf_file,gf_name,'/O/B:8');
if eof(gf_file) then abort('GF file does not exist!');
@z

@x
begin rewrite(pxl_file);
@y
begin rewrite(pxl_file,pxl_name,'/O/B:8');
@z

@x
@!pxl_loc:integer; {where we are about to write, in |pxl_file|}
@y
@!pxl_loc:integer; {where we are about to write, in |pxl_file|}
@!gf_name,@!pxl_name: packed array[1..name_length] of char ;
@z

@x
  initialize ;
@y
  initialize ;
  startup := true ;
  @<Get command line and check for file name@> ;
  if not startup then begin
    print('GF File Name:   ') ;
    read(tty, gf_name) ;
    read_ln(tty) ;
    print('PXL File Name:  ') ;
    read(tty, pxl_name) ;
    read_ln(tty) ;
  end ;
@z

@x
@* System-dependent changes.
This section should be replaced, if necessary, by changes to the program
that are necessary to make \.{GFread} 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 \.{GFread} 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 command line and check for file name@>=
jsys(RSCAN,1,i;0;j); {get the command line}
if (i<>2) or (j<=0) then startup := false
else begin
  if eoln(tty) then read_ln(tty); {for some TOPS-20's}
  read(tty,rescan_buffer:rescan_len); {read in rescan buffer}
  if rescan_len>max_rescan then abort('command line too long!');
  read_ln(tty);
  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
      for j := 1 to name_length do begin
        gf_name[j] := ' ' ; pxl_name[j] := ' ' ;
      end ;
      j := 1 ;
      last_ext := -1 ;
      while ( i <= rescan_len ) and ( rescan_buffer[i] <> ' ' ) do begin
        gf_name[j] := rescan_buffer[i] ;
        pxl_name[j] := rescan_buffer[i] ;
        if (rescan_buffer[i] = '.') and (last_ext = -1) then last_ext := j ;
        if rescan_buffer[i] in [':',']','>'] then last_ext := -1 ;
        incr(j) ; incr(i) ;
      end ;
      if last_ext = -1 then begin
        last_ext := j ;
        gf_name[j] := '.' ; gf_name[j+1] := 'g' ; gf_name[j+2] := 'f' ;
      end ;
      pxl_name[last_ext] := '.' ; pxl_name[last_ext+1] := 'p' ;
      pxl_name[last_ext+2] := 'x' ; pxl_name[last_ext+3] := 'l' ;
      for i := last_ext+4 to name_length do pxl_name[i] := ' ' ;
    end ;
  end ;
end

@ @<Glob...@>=
@!rescan_buffer:packed array[1..max_rescan] of char;
@!rescan_len:integer;
@!i, @!j : integer ; {general purpose indices}
@!startup : boolean ; {did we have a file name?}
@!last_ext : integer ; {where was the dot?}
@z