-
Notifications
You must be signed in to change notification settings - Fork 0
/
LRFP.PAS
150 lines (143 loc) · 4.31 KB
/
LRFP.PAS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
{$I-} {$A+} {$R-} {$S-} {$Q-} {$G+} {$N+} {$E-} {$D+} {$L-} {$Y-} {$X-}
Program LRFP;
Uses
LMem, LUtils, LRF;
Const
CUsageText = 'Usage: lrfp.exe am resfilename mask' + Chr(13) + Chr(10) +
'Or lrfp.exe al resfilename listfilename' + Chr(13) + Chr(10) +
'Or lrfp.exe e resfilename subfilename' + Chr(13) + Chr(10) +
'Or lrfp.exe ea resfilename' + Chr(13) + Chr(10) +
'Or lrfp.exe d resfilename subfilename';
CAddText = 'added';
CDeleteText = 'deleted';
CExtractText = 'extracted';
COverwrite = 'file is already exist. Overwrite? [Y/N]?: ';
CSkipped = 'file skipped';
Procedure AddFileByMask(Var AResP: TResP; Var ADTAP: TDTARecP; AMask: String);
Begin
FindFirstFile(ADTAP, AMask);
While ADTAP^.FErrCode = 0 Do Begin
AddFileToRF(AResP, GetDTAName(ADTAP));
If GetErr(AResP) <> TRE_Ok Then Begin
WriteLn(GetDTAName(ADTAP) + ' - ' + LRF.CLRFErrMsgs[Byte(GetErr(AResP))]);
ClearErr(AResP);
End
Else
WriteLn(GetDTAName(ADTAP) + ' - ' + CAddText);
FindNextFile(ADTAP);
End;
ADTAP:= DestroyBuf(ADTAP);
End;
Procedure Check_N_CreateRes(Var AResP: TResP; Var AFName: String);
Begin
CreateRes(AResP);
OpenRF(AResP, AFName);
If GetErr(AResP) <> TRE_OK Then Begin
ClearErr(AResP);
CreateRF(AResP, AFName);
End;
End;
Procedure ReportResError(Var AResP: TResP; ABool: Boolean);
Begin
If Not ABool Or (GetErr(AResP) = TRE_Ok) Then Exit;
WriteLn(LRF.CLRFErrMsgs[Byte(GetErr(AResP))]);
Halt(Byte(GetErr(AResP)));
End;
Procedure ExtractPromptOverwrite(Var AResP: TResP; AFName: String);
Var
Tex: String;
Begin
Write(AFName, ' - ', COverwrite);
ReadLn(Tex);
If UpperCase(Tex) = 'Y' Then Begin
ExtractFromRF(AResP, AFName);
ReportResError(AResP, True);
WriteLn(AFName, ' - ', CExtractText);
End
Else
WriteLn(AFName, ' - ', CSkipped);
End;
Procedure G_n_R_Sex_Drugs_n_Rock_n_Roll;
Var
DTAP: TDTARecP;
Par1, Par2, Par3, Tex: String;
FD: Text;
ResP: TResP;
Begin
Par1:= UpperCase(ParamStr(1));
Par2:= UpperCase(ParamStr(2));
Par3:= UpperCase(ParamStr(3));
If Par1 = 'AL' Then Begin
If Not IsFileExist(Par3) Then Begin
WriteLn('>list file ' + Par3 + ' not exist');
Halt(2);
End;
Assign(FD, Par3);
Reset(FD);
Check_N_CreateRes(ResP, Par2);
While Not EOF(FD) Do Begin
ReadLn(FD, Tex);
AddFileByMask(ResP, DTAP, Tex);
End;
Close(FD);
DestroyRes(ResP);
End
Else If Par1 = 'AM' Then Begin
Check_N_CreateRes(ResP, Par2);
AddFileByMask(ResP, DTAP, Par3);
DestroyRes(ResP);
End
Else If Par1 = 'E' Then Begin
CreateRes(ResP);
OpenRF(ResP, Par2);
ReportResError(ResP, True);
If IsFileExist(Par3) Then
ExtractPromptOverwrite(ResP, Par3)
Else Begin
ExtractFromRF(ResP, Par3);
ReportResError(ResP, True);
WriteLn(Par3, ' - ', CExtractText);
End;
DestroyRes(ResP);
End
Else If Par1 = 'EA' Then Begin
CreateRes(ResP);
OpenRF(ResP, Par2);
ReportResError(ResP, True);
OpenFirstSF(ResP);
ReportResError(ResP, True);
If IsFileExist(SFName(ResP)) Then
ExtractPromptOverwrite(ResP, SFName(ResP))
Else Begin
ExtractFromRF(ResP, SFName(ResP));
ReportResError(ResP, True);
WriteLn(SFName(ResP), ' - ', CExtractText);
End;
While OpenNextSF(ResP) <> 0 Do Begin
If IsFileExist(SFName(ResP)) Then
ExtractPromptOverwrite(ResP, SFName(ResP))
Else Begin
ExtractFromRF(ResP, SFName(ResP));
ReportResError(ResP, True);
WriteLn(SFName(ResP), ' - ', CExtractText);
End;
End;
DestroyRes(ResP);
End
Else If Par1 = 'D' Then Begin
CreateRes(ResP);
OpenRF(ResP, Par2);
ReportResError(ResP, True);
DeleteFromRF(ResP, Par3);
ReportResError(ResP, True);
WriteLn(Par3, ' - ', CDeleteText);
DestroyRes(ResP);
End
Else Begin
WriteLn(CUsageText);
ReadLn;
End;
End;
Begin
G_n_R_Sex_Drugs_n_Rock_n_Roll;
End.