fpkg.pas 2.9 KB

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