Program BOX; { Version 3, March 19, 1987 by Loring Chien, Houston, Texas } { places a box around text, centers, right justify, or left justify using .CE, .LJ, or .RJ commands. } Const Width : integer = 00; LftJustify=1; Center=2; RtJustify=3; IBM_PC : Boolean = True; { this only affects the cosmetics of the title block, nothing else. Set to False for CP/M or MS-DOS w/o IBM char set } Type Strng132 = String[132]; Strng80 = String[80]; Strng20 = string[20]; FName = String[20]; Var BoxChar,ans,WSChar,NxtWSChar : Char; TopCHar,SideChar,UpLftChar,LowLftChar,UpRtChar,LowRtChar : CHar; Prefix,PostFix : Strng80; TextIn, TextOut : strng132; FileIn, Fileout, ViewIn, WSFile : Text; TExtFile, BoxFile : fname; I,TxtLen,PadLen,PadLenLeft,PadLenRt, LineNo, CmdCnt : Integer; Basefile : FName; MOde : integer; { 1= left justify, 2=center, 3=right justify} BoxMode : Integer; Function Exist(filename:fname):Boolean; {This function returns true if the filename exists, otherwise, it returns false.} Var Fil:file; Begin Assign(fil, filename); {$I-} Reset (Fil); {$I+} EXIST := (IOresult = 0); End; Procedure GetFileName (Var FileName: fname; Style:fname; var BaseFile:Fname; DefaultExt:fname;BFUse:integer); { read in a file name, make sure it exists } { FileName - output gets put here, a legal filename} { Style - asks 'Input ',STYLE,' file name' } { BaseFile - default file less ext on input. Used if BFUse =1 or 3 } { DefaultExt - ext used if none supplied } { BFUse - if 1 or 3, use BaseFIle, if 2 or 3, make Basefile from result } { BFUse : 00000xxxb ||| ||+---- use Basefile as default base |+----- make entered base filename as new BaseFile +------ Do not Check to make sure file exists, i.e. to be used as an input file } Var FileNameBad: Boolean; I : integer; Begin FileNameBad:=True; While FileNameBad do begin write ('Enter file name for ',Style,' '); IF (BFUse and 1) = 1 then write ('[',Basefile); Write ('[.',DefaultExt,']'); If (BFUse and 1) = 1 then write (']'); Write (' : '); readln (FileName); If ((BFUse and 1)=1) and (Length(FileName)=0) then Filename:=BaseFile; If pos('.',FileName)=0 then FileName :=FileName+'.'+DefaultExt; For I :=1 to length(FileName) do FileName[i]:=upCase(FileName[i]); If (BFUse and 4) =4 then FileNameBad :=false else FileNameBad := not exist(FileName); If FileNameBad then writeln (FileName,' not found.'); end; If (BFUse and 2) =2 then BaseFile := Copy(FileName,1,pos('.',FileName)-1); end; { GetFileName } Begin {program BOX } ClrScr; If not IBM_PC then Begin Writeln ('+----------------------------------------------------------------------------+'); Writeln ('| |'); Writeln ('| BOX.COM / BOX.PAS by Loring Chien 3/19/87 |'); Writeln ('| |'); Writeln ('| This program places a "BOX" around text from an Input File and writes it |'); Writeln ('| into an Output File. You specify the width (must be 4 greater than the |'); Writeln ('| longest line) of the box, or let the program choose it by specifying zero. |'); Writeln ('| |'); Writeln ('| There are three "dot" commands - |'); Writeln ('| |'); Writeln ('| ".LJ" to left justify text |'); Writeln ('| |'); Writeln ('| ".CE" to center text, and |'); Writeln ('| |'); Writeln ('| ".RJ" to right justify text. |'); Writeln ('| |'); Writeln ('| The dot must be in column one and the mode remains in effect until |'); Writeln ('| changed. Mode commands must be in upper case and the default is ".CE". |'); Writeln ('| |'); Writeln ('| (note: this title block was done with BOX.PAS) |'); Writeln ('| |'); Writeln ('+----------------------------------------------------------------------------+'); End Else Begin Writeln ('ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»'); Writeln ('º º'); Writeln ('º BOX.COM / BOX.PAS by Loring Chien 3/19/87 º'); Writeln ('º º'); Writeln ('º This program places a "BOX" around text from an Input File and writes it º'); Writeln ('º into an Output File. You specify the width (must be 4 greater than the º'); Writeln ('º longest line) of the box, or let the program choose it by specifying zero. º'); Writeln ('º º'); Writeln ('º There are three "dot" commands - º'); Writeln ('º º'); Writeln ('º ".LJ" to left justify text º'); Writeln ('º º'); Writeln ('º ".CE" to center text, and º'); Writeln ('º º'); Writeln ('º ".RJ" to right justify text. º'); Writeln ('º º'); Writeln ('º The dot must be in column one and the mode remains in effect until º'); Writeln ('º changed. Mode commands must be in upper case and the default is ".CE". º'); Writeln ('º º'); Writeln ('º (note: this title block was done with BOX.PAS) º'); Writeln ('º º'); Writeln ('ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ'); end; writeln; GetFileName (TextFile,'Text to be Boxed',BaseFile,'TXT',2); Write ('Is this a Wordstar Document-mode file (Y/[N]) ? '); Begin Read (kbd,ans); Ans := UpCase (ans); End; Writeln (ans); If ans = 'Y' then Begin { fixing Wordstar file } Writeln ('Fixing Wordstar Document-mode file...'); Assign (WSFile,TextFile); Reset (WSFile); Assign (FileIn,BaseFile+'.$$$'); {temp file} Rewrite (FileIn); Repeat Read (WSFIle,WSChar); WSChar := Chr ( Ord (WSChar) and 127 ); If Ord(WSChar) = $1F then WSCHar := '-'; If Ord(WSChar) = $1E then Begin Read (WSFIle,WSChar); WSChar := Chr ( Ord (WSChar) and 127 ); End; Write (FileIn,WSChar); Until Ord(WSChar) = 26; {end-of-file} CLose (FileIn); Close (WSFIle); TextFile := BaseFile+'.$$$'; End; {Fixing Wordstar file } Assign (FileIn, TextFile); Reset (FileIn); GetFileName (BoxFile,'Output of Boxed Text', BaseFile,'BOX',5); Assign (FileOut, BoxFile); Rewrite (FileOut); Width :=0; Write ('Enter desired width (columns) of Boxed text (0=AutoSize) [',Width,'] : '); Readln (Width); If width =0 then { Auto-Size Input File } Begin Write ('Auto-Sizing ',TextFile,'... '); While not EOF (FileIn) do Begin Readln (FileIn,TExtIn); If Length(TextIn) > Width then Width := Length(TextIn); End; Width := Width +4; Reset (FileIn); Writeln ('Width set to ',Width, ' columns.'); End; Mode := Center; BoxChar := '*'; TopChar := '-'; SideChar := '|'; UpLftChar := '+'; UpRtChar := '+'; LowRtChar := '+'; LowLftChar := '+'; Prefix := ''; PostFix := ''; BoxMode := 1; Writeln; writeln ('Choose Box Mode :'); Writeln ('1 = line box, 2 = "*" box'); Writeln ('3 = Double-line Graphic box, 4 = Single-line graphic box'); Writeln ('5 = custom box'); Write ('Enter ([1], 2, 3, 4, or 5) : '); Readln (Boxmode); Case BoxMode of 1: Begin { character line box } End; 2: Begin { Box of Asterisks } TopChar := Boxchar; SideChar := BoxChar; UpLftChar := BoxChar; UpRtChar := BoxChar; LowLftChar := Boxchar; LowRtChar := BoxChar; End; 3: Begin { Doouble-line Graphic Box } TopChar := Chr($CD); SideChar := Chr($BA); UpLftChar := Chr($C9); UpRtChar := Chr($BB); LowLftChar := Chr($C8); LowRtChar := Chr($BC); End; 4: Begin { single-line graphic box } TopChar := Chr($C4); SideChar := Chr($B3); UpLftChar := Chr($DA); UpRtChar := Chr($BF); LowLftChar := Chr($C0); LowRtChar := Chr($D9); End; 5: Begin Writeln; Write ('Enter Top Line Character : '); Readln (TopChar); Write ('Enter Side Character : '); Readln (SideChar); Write ('Enter Upper Left Character : '); Readln (UpLftChar); Write ('Enter Upper Rt. Character : '); Readln (UpRtChar); Write ('Enter Lower Left Character : '); Readln (LowLftChar); Write ('Enter Lower Rt. Character : '); Readln (LowRtChar); End; End; {Case BoxMode} Writeln; Write ('Use Prefix (Y/[N]) ? '); Begin Read (Kbd,Ans); Ans := UpCase (Ans); end; If Ans = 'Y' then Begin Write ('Enter Prefix string : '); Readln (Prefix); End else writeln; Write ('Use Postfix (Y/[N]) ? '); Begin Read (Kbd,Ans); Ans := UpCase (Ans); end; If Ans = 'Y' then Begin Write ('Enter Postfix string : '); Readln (PostFix); End else writeln; Write (FileOut,Prefix,UpLftChar); For i:= 2 to Width-1 do write (FileOut,TopChar); Writeln (FileOut,UpRtChar,Postfix); Write (Fileout,Prefix,SideChar); For I:= 1 to Width-2 do Write (FileOut,' '); Writeln (FileOut, SideChar,PostFix); LineNo := 0; CmdCnt := 0; While not EOF(FileIn) do Begin { handling input lines } Readln (FileIn, TextIn); If (Length(TextIn)>2) and (TextIn[1] = '.') then Begin If TextIn = '.CE' then Mode := Center; If TextIn = '.LJ' then Mode := LftJustify; If TextIn = '.RJ' then Mode := RtJustify; CmdCnt := CmdCnt + 1; End Else Begin { Boxing text lines } LineNo := LineNo +1; PadLen := Width - 2 - Length(TextIn); If PadLen <=0 then Begin PadLen :=1; Writeln ('Warning - Line # ',LineNo+CmdCnt,'in input file too long!'); Writeln (TextIn); End; If Mode = Center then Begin PadLenRt := PadLen Div 2; PadLenLeft := PadLen - PadLenRt; End; If Mode = LftJustify then Begin PadLenLeft :=1; PadLenRt :=PadLen-PadLenLeft; End; If Mode = RtJustify then Begin PadLenRt :=1; PadLenLeft := PadLen-PadLenRt; End; Write (FileOut,Prefix,SideChar); For i:=1 to PadLenLeft do write (FileOut,' '); Write (FileOut,TextIn); For I:=1 to PadLenRt do write (FileOut,' '); Writeln (FileOut, SideChar,PostFix); End; { else Box text lines } End; { While... handle input lines } Write (FileOut,Prefix,SideChar); For I:=1 to Width -2 do Write (FileOut,' '); Writeln (FileOUt, SideChar,PostFix); Write (FileOut,Prefix,LowLftChar); For I:=2 to Width-1 do write (FileOut,TopChar); Writeln (FileOut,LowRtChar,PostFix); Close (FileIn); Close (FileOut); Writeln; Writeln (LineNo,' text lines read from input file.'); Writeln (CmdCnt,' justify commands in input file.'); Writeln (LineNo+4,' lines written to ',BoxFile,'.'); Writeln; Write ('View Boxed Text ([Y]/N) ? '); Read (Kbd,Ans); Ans := UpCase (Ans); Writeln (Ans); Writeln; If not (ans = 'N') then Begin { View output file } assign (ViewIn,BoxFile); Reset (ViewIn); Repeat Begin Readln (ViewIn, TextIn); Writeln (TextIn); End; Until EOF (ViewIn); Close (ViewIn); End; { view output file } End. { program BOX }