program convert(input,output); (* Written by Kim Moser *) (* v870831 *) const max_cmd_len=254; UDK='~'; red=12; yellow=14; cyan=11; normal=yellow; type cmd_type=string [max_cmd_len]; error_type=string [254]; var tack_filename,filename,filename2:string [12]; {Temporary storage of filename} input,output:text; cmd:cmd_type; loop,cmd_len:integer; {Holds length of current command string} empty,character,buffer:char; error_message:string [80]; LE:string [2]; title_bar:string [1]; display_errors,okay:boolean; procedure error (error_message:error_type); var errkey:char; begin if display_errors=true then begin {Display error} writeln; textcolor (red); writeln (error_message); writeln ('Press RETURN to continue....'); textcolor (normal); read (kbd,errkey); textcolor (normal); end; {Display error} end; procedure read_char; {reads character from file (or buffer) into 'character'} begin if buffer=EMPTY then read (input,character) else begin character:=buffer; buffer:=EMPTY; end; end; procedure read_cmd (write_also:boolean); {If write_also is TRUE, then write each character that's not part of command to output file} begin read_char; while (character <> chr(27)) and (character <> UDK) and (not eof (input)) do begin if write_also = TRUE then begin write (output,character); end; read_char; end; if eof(input) then error ('End of file encountered while searching for command!'); cmd:=UDK; cmd_len:=1; read_char; while (character <> chr(27)) and (character <> chr(10)) and (cmd_len <= max_cmd_len) and (not eof(input)) do begin cmd:=cmd+character; cmd_len:=cmd_len+1; read_char; end; if character=chr(27) then buffer:=UDK else buffer:=EMPTY; if character=chr(10) then cmd:=cmd+LE; if eof(input) then error ('End of file encountered while reading command!'); if cmd_len >= max_cmd_len then begin error ('Command is too long! Command is:'); error (cmd); end; end; begin filename:=''; le:=CHR(13)+CHR(10); display_errors:=true; okay:=false; while okay=false do begin textcolor (normal); writeln ('CONVERT (v870831) Copyright (C) 1987 by Kim Moser, All Rights Reserved.'); writeln ('This program converts Ventura Publisher ".C00" files to mountable Xerox'); writeln ('4045 laser printer form files (i.e. constant pages) with ".LTR" extensions.'); writeln; write ('Which file to convert? '); textcolor (cyan); readln (filename); textcolor (normal); assign (input,filename); {filename is assigned to variable 'input'} {Compute filename2 from filename, and add '.LTR' to it} filename2:=''; tack_filename:=''; loop:=1; repeat filename2:=filename2+filename[loop]; tack_filename:=tack_filename+filename[loop]; loop:=loop+1; until (loop=9) or (filename[loop]='.'); if (filename[loop]<>'.') and (loop = 9) then error ('Filename is too long or does not include extension!') else begin okay:=true; filename2:=filename2+'.LTR'; tack_filename:=tack_filename+'.TAK'; assign (output,filename2); end; end; {Do while okay=false} title_bar:=EMPTY; writeln; writeln ('Use title bar (Y/N)? '); read (kbd,title_bar); writeln; write ('Press any key to begin converting '); textcolor (cyan); write (filename); textcolor (normal); write (' to '); textcolor (cyan); writeln (filename2); textcolor (normal); if (title_bar='Y') or (title_bar='y') then begin write ('WITH title bar file '); textcolor (cyan); writeln (tack_filename); textcolor (normal); end else writeln ('WITHOUT title bar....'); read (kbd,character); {Initialize variables/files} empty:=CHR(0); reset (input); rewrite (output); buffer:=EMPTY; character:=EMPTY; LE:=CHR(13)+CHR(10); (*empty:=CHR(0);*) display_errors:=false; {Don't display errors (namely "Command encountered is too long") while skipping fonts} {Main procedure:} write (output,'=UDK=',UDK,LE); {Write '=UDK=' at top of output file} read_cmd (false); {+X} read_cmd (false); {+zf} {used to be +U} write (output,UDK,'+M',LE); {+M} read_cmd (false); {+m...} {used to be zf} write (output,cmd); {+m...} {used to be zf} read_cmd (false); {+A...} (* write (output,cmd); {+A...} {used to be +m} *) {Skip fonts} writeln; writeln ('Skipping fonts....'); read_cmd (false); while (cmd [2] <> 'm') and (not eof(input)) do read_cmd (false); if eof(input) then error ('Command ESCm not found!'); read_cmd (false); {Read past fonts until command ESCw encountered} while (cmd <> UDK+'w') and (not eof(input)) do read_cmd (false); if eof(input) then error ('Command ESCw not found!'); write (output,cmd); {w} display_errors:=true; {Okay to display errors from this point on} {Read and write main file} writeln ('Writing main file....'); display_errors:=true; read_cmd (true); {Read and write all until command ESCx... encountered} while (cmd <> UDK+'x0,3400,2,2'+LE) and (not eof(input)) do begin write (output,cmd); read_cmd (true); {Read and write until cmd ESCx is encountered} end; if eof(input) then error ('Command ESCx not found at end of main text!'); {Open TACK file} write ('Writing TACK file....'); close (input); textcolor (cyan); if (title_bar = 'y') or (title_bar = 'Y') then begin assign (input,tack_filename); write (tack_filename); end else begin assign (input,'TACK.'); write ('TACK'); end; textcolor (normal); writeln ('....'); {Write TACK file} reset (input); read (input,character); while not eof(input) do begin write (output,character); read (input,character); end; close (input); close (output); end.