% Change file for chtopx by Mike Harrison
% History:
% 11/15/83 MH	Initially brought up
% 11/22/83 RKF	Updated to Version 1 of chtopx

@x Only print changes
\pageno=\contentspagenumber \advance\pageno by 1
@y
\pageno=\contentspagenumber \advance\pageno by 1
\let\maybe=\iffalse
@z

@x
@d print(#)==write(error_file,#)
@d print_ln(#)==write_ln(error_file,#)
@y
@d error_file==output	{here, errors go to the standard output}
@d print(#)==write(error_file,#)
@d print_ln(#)==write_ln(error_file,#)
@z

@x
@p program CHtoPX(@!chr_file,@!pxl_file,@!error_file);
@y
@p program CHtoPX(@!chr_file,@!pxl_file,@!output);
@z

@x
var@?@<Global Variables@>@/
@y
var @<Global Variables@>@/
@#
@\@=#include "chext.h"@>@\ {declarations for external C procedures}
@z

@x
@!save_raster_width:integer;    {value read in from |chr_file|}
@y
@!save_raster_width:integer;    {value read in from |chr_file|}
@!new_pointer:integer;		{used to caluculate new pointers}
@!count:integer;
@z

@x
@ Additionally, an error file is provided which contains all error messages
for each character. This file can be specified to be the terminal, in which
case all the error messages will be displayed when the program is run.

@<Glob...@>=
@!error_file:text;
@y
@ In this version, all error messages go to the standard output.  The
definition of |error_file| had to be made earlier because of the
preceding definitions for |print| and |print_ln|.
@z

@x
@<Type...@>=
@!byte=0..255;
@y
@<Type...@>=
@!byte=-128..127;
@z

@x
@!pxl_file:packed file of byte;
@y
@!pxl_file:packed file of byte;
@!pxl_fname,@!chr_fname:packed array [1..40] of char;
@z

@x
@<Open input...@>=
rewrite(pxl_file);@/
reset(chr_file);@/
rewrite(error_file);
@y
@<Open input...@>=
if argc < 3 then begin
    print_ln('Usage: CHtoPX <chr-file> <pxl-file>');
    halt;
end;
argv(1, chr_fname);
reset(chr_file, chr_fname);
argv(2,pxl_fname);
rewrite (pxl_file,pxl_fname);
@z

@x
@p procedure write_pxl(@!oneword:integer);
var k,l,m,n:byte;
begin
k:= oneword div @'100000000;@/
l:=(oneword div @'200000) mod 256;@/
m:=(oneword div 256) mod 256;@/
n:=oneword mod 256;@/
write (pxl_file,k,l,m,n);
end;
@y
@p procedure write_pxl(@!oneword: integer);
var u,v,w,x:byte;
begin
u := getb(oneword,1);@/
v := getb(oneword,2);@/
w := getb(oneword,3);@/
x := getb(oneword,4);@/
write(pxl_file,u,v,w,x);
end;
@z

@x
@p procedure write_half_pxl(oneword:integer);
var m,n:byte;
begin
if oneword < 0 then 
oneword:=(oneword + 65536);
m:=(oneword div 256);@/
n:=(oneword mod 256);@/
write(pxl_file,m,n);
end;
@y
@p procedure write_half_pxl(oneword: integer);
var u,v :byte;
begin
u := getb(oneword,3);@/
v := getb(oneword,4);@/
write(pxl_file,u);@/
write(pxl_file,v);
end;
@z

@x
old_raster_addr:=raster_addr;@/
@y
old_raster_addr:=new_pointer;@/
@z

@x
first_line:=true;@/
@y
first_line:=true;@/
count:=-1;@/
@z

@x
  end;@/
    if raster_found then incr(raster_addr);@/
@y
  end;@/
    incr(count);@/
    if raster_found then incr(raster_addr);@/
@z

@x
until end_of_page or not raster_found;
if not raster_found then skip_to_next_pg;
@y
until end_of_page or not raster_found;
new_pointer := new_pointer + count;@/
if not raster_found then skip_to_next_pg;
@z

@x Boy oh boy is pc literal minded---it rejects null strings in a write!
font_info[chr_index].raster_addr:=old_raster_addr;@/
if not all_match then
begin @/
error ('');   {skip to next line}@/
@y
font_info[chr_index].raster_addr:=old_raster_addr;@/
if not all_match then
begin @/
error (' ');   {skip to next line}@/
@z

@x
check_match(raster_addr,directory_ptr,all_match);
@y
check_match(new_pointer,directory_ptr,all_match);
@z

@x
raster_addr:=1;@/
@y
raster_addr:=1;@/
new_pointer := 1;@/
@z