fpkg.pas 3.0 KB

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