home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
pascal
/
library
/
dos
/
btree
/
btv115
/
recover.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1992-06-04
|
5KB
|
218 lines
PROGRAM RECOVER;
{$V-,S-,R-,A-,I-,X-}
USES
CRT,
DOS,
BTV;
TYPE
{ declare an error display type }
ErrorType = Object(ErrorDisplay)
Function Display(Error : Integer;
ErrorMsg : String;
OpCode : Byte;
OpCodeMsg : String;
FileName : PathStr
): ErrorAction; Virtual;
end;
{ declare a progress display type }
TNewProgress = Object(TProgress)
X,Y : Byte;
Constructor Init;
Procedure Display(Count : LongInt); Virtual;
end;
VAR
ErrDisplay : ErrorType;
ErrHandler : ErrorHandler;
BFile : BtrieveFile;
i,j : Integer;
Name1 : PathStr;
Name2 : PathStr;
Param : PathStr;
Buff : Pointer;
Switch : Char;
Display : TNewProgress;
Procedure DosWriteln(S : String);
var
Regs : Registers;
Temp : Array[0..80] of Char;
SLen : Byte Absolute S;
begin
Move(S[1], Temp[0], SLen);
Temp[SLen] := #13;
Temp[SLen+1] := #10;
Temp[SLen+2] := '$';
Regs.DS := Seg(Temp);
Regs.DX := Ofs(Temp);
Regs.AH := $09;
{ call DOS int 21h function 09h to print the string because unlike
Turbo's Writeln this output will get redirected
}
MsDos(Regs);
end;
Procedure DosWrite(S : String);
var
Regs : Registers;
Temp : Array[0..80] of Char;
SLen : Byte Absolute S;
begin
Move(S[1], Temp[0], SLen);
Temp[SLen] := '$';
Regs.DS := Seg(Temp);
Regs.DX := Ofs(Temp);
Regs.AH := $09;
{ call DOS int 21h function 09h to print the string because unlike
Turbo's Writeln this output will get redirected
}
MsDos(Regs);
end;
Function ErrorType.Display(Error : Integer;
ErrorMsg : String;
OpCode : Byte;
OpCodeMsg : String;
FileName : PathStr
): ErrorAction;
var
St : String[5];
begin
DosWriteln(FileName);
Str(Error, St);
DosWriteln(ErrorMsg + '# ' + St);
Str(OpCode, St);
DosWriteln(OpCodeMsg + '# ' + St);
Display := erAbort;
end;
Constructor TNewProgress.Init;
begin
TProgress.Init;
X := WhereX;
Y := WhereY;
end;
Procedure TNewProgress.Display(Count : LongInt);
var
S : String[12];
begin
GotoXY(X,Y);
Str(Count, S);
DosWrite('Records so far ' + S);
end;
BEGIN
{ init command line params }
Name1 := '';
Name2 := '';
Switch := ' ';
{ load command line params }
for i := 1 to ParamCount do
begin
Param := ParamStr(i);
if (Param[1] = '-') or (Param[1] = '/') then
Delete(Param, 1,1);
for j := 1 to Length(Param) do
Param[j] := UpCase(Param[j]);
if (Param = 'R') then
Switch := 'R'
else if (Param = 'S') then
Switch := 'S'
else if (Param = 'L') then
Switch := 'L'
else if (Name1 = '') then
Name1 := Param
else if (Name2 = '') then
Name2 := Param;
end;
{ all params not specified }
if (ParamCount <> 3) or (Switch = ' ') or (Name1 = '') or (Name2 = '') then
begin
DosWriteln('Recover, Save or Load a Btrieve file');
DosWriteln('Usage : Recover -R <Btrieve Input File> <Btrieve Output file>');
DosWriteln(' Recover -S <Btrieve Input File> <DOS Output file>');
DosWriteln(' Recover -L <DOS Input File> <Btrieve Output file>');
Halt;
end;
{ make sure Btrieve is loaded }
CheckForBtrieve;
{ allocate file data buffer }
GetMem(Buff, $FFF0);
if (Buff = nil) then
begin
DosWriteln('Not enough memory!');
Halt;
end;
{ first make a error display }
ErrDisplay.Init;
{ make an error handler, it needs a display object }
ErrHandler.Init(@ErrDisplay);
{ init progress display }
Display.Init;
DosWriteln('');
{ execute selected option }
Case Switch of
'R' :
begin
BFile.Init(Name1, @ErrHandler, Buff, $FFF0);
BFile.Open(bReadOnly, '');
i := BFile.Recover(Name2, @Display);
end;
'S' :
begin
BFile.Init(Name1, @ErrHandler, Buff, $FFF0);
BFile.Open(bReadOnly, '');
i := BFile.Save(Name2, @Display);
end;
'L' :
begin
BFile.Init(Name2, @ErrHandler, Buff, $FFF0);
BFile.Open(bAccelerated, '');
i := BFile.Load(Name1, @Display);
end;
end;
DosWriteln('');
DosWriteln('');
if (i <> 0) then
DosWriteln('FAILURE!')
else
DosWriteln('SUCCESS!');
END.