PLtoTF change file for Vax/VMS
Copyright (C) 1983 by David Fuchs.  All rights are reserved.

@x
\pageno=\contentspagenumber \advance\pageno by 1
@y
\pageno=\contentspagenumber \advance\pageno by 1
\let\maybe=\iffalse
\def\title{PL\lowercase{to}TF changes for Vax/VMS}
@z

@x
@d banner=='This is PLtoTF, Version 2.3' {printed when the program starts}
@y
@d banner=='This is PLtoTF, Vax/VMS version 2.3'
@z

@x
@d print(#)==write(#)
@d print_ln(#)==write_ln(#)
@y
@d print(#)==write_ln(term_out,#)
@d print_ln(#)==write_ln(term_out,#,chr(13),chr(10))
@z

@x
@p program PLtoTF(@!pl_file,@!tfm_file,@!output);
@y
@p program PLtoTF(@!pl_file,@!tfm_file,@!output,@!input,@!term_out);
label 223; {for abort}
@z

@x
procedure initialize; {this procedure gets things started properly}
  var @<Local variables for initialization@>@/
  begin print_ln(banner);@/
@y
@<Procedures for initialization@>@/
procedure initialize; {this procedure gets things started properly}
  var @<Local variables for initialization@>@/
  begin
  @<Preset initial values@>@/
  print_ln(banner);@/
@z

@x
@!tfm_file:packed file of 0..255;
@y
@!tfm_file:packed file of block;
@!tfm_count:0..VAX_block_length; {where the next byte goes}
@z

@x
@d out(#)==write(tfm_file,#)
@y
@d out(#)==begin
	if tfm_count=VAX_block_length then begin
		put(tfm_file); tfm_count:=0; end;
	tfm_file^[tfm_count]:=#;
	incr(tfm_count);
	end
@d flush_tfm==begin
	while tfm_count<VAX_block_length do begin
		tfm_file^[tfm_count]:=0; incr(tfm_count); end;
	put(tfm_file);
	end
@<Set init...@>==
tfm_count:=0;
@z

@x
end.
@y
flush_tfm;
close(tfm_file,@=disposition:=save@>);
223:
end.
@z

@x
This section should be replaced, if necessary, by changes to the program
that are necessary to make \.{PLtoTF} 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.
@y
Here are the remaining changes to the program
that are necessary to make \.{PLtoTF} work on Vax/VMS.

@ Here's the extra stuff we need for buffering the |tfm_file|.
@<Const...@>==
@!VAX_block_length=512;

@ @<Types...@>==
@!block=packed array [0..VAX_block_length-1] of 0..255;

@ On Vax/VMS we need the following special definitions, types, variables
and procedures to be able to get the file name from the command line,
or to prompt for them.

@d VAX_volatile==@=volatile@>
@d VAX_immed==@=%immed @>
@d VAX_external==@=external@>
@d VAX_stdescr==@=%stdescr @>
@d VAX_lib_get_foreign==@= lib$get_foreign@>
@d VAX_length==@=length @>

@ @<Types...@>=
@!sixteen_bits= 0..65535;

@ @<Glob...@>==
@!term_out: text; {for progress report to user's terminal}
@!command_line:packed array[1..300] of char;
@!cmd_len:sixteen_bits;
@!cmd_i:integer;
@!file_name,@!default_file_name:varying [300] of char;
@!ask,@!got_file_name: boolean;

@ @<Preset init...@>=
open(term_out,'SYS$OUTPUT',@=carriage_control:=none@>);
rewrite(term_out);
cmd_i:=0;
VAX_lib_get_foreign(command_line,,cmd_len,cmd_i);
cmd_i:=1; while (cmd_i<=cmd_len) and (command_line[cmd_i]=' ') do incr(cmd_i);
got_file_name:=cmd_i<=cmd_len;
if got_file_name then
	default_file_name:=substr(command_line,cmd_i,cmd_len-cmd_i+1);

if got_file_name then begin
	file_name:=default_file_name+'.PL';
	open(pl_file,file_name,@=readonly,error:=continue@>);
	ask:=status(pl_file)<>0;
	if ask then write_ln('Couldn''t open ',file_name);
	end
else ask:=true;
while ask do begin
	got_file_name:=false;
	write('PL file: ');
	if eof then goto 223;
	read_ln(file_name);
	open(pl_file,file_name,@=readonly,error:=continue@>);
	ask:=status(pl_file)<>0;
	if ask then write_ln('Couldn''t open ',file_name);
	end;

if got_file_name then begin
	cmd_i:=1;
	for cmd_len:=1 to default_file_name.VAX_length do
		if (default_file_name[cmd_len]=']')
		or (default_file_name[cmd_len]=':')
		then cmd_i:=cmd_len+1;
	if cmd_i<=default_file_name.VAX_length then
		default_file_name:=substr(default_file_name,cmd_i,
			default_file_name.VAX_length-cmd_i+1);
	file_name:=default_file_name+'.TFM';
	open(tfm_file,file_name,@=new,disposition:=delete@>,
		@=error:=continue@>);
	ask:=status(tfm_file)>0;
	if ask then write_ln('Couldn''t open ',file_name);
	end
else ask:=true;
while ask do begin
	write('TFM file: ');
	if eof then goto 223;
	read_ln(file_name);
	open(tfm_file,file_name,@=new,disposition:=delete@>,
		@=error:=continue@>);
	ask:=status(tfm_file)>0;
	if ask then write_ln('Couldn''t open ',file_name);
	end;

@ Here is the library procedure that gets the user's command line.

@<Procedures for ...@>=
[VAX_external] function VAX_lib_get_foreign(
  VAX_stdescr cmdlin:[VAX_volatile] packed array [$l1..$u1:integer] of char
	:= VAX_immed 0;
  VAX_stdescr prompt:[VAX_volatile] packed array [$l2..$u2:integer] of char
	:= VAX_immed 0;
  var len : [VAX_volatile] sixteen_bits := VAX_immed 0;
  var flag : [VAX_volatile] integer := VAX_immed 0)
    :integer; extern;

@z