home *** CD-ROM | disk | FTP | other *** search
- (*
- ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓·── ──·▓▓▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓│ │░░▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓ USR was conceived, designed and written ░░▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓ by Floor A.C. Naaijkens for ░░▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓ UltiHouse Software / The ECO Group. ░░▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓ ░░▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓ (C) MCMXCII by EUROCON PANATIONAL CORPORATION. ░░▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓ All Rights Reserved for The ECO Group. ░░▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓│ │░░▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓·── ──·░░▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
- *)
- {$A-,B-,D-,E-,F-,I-,L-,N-,O-,R-,S-,V-}
- {$M 4096, 0, 40960}
-
-
- uses
- dos, crt,
- eco_srch, eco_lib
-
- ;
-
-
- const
- pk : boolean = false;
- lz : boolean = false;
- bor : boolean = false;
- pkchkstring = 'PKLITE Copr. 1990-91 PKWARE Inc. All Rights Reserved';
- borland6 = 'Portions_Copyright_(c)_1983,90_Borland';
- borland7 = 'Portions_Copyright_(c)_1983,92_Borland';
- lzchkstring = 'LZ91';
- junk = 'USRUǺ≈─»89W%$()P*(7¿gpè¼╨▐9)*-1`g>EG{}%${^}::"#@$:$#';
-
- var
- sb, ll, tl,
- filesiz,
- back : longint;
- startx,
- starty,
- index1,
- index2,
- i, bytes : word;
- cvtfile : file of char;
- c : char;
- tmp,
- chkstring,
- new,
- chk : string;
-
-
-
- procedure help;
- begin
- writeln;
- writeln('Usage: USR INFILE {SEARCHSTRING [REPLACEMENTMSG]} options');
- writeln(' Search for selected string, replacement if specified, padded with');
- writeln(' junk is inserted. Of course, no more than length(searchstring) bytes');
- writeln(' are used in the replacement. By default 2048 bytes are searched.');
- writeln;
- writeln('Options:');
- writeln(' /lz search for LZEXE header.');
- writeln(' /pk search for PKLITE header.');
- writeln(' /bor6 search for Turbo Pascal 6.0 header.');
- writeln(' /bor7 search for Borland Pascal 7.0 header.');
- writeln(' /r reverse: replace junk with header. (specify further as normal cvt)');
- writeln(' /s 0 search whole file');
- writeln(' /s xxxx search first xxxx bytes of file.');
- writeln(' /t do not translate _ into spaces in strings.');
- writeln(' Use /s as last option on the commandline');
- writeln;
- writeln('Examples:');
- writeln(' USR fil FIND search file for FIND');
- writeln(' USR fil FIND REPL search file for FIND, replace it with REPLACE');
- writeln(' USR fil /p search file for PKLITE header, replace that with junk');
- writeln(' USR fil /p JUNK /r search file for JUNKjunk header, replace that PKhdr');
- write (' USR fil /l REPL /s 500 search file''s first 5000 bytes for LZhdr, r/with REPL');
- readkey; halt(1);
- end;
-
-
-
- function seekposinfile: longint;
- var
- oldattr : word;
- sizeread : word;
- bufpointer,
- longbufpos : longint;
- casesensitive,
- nf : boolean;
- searchfile : file;
-
- begin
- assign(searchfile, paramstr(1));
- getfattr(searchfile, oldattr); setfattr(searchfile, archive);
- {$I-} reset(searchfile,1); {$I+}
- if ioresult<>0 then begin
- writeln('File not found / cannot be accessed.'); halt;
- end;
- target := chkstring; nf := false; casesensitive := true;
- make_boyer_moore_table(target, table1, table2, casesensitive);
- longbufpos := 0; seekposinfile := 0;
-
- repeat
- seek(searchfile, longbufpos);
- blockread(searchfile, buffer, maxbuffer, sizeread);
- maxpos := sizeread - ord(target[0]); bufpointer := 0;
- repeat
- i := boyer_moore_search(
- buffer, bufpointer, sizeread,
- target, table1, table2, casesensitive
- );
- if (i > 0) then begin
- bufpointer := i+length(target);
- if keypressed then if readkey = #27 then nf := true;
- seekposinfile := longbufpos + i;
- end
- until (i = 0) or (bufpointer > maxpos) or (sizeread=0) or nf;
- longbufpos := longbufpos + maxpos;
- until nf or (sizeread < maxbuffer);
- setfattr(searchfile, oldattr); close(searchfile);
- end;
-
-
-
- {main}begin
- if not __isconfil(__handlfil(output)) then __stdio;
- textcolor(yellow);
- writeln('USR - Universal String Replacement Utility -- Version 1.1');
- writeln('(C) MCMXCIII by UltiHouse Software / The ECO Group.');
- writeln('Part of the UltiGREP package: GSR, USR, QF, UGREP.');
- textcolor(lightgray);
- if (
- (paramcount = 0) or __inparams('/?', i) or
- __inparams('-?', i) or __inparams('?', i)
- ) then help;
-
- chkstring := pkchkstring; ll := length(pkchkstring);
-
- chkstring := paramstr(2);
- if chkstring[1] = '/' then begin { no searchstring specified }
- if __inparams('/pk', i) then begin
- pk := true; chkstring := pkchkstring
- end else if __inparams('/lz', i) then begin
- lz := true; chkstring := lzchkstring
- end else if __inparams('/bor6', i) then begin
- bor := true; chkstring := borland6;
- end else if __inparams('/bor7', i) then begin
- bor := true; chkstring := borland7;
- end else begin { no alternative, so: }
- writeln('No searchstring, no /pk, /lz /bor6 or /bor7 specified.');
- halt(0);
- end;
- end;
- ll := length(chkstring);
- if not __inparams('/t', i) then for i := 1 to ll do
- if chkstring[i] = '_' then chkstring[i] := ' ' else chkstring[i] := chkstring[i];
-
- tmp := paramstr(3);
- new := junk; { replacement also specified }
- if tmp[1] <> '/' then if not __inparams('/t', i) then
- for i := 1 to length(tmp) do
- if tmp[i] = '_' then new[i] := ' ' else new[i] := tmp[i];
- new[0] := chr(ll); { whatever, junk, or (partially) covered with user specs }
-
-
- filesiz := __sizefil(paramstr(1));
- sb := 2048;
- if __inparams('/s', i) then begin
- sb := __val(paramstr(i));
- if sb = 0 then sb := filesiz - ll - 1;
- if sb < ll then sb := ll + 1;
- write('Searching ', sb, ' bytes in a ');
- end else write('Searching in a ');
- if lz then writeln('LZEXE file.') else if pk then
- writeln('PKLITE file.') else if bor then writeln('Borland EXE-file.') else
- writeln('file.');
-
- if __inparams('/r', i) then begin
- tmp := chkstring; chkstring := new; new := tmp;
- writeln('Reverse mode --');
- write(
- ' ' + copy(paramstr(3), 1, ll) + ' + standaardjunk is' +#13#10 +
- ' replaced with a '
- );
- if pk then writeln('PKLITE header.') else
- if lz then writeln('LZEXE header.') else
- if bor then writeln('Borland EXE header.') else
- writeln('Original header');
- end;
-
-
-
-
- { SEARCHING }
- write('Seeking . . .'); chk := ''; bytes := 0;
- if (filesiz > 5000) and (sb > 2000) then begin
- write(' quick . . .');
- tl := seekposinfile;
- assign(cvtfile, paramstr(1)); reset(cvtfile); seek(cvtfile, tl);
- if tl > 0 then begin
- write(' found . . .'); chk := chkstring;
- end;
- end else begin
- assign(cvtfile, paramstr(1)); reset(cvtfile); read(cvtfile, c);
- while not(eof(cvtfile) or (chk = chkstring) or (bytes > sb)) do begin
- while not((c = chkstring[1]) or eof(cvtfile)) do begin
- read(cvtfile, c); inc(bytes);
- end;
- { char found, if not base of correct string, jump back to one after it }
- back := filepos(cvtfile) + 1;
- i := 1; chk := chkstring[1];
- while ((i < ll) and (chk[i]=chkstring[i]) and not(eof(cvtfile))) do begin
- read(cvtfile, c); chk := chk + c; inc(i); inc(bytes);
- end;
- if chk <> chkstring then seek(cvtfile, back);
- end;
- if chk = chkstring then seek(cvtfile, filepos(cvtfile) - ll);
- end;
-
-
-
- { REPLACEMENT }
- if chk = chkstring then begin
- write(' converting . . .');
- for i := 1 to ll do write(cvtfile, new[i]);
- writeln(' done.');
- end else begin
- writeln(' not found!');
- if pk then writeln('Not a PKLITE file.') else
- if lz then writeln('Not a LZEXE file.') else
- writeln('Not a file containing "', chkstring, '"');
- end;
- close(cvtfile);
- {happy}end.
- Old units:
- eco_ext, eco_fil,
- eco_str,
- unit_fil
-