ppufiles.pp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. {
  2. $Id$
  3. Copyright (c) 1999-2000 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 0.99.14';
  23. Title = 'PPU-Files';
  24. Copyright = 'Copyright (c) 1999-2000 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. const
  71. {$IFDEF LINUX}
  72. PathCh='/';
  73. {$ELSE}
  74. PathCh='\';
  75. {$ENDIF}
  76. Function SplitPath(Const HStr:String):String;
  77. var
  78. i : byte;
  79. begin
  80. i:=Length(Hstr);
  81. while (i>0) and (Hstr[i]<>PathCh) do
  82. dec(i);
  83. SplitPath:=Copy(Hstr,1,i);
  84. end;
  85. Procedure AddFile(const s:string);
  86. var
  87. p : poutfile;
  88. begin
  89. p:=nil;
  90. if skipdup then
  91. begin
  92. p:=outfiles;
  93. while assigned(p) do
  94. begin
  95. if s=p^.name then
  96. break;
  97. p:=p^.next;
  98. end;
  99. end;
  100. if not assigned(p) then
  101. begin
  102. new(p);
  103. p^.name:=s;
  104. p^.next:=outfiles;
  105. outfiles:=p;
  106. end;
  107. end;
  108. Function DoPPU(const PPUFn:String):Boolean;
  109. {
  110. Convert one file (in Filename) to library format.
  111. Return true if successful, false otherwise.
  112. }
  113. Var
  114. inppu : pppufile;
  115. b : byte;
  116. procedure showfiles;
  117. begin
  118. while not inppu^.endofentry do
  119. begin
  120. AddFile(inppu^.getstring);
  121. inppu^.getlongint;
  122. end;
  123. end;
  124. begin
  125. DoPPU:=false;
  126. inppu:=new(pppufile,init(PPUFn));
  127. if not inppu^.open then
  128. begin
  129. dispose(inppu,done);
  130. Error('Error: Could not open : '+PPUFn,false);
  131. Exit;
  132. end;
  133. { Check the ppufile }
  134. if not inppu^.CheckPPUId then
  135. begin
  136. dispose(inppu,done);
  137. Error('Error: Not a PPU File : '+PPUFn,false);
  138. Exit;
  139. end;
  140. if inppu^.GetPPUVersion<CurrentPPUVersion then
  141. begin
  142. dispose(inppu,done);
  143. Error('Error: Wrong PPU Version : '+PPUFn,false);
  144. Exit;
  145. end;
  146. { read until the object files are found }
  147. repeat
  148. b:=inppu^.readentry;
  149. case b of
  150. ibendinterface,
  151. ibend :
  152. break;
  153. iblinkunitstaticlibs :
  154. if showstatic then
  155. showfiles;
  156. iblinkunitsharedlibs :
  157. if showshared then
  158. showfiles;
  159. iblinkunitofiles :
  160. if showobjects then
  161. showfiles;
  162. end;
  163. until false;
  164. dispose(inppu,done);
  165. DoPPU:=True;
  166. end;
  167. var
  168. i,parafile : longint;
  169. dir : SearchRec;
  170. s,InFile : String;
  171. p : poutfile;
  172. begin
  173. { defaults }
  174. skipdup:=true;
  175. { options }
  176. i:=1;
  177. while (i<=paramcount) do
  178. begin
  179. s:=paramstr(i);
  180. if s[1]<>'-' then
  181. break;
  182. case upcase(s[2]) of
  183. 'L' : showshared:=true;
  184. 'S' : showstatic:=true;
  185. 'O' : showobjects:=true;
  186. 'A' : skipdup:=false;
  187. '?','H' :
  188. begin
  189. writeln('usage: ppufiles [options] <files>');
  190. writeln('options:');
  191. writeln(' -A Show all files (don''t remove duplicates)');
  192. writeln(' -L Show only shared libraries');
  193. writeln(' -S Show only static libraries');
  194. writeln(' -O Show only object files');
  195. writeln(' -H This helpscreen');
  196. end;
  197. end;
  198. inc(i);
  199. end;
  200. { default shows everything }
  201. if i=1 then
  202. begin
  203. showshared:=true;
  204. showstatic:=true;
  205. showobjects:=true;
  206. end;
  207. { files }
  208. parafile:=i;
  209. for i:=parafile to ParamCount do
  210. begin
  211. InFile:=AddExtension(ParamStr(i),PPUExt);
  212. FindFirst(InFile,$20,Dir);
  213. while (DosError=0) do
  214. begin
  215. DoPPU(SplitPath(InFile)+Dir.Name);
  216. FindNext(Dir);
  217. end;
  218. {$ifdef fpc}
  219. FindClose(Dir);
  220. {$endif}
  221. end;
  222. { Display the files }
  223. while assigned(outfiles) do
  224. begin
  225. p:=outfiles;
  226. write(outfiles^.name);
  227. outfiles:=outfiles^.next;
  228. dispose(p);
  229. if assigned(outfiles) then
  230. write(' ');
  231. end;
  232. end.
  233. {
  234. $Log$
  235. Revision 1.3 2000-01-24 12:32:22 daniel
  236. * use a linkedlist instead of ansistring
  237. Revision 1.2 2000/01/07 16:46:04 daniel
  238. * copyright 2000
  239. Revision 1.1 1999/11/23 09:44:41 peter
  240. * initial version
  241. }