ppufiles.pp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. {
  2. $Id$
  3. Copyright (c) 1999-2002 by Peter Vreman
  4. List files needed by PPU
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************}
  17. Program ppufiles;
  18. uses
  19. dos,
  20. ppu;
  21. const
  22. Version = 'Version 1.00';
  23. Title = 'PPU-Files';
  24. Copyright = 'Copyright (c) 1999-2002 by the Free Pascal Development Team';
  25. PPUExt = 'ppu';
  26. type
  27. poutfile = ^toutfile;
  28. toutfile = record
  29. name : string;
  30. next : poutfile;
  31. end;
  32. var
  33. skipdup,
  34. showstatic,
  35. showshared,
  36. showobjects : boolean;
  37. OutFiles : poutfile;
  38. {*****************************************************************************
  39. Helpers
  40. *****************************************************************************}
  41. Procedure Error(const s:string;stop:boolean);
  42. {
  43. Write an error message to stderr
  44. }
  45. begin
  46. {$ifdef FPC}
  47. writeln(stderr,s);
  48. {$else}
  49. writeln(s);
  50. {$endif}
  51. if stop then
  52. halt(1);
  53. end;
  54. Function AddExtension(Const HStr,ext:String):String;
  55. {
  56. Return a filename which will have extension ext added if no
  57. extension is found
  58. }
  59. var
  60. j : longint;
  61. begin
  62. j:=length(Hstr);
  63. while (j>0) and (Hstr[j]<>'.') do
  64. dec(j);
  65. if j=0 then
  66. AddExtension:=Hstr+'.'+Ext
  67. else
  68. AddExtension:=HStr;
  69. end;
  70. Function SplitPath(Const HStr:String):String;
  71. var
  72. i : longint;
  73. begin
  74. i:=Length(Hstr);
  75. while (i>0) and not(Hstr[i] in ['\','/']) do
  76. dec(i);
  77. SplitPath:=Copy(Hstr,1,i);
  78. end;
  79. Procedure AddFile(const s:string);
  80. var
  81. p : poutfile;
  82. begin
  83. p:=nil;
  84. if skipdup then
  85. begin
  86. p:=outfiles;
  87. while assigned(p) do
  88. begin
  89. if s=p^.name then
  90. break;
  91. p:=p^.next;
  92. end;
  93. end;
  94. if not assigned(p) then
  95. begin
  96. new(p);
  97. p^.name:=s;
  98. p^.next:=outfiles;
  99. outfiles:=p;
  100. end;
  101. end;
  102. Function DoPPU(const PPUFn:String):Boolean;
  103. {
  104. Convert one file (in Filename) to library format.
  105. Return true if successful, false otherwise.
  106. }
  107. Var
  108. inppu : tppufile;
  109. b : byte;
  110. procedure showfiles;
  111. begin
  112. while not inppu.endofentry do
  113. begin
  114. AddFile(inppu.getstring);
  115. inppu.getlongint;
  116. end;
  117. end;
  118. begin
  119. DoPPU:=false;
  120. inppu:=tppufile.create(PPUFn);
  121. if not inppu.openfile then
  122. begin
  123. inppu.free;
  124. Error('Error: Could not open : '+PPUFn,false);
  125. Exit;
  126. end;
  127. { Check the ppufile }
  128. if not inppu.CheckPPUId then
  129. begin
  130. inppu.free;
  131. Error('Error: Not a PPU File : '+PPUFn,false);
  132. Exit;
  133. end;
  134. if inppu.GetPPUVersion<CurrentPPUVersion then
  135. begin
  136. inppu.free;
  137. Error('Error: Wrong PPU Version : '+PPUFn,false);
  138. Exit;
  139. end;
  140. { read until the object files are found }
  141. repeat
  142. b:=inppu.readentry;
  143. case b of
  144. ibendinterface,
  145. ibend :
  146. break;
  147. iblinkunitstaticlibs :
  148. if showstatic then
  149. showfiles;
  150. iblinkunitsharedlibs :
  151. if showshared then
  152. showfiles;
  153. iblinkunitofiles :
  154. if showobjects then
  155. showfiles;
  156. end;
  157. until false;
  158. inppu.free;
  159. DoPPU:=True;
  160. end;
  161. var
  162. i,parafile : longint;
  163. dir : SearchRec;
  164. s,InFile : String;
  165. p : poutfile;
  166. begin
  167. { defaults }
  168. skipdup:=true;
  169. { options }
  170. i:=1;
  171. while (i<=paramcount) do
  172. begin
  173. s:=paramstr(i);
  174. if s[1]<>'-' then
  175. break;
  176. case upcase(s[2]) of
  177. 'L' : showshared:=true;
  178. 'S' : showstatic:=true;
  179. 'O' : showobjects:=true;
  180. 'A' : skipdup:=false;
  181. '?','H' :
  182. begin
  183. writeln('usage: ppufiles [options] <files>');
  184. writeln('options:');
  185. writeln(' -A Show all files (don''t remove duplicates)');
  186. writeln(' -L Show only shared libraries');
  187. writeln(' -S Show only static libraries');
  188. writeln(' -O Show only object files');
  189. writeln(' -H This helpscreen');
  190. end;
  191. end;
  192. inc(i);
  193. end;
  194. { default shows everything }
  195. if i=1 then
  196. begin
  197. showshared:=true;
  198. showstatic:=true;
  199. showobjects:=true;
  200. end;
  201. { files }
  202. parafile:=i;
  203. for i:=parafile to ParamCount do
  204. begin
  205. InFile:=AddExtension(ParamStr(i),PPUExt);
  206. FindFirst(InFile,$20,Dir);
  207. while (DosError=0) do
  208. begin
  209. DoPPU(SplitPath(InFile)+Dir.Name);
  210. FindNext(Dir);
  211. end;
  212. {$ifdef fpc}
  213. FindClose(Dir);
  214. {$endif}
  215. end;
  216. { Display the files }
  217. while assigned(outfiles) do
  218. begin
  219. p:=outfiles;
  220. write(outfiles^.name);
  221. outfiles:=outfiles^.next;
  222. dispose(p);
  223. if assigned(outfiles) then
  224. write(' ');
  225. end;
  226. end.
  227. {
  228. $Log$
  229. Revision 1.5 2002-05-18 13:34:27 peter
  230. * readded missing revisions
  231. Revision 1.4 2002/05/16 19:46:54 carl
  232. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  233. + try to fix temp allocation (still in ifdef)
  234. + generic constructor calls
  235. + start of tassembler / tmodulebase class cleanup
  236. }