home *** CD-ROM | disk | FTP | other *** search
- (*
- ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓·── ──·▓▓▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓│ │░░▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓ GSR 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. ░░▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓ ░░▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓ Global Search and Replace uses a library file ░░▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓ to search for certain words/patterns and ░░▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓ places them with a translation. Multiple files. ░░▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓│ │░░▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓·── ──·░░▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
- ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
- *)
- {$A-,B-,D-,E-,F+,I-,L-,N-,O-,R-,S-,V-}
- {$M 65520, 0, 655360}
-
- uses
- dos, crt, eco_lib
-
- ;
-
-
-
- type
- str80 = string[80];
- heap = array[1..2000] of ^str80;
- buftype = array[1..32768] of char;
-
-
- const
- reppos : byte = 41;
- numfiles : word = 0;
- fctotal : word = 0;
-
- var
- allfiles : array[1..2048] of ^searchrec;
- nextfile : searchrec;
- inbuf, outbuf : ^buftype;
- first, makebak,
- questionmode, show,
- debugmode,initques,
- sensi, quit : boolean;
- b : word;
- reps, k, totreps,
- libentries, fc,
- i, j, match,
- error, nrs : word;
- numbytes : longint;
- tmps, st,
- librar,
- out_filename,
- in_filename : string;
-
- check, replace : heap;
-
- in_file, out_file,
- check_file : text;
-
-
-
- function __trail(s: string): string;
- var i : byte;
- begin
- i := length(s); while s[i] = ' ' do dec(i);
- __trail := copy(s, 1, i);
- end;
-
-
-
- function __case(s: string): string;
- begin
- if not sensi then __case := __up(s) else __case := s;
- end;
-
-
-
- procedure microhelp;
- begin
- writeln('GSR - Global Search & Replace Utility -- Version 1.0');
- writeln('(C) MCMXCII by UltiHouse Software / The ECO Group.');
- writeln('Part of the UltiGREP package: GSR, USR, QF, UGREP.');
- end;
-
-
-
- procedure help;
- begin
- writeln;
- writeln('Usage: GSR INTEXT {librar | /r} {options}');
- writeln;
- writeln(' Search for strings in librar (default: gsr_std.lib) and replaces');
- writeln(' each occurence with replacement string. librar layout: each string');
- writeln(' contains in pos(1) the searchstring, and in pos(41) the replacement.');
- writeln(' No more than 2000 entities may be specified.');
- writeln;
- writeln('Options:');
- writeln(' /b create backupfiles.');
- writeln(' /c search casesensitive.');
- writeln(' /d debugmode: shows info during scan.');
- writeln(' /p xx position replacmentstring on line (up to 80, line 160).');
- writeln(' /q questionmode after each find, whether you want replacement.');
- writeln(' /r special option (note place) to have user specify s&r');
- writeln(' /s show strings on screen. (one line)');
- writeln;
- writeln('During operation, <Esc> will bring you back to the OS.');
- writeln; halt;
- end;
-
-
-
- procedure scroll;
- var x, y: byte;
- begin
- y := wherey; x := wherex; gotoxy(1, 25); clreol; writeln; gotoxy(x, y)
- end;
-
-
-
- procedure curstr;
- begin
- textcolor(7); textbackground(0);
- gotoxy(1, wherey); write(copy(st, 1, 79)); clreol;
- end;
-
-
-
- procedure userlibrar;
- var
- eoinput : boolean;
- st, st1, st2 : string;
- i : byte;
- c : char;
- libtext : text;
-
- begin
- eoinput := false; libentries := 0;
- writeln('Enter librar:');
- repeat
- write('Search: '); readln(st1);
- if st1 = '' then eoinput := true else begin
- write('Replace: '); readln(st2);
- inc(libentries); new(check[libentries]); new(replace[libentries]);
- check[libentries]^ := __trail(st1);
- replace[libentries]^ := __trail(st2);
- end;
- until eoinput;
- write('Save this into librar? (Y/N/Q) ');
- repeat c := readkey until upcase(c) in ['Y', 'N', 'Q'];
- writeln(upcase(c));
- if upcase(c) = 'Y' then begin
- write('Name (No .LIB needed) ? ');
- readln(st);
- if pos('.', __extractname(st)) = 0 then st := fexpand(st + '.LIB');
- writeln('Writing ', st);
- assign(libtext, st); rewrite(libtext);
- for i := 1 to libentries do writeln(libtext,
- __juststr(check[i]^, ' ', 40, _left_just_str) +
- __juststr(replace[i]^, ' ', 40, _left_just_str)
- );
- close(libtext);
- end else if upcase(c) = 'Q' then halt;
- end;
-
-
-
- function yesanswer: boolean;
- var
- c : char;
- oldy : byte;
-
- begin
- oldy := wherey;
- if (oldy > 24) and first then begin scroll; gotoxy(1, 24) end;
- curstr; gotoxy(j, wherey); textcolor(0); textbackground(7);
- write(copy(check[i]^, 1, 80-j)); gotoxy(1, 25);
- write('File: ', __extractname(in_filename), ' Reps: ', reps,
- ' Pos: ', fc, ':', j,
- ' Rep: "', copy(replace[i]^, 1, 14), '" Replace Y/G/N/Q '
- );
- clreol; textcolor(7); textbackground(0); __flushkey;
- repeat c := readkey until upcase(c) in ['Y', 'G' ,'N', 'Q'];
- yesanswer := upcase(c) in ['Y', 'G']; write(upcase(c));
- if upcase(c) = 'G' then questionmode := false;
- if upcase(c) = 'Q' then quit := true;
- first := false;
- if (oldy >= 24) then gotoxy(1, 24) else gotoxy(1, oldy);
- end;
-
-
- procedure chkesc;
- begin
- if keypressed and (readkey = #27) then begin
- __erasefil(out_filename, error); halt
- end;
- end;
-
-
-
-
- {main}begin
- if not __isconfil(__handlfil(output)) then __stdio;
- textcolor(yellow); microhelp; textcolor(lightgray);
- if __inparams('?', b) or __inparams('/?', b) or __inparams('-?', b) then help;
-
- if __inparams('/p', b) then begin
- reppos := __val(paramstr(b));
- writeln('Replacement position set to: ', reppos);
- end;
-
- new(inbuf); new(outbuf);
- show := false;
- sensi := __inparams('/c', b);
- questionmode := __inparams('/q', b);
- initques := questionmode;
- show := questionmode or __inparams('/s', b);
- debugmode := __inparams('/d', b);
- makebak := __inparams('/b', b);
-
-
- if paramcount > 1 then st := paramstr(2); { read librar }
- if st = '/r' then userlibrar else begin
- if (st[1] <> '/') and (paramcount > 1) then librar := __up(st) else
- librar := __backapp(__extractpath(paramstr(0))) + 'GSR_STD.LIB';
- if pos('.', librar) = 0 then librar := librar + '.LIB';
- write('Searching librar: ', librar);
- if not __existfil(librar) then begin
- writeln(' -- Error - librar not found!'); halt(1)
- end;
- assign(check_file, librar); reset(check_file);
- settextbuf(check_file, inbuf^);
- libentries := 0;
- repeat
- readln(check_file, tmps);
- if __nw(tmps) <> '' then begin
- inc(libentries); new(check[libentries]); new(replace[libentries]);
- check[libentries]^ := __trail(copy(tmps, 1, reppos-1));
- replace[libentries]^ := __trail(copy(tmps, reppos, reppos-1));
- end;
- until eof(check_file); close(check_file);
- end;
- writeln('... read.');
-
- if paramcount > 0 then tmps := paramstr(1) else tmps := '*.*';
- if tmps[1] <> '/' then in_filename := fexpand(tmps) else
- in_filename := fexpand('*.PAS');
- match := 0;
- if pos('.', in_filename) = 0 then in_filename := in_filename + '.PAS';
- findfirst(in_filename, anyfile, nextfile); numbytes := 0;
- while doserror = 0 do begin { not using "notnone" or "only" attrs }
- if (
- __attrfilter(nextfile.attr, archive + readonly + hidden) and
- __existfil(nextfile.name)
- ) then begin
- inc(numfiles); new(allfiles[numfiles]);
- allfiles[numfiles]^ := nextfile; inc(numbytes, nextfile.size);
- end;
- findnext(nextfile);
- end; { allfiles }
-
- if numfiles = 0 then begin
- writeln('Error - No inputfile(s) found.'); halt
- end;
- writeln(numfiles, ' files found, ', __pntstr(numbytes), ' bytes.');
- totreps := 0;
- for k := 1 to numfiles do begin
- reps := 0;
- out_filename := fexpand('');
- __uniquefil(out_filename, out_file, error);
- if sensi then writeln('Case sensitive mode');
- if debugmode then writeln('debugmode mode.');
- if questionmode then clrscr;
-
- assign(in_file, allfiles[k]^.name); reset(in_file);
- assign(out_file, out_filename); rewrite(out_file);
- gotoxy(6, wherey);
- if not questionmode then write(
- fexpand(__up(allfiles[k]^.name)) + ' '
- );
- textcolor(lightgray);
- settextbuf(in_file, inbuf); settextbuf(out_file, outbuf^);
- fc := 0; quit := false;
-
- while not(eof(in_file) or quit) do begin
- readln(in_file, st);
- inc(fc); if fc mod 7 = 0 then begin gotoxy(1, wherey); write(fc) end;
- chkesc;
-
- first := true;
-
- for i := 1 to libentries do begin { recurse though string }
- if not quit then begin
- j := 1;
- repeat
- if debugmode then writeln(st);
- b := pos(__case(check[i]^), __case(copy(st, j, length(st)-j+1)));
- if b > 0 then j := b + j - 1 else j := 0;
- if debugmode then begin
- if j < 78 then gotoxy(j, wherey) else gotoxy(77, wherey);
- writeln('Lib: ', i, ' Line: ', fc, ' Linepos = ', j);
- end;
-
- if (j > 0) then if not(questionmode and not yesanswer) then begin
- delete(st, j, length(check[i]^)); insert(replace[i]^, st, j);
- inc(j, length(replace[i]^)); inc(reps);
- end else inc(j, length(check[i]^));
- chkesc;
- until (j = 0) or (j >= length(st)) or quit;
- end;
- end;
- if show then curstr;
- if questionmode then writeln;
- { if (wherey < 25) or (not(questionmode) and initques) then writeln;}
- writeln(out_file, st);
- end;
- gotoxy(1, wherey);
- write(fc); gotoxy(50, wherey); inc(totreps, reps); write('R:', reps);
- close(in_file); close(out_file);
- if not quit then begin
- if makebak then __renamfil(
- allfiles[k]^.name, fexpand(__bak(allfiles[k]^.name)), error
- ) else erase(in_file);
- rename(out_file, allfiles[k]^.name);
- end else __erasefil(out_filename, error);
- writeln;
- inc(fctotal, fc);
- end; { for k }
-
- gotoxy(1, wherey);
- write(fctotal, ' lines, ', libentries, ' librar entries and ',
- totreps, ' replacements in ', copy(getlaptime(0), 1, 8)
- );
- clreol; writeln;
- {happy}end.
-