home *** CD-ROM | disk | FTP | other *** search
- { This is a simple demo for STRINGS.TPU copyright 1989 by Richard Winkel }
- program scanfor;
- uses strings;
- type buftype=array[0..$FFF0] of char;
- var i,p,cnt,size,inlen:word;
- fstr:string;
- offset:longint;
- args:string;
- parms:^string;
- dlm:char;
- buf,blkptr:^buftype;
- infile:file;
-
- procedure help;
- begin
- writeln('Syntax: SCANFOR /target string/ IN file');
- writeln('Finds all occurrances of the target string in the specified file.');
- writeln('Use any unique characters to delimit the target string.');
- halt;
- end;
-
- begin
- parms:=ptr(prefixseg,$80);
- args:=strip(parms^,'b',' ');
- if (args='?') or (length(args)=0) then help;
- dlm:=args[1];
- i:=firstpos(dlm,args,2); if i=0 then help;
- fstr:=substr(args,2,i-2);
- args:=substr(args,i+1,255);
- if (uppercase(werd(args,1))<>'IN') or (words(args)<>2) then help;
- assign(infile,werd(args,2));
- if maxavail>$FFF1 then size:=$FFF1 else size:=maxavail;
- getmem(buf,size);
- reset(infile,1);
- offset:=0;
- repeat
- blockread(infile,buf^,size,inlen);
- blkptr:=buf; cnt:=inlen;
- repeat
- p:=scanmem(fstr,blkptr,cnt);
- if p<$FFFF then begin
- writeln('Found at file offset ',offset+ofs(blkptr^)+p-ofs(buf^));
- cnt:=cnt-p-1;
- blkptr:=@blkptr^[p+1];
- end;
- until p=$FFFF;
- offset:=offset+inlen;
- until eof(infile);
- close(infile);
- freemem(buf,size);
- end.