fpkg.pas 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. {
  2. Copyright (c) 2013-2014 by Free Pascal Development Team
  3. This unit implements basic parts of the package system
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  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. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit fpkg;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. cclasses,
  22. globtype,
  23. finput;
  24. type
  25. tcontainedunit=record
  26. module:tmodulebase;
  27. ppufile:tpathstr;
  28. end;
  29. pcontainedunit=^tcontainedunit;
  30. tpackage=class
  31. public
  32. realpackagename,
  33. packagename : pshortstring;
  34. containedmodules : TFPHashList;
  35. requiredpackages : TFPHashObjectList;
  36. pcpfilename,
  37. ppafilename,
  38. pplfilename : tpathstr;
  39. constructor create(const pn:string);
  40. destructor destroy;override;
  41. end;
  42. tpackageentry=record
  43. package : tpackage;
  44. realpkgname : string;
  45. usedunits : longint;
  46. end;
  47. ppackageentry=^tpackageentry;
  48. implementation
  49. uses
  50. cutils,globals;
  51. { tpackage }
  52. constructor tpackage.create(const pn: string);
  53. begin
  54. realpackagename:=stringdup(pn);
  55. packagename:=stringdup(upper(pn));
  56. containedmodules:=TFPHashList.Create;
  57. requiredpackages:=TFPHashObjectList.Create(false);
  58. end;
  59. destructor tpackage.destroy;
  60. var
  61. p : pcontainedunit;
  62. i : longint;
  63. begin
  64. if assigned(containedmodules) then
  65. for i:=0 to containedmodules.count-1 do
  66. begin
  67. p:=pcontainedunit(containedmodules[i]);
  68. dispose(p);
  69. end;
  70. containedmodules.free;
  71. requiredpackages.free;
  72. inherited destroy;
  73. end;
  74. procedure packageinit;
  75. begin
  76. packagelist:=TFPHashList.Create;
  77. end;
  78. procedure packagedone;
  79. var
  80. i : longint;
  81. pkgentry : ppackageentry;
  82. begin
  83. if assigned(packagelist) then
  84. begin
  85. for i:=0 to packagelist.count-1 do
  86. begin
  87. pkgentry:=ppackageentry(packagelist[i]);
  88. pkgentry^.package.free;
  89. dispose(pkgentry);
  90. end;
  91. end;
  92. packagelist.Free;
  93. packagelist:=nil;
  94. end;
  95. initialization
  96. register_initdone_proc(@packageinit,@packagedone);
  97. end.