fixuses.pp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. {
  2. This file is part of the Free Component Library
  3. Copyright (c) 2022 by Michael Van Canneyt, [email protected]
  4. Take a uses clause from standard input,
  5. and replace it with a conditional uses clause that allows dotted and non-dotted units.
  6. To be used in shell scripts or to be invoked from an editor
  7. that allows you to filter a selection through a command.
  8. See the file COPYING.FPC, included in this distribution,
  9. for details about the copyright.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. **********************************************************************}
  14. program fixuses;
  15. uses classes, prefixer;
  16. Var
  17. aIn,aOut : TStrings;
  18. P : TPrefixer;
  19. S : String;
  20. begin
  21. if ParamStr(1)='' then
  22. begin
  23. Writeln('Error : need name of known namespaces');
  24. Halt(1);
  25. end;
  26. P:=nil;
  27. aOut:=nil;
  28. aIn:=TStringList.Create;
  29. try
  30. aOut:=TStringList.Create;
  31. While not EOF do
  32. begin
  33. ReadLn(S);
  34. aIn.Add(S);
  35. end;
  36. P:=TPrefixer.Create(Nil);
  37. P.KnownNameSpaces.LoadFromFile(ParamStr(1));
  38. P.ReworkUses(aIn,aOut);
  39. For S in aout do
  40. Writeln(S);
  41. finally
  42. aIn.Free;
  43. aOut.Free;
  44. P.Free;
  45. end;
  46. end.