home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CP/M
/
CPM_CDROM.iso
/
mbug
/
mbug017.arc
/
WB-ESC.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1979-12-31
|
4KB
|
114 lines
const
Name_length = 14;
Bufsize = 250;
Bufbytesize = 32000;
Change_char = 94; { ^ }
Type
Name = String[Name_length]; { To save filenames in }
Var
Filename : Name; { Where the filename is kept}
Master_File,
New_File : File; { File variables }
{ Buffer is where Blockread and Blockwrite keep the
information which has been read from the file }
Buffer : Array[1..Bufbytesize] of Byte;
Recs_To_Read, Remaining:
I : Integer;
No_Error : Boolean;
Function Exist(Filename :Name) :Boolean;
{ Finds if the file already exists on the Disk. }
{ If so returns TRUE. }
var
Fil : file;
Begin
Assign(Fil,Filename);
{$I-} Reset(fil) {$I+}; { Errors are captured not reported }
if IOresult <> 0 then Exist := False else Exist := True;
end;
Begin
ClrScr;
Writeln('WordBee ESC Converter.':52);
writeln('~~~~~~~~~~~~~~~~~~~~~~':52);
Writeln(' By S.Jepson 20/1/85':78);
Writeln;Writeln;writeln;
Write('This Program will find a certain Character ');
Writeln('and convert it to the ESC character');
Write('in the Wordbee file. It also produces a Backup of ');
writeln('the original file.');
Writeln;writeln;writeln;writeln;
Writeln('Enter the name of the WordBee file , only the name.');
Writeln;
Write('eg ''FRED'' NOT ''FRED.WBF'' Filename :');
Filename:=' ' ;
Readln(Filename);
{ Change to Upper Case }
For I := 1 to Name_length do
Filename[I] := UpCase(Filename[I]);
IF Exist(Filename+'.WBF') { See if file is on disk}
Then
Begin
If Exist(Filename+'.BAK') { erase old backup}
then begin
Assign(New_File,Filename+'.BAK');
Erase(New_File);
end;
Assign(Master_File,Filename+'.WBF'); {Create a backup }
Rename(Master_File,Filename+'.BAK'); {file of masterfile}
Assign(New_File,Filename+'.WBF'); {Open newfile in the }
{ oldfiles name }
Rewrite(New_File); { clear the new file }
Reset(Master_File); { point to start of master file }
No_Error := True; { there are no errors }
Remaining := Filesize(Master_File); {what is size of file}
While ( Remaining > 0 ) and No_Error do {do until EOF }
Begin
{ how much can we read from master file ?? }
If Bufsize <= Remaining Then
Recs_To_Read := Bufsize
Else
Recs_To_Read := Remaining;
{ Read the block of file and disable I/O errors }
{$I-} Blockread(Master_File,Buffer,Recs_To_Read) {$I+};
{ If there was an error then EOF has occurred }
If I or esult <> 0 Then No_Error := False;
{ Change all `change_char's to ESC }
For I:=1 To Recs_To_Read * 128 do
If Buffer[I] = Change_Char Then Buffer[I]:= 27;
{ Write the changed block of file to new file }
Blockwrite(New_File,Buffer,Recs_To_Read);
{ How much of Master File is left to read }
Remaining := Remaining - Recs_To_Read;
End; {of while loop}
Close(Master_File); {close files}
Close(New_File);
End {of if then}
Else {File does not exist. Produce Error.}
begin
writeln;writeln;
Writeln('..FILE_ERROR.. File ',filename,'.WBF does not exist.');
end;
End. { of program }