addnamespacetofpmake.pp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. {
  2. This file is part of the Free Component Library
  3. Copyright (c) 2022 by Michael Van Canneyt, [email protected]
  4. Utility to add a statement to add a namespace to a fpmake program file for FPC packages.
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. program addnamespacetofpmake;
  12. uses classes, sysutils;
  13. const
  14. namespacelist = 'namespaces.lst';
  15. Function HandleFile(const aFileName : string) : boolean;
  16. Var
  17. aFile : TStringList;
  18. I : Integer;
  19. aLine : string;
  20. begin
  21. Result:=False;
  22. aFile:=TStringList.Create;
  23. try
  24. aFile.LoadFromFile(aFileName);
  25. i:=aFile.Count-1;
  26. while (I>=0) and not Result do
  27. begin
  28. aLine:=aFile[i];
  29. if pos('{$ifndef ALLPACKAGES}',aLine)>0 then
  30. if Pos('run',Lowercase(aFile[i+1]))>0 then
  31. begin
  32. aFile.Insert(I,'');
  33. aFile.Insert(I,Format(' P.NamespaceMap:=''%s'';',[namespacelist]));
  34. aFile.Insert(I,'');
  35. Result:=True;
  36. end;
  37. Dec(I);
  38. end;
  39. if Result then
  40. aFile.SaveToFile(aFileName);
  41. finally
  42. aFile.Free;
  43. end;
  44. end;
  45. var
  46. I : Integer;
  47. begin
  48. for I:=1 to ParamCount do
  49. if not handleFile(Paramstr(i)) then
  50. Writeln('Could not modify file: ',Paramstr(i));
  51. end.