replaceword.pp 841 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. program replaceword;
  2. {$mode objfpc}
  3. {$h+}
  4. uses regexpr,sysutils, classes;
  5. function ReplaceWord(aLine, aName, aFull: String): String;
  6. var
  7. RE : TRegExpr;
  8. begin
  9. RE:=TRegExpr.Create('\b'+aName+'\b');
  10. try
  11. // RE.ModifierI:=True;
  12. Result:=RE.Replace(aLine,aFull);
  13. // Writeln(aLine,': ',aName,' -> ',aFull,' = ',Result);
  14. finally
  15. RE.Free;
  16. end;
  17. end;
  18. var
  19. I,J : Integer;
  20. aMakeFile: TStrings;
  21. W1,W2,aFN : String;
  22. begin
  23. W1:=ParamStr(1);
  24. W2:=ParamStr(2);
  25. aMakeFile:=TStringList.Create;
  26. try
  27. for I:=3 to ParamCount do
  28. begin
  29. aFN:=Paramstr(I);
  30. aMakeFile.LoadFromFile(aFN);
  31. aMakeFile.SaveToFile(aFn+'.bak');
  32. For J:=0 to aMakefile.Count-1 do
  33. aMakefile[J]:=ReplaceWord(aMakefile[J],W1,W2);
  34. aMakeFile.SaveToFile(AFN);
  35. end;
  36. finally
  37. aMakeFile.Free;
  38. end;
  39. end.