home *** CD-ROM | disk | FTP | other *** search
- Program Pretty;
- {$V-,C-}
-
- Const
- Cap_Set: Set Of Char = [' ','_','(','[','.',',','=','+','-','*','/','\',':','$'];
- Work_Fn = 'PTY_TEMP.WRK';
-
- Type
- Str6 = String[6];
- Str8 = String[8];
- Str12 = String[12];
- Str15 = String[15];
- Str25 = String[25];
- Str80 = String[80];
- Str132 = String[132];
- Str255 = String[255];
-
- Var
- In_Fn, Out_Fn : Str25;
- In_Fl, Out_Fl : Text[$1000];
- Err : Integer;
- Ioerr : Integer;
-
- Procedure Lc(Var Ch1 : Char);
-
- Begin
- If (Ch1 in ['A'..'Z']) then Ch1 := Chr(Ord(Ch1)+32);
- End;
-
- Function Exist(F : Str25) : Boolean;
- Var Fil : File;
-
- Begin
- Exist := True;
- Assign(Fil,F);
- {$I-}
- Reset(Fil);
- {$I+}
- Exist := (Ioresult = 0);
- Close(Fil);
- End;
-
- Procedure Clrpos(First, Last : Byte);
- Var Line : Byte;
-
- Begin
- For Line := First to Last Do
- Begin
- Gotoxy(1,Line);
- Clreol;
- End;
- Gotoxy(1,Line);
- End;
-
- Function Get_Filename(Present : Boolean; Ext : Str6) : Str25;
- {returns an acceptable filename. present indicates whether it must already
- exist or be a new file; ext is an optional extension that will be added if
- it has length > 0. }
- Var Ch : Char;
- St : Str25;
- There : Boolean;
- Xhold, Yhold : Byte;
- L : Byte;
- Ok : Boolean;
-
- Begin
- Xhold := Wherex;
- Yhold := Wherey;
- Repeat
- Ok := True;
- Gotoxy(Xhold,Yhold);
- Clreol;
- Readln(St);
- If (St = '') then St := ' ';
- If (Length(Ext) >= 1) then If (Pos('.',St) = 0) then St := Concat(St,Ext);
- For L := 1 to Length(St) Do
- If not (St[L] in ['A'..'Z','a'..'z','.',':','\','0'..'9','_']) Then
- Ok := False;
- If (St[1] in ['0'..'9','.']) then Ok := False;
- If Ok Then
- Begin
- There := Exist(St);
- If There <> Present Then
- Begin
- Gotoxy(1,Yhold+2);
- Clreol;
- Write(Chr(7));
- If There Then
- Begin
- Write('File exists already. Overwrite (Y/N) ? ');
- Repeat
- Read(Kbd,Ch);
- Ch := Upcase(Ch);
- Until Ch in ['Y','N'];
- If Ch = 'Y' then There := Present;
- End
- else Write('Error - file not found');
- Delay(1000);
- Gotoxy(1,Yhold+2);
- Clreol;
- End;
- End
- else
- Begin
- Gotoxy(1,Yhold+2);
- Clreol;
- There := not Present;
- Write(Chr(7),'Error - invalid file name');
- Delay(1000);
- Gotoxy(1,Yhold+2);
- Clreol;
- End;
- Until There = Present;
- Get_Filename := St;
- End;
-
- Procedure Get_In_File;
- Var Numpar : Byte;
- L : Byte;
- Ok : Boolean;
-
- Begin
- Numpar := Paramcount;
- If (Numpar > 0) Then
- Begin
- In_Fn := Paramstr(1);
- Ok := True;
- For L := 1 to Length(In_Fn) Do
- If not (In_Fn[L] in ['A'..'Z','a'..'z','.',':','\','0'..'9','_']) Then
- Ok := False;
- If (In_Fn[1] in ['0'..'9','.']) then Ok := False;
- If Ok then Ok := Exist(In_Fn);
- If not Ok Then
- Begin
- Gotoxy(1,8);
- Clreol;
- Write('Input file name : ');
- In_Fn := Get_Filename(True,'');
- End;
- End
- else
- Begin
- Write('This program alters case appropriately in the input source');
- Writeln(' text file.');
- Gotoxy(1,8);
- Write('Input file name : ');
- In_Fn := Get_Filename(True,'');
- End;
- Assign(In_Fl,In_Fn);
- Rename(In_Fl,Work_Fn);
- Assign(Out_Fl,In_Fn);
- End;
-
- Procedure Special_Lower(Var Inst: Str255; Wrd : Str8);
- Var Place : Integer;
- Letter : Integer;
- Quote : Boolean;
-
- Begin
- Place := Pos(Wrd,Inst);
- If (Place <> 0) Then
- Repeat
- Quote := False;
- Begin
- For Letter := 1 to Place Do
- If (Inst[Letter] in ['''']) then Quote := not Quote;
- If (Not Quote) then For Letter := Place to (Place+1) Do
- Lc(Inst[Letter]);
- Place := Pos(Wrd,Inst);
- End;
- Until (Place = 0) or Quote;
- End;
-
- Procedure Change_Case;
- Var L, P : Integer;
- In_Line : Str255;
- Quote, Cap : Boolean;
-
- Begin
- Rewrite(Out_Fl);
- Gotoxy(1,10);
- Clreol;
- Write('Working...');
- Reset(In_Fl);
- Ioerr := 0;
- While (Ioerr = 0) and (Not Eof(In_Fl)) Do
- Begin
- Readln(In_Fl,In_Line);
- Cap := True;
- For P := 1 to Length(In_Line) Do
- Begin
- If (In_Line[P] in ['''','{','}']) then Quote := not Quote;
- If (Not Quote) Then
- Begin
- If (Not Cap) then Lc(In_Line[P])
- else In_Line[P] := Upcase(In_Line[P]);
- If (In_Line[P] in Cap_Set) Then
- Cap := True
- else Cap := False;
- End;
- End;
- Special_Lower(In_Line,' Then ');
- Special_Lower(In_Line,' Do ');
- Special_Lower(In_Line,' In ');
- Special_Lower(In_Line,' Else');
- Special_Lower(In_Line,' And ');
- Special_Lower(In_Line,' Or ');
- Special_Lower(In_Line,' Not ');
- Special_Lower(In_Line,' To ');
- Special_Lower(In_Line,' Downto ');
- Writeln(Out_Fl,In_Line);
- End;
- If (Ioerr = 0) Then
- Begin
- {$I-}
- Close(In_Fl);
- Erase(In_Fl);
- Flush(Out_Fl);
- {$I+}
- Ioerr := Ioresult;
- Close(Out_Fl);
- If (Ioerr <> 0) Then
- Begin
- Erase(Out_Fl);
- Rename(In_Fl,In_Fn);
- Writeln;
- Writeln('Error - Disk full');
- End;
- End;
- End;
-
- Begin
- Clrscr;
- Gotoxy(15,1);
- Writeln('= = P A S C A L P R E T T Y F O R M A T T E R = =');
- Gotoxy(1,6);
- Get_In_File;
- Clrpos(2,13);
- Gotoxy(1,4);
- Write('Changing ',In_Fn);
- Change_Case;
- End.
-