home *** CD-ROM | disk | FTP | other *** search
/ Chip 1999 August / Chip_1999-08_cd.bin / zkuste / Delphi / d3 / edf / find / findstr.dpr
Text File  |  1999-06-07  |  2KB  |  65 lines

  1. {$APPTYPE CONSOLE}
  2.  
  3. program FindStr;
  4.  
  5. uses
  6.   Windows,
  7.   SysUtils,
  8.   HyperStr,
  9.   Crt_efd;  //freeware at http://www.mindspring.com/~efd/tools.htm
  10.  
  11. {$R *.RES}
  12.  
  13. var
  14.   F,SS:AnsiString;
  15.   I,L:Integer;
  16.   H,M:THandle;
  17.   P,PP:PByte;
  18.  
  19. begin
  20.   WriteLn('HyperStr File Search Demo v1.0 (c)1998 EFD Systems');
  21.   if ParamCount<2 then begin
  22.     WriteLn('');
  23.     WriteLn('Syntax: FINDSTR FileName SearchString');
  24.   end else begin
  25.     F:=ParamStr(1);  //file name
  26.     SS:=ParamStr(2); //search string
  27.     if FileExists(F) and (Length(SS)>0) then begin
  28.       H:=FileOpen(F,fmOpenReadWrite OR fmShareDenyNone);
  29.       if H<>0 then begin
  30.         M:=0;
  31.         try
  32.           P:=nil;
  33.           L:=GetFileSize(H,Nil);
  34.           if L>=Length(SS) then begin
  35.             M:=CreateFileMapping(H,nil,PAGE_READWRITE,0,L,nil);
  36.             P:=MapViewOfFile(M,FILE_MAP_ALL_ACCESS,0,0,L);
  37.           end else WriteLn('Invalid file');
  38.         finally
  39.           CloseHandle(H);
  40.           CloseHandle(M);
  41.         end;
  42.         if P<>nil then begin
  43.           try
  44.             WriteLn('Working...Please wait');
  45.             WriteLn('');
  46.             PP:=ScanBfr(P,SS,-L);  //neg. length ignores case
  47.             while PP<>nil do begin
  48.               I:=Integer(PP)-Integer(P);
  49.               WriteLn('Offset '+IntToStr(I));
  50.               Inc(PP,Length(SS));
  51.               PP:=ScanBfrC(PP,SS,-(L-I-Length(SS)));
  52.             end;
  53.           finally
  54.             UnmapViewOfFile(P);
  55.           end;
  56.         end else WriteLn('File Mapping failed');;
  57.       end else WriteLn('File access error');
  58.     end else WriteLn('File not found/Invalid search string');
  59.   end;
  60.   WriteLn('');
  61.   Write('Press any key to continue . . .');
  62.   FlushInputBuffer;
  63.   ReadKey;
  64. end.
  65.