fpkg.pas 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. end;
  46. ppackageentry=^tpackageentry;
  47. implementation
  48. uses
  49. cutils,globals;
  50. { tpackage }
  51. constructor tpackage.create(const pn: string);
  52. begin
  53. realpackagename:=stringdup(pn);
  54. packagename:=stringdup(upper(pn));
  55. containedmodules:=TFPHashList.Create;
  56. requiredpackages:=TFPHashObjectList.Create(false);
  57. end;
  58. destructor tpackage.destroy;
  59. var
  60. p : pcontainedunit;
  61. i : longint;
  62. begin
  63. if assigned(containedmodules) then
  64. for i:=0 to containedmodules.count-1 do
  65. begin
  66. p:=pcontainedunit(containedmodules[i]);
  67. dispose(p);
  68. end;
  69. containedmodules.free;
  70. requiredpackages.free;
  71. inherited destroy;
  72. end;
  73. procedure packageinit;
  74. begin
  75. packagelist:=TFPHashList.Create;
  76. end;
  77. procedure packagedone;
  78. var
  79. i : longint;
  80. pkgentry : ppackageentry;
  81. begin
  82. if assigned(packagelist) then
  83. begin
  84. for i:=0 to packagelist.count-1 do
  85. begin
  86. pkgentry:=ppackageentry(packagelist[i]);
  87. pkgentry^.package.free;
  88. dispose(pkgentry);
  89. end;
  90. end;
  91. packagelist.Free;
  92. packagelist:=nil;
  93. end;
  94. initialization
  95. register_initdone_proc(@packageinit,@packagedone);
  96. end.