program WS4HTM(input,output); { Convert Wordstar to HTML file Bases upon WS4HTM.BAS by Emmanuel ROCHE Adapted for TURBO PASCAL by W.Cirsovius V1.0 - Straight forward from BASIC source. V2.0 - Optimize PASCAL source. V3.0 - Make lables more readable. V4.0 - Final optimization. } const { Unnecessary but makes the source more readable } bell = #$07; lf = #$0a; lfhi = $8a; cr = #$0d; enf = #$1a; LOMASK = $0f; NOMSB = $7f; { We need some toggle flags to be preset to false } flag02 : boolean=false; flag04 : boolean=false; flag13 : boolean=false; flag14 : boolean=false; flag16 : boolean=false; flag18 : boolean=false; flag19 : boolean=false; type fstr = string[14]; mstr = string[80]; var FName1, FName2 : fstr; file1, file2 : text; {Character and bytes read from source} byteo : byte; {Last original byte read} bytes : byte; {Last byte read less hi bit} bytec : char; {Last character read less hi bit} procedure getFiles; { Get file names and set default extensions} var files : fstr; p : integer; procedure LoadFilename; { Sample main file name} begin if Paramcount=0 then begin repeat write('WS4-to-HTM: Enter WS4 File Name: '); readln(files); until length(files)>0; end else files:=Paramstr(1); for p:=1 to length(files) do files[p]:=upcase(files[p]); end; Begin {getFiles} LoadFilename; p:=pos('.',files); if p=0 then p:=length(files) else p:=pred(p); FName1:=copy(files,1,p)+'.WS4'; FName2:=copy(files,1,p)+'.HTM'; End; procedure openFiles; { Prepare files } Begin assign(file1,FName1); {$I-} reset(file1); {$I+} if IOresult<>0 then begin writeln(bell,'File not found.'); writeln; halt; end; assign(file2,FName2); rewrite(file2); End; procedure get1; { Read character from file } Begin if eof(file1) then bytec:=enf else read(file1,bytec); byteo:=ord(bytec); bytes:=byteo and NOMSB; bytec:=chr(bytes); End; procedure put2(c:char); { Put character to file } Begin write(file2,c); End; procedure HTMLprolog; { Do prolog } Begin writeln(file2,''); writeln(file2,''); writeln(file2,''); writeln(file2,''); writeln(file2,''); writeln(file2,'Converted from file "',FName1,'"'); writeln(file2,''); writeln(file2,''); writeln(file2,''); writeln(file2,'
');
End;

procedure HTMLepilog;
{ Do epilog }
Begin
  writeln(file2,'
'); writeln(file2,''); writeln(file2,''); End; procedure WS4char; { Process character } procedure Toggle(var flag:boolean; msg:mstr); { Give toggle prefix } begin write(file2,'<'); flag:=not flag; if not flag then write(file2,'/'); write(file2,msg); end; procedure ToggleStrg(var flag:boolean; msg:mstr); { Set html attribute on or off } begin Toggle(flag,msg); end; procedure ToggleChr(var flag:boolean; c:char); { Set html attribute on or off } begin Toggle(flag,c+'>'); end; procedure Log; { Log message to console } const logMsg : string[4]='[hl]'; function hex(hx:byte):char; { Convert byte to hex character } begin if hx<10 then hex:=chr(hx+ord('0')) else hex:=chr(hx-10+ord('A')); end; begin {Log} if bytes<16 then begin logMsg[2]:='0'; logMsg[3]:=hex(bytes); end else begin logMsg[2]:='1'; logMsg[3]:=hex(bytes and LOMASK); end; write(logMsg); end; Begin {WS4char} case bytes of $00 , { 00h: Fix the print position. } $03 : ; { 03h: Pause for user response during print. } $05, { 05h: Custom print control Ctrl-E. } $08, { 08h: Overprint previous character. } $09, { 09h: Horizontal Tabulation character. } $0b, { 0Bh: Mark index entry. } $0c, { 0Ch: Form Feed. } $10..$12, { 10h: Reserved. } { 11h: Custom print control Ctrl-Q. } { 12h: Custom print control Ctrl-R. } $15, { 15h: Reserved. } $17, { 17h: Custom print control Ctrl-W. } $1a, { 1Ah: End Of File character. } $1c..$1f : Log; { 1Ch: Extended character trailer code. } { 1Dh: Reserved. } { 1Eh: Inactive soft hyphen. } { 1Fh: Active soft hyphen. } $01 : write(file2,''); { 01h: Alternate character width. } $0e : write(file2,''); { 0Eh: Return to the normal character width. } $0f : write(file2,' '); { 0Fh: Binding space. } $06 : put2(' '); { 06h: Phantom space (default: 20h). } $07 : put2('~'); { 07h: Phantom rubout (default: 7Eh). } $0a : put2(lf); { 0Ah: Line Feed. } $0d : put2(cr); { 0Dh: Carriage Return. } $02 : ToggleChr(flag02,'b'); { 02h: Boldface type ON/OFF toggle. } $13 : ToggleChr(flag13,'u'); { 13h: Underline ON/OFF toggle. } $19 : ToggleChr(flag19,'i'); { 19h: Italics ON/OFF toggle. } $04 : ToggleStrg(flag04,'strong>'); { 04h: Double strike printing ON/OFF toggle. } $14 : ToggleStrg(flag14,'sup>'); { 14h: Superscript ON/OFF toggle. } $16 : ToggleStrg(flag16,'sub>'); { 16h: Subscript ON/OFF toggle. } $18 : ToggleStrg(flag18,'strike>'); { 18h: Strikeout ON/OFF toggle. } $1b : begin { 1Bh: Extended character lead-in code. } get1; put2(bytec); get1; end; else put2(bytec); end End; procedure ProcessChar; { Process WS4 character } function morefile:boolean; { Test end of line or file } begin morefile:=(byteo<>ord(lf)) and (bytes<>ord(enf)); end; procedure ProcessLine(WS4:boolean); { Skip or process characters } begin if WS4 then WS4char; while morefile do begin get1; if WS4 then WS4char; if byteo=lfhi then exit; end; end; Begin {ProcessChar} { Process WS4 text or dot commands } if chr(byteo)='.' then ProcessLine(false) else ProcessLine(true); End; procedure ProcessWS4; { Process file } Begin repeat get1; if bytes<>ord(enf) then begin if bytec=' ' then put2(bytec) else ProcessChar; end; until bytes=ord(enf); End; BEGIN { ** M A I N ** } getFiles; openFiles; HTMLprolog; ProcessWS4; HTMLepilog; close(file1); close(file2); END.