home *** CD-ROM | disk | FTP | other *** search
- Program WS_2_Ascii;
-
- {$C-,K-}
-
- { Copyright (c) John Friel III
-
-
- Converts files created by WordStar in (D)ocument mode to
- Non document files by stripping the high bit of every byte
- in the file. This program may be modified in any way to
- suit your personal tastes. You are also encouraged to pass
- this program on to anyone provided the source code is unmodified.
- Please keep an unmodified copy around just for this purpose.
- For more information on this program or mode detailed info
- on interfacing TURBO Pascal with the I.B.M. PC (r) or
- Compatibles (this was developed on a Tava PC!) write to:
-
- John Friel III
- 715 Walnut Street
- Cedar Falls, Iowa 50613
-
-
- }
-
- Const
- Color = true;
- Type
- Names = String[80];
- Screen_Array = Array [1..4000] of byte;
- Var
- InFile, OutFile : Text;
- x, i, y, q, in_X, in_Y,
- out_X, out_Y : Integer;
- total_chars, total_words : real;
- Ok, bool, done, Screen_IO,
- Stats : Boolean;
- InFileName, OutFileName : Names;
- Real_Screen : Screen_Array absolute $B800:$0000;
- Temp_Screen, Help_Screen,
- Help_Screen2 : Screen_Array;
- Ch, ch_in, ch_out, last_char : Char;
-
- Procedure check_for_abort; forward;
-
- Procedure Statistics;
- begin
- total_chars := total_chars + 1;
- if (ch_out in [' ', chr(10), chr(13)]) and
- not (last_char in [' ', chr(10), chr(13)]) then
- total_words := total_words + 1;
- last_char := ch_out;
- end;
-
- Procedure Big_exit;
- begin
- textbackground(black);
- if color then textcolor(yellow);
- window (1,1,80,25);
- for x := 10 downto 1 do
- for y := 2 downto 1 do
- begin
- window (x+y-1,x+4,82-x-y,25-x);
- clrscr;
- delay (5);
- end;
- gotoxy (25,12);
- writeln ('WS2ASCII completed.');
- halt;
- end;
-
- Procedure OpenInFile;
- Begin
- Repeat
- Write ('Enter name of Input file :');
- buflen := 14;
- readln(InFileName);
- if length(InFileName) = 0 then
- begin
- check_for_abort;
- if color then textcolor(yellow);
- window (2,6,79,7);
- gotoxy (1,2);
- end;
- assign(Infile, InFileName);
- {$I-} reset (InFile) {$I+};
- Ok := (IOresult = 0);
- if not Ok then Writeln ('Cannot find file ',InFileName);
- until Ok;
- end;
-
- Procedure OpenOutFile;
- var
- answer : String[14];
- Begin
- Repeat
- Repeat
- Write ('Enter name of Output file :');
- buflen := 14;
- readln(OutFileName);
- if OutFileName = '' then
- begin
- check_for_abort;
- if color then textcolor(yellow);
- window (2,6,79,7);
- gotoxy (1,2);
- end;
- if OutFileName = InFileName then
- Writeln ('Input filename matches Output filename');
- until (OutFileName <> InFileName) and (OutFileName <> '');
- assign(Outfile, OutFileName);
- {$I-} Reset (OutFile) {$I+};
- Ok := (IOresult = 0);
- if Ok then
- Begin
- Write ('File ',OutFileName,' exists, use it anyway ?');
- readln (answer);
- if answer[1] in ['Y','y']
- then Begin
- Ok := True;
- reWrite (OutFile);
- end
- else
- Ok := False;
- end
- else
- Begin
- Ok := True;
- ReWrite (OutFile);
- end;
- until Ok;
- end;
-
- Procedure Drawbox_IBM (x1,y1,x2,y2,FG,BG : Integer; Boxname : Names);
- Begin
- Window(x1,y1,x2,y2+1);
- if color then
- begin
- textcolor(FG);
- textbackground(BG);
- end;
- GotoXY(1,1);
- x := x2-x1;
- if length(boxname) > x then boxname[0] := chr(x-4);
- Write('U',boxname);
- for q := x1+length(boxname)+1 to x2-1 do Write('M');
- Write('8');
- for q := 2 to y2-y1 do
- Begin
- GotoXY(1,q); Write('3');
- GotoXY(x2-x1+1,q); Write('3');
- end;
- gotoXY(1,y2-y1+1);
- Write('T');
- for q := x1+1 to x2-1 do Write('M');
- Write('>');
- end;
-
- Procedure Drawbox (x1,y1,x2,y2,FG,BG : Integer; boxname : Names);
- Begin
- Drawbox_IBM (x1,y1,x2,y2,FG,BG,Boxname);
- Window (x1+1,y1+1,x2-1,y2-1);
- Clrscr;
- end;
-
- Procedure Display_In;
- Begin
- Window (2,10,79,15);
- if color then textcolor(lightcyan);
- GotoXY (in_X, in_Y);
- write (ch_in);
- in_X := whereX;
- in_Y := whereY;
- end;
-
- Procedure Display_Out;
- Begin
- Window (2,18,79,23);
- if color then textcolor(lightcyan);
- gotoxy (out_X, out_Y);
- Write(ch_out);
- out_X := whereX;
- out_Y := whereY;
- end;
-
- procedure Abort;
- Begin
- if (length(InFileName) <> 0) and (length(OutFileName) <> 0) then
- begin
- close (OutFile);
- erase (OutFile);
- end;
- move (temp_Screen, real_Screen, 4000); { restore old Screen }
- big_exit;
- end;
-
- Procedure Toggle_Screen;
- Begin
- Screen_IO := not Screen_IO;
- end;
-
- Procedure Toggle_Stats;
- Begin
- stats := not stats;
- end;
-
- Procedure More_Help;
- Begin
- move (real_Screen, help_Screen2, 4000); { save current Screen }
- drawbox (20,15,77,24,White,magenta,'[ Additional Information Window ]');
- Writeln (' TURBO Pascal v2.0 was used in creating this program.');
- Writeln (' Anyone that uses WordStar will understand why this');
- Writeln (' program was written. It strips the HIGH bit of');
- Writeln (' everything in the input file creating a new file');
- Writeln (' that can be TYPED or sent over the Comm lines to');
- Writeln (' computers that only use a word-length of 7. That');
- Writeln (' and to show off TURBO''s windowing capabilities!');
- if color then textcolor(lightcyan);
- Write (' Press any key to Return, `M'' for More');
- read (Kbd,ch);
- if ch in ['M','m'] then
- begin
- writeln;
- if color then textcolor(white);
- writeln (' In fact... All of the boxes on the screen now');
- writeln (' are actually independent Windows! Just as you');
- writeln (' saw this text scroll through this window, so');
- writeln (' will text scroll through all the other ones too.');
- writeln (' If you ever had reservations on buying TURBO');
- writeln (' Pascal because of price, fear not! It''s the BEST!');
- if color then textcolor(lightcyan);
- write (' Press any key to return...');
- read (kbd,ch);
- end;
- move ( help_Screen2,real_Screen, 4000);
- end;
-
- Procedure Help_Window;
- Begin
- move (real_Screen, help_Screen, 4000); { save current Screen }
- drawbox (13,8,70,16,white,red,'[ Help Window ]');
- Writeln (' ');
- Writeln (' 1) Help. What you are reading now!');
- Writeln (' 2) Continue. Exit the Intervention Window');
- Writeln (' 3) Screen Toggles ON/OFF. Off speeds up');
- Writeln (' the conversion greatly.');
- Writeln (' 4) Abort Cancels the current conversion and Ends');
- Repeat
- if color then textcolor(lightcyan);
- if color then textbackground(red);
- window (14,9,69,17);
- gotoxy (1,7);
- Write (' Press `M'' for More or `R'' to Return');
- GotoXY(12,7);
- read (Kbd, ch);
- if ch in ['m','M'] then
- Begin
- more_help;
- end;
- until ch in ['r','R'];
- move ( help_Screen,real_Screen, 4000);
- end;
-
- Procedure first_time_through;
- Begin
- move (real_Screen, temp_Screen, 4000); { save current Screen }
- Drawbox (10,10,62,19,lightmagenta,Black,'[ Initialization ]');
- Repeat
- Window (11,11,61,18); GotoXY(1,2);
- if color then
- begin
- textcolor(lightmagenta);
- textbackground(black);
- end;
- Writeln (' Set Parameters ');
- if color then textcolor(yellow);
- writeln (' C - Continue with the program');
- writeln (' ( leave parameters as is )');
- Writeln (' H - Help Window');
- Write (' S - Screen output toggle. Now ');
- if color then textcolor(lightgreen);
- if Screen_IO then Writeln ('ON ')
- else Writeln ('OFF');
- if color then textcolor(yellow);
- Write (' T - Statistics toggle. Now ');
- if color then textcolor(lightgreen);
- if stats then Writeln ('ON ')
- else Writeln ('OFF');
- Write (' ');
- Repeat
- read (Kbd, ch);
- until ch in ['h','H','s','S','c','C','t','T'];
- case ch of
- 's','S' : Toggle_Screen;
- 't','T' : Toggle_stats;
- 'h','H' : Help_Window;
- end;
- until ch in ['c','C'];
- move (temp_Screen, real_Screen, 4000);
- if color then textbackground(black);
- if color then textcolor(yellow);
- end;
-
- Procedure check_for_abort;
- Begin
- move (real_Screen, temp_Screen, 4000); { save current Screen }
- Drawbox (7,1,63,9,white,blue,'[ Intervention Window ]');
- Repeat
- Window (8,2,61,8); GotoXY(1,1);
- if color then textcolor(white);
- if color then textbackground(blue);
- Writeln (' Command Menu Window! ');
- Writeln (' H - Help Window');
- Writeln (' C - Continue on with conversion');
- Write (' S - Screen output toggle. Now ');
- if Screen_IO then Writeln ('ON ')
- else Writeln ('OFF');
- Write (' T - Statistics toggle. Now ');
- if stats then Writeln ('ON ')
- else Writeln ('OFF');
- Writeln (' A - Abort conversion');
- Write (' ');
- Repeat
- read (Kbd, ch);
- until ch in ['h','H','c','C','s','S','a','A','t','T'];
- case ch of
- 'a','A' : Abort;
- 's','S' : Toggle_Screen;
- 'h','H' : Help_Window;
- 't','T' : Toggle_stats;
- end;
- until ch in ['c','C'];
- move (temp_Screen, real_Screen, 4000);
- if color then
- begin
- textbackground(black);
- textcolor(lightcyan);
- end;
- end;
-
- Procedure Init;
- Begin
- textcolor(white);
- Screen_io := true;
- stats := true;
- in_X := 1;
- in_Y := 1;
- out_X := 1;
- out_Y := 1;
- done := False;
- Window (1,1,80,25);
- ClrScr;
- DrawBox (1,1,80,4,lightgreen,black,'');
- if color then textcolor(yellow);
- Writeln (' Convert WordStar Document files to Ascii files.');
- Write (' (c) John Friel III July 11, 1984 Using TURBO Pascal.');
- DrawBox (1,5,80,8,lightgreen,black,'');
- DrawBox (1,9,80,16,lightgreen,black,'[ InFile = ]');
- DrawBox (1,17,80,24,lightgreen,black,'[ OutFile = ]');
- end;
-
- Procedure Do_conversion;
- Begin
- total_words := 0.0;
- total_chars := 0.0;
- While not eof(InFile) do
- Begin
- if keypressed then check_for_abort;
- read (InFile,ch_in);
- if ord(ch_in) > 127 then
- ch_out := chr(ord(ch_in)-128)
- else
- ch_out := ch_in;
- if Screen_IO then
- begin
- Display_in;
- Display_Out;
- end;
- Write (OutFile,ch_out);
- if stats then statistics;
- end;
- close (OutFile);
- end;
-
- Procedure Show_statistics;
- Begin
- if stats then
- begin
- DrawBox (15,11,50,14,lightcyan,blue,'[ OutFile Statistics ]');
- if color then textcolor(white);
- gotoxy (1,1);
- total_chars := total_chars - 1;
- writeln (' Total Words = ',total_words:6:0);
- write (' Total Characters = ',total_chars:6:0);
- end;
- end;
-
- Procedure Open_the_files;
- Begin
- window (2,6,79,7);
- if color then textcolor(yellow);
- gotoXY (1,1);
- writeln ('Enter a NULL entry to show the Intervention Window.');
- gotoXY (1,2);
- OpenInFile;
- OpenOutFile;
- ClrScr;
- writeln (' Press any key for more information...');
- DrawBox (1,9,80,16,lightgreen,black,'[ InFile = '+InFileName+' ]');
- DrawBox (1,17,80,24,lightgreen,black,'[ OutFile = '+OutFileName+' ]');
- end;
-
- Begin { WS2ASCII }
- Init;
- first_time_through;
- repeat
- Open_the_files;
- Do_conversion;
- Show_statistics;
- Window (2,6,79,7); { point to middle Window }
- if color then
- begin
- textcolor(yellow);
- textbackground(black);
- end;
- ClrScr;
- Writeln ('All Done!');
- GotoXY(1,9);
- until done;
- end.