$Id$
Second-level change file for Metapost compilation on RISC OS
Linenumbers refer the the result of merging mp.web and mp.ch from Web2c 7.2

The changes are:
   Filename parsing: begin_name, more_name.
   Filetypes: All ?_open_out calls have a filetype added.
   direct-io: The input file stack, rd_file, wr_file are dio handles
   Throwback: print_visible_char, print_err and error

dio for wr_file
@x 1570
othercases write_ln(wr_file[selector])
@y
othercases dio_write_ln(wr_file[selector])
@z

dio and throwback
@x 1618
othercases write(wr_file[selector],xchr[s])
endcases;
@y
othercases dio_write(wr_file[selector],xchr[s])
endcases;
throwback_char(xchr[s]);
@z

print_err: enable throwback
@x 1798
  print_nl("! "); print(#);
@y
  print_nl("! "); throwback_start; print(#);
@z

error: disable throwback and send the message.
@x 1943
print_char("."); show_context;
@y
throwback_stop; print_char("."); show_context;
{ |throwback_xsend| is called like |call_edit| }
if throwback_flag and (file_ptr>0) then
  throwback_xsend(str_pool, str_start[input_stack[file_ptr].name_field],
	length(input_stack[file_ptr].name_field), line);
@z

We provide a "T" option on error stops
@x 1983
"E": if file_ptr>0 then
@y
"T": if (not throwback_flag) and (file_ptr>0) then begin
       throwback_flag:=true; { enable throwback }
       throwback_xsend(str_pool, str_start[edit_file.name_field],
		length(edit_file.name_field), line);
       { and send the current message }
       interaction:=nonstop_mode;
       return;
     end;
"E": if file_ptr>0 then
@z

@x 2004
if file_ptr>0 then print("E to edit your file,");
@y
if file_ptr>0 then begin
  print("E to edit your file,");
  if not throwback_flag then
    print_nl("T to start throwback and run without stopping,");
end;
@z

direct-io on the input files
@x 11401
@!input_file : array[1..max_in_open] of alpha_file;
@y
@!input_file : array[1..max_in_open] of dio_handle;
@z

@x 11839
  else begin a_close(input_file[in_open]); {close an \.{MPX} file}
@y
  else begin dio_close(input_file[in_open]); {close an \.{MPX} file}
@z

@x 11846
  begin a_close(cur_file);
@y
  begin dio_close(cur_file);
@z

@x 12334
  begin if input_ln(cur_file,true) then {not end of file}
@y
  begin if dio_input_ln(cur_file,true) then {not end of file}
@z

--- Filename parsing ---
We accept '.' or ':' as directory separator and '.' or '/' as extension
separator. This will fail for Unix-style names, but that is not
important since the filename is rescanned after path searching which
will translate it to RISC OS style.

These changes are virtually identical in TeX, Metafont and Metapost.

The last "." is not always the area_delimiter, so we need area_delimiter2
@x 13929
@!area_delimiter:integer; {most recent `\./' relative to |str_start[str_ptr]|}
@!ext_delimiter:integer; {the relevant `\..', if any}
@y
@!area_delimiter:integer; {the most recent `\..' before the extension, if any}
@!ext_delimiter:integer; {the most recent `\..' or `\./', if any}
@!area_delimiter2:integer; {the last `\..', if any}
@z

|begin_name|: Initialise |area_delimiter2| also.
@x 13948
area_delimiter:=-1; ext_delimiter:=-1;
@y
area_delimiter:=-1; ext_delimiter:=-1; area_delimiter2:=-1;
@z

|more_name|: |DIR_SEP| can be the extension delimiter.
@x 13957
else  begin if IS_DIR_SEP (c) then
    begin area_delimiter:=pool_ptr-str_start[str_ptr]; ext_delimiter:=-1;
    end
  else if (c=".") then
    ext_delimiter:=pool_ptr-str_start[str_ptr];
@y
else  begin if IS_DIR_SEP(c) then
    { |DIR_SEP| can start the extension or the area. }
    begin ext_delimiter:=pool_ptr-str_start[str_ptr];
      area_delimiter:=area_delimiter2;
      area_delimiter2:=ext_delimiter;
    end
  else if c="/" then
    { |"/"| can start the extension only }
    begin ext_delimiter:=pool_ptr-str_start[str_ptr];
      area_delimiter:=area_delimiter2;
    end
  else if c=":" then
    { |":"| means area delimiter }
    begin area_delimiter:=pool_ptr-str_start[str_ptr];
      area_delimiter2:=pool_ptr-str_start[str_ptr];
      ext_delimiter:=-1;
    end;
@z

Logfiles are type Text
@x 14264
while not a_open_out(log_file) do @<Try to get a different log file name@>;
@y
while not a_open_out(log_file, riscos_TEXT_type) do
  @<Try to get a different log file name@>;
@z

dio for cur_file
@x 14318
  try_extension:=a_open_in(cur_file, kpse_mf_format)
else try_extension:=a_open_in(cur_file, kpse_mp_format);
@y
  try_extension:=dio_open_in(cur_file, kpse_mf_format)
else try_extension:=dio_open_in(cur_file, kpse_mp_format);
@z

After opening the first input file, we set the output_mode according to its
extension conventions. We also set the prefix if desktop_flag is set.
@x 14352
    job_name:=cur_name;
@y
    job_name:=cur_name;
    riscos_set_output_mode (name_of_file + 1);
    if riscos_desktop_flag then
      riscos_initialise_prefix (name_of_file + 1);
@z

@x 14387
if input_ln(cur_file,false) then do_nothing;
@y
if dio_input_ln(cur_file,false) then do_nothing;
@z

@x 14440
if not a_open_in(cur_file,no_file_path) then
@y
if not dio_open_in(cur_file,no_file_path) then
@z

dio for wr_file and rd_file
@x 14487
rd_file:array [readf_index] of alpha_file; {\&{readfrom} files}
@y
rd_file:array [readf_index] of dio_handle; {\&{readfrom} files}
@z

@x 14491
wr_file:array [write_index] of alpha_file; {\&{write} files}
@y
wr_file:array [write_index] of dio_handle; {\&{write} files}
@z

@x 14509
if not a_open_in(rd_file[n],no_file_path) then goto not_found;
if not input_ln(rd_file[n],false) then
  begin a_close(rd_file[n]); goto not_found; end;
@y
if not dio_open_in(rd_file[n],no_file_path) then goto not_found;
if not dio_input_ln(rd_file[n],false) then
  begin dio_close(rd_file[n]); goto not_found; end;
@z

@x 14542
        a_close(rd_file[n0]);
@y
        dio_close(rd_file[n0]);
@z

Textual output files are type MP (currently Text)
@x 14553
      or not a_open_out(wr_file[n]) do
@y
      or not dio_open_out(wr_file[n], riscos_MP_type) do
@z

@x 17092
if input_ln(rd_file[n],true) then goto found;
@y
if dio_input_ln(rd_file[n],true) then goto found;
@z

@x 17117
  begin a_close(rd_file[n]); goto not_found; end
@y
  begin dio_close(rd_file[n]); goto not_found; end
@z

@x 19773
begin a_close(wr_file[n]);
@y
begin dio_close(wr_file[n]);
@z

TFM file are type TFM
@x 20705
while not b_open_out(tfm_file) do
@y
while not b_open_out(tfm_file, riscos_TFM_type) do
@z

The output PostScript files have type PoScript
@x 21304
while not a_open_out(ps_file) do
@y
while not a_open_out(ps_file, riscos_PS_type) do
@z

Mem files are type Data
@x 22781
while not w_open_out(mem_file) do
@y
while not w_open_out(mem_file, riscos_DUMP_type) do
@z

@x 22957
@ @<Close all open files in the |rd_file| and |wr_file| arrays@>=
for k:=0 to read_files-1 do
  if rd_fname[k]<>0 then a_close(rd_file[k]);
for k:=0 to write_files-1 do
  if wr_fname[k]<>0 then a_close(wr_file[k])
@y
@ @<Close all open files in the |rd_file| and |wr_file| arrays@>=
for k:=0 to read_files-1 do
  if rd_fname[k]<>0 then dio_close(rd_file[k]);
for k:=0 to write_files-1 do
  if wr_fname[k]<>0 then dio_close(wr_file[k])
@z
