ppufiles.pp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. {
  2. Copyright (c) 1999-2002 by Peter Vreman
  3. List files needed by PPU
  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. Program ppufiles;
  17. uses
  18. dos,
  19. ppu;
  20. const
  21. Version = 'Version 1.00';
  22. Title = 'PPU-Files';
  23. Copyright = 'Copyright (c) 1999-2002 by the Free Pascal Development Team';
  24. PPUExt = 'ppu';
  25. type
  26. poutfile = ^toutfile;
  27. toutfile = record
  28. name : string;
  29. next : poutfile;
  30. end;
  31. var
  32. skipdup,
  33. showstatic,
  34. showshared,
  35. showobjects : boolean;
  36. OutFiles : poutfile;
  37. {*****************************************************************************
  38. Helpers
  39. *****************************************************************************}
  40. Procedure Error(const s:string;stop:boolean);
  41. {
  42. Write an error message to stderr
  43. }
  44. begin
  45. {$ifdef FPC}
  46. writeln(stderr,s);
  47. {$else}
  48. writeln(s);
  49. {$endif}
  50. if stop then
  51. halt(1);
  52. end;
  53. Function AddExtension(Const HStr,ext:String):String;
  54. {
  55. Return a filename which will have extension ext added if no
  56. extension is found
  57. }
  58. var
  59. j : longint;
  60. begin
  61. j:=length(Hstr);
  62. while (j>0) and (Hstr[j]<>'.') do
  63. dec(j);
  64. if j=0 then
  65. AddExtension:=Hstr+'.'+Ext
  66. else
  67. AddExtension:=HStr;
  68. end;
  69. Function SplitPath(Const HStr:String):String;
  70. var
  71. i : longint;
  72. begin
  73. i:=Length(Hstr);
  74. while (i>0) and not(Hstr[i] in ['\','/']) do
  75. dec(i);
  76. SplitPath:=Copy(Hstr,1,i);
  77. end;
  78. Procedure AddFile(const s:string);
  79. var
  80. p : poutfile;
  81. begin
  82. p:=nil;
  83. if skipdup then
  84. begin
  85. p:=outfiles;
  86. while assigned(p) do
  87. begin
  88. if s=p^.name then
  89. break;
  90. p:=p^.next;
  91. end;
  92. end;
  93. if not assigned(p) then
  94. begin
  95. new(p);
  96. p^.name:=s;
  97. p^.next:=outfiles;
  98. outfiles:=p;
  99. end;
  100. end;
  101. Function DoPPU(const PPUFn:String):Boolean;
  102. {
  103. Convert one file (in Filename) to library format.
  104. Return true if successful, false otherwise.
  105. }
  106. Var
  107. inppu : tppufile;
  108. b : byte;
  109. procedure showfiles;
  110. begin
  111. while not inppu.endofentry do
  112. begin
  113. AddFile(inppu.getstring);
  114. inppu.getlongint;
  115. end;
  116. end;
  117. begin
  118. DoPPU:=false;
  119. inppu:=tppufile.create(PPUFn);
  120. if not inppu.openfile then
  121. begin
  122. inppu.free;
  123. Error('Error: Could not open : '+PPUFn,false);
  124. Exit;
  125. end;
  126. { Check the ppufile }
  127. if not inppu.CheckPPUId then
  128. begin
  129. inppu.free;
  130. Error('Error: Not a PPU File : '+PPUFn,false);
  131. Exit;
  132. end;
  133. if inppu.GetPPUVersion<CurrentPPUVersion then
  134. begin
  135. inppu.free;
  136. Error('Error: Wrong PPU Version : '+PPUFn,false);
  137. Exit;
  138. end;
  139. { read until the object files are found }
  140. repeat
  141. b:=inppu.readentry;
  142. case b of
  143. ibendinterface,
  144. ibend :
  145. break;
  146. iblinkunitstaticlibs :
  147. if showstatic then
  148. showfiles;
  149. iblinkunitsharedlibs :
  150. if showshared then
  151. showfiles;
  152. iblinkunitofiles :
  153. if showobjects then
  154. showfiles;
  155. end;
  156. until false;
  157. inppu.free;
  158. DoPPU:=True;
  159. end;
  160. var
  161. i,parafile : longint;
  162. dir : SearchRec;
  163. s,InFile : String;
  164. p : poutfile;
  165. begin
  166. { defaults }
  167. skipdup:=true;
  168. { options }
  169. i:=1;
  170. while (i<=paramcount) do
  171. begin
  172. s:=paramstr(i);
  173. if s[1]<>'-' then
  174. break;
  175. case upcase(s[2]) of
  176. 'L' : showshared:=true;
  177. 'S' : showstatic:=true;
  178. 'O' : showobjects:=true;
  179. 'A' : skipdup:=false;
  180. '?','H' :
  181. begin
  182. writeln('usage: ppufiles [options] <files>');
  183. writeln('options:');
  184. writeln(' -A Show all files (don''t remove duplicates)');
  185. writeln(' -L Show only shared libraries');
  186. writeln(' -S Show only static libraries');
  187. writeln(' -O Show only object files');
  188. writeln(' -H This helpscreen');
  189. end;
  190. end;
  191. inc(i);
  192. end;
  193. { default shows everything }
  194. if i=1 then
  195. begin
  196. showshared:=true;
  197. showstatic:=true;
  198. showobjects:=true;
  199. end;
  200. { files }
  201. parafile:=i;
  202. for i:=parafile to ParamCount do
  203. begin
  204. InFile:=AddExtension(ParamStr(i),PPUExt);
  205. FindFirst(InFile,$20,Dir);
  206. while (DosError=0) do
  207. begin
  208. DoPPU(SplitPath(InFile)+Dir.Name);
  209. FindNext(Dir);
  210. end;
  211. {$ifdef fpc}
  212. FindClose(Dir);
  213. {$endif}
  214. end;
  215. { Display the files }
  216. while assigned(outfiles) do
  217. begin
  218. p:=outfiles;
  219. write(outfiles^.name);
  220. outfiles:=outfiles^.next;
  221. dispose(p);
  222. if assigned(outfiles) then
  223. write(' ');
  224. end;
  225. end.