options.pas 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Florian Klaempfl
  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. unit options;
  17. interface
  18. const
  19. version = '0.99.16';
  20. var
  21. inputfilename, outputfilename : string; { Filenames }
  22. LibFileName, unitname : string; { external library name }
  23. CompactMode,
  24. stripinfo, { Don't write info comments to output }
  25. UseLib, { Append external to implementation ? }
  26. UseName, { Append 'libname name 'funcname ' }
  27. UsePPOinters, { Use P instead of ^ for pointers }
  28. EnumToConst, { Write enumeration types as constants }
  29. Win32headers, { allows dec_specifier }
  30. stripcomment, { strip comments from inputfile }
  31. PrependTypes, { Print T in front of type names ? }
  32. createdynlib, { creates a unit which loads dynamically the imports to proc vars }
  33. RemoveUnderscore : Boolean;
  34. usevarparas : boolean; { generate var parameters, when a pointer }
  35. { is passed }
  36. includefile : boolean; { creates an include file instead of a unit }
  37. palmpilot : boolean; { handling of PalmOS SYS_CALLs }
  38. packrecords: boolean; { All records should be packed in the file }
  39. { Helpers }
  40. Function ForceExtension(Const HStr,ext:String):String;
  41. Function MaybeExtension(Const HStr,ext:String):String;
  42. { Options }
  43. Procedure ProcessOptions;
  44. Implementation
  45. {*****************************************************************************
  46. Helpers
  47. *****************************************************************************}
  48. Function ForceExtension(Const HStr,ext:String):String;
  49. {
  50. Return a filename which certainly has the extension ext
  51. (no dot in ext !!)
  52. }
  53. var
  54. j : longint;
  55. begin
  56. j:=length(Hstr);
  57. while (j>0) and (Hstr[j]<>'.') do
  58. dec(j);
  59. if j=0 then
  60. j:=255;
  61. ForceExtension:=Copy(Hstr,1,j-1)+'.'+Ext;
  62. end;
  63. Function MaybeExtension(Const HStr,ext:String):String;
  64. {
  65. Return a filename which certainly has the extension ext
  66. (no dot in ext !!)
  67. }
  68. var
  69. j : longint;
  70. begin
  71. j:=length(Hstr);
  72. while (j>0) and (Hstr[j]<>'.') do
  73. dec(j);
  74. if j=0 then
  75. MaybeExtension:=Hstr+'.'+Ext
  76. else
  77. MaybeExtension:=Hstr;
  78. end;
  79. {*****************************************************************************
  80. Options
  81. *****************************************************************************}
  82. Procedure Usage;
  83. begin
  84. writeln ('Usage : ',paramstr(0),' [options] filename');
  85. writeln (' Where [options] is one or more of:');
  86. writeln (' -d Use external;');
  87. writeln (' -D use external libname name ''func_name'';');
  88. writeln (' -e change enum type to list of constants');
  89. writeln (' -c Compact outputmode, less spaces and empty lines');
  90. writeln (' -i create include files (no unit header)');
  91. writeln (' -l libname Specify the library name for external');
  92. writeln (' -o outputfilename Specify the outputfilename');
  93. writeln (' -p Use "P" instead of "^" for pointers');
  94. writeln (' -pr Pack all records (1 byte alignment)');
  95. writeln (' -P use proc. vars for imports');
  96. writeln (' -s strip comments from inputfile');
  97. writeln (' -S strip comments and don''t write info to outputfile.');
  98. writeln (' -t Prepend typedef type names with T');
  99. writeln (' -T Prepend typedef type names with T, and remove _');
  100. writeln (' -u unitname Specify the name of the unit.');
  101. writeln (' -v replace pointer parameters by call by');
  102. writeln (' reference parameters');
  103. writeln (' -w special for win32 headers');
  104. writeln (' -x handle SYS_TRAP of PalmOS header files');
  105. halt (0);
  106. end;
  107. Procedure ProcessOptions;
  108. Var
  109. cp : string;
  110. I : longint;
  111. Function GetNextParam (const Opt,Name : String) : string;
  112. begin
  113. if i=paramcount then
  114. begin
  115. writeln ('Error : -',Opt,' : ',name,' expected');
  116. halt(1);
  117. end
  118. else
  119. begin
  120. GetNextParam:=paramstr(i+1);
  121. inc(i);
  122. end;
  123. end;
  124. begin
  125. if paramcount=0 then
  126. Usage;
  127. inputfilename:='';
  128. outputfilename:='';
  129. LibFileName:='';
  130. UnitName:='';
  131. CompactMode:=false;
  132. UseLib:=false;
  133. UseName:=false;
  134. StripComment:=false;
  135. StripInfo:=false;
  136. UsePPointers:=false;
  137. EnumToCOnst:=false;
  138. usevarparas:=false;
  139. palmpilot:=false;
  140. includefile:=false;
  141. packrecords:=false;
  142. createdynlib:=false;
  143. i:=1;
  144. while i<=paramcount do
  145. begin
  146. cp:=paramstr(i);
  147. if cp[1]='-' then
  148. begin
  149. case cp[2] of
  150. 'c' : CompactMode:=true;
  151. 'e' : EnumToConst :=true;
  152. 'd' : UseLib :=true;
  153. 'D' : begin
  154. UseLib :=true;
  155. usename :=true;
  156. end;
  157. 'i' : includefile:=true;
  158. 'l' : LibFileName:=GetNextParam ('l','libname');
  159. 'o' : outputfilename:=GetNextParam('o','outputfilename');
  160. 'P' : createdynlib:=true;
  161. 'p' : begin
  162. if (cp[3] = 'r') then
  163. begin
  164. PackRecords := true;
  165. end
  166. else
  167. UsePPointers:=true;
  168. end;
  169. 's' : stripcomment:=true;
  170. 'S' : begin
  171. stripcomment:=true;
  172. stripinfo:=true;
  173. end;
  174. 't' : PrependTypes:=true;
  175. 'T' : begin
  176. PrependTypes:=true;
  177. RemoveUnderscore:=true;
  178. end;
  179. 'u' : UnitName:=GetNextParam ('u','unitname');
  180. 'v' : usevarparas:=true;
  181. 'w' : begin
  182. Win32headers:=true;
  183. UseLib:=true;
  184. usename:=true;
  185. usevarparas:=true;
  186. LibFileName:='kernel32';
  187. end;
  188. 'x' : palmpilot:=true;
  189. else
  190. Writeln ('Illegal option : ',cp);
  191. end
  192. end
  193. else
  194. begin { filename }
  195. if inputfilename<>'' then
  196. begin
  197. writeln ('Error : only one filename supported. Found also :',cp);
  198. halt(1);
  199. end;
  200. inputfilename:=MaybeExtension(cp,'h');
  201. if outputfilename='' then
  202. outputfilename:=ForceExtension (inputfilename,'pp');
  203. end;
  204. inc(i);
  205. end;
  206. If inputfilename='' then
  207. Usage;
  208. if UnitName='' then
  209. begin
  210. i:=pos('.',outputfilename)-1;
  211. if i<=0 then
  212. UnitName:=outputfilename
  213. else
  214. UnitName:=Copy(OutputFileName,1,i);
  215. end;
  216. end;
  217. end.
  218. {
  219. $Log$
  220. Revision 1.6 2005-02-20 11:09:41 florian
  221. + added -P:
  222. allows to generate headers which load proc. dyn. from libs
  223. Revision 1.5 2005/02/14 17:13:39 peter
  224. * truncate log
  225. Revision 1.4 2004/09/08 22:21:41 carl
  226. + support for creating packed records
  227. * var parameter bugfixes
  228. Revision 1.3 2004/08/13 02:35:30 carl
  229. + bugfixes with C++ comments, they are now placed above the definition
  230. * some bugfixes with the _label reserved word.
  231. Revision 1.2 2002/09/07 15:40:34 peter
  232. * old logs removed and tabs fixed
  233. }