proxyunit.pp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. {
  2. This file is part of the Free Component Library
  3. Copyright (c) 2022 by Michael Van Canneyt, [email protected]
  4. Generate a skeleton unit with namespaced name which defines FPC_DOTTEDUNITS and
  5. includes the original non-dotted unit.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. program proxyunit;
  13. uses StrUtils, SysUtils, Classes;
  14. Function MaybeExt(S : String) : String;
  15. begin
  16. Result:=S;
  17. if IndexText(ExtractFileExt(S),['.pas','.pp'])=-1 then
  18. Result:=Result+'.pp'
  19. end;
  20. Function MaybeStripExt(S : String) : String;
  21. begin
  22. Result:=S;
  23. if IndexText(ExtractFileExt(S),['.pas','.pp'])<>-1 then
  24. Result:=ChangeFileExt(Result,'')
  25. end;
  26. var
  27. aFile : TStrings;
  28. begin
  29. if (ParamCount<>2) then
  30. begin
  31. Writeln('Usage: dottedunit nondottedunit');
  32. Writeln('Default extension is .pp and is appended if needed');
  33. Halt(1);
  34. end;
  35. aFile:=TStringList.Create;
  36. try
  37. aFile.Add('unit '+MaybeStripExt(ExtractFileName(ParamStr(1)))+';');
  38. aFile.Add('{$DEFINE FPC_DOTTEDUNITS}');
  39. aFile.Add('{$i '+MaybeExt(ParamStr(2))+'}');
  40. aFile.SaveToFile(MaybeExt(ParamStr(1)));
  41. finally
  42. aFile.Free;
  43. end;
  44. end.