home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1999 August
/
Chip_1999-08_cd.bin
/
zkuste
/
Delphi
/
d3
/
edf
/
find
/
findstr.dpr
Wrap
Text File
|
1999-06-07
|
2KB
|
65 lines
{$APPTYPE CONSOLE}
program FindStr;
uses
Windows,
SysUtils,
HyperStr,
Crt_efd; //freeware at http://www.mindspring.com/~efd/tools.htm
{$R *.RES}
var
F,SS:AnsiString;
I,L:Integer;
H,M:THandle;
P,PP:PByte;
begin
WriteLn('HyperStr File Search Demo v1.0 (c)1998 EFD Systems');
if ParamCount<2 then begin
WriteLn('');
WriteLn('Syntax: FINDSTR FileName SearchString');
end else begin
F:=ParamStr(1); //file name
SS:=ParamStr(2); //search string
if FileExists(F) and (Length(SS)>0) then begin
H:=FileOpen(F,fmOpenReadWrite OR fmShareDenyNone);
if H<>0 then begin
M:=0;
try
P:=nil;
L:=GetFileSize(H,Nil);
if L>=Length(SS) then begin
M:=CreateFileMapping(H,nil,PAGE_READWRITE,0,L,nil);
P:=MapViewOfFile(M,FILE_MAP_ALL_ACCESS,0,0,L);
end else WriteLn('Invalid file');
finally
CloseHandle(H);
CloseHandle(M);
end;
if P<>nil then begin
try
WriteLn('Working...Please wait');
WriteLn('');
PP:=ScanBfr(P,SS,-L); //neg. length ignores case
while PP<>nil do begin
I:=Integer(PP)-Integer(P);
WriteLn('Offset '+IntToStr(I));
Inc(PP,Length(SS));
PP:=ScanBfrC(PP,SS,-(L-I-Length(SS)));
end;
finally
UnmapViewOfFile(P);
end;
end else WriteLn('File Mapping failed');;
end else WriteLn('File access error');
end else WriteLn('File not found/Invalid search string');
end;
WriteLn('');
Write('Press any key to continue . . .');
FlushInputBuffer;
ReadKey;
end.