fpkg.pas 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. {
  2. Copyright (c) 2013-2016 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. offset:longint;
  29. size:longint;
  30. end;
  31. pcontainedunit=^tcontainedunit;
  32. tpackage=class
  33. public
  34. realpackagename,
  35. packagename : pshortstring;
  36. containedmodules : TFPHashList;
  37. requiredpackages : TFPHashObjectList;
  38. pcpfilename,
  39. ppafilename,
  40. pplfilename : tpathstr;
  41. constructor create(const pn:string);
  42. destructor destroy;override;
  43. end;
  44. tpackageentry=record
  45. package : tpackage;
  46. realpkgname : string;
  47. usedunits : longint;
  48. direct : boolean;
  49. end;
  50. ppackageentry=^tpackageentry;
  51. implementation
  52. uses
  53. cutils,globals;
  54. { tpackage }
  55. constructor tpackage.create(const pn: string);
  56. begin
  57. realpackagename:=stringdup(pn);
  58. packagename:=stringdup(upper(pn));
  59. containedmodules:=TFPHashList.Create;
  60. requiredpackages:=TFPHashObjectList.Create(false);
  61. end;
  62. destructor tpackage.destroy;
  63. var
  64. p : pcontainedunit;
  65. i : longint;
  66. begin
  67. if assigned(containedmodules) then
  68. for i:=0 to containedmodules.count-1 do
  69. begin
  70. p:=pcontainedunit(containedmodules[i]);
  71. dispose(p);
  72. end;
  73. containedmodules.free;
  74. requiredpackages.free;
  75. inherited destroy;
  76. end;
  77. procedure packageinit;
  78. begin
  79. packagelist:=TFPHashList.Create;
  80. end;
  81. procedure packagedone;
  82. var
  83. i : longint;
  84. pkgentry : ppackageentry;
  85. begin
  86. if assigned(packagelist) then
  87. begin
  88. for i:=0 to packagelist.count-1 do
  89. begin
  90. pkgentry:=ppackageentry(packagelist[i]);
  91. pkgentry^.package.free;
  92. dispose(pkgentry);
  93. end;
  94. end;
  95. packagelist.Free;
  96. packagelist:=nil;
  97. end;
  98. initialization
  99. register_initdone_proc(@packageinit,@packagedone);
  100. end.