ppufiles.pp 5.0 KB

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