%%%  WEB Change File for DVItoMP (Win32 version)
%%%  Time-stamp: "97/08/03 01:45:49 mik"
%%%
%%%  Copyright (C) 1997
%%%	Christian Schenk  <cschenk@berlin.snafu.de>
%%%
%%%  This file is part of MiKTeX.
%%%
%%%  MiKTeX is free software; you can redistribute it and/or
%%%  modify it under the terms of the GNU General Public License as
%%%  published by the Free Software Foundation; either version 2, or (at
%%%  your option) any later version.
%%%  
%%%  MiKTeX is distributed in the hope that it will be useful, but
%%%  WITHOUT ANY WARRANTY; without even the implied warranty of
%%%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
%%%  General Public License for more details.
%%%  
%%%  You should have received a copy of the GNU General Public License
%%%  along with MiKTeX; if not, write to the Free Software
%%%  Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
%%%  USA.

@x
\def\title{DVI$\,$\lowercase{to}MP}
@y
\def\MiKTeX{MiK\TeX}
\def\title{DVI$\,$\lowercase{to}MP for Win32 (\MiKTeX\ 1.06)}
@z

%% **     3  ******************************************************************

@x
procedure initialize; {this procedure gets things started properly}
@y
@<External C routines@>@/
procedure initialize; {this procedure gets things started properly}
@z

%% **     5  ******************************************************************

@x
@!name_length=50; {a file name shouldn't be longer than this}
@y
@!name_length=50; {a file name shouldn't be longer than this}
@!namez_length=51;
@z

%% **    10  ******************************************************************

@x
@p procedure jump_out;
begin goto final_end;
@y
@d goto_final_end==c4p_longjmp(env_buf,1)

@p procedure jump_out;
begin goto_final_end
@z

%% **    12  ******************************************************************

@x
@d text_char == char {the data type of characters in text files}
@d first_text_char=0 {ordinal number of the smallest element of |text_char|}
@d last_text_char=127 {ordinal number of the largest element of |text_char|}
@y
@d text_char == char {the data type of characters in text files}
@d first_text_char=0 {ordinal number of the smallest element of |text_char|}
@d last_text_char=127 {ordinal number of the largest element of |text_char|}
@z

%% **    14  ******************************************************************

@x
@ To prepare the |mpx_file| for output, we |rewrite| it.
@^system dependencies@>

@p procedure open_mpx_file; {prepares to write text on |mpx_file|}
begin rewrite(mpx_file);
end;
@y
@ To prepare the |mpx_file| for output, we |rewrite| it.
@^system dependencies@>

@p procedure open_mpx_file; {prepares to write text on |mpx_file|}
begin
if (c4pargc <> 3) then
 abort('Usage: dvitomp inputfile outputfile');
c4p_fopen(mpx_file,c4p_argv[2],c4p_w_mode,true);
rewrite(mpx_file);
end;
@z

%% **    19  ******************************************************************

@x
@ To prepare these files for input, we |reset| them. An extension of
\PASCAL\ is needed in the case of |tfm_file|, since we want to associate
it with external files whose names are specified dynamically (i.e., not
known at compile time). The following code assumes that `|reset(f,s)|'
does this, when |f| is a file variable and |s| is a string variable that
specifies the file name. If |eof(f)| is true immediately after |reset(f,s)|
has acted, these routines assume that no file named |s| is accessible.
@^system dependencies@>

@p procedure open_dvi_file; {prepares to read packed bytes in |dvi_file|}
begin reset(dvi_file);
if eof(dvi_file) then abort('DVI file not found');
end;
@#
function open_tfm_file:boolean; {prepares to read packed bytes in |tfm_file|}
begin reset(tfm_file,cur_name);
open_tfm_file:=(not eof(tfm_file));
end;
@#
function open_vf_file:boolean; {prepares to read packed bytes in |vf_file|}
begin reset(vf_file,cur_name);
open_vf_file:=(not eof(vf_file));
end;
@y
@ To prepare these files for input, we |reset| them. An extension of
\PASCAL\ is needed in the case of |tfm_file|, since we want to associate
it with external files whose names are specified dynamically (i.e., not
known at compile time). The following code assumes that `|reset(f,s)|'
does this, when |f| is a file variable and |s| is a string variable that
specifies the file name. If |eof(f)| is true immediately after |reset(f,s)|
has acted, these routines assume that no file named |s| is accessible.
@^system dependencies@>

@p procedure open_dvi_file; {prepares to read packed bytes in |dvi_file|}
begin
if (c4pargc <> 3) then
 abort('Usage: dvitomp inputfile outputfile');
c4p_fopen(dvi_file,c4p_argv[1],c4p_rb_mode,true);
reset(dvi_file);
end;
@#
function open_tfm_file:boolean; {prepares to read packed bytes in |tfm_file|}
begin open_tfm_file:=mt_open_tfm_file(tfm_file,cur_name);
end;
@#
function open_vf_file:boolean; {prepares to read packed bytes in |vf_file|}
begin open_vf_file:=mt_open_vf_file(vf_file,cur_name);
end;
@z

%% **    20  ******************************************************************

@x
@!cur_name:packed array[1..name_length] of char; {external name,
  with no lower case letters}
@y
@!cur_name:packed array[1..namez_length] of char; {external name,
  with no lower case letters}
@z

%% **    61  ******************************************************************

@x
@ If |area_length[f]=0|, i.e., if no font directory has been specified,
\.{DVItoMP} is supposed to use the default font directory, which is a
system-dependent place where the standard fonts are kept.
The string variable |default_directory| contains the name of this area.
@^system dependencies@>

@d default_directory_name=='TeXfonts:' {change this to the correct name}
@d default_directory_name_length=9 {change this to the correct length}

@<Glob...@>=
@!default_directory:packed array[1..default_directory_name_length] of char;
@y
@ If |area_length[f]=0|, i.e., if no font directory has been specified,
\.{DVItoMP} is supposed to use the default font directory, which is a
system-dependent place where the standard fonts are kept.
The string variable |default_directory| contains the name of this area.
@^system dependencies@>

@d default_directory_name=='[TeX]Font Metric Dirs:'
@d default_directory_name_length=22
@d def_dir_namez_length=23

@<Glob...@>=
@!default_directory:packed array[1..def_dir_namez_length] of char;
@z

%% **    62  ******************************************************************

@x
@ @<Set init...@>=
default_directory:=default_directory_name;
@y
@ @<Set init...@>=
c4p_strcpy (default_directory, default_directory_name);
@z

%% **    63  ******************************************************************

@x
@ The string |cur_name| is supposed to be set to the external name of the
\.{VF} file for the current font. This usually means that we need to
prepend the name of the default directory, and
to append the suffix `\.{.VF}'. Furthermore, we change lower case letters
to upper case, since |cur_name| is a \PASCAL\ string.
@^system dependencies@>

@<Move the \.{VF} file name into the |cur_name| string@>=
for k:=1 to name_length do cur_name[k]:=' ';
if area_length[f]=0 then
  begin for k:=1 to default_directory_name_length do
    cur_name[k]:=default_directory[k];
  l:=default_directory_name_length;
  end
else l:=0;
for k:=font_name[f] to font_name[f+1]-1 do
  begin incr(l);
  if l+3>name_length then
    abort('DVItoMP capacity exceeded (max font name length=',
      name_length:1,')!');
@.DVItoMP capacity exceeded...@>
  if (names[k]>="a")and(names[k]<="z") then
      cur_name[l]:=xchr[names[k]-@'40]
  else cur_name[l]:=xchr[names[k]];
  end;
cur_name[l+1]:='.'; cur_name[l+2]:='V'; cur_name[l+3]:='F'
@y
@ The string |cur_name| is supposed to be set to the external name of the
\.{VF} file for the current font. This usually means that we need to
prepend the name of the default directory, and
to append the suffix `\.{.VF}'.
@^system dependencies@>

@<Move the \.{VF} file name into the |cur_name| string@>=
for k:=1 to name_length do cur_name[k]:=chr(0);
if area_length[f]=0 then
  begin for k:=1 to default_directory_name_length do
    cur_name[k]:=default_directory[k];
  cur_name[default_directory_name_length + 1]:=chr(0);
  l:=default_directory_name_length;
  end
else l:=0;
for k:=font_name[f] to font_name[f+1]-1 do
  begin incr(l);
  if l+3>name_length then
    abort('DVItoMP capacity exceeded (max font name length=',
      name_length:1,')!');
@.DVItoMP capacity exceeded...@>
  cur_name[l]:=xchr[names[k]];
  end;
cur_name[l+1]:='.'; cur_name[l+2]:='v'; cur_name[l+3]:='f';
cur_name[l+4]:=chr(0)
@z

%% **    64  ******************************************************************

@x
@ It is fairly simple to change a \.{VF} file name to a \.{TFM} file name.
@^system dependencies@>

@<Change \.{.VF} to \.{.TFM} in the |cur_name| string@>=
l:=area_length[f];
if l=0 then l:=default_directory_name_length;
l:=l+font_name[f+1]-font_name[f];
if l+4>name_length then
  abort('DVItoMP capacity exceeded (max font name length=',
    name_length:1,')!');
@.DVItoMP capacity exceeded...@>
cur_name[l+2]:='T'; cur_name[l+3]:='F'; cur_name[l+4]:='M'
@y
@ It is fairly simple to change a \.{VF} file name to a \.{TFM} file name.
@^system dependencies@>

@<Change \.{.VF} to \.{.TFM} in the |cur_name| string@>=
l:=area_length[f];
if l=0 then l:=default_directory_name_length;
l:=l+font_name[f+1]-font_name[f];
if l+4>name_length then
  abort('DVItoMP capacity exceeded (max font name length=',
    name_length:1,')!');
@.DVItoMP capacity exceeded...@>
cur_name[l+2]:='t'; cur_name[l+3]:='f'; cur_name[l+4]:='m';
cur_name[l+5]:=chr(0)
@z

%% **    98  ******************************************************************

@x
@p begin initialize; {get all variables initialized}
@<Process the preamble@>;
open_mpx_file;
print_ln(banner);
@y
@p begin
if c4p_setjmp (env_buf) <> 0 then goto final_end;
initialize; {get all variables initialized}
@<Process the preamble@>;
open_mpx_file;
print(banner); miktex_banner(mpx_file); write_ln(mpx_file);
@z

%% **   103  ******************************************************************
@x
@* System-dependent changes.
This section should be replaced, if necessary, by changes to the program
that are necessary to make \.{DVItoMP} 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 \.{DVItoMP} 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@>

@ @<External C routines@>=
procedure miktex_banner (var f:text_file); forward;
function mt_open_tfm_file (var f:byte_file; n:integer) : boolean; forward;
function mt_open_vf_file (var f:byte_file; n:integer) : boolean; forward;

@ @<Globals...@>=
@!env_buf : c4p_jmp_buf;
@z
