fpkg.pas 3.1 KB

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