home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
ss.zip
/
ss.pas
< prev
Wrap
Pascal/Delphi Source File
|
1996-11-05
|
5KB
|
123 lines
Program SS;
uses dos,crt;
var x,y,z: integer;
uprcase, replace, chng, verbose : boolean;
ttt, yyy, filespec, searchstring, replacestring, curntline, cul: string; /*ttt and yyy is holdstrings */
curntfile, otf: text;
DirInfo: TSearchRec;
/*========-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
Procedure ErrExit; { Clean exit procedure }
Begin
TextBackground(2);
Writeln('SuperSearch v1.0.os2 - Text Search & Replace inside files by E.S. Dunckley 1994/9 ');
TextBackground(0);
Writeln('SS.EXE filespec searchstring replacesting [/c] ');
Writeln;
Writeln(' filespec - A valid filespec eg. *.ini or w*.bat');
Writeln(' searchstring - Any textstring NOT containing spaces');
Writeln(' replacestring - Any textstring NOT containting spaces');
Writeln(' /c - Do a case sensitive search (and replace)');
Writeln(' /v - Run in Verbose mode');
Writeln;
Writeln('eg. SS *.ini C: D: {Replaces all C:''s to D:''s in *.ini}');
Writeln(' SS A*.txt mystake mistake {Replaces a typo in all docs starting with A. }');
Halt(1);
End;
/*========-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
Begin
uprcase:=False;
verbose:=false;
replace:=true;
x:=paramcount;
if (x<2) then begin {Too little parameters to make sense }
Writeln('Error. Needs at least 2 parameters to process');
ErrExit;
End;
filespec:=paramstr(1);
searchstring:=paramstr(2);
replacestring:=paramstr(3);
if ((paramstr(4)='/v') or (replacestring='/v') or (paramstr(5)='/v')) then verbose:=true;
if ((paramstr(4)='/V') or (replacestring='/V') or (paramstr(5)='/V')) then verbose:=true;
if not ((replacestring='/C') or (paramstr(4)='/C') or (paramstr(5)='/C')
or (replacestring='c') or (paramstr(5)='c') or (paramstr(4)='c')) then begin
for z:=1 to length(searchstring) do searchstring[z]:=upcase(searchstring[z]);
if verbose then writeln('Running in UPPERCASE mode');
uprcase:=True;
end;
WriteLn('SearchString: ',searchstring);
if (replacestring='/c') or (replacestring='/C') or (replacestring='') then begin
replacestring:='';
if verbose then writeln('Running without replacing files - no replace string given');
replace:=false;
end;
if (uprcase and replace) then for z:=1 to length(replacestring) do replacestring[z]:=upcase(replacestring[z]);
if replace then writeln('Replace String: ',replacestring);
if (filespec='/?') or (filespec='/h') or (filespec='/H') or (filespec='-?') then begin
Writeln('SS.EXE - Search (and replace) ascii strings in files');
ErrExit;
End;
/*=Mainloop=======-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
FindFirst(filespec, Anyfile, DirInfo);
while DosError = 0 do
begin
Assign(curntfile,DirInfo.Name);
if replace then Assign(Otf,'$$SS.tmp');
if replace then Rewrite(otf);
Reset(curntfile);
if verbose then writeln('Opening file');
Chng:=false;
While not EOF(curntfile) do begin
Readln(curntfile,curntline);
cul:=curntline;
if uprcase then for z:=1 to length(cul) do cul[z]:=upcase(cul[z]);
if (pos(searchstring,cul)>0) then writeln(dirinfo.name,': ',curntline);
while (pos(searchstring,cul)>0) and (replace) do begin
Chng:=true;
y:=pos(searchstring,cul);
if replace then begin
ttt:=concat(copy(curntline,1,y-1));
/* writeln(ttt); */
yyy:=copy(curntline,y+length(searchstring),length(curntline)-y-length(searchstring)+1);
/* writeln(yyy); */
end;
if replace then curntline:=concat(ttt,replacestring,yyy);
/* curntline:=concat(copy(curntline,1,y-1),replacestring,copy(curntline,y+length(searchstring),length(curntline)-y-length(searchstring)+1)); */
if replace then writeln(curntline);
cul:=curntline;
if uprcase then for z:=1 to length(cul) do cul[z]:=upcase(cul[z]);
end;
if replace then writeln(otf,curntline);
end;
close(curntfile);
if verbose then writeln('Closing file');
if replace then begin
close(otf);
if chng then begin
if verbose then writeln('File needs updating, rewriting file');
Assign(curntfile,dirinfo.name);
rewrite(curntfile);
Assign(otf,'$$SS.tmp');
reset(otf);
while not eof(otf) do begin
readln(otf,curntline);
writeln(curntfile,curntline);
end;
close(otf);
close(curntfile);
chng:=false;
end;
end;
FindNext(DirInfo); /* Locate the next file to update */
end;
end.