options.pas 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. {
  2. Copyright (c) 1998-2000 by Florian Klaempfl
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14. ****************************************************************************}
  15. unit options;
  16. interface
  17. const
  18. version = '0.99.16';
  19. var
  20. inputfilename, outputfilename : string; { Filenames }
  21. LibFileName, unitname : string; { external library name }
  22. CompactMode,
  23. stripinfo, { Don't write info comments to output }
  24. UseLib, { Append external to implementation ? }
  25. UseName, { Append 'libname name 'funcname ' }
  26. UsePPOinters, { Use P instead of ^ for pointers }
  27. EnumToConst, { Write enumeration types as constants }
  28. Win32headers, { allows dec_specifier }
  29. stripcomment, { strip comments from inputfile }
  30. PrependTypes, { Print T in front of type names ? }
  31. UseCTypesUnit, { Use types defined in the ctypes unit}
  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 (' -C Use types in ctypes unit');
  91. writeln (' -i create include files (no unit header)');
  92. writeln (' -l libname Specify the library name for external');
  93. writeln (' -o outputfilename Specify the outputfilename');
  94. writeln (' -p Use "P" instead of "^" for pointers');
  95. writeln (' -pr Pack all records (1 byte alignment)');
  96. writeln (' -P use proc. vars for imports');
  97. writeln (' -s strip comments from inputfile');
  98. writeln (' -S strip comments and don''t write info to outputfile.');
  99. writeln (' -t Prepend typedef type names with T');
  100. writeln (' -T Prepend typedef type names with T, and remove _');
  101. writeln (' -u unitname Specify the name of the unit.');
  102. writeln (' -v replace pointer parameters by call by');
  103. writeln (' reference parameters');
  104. writeln (' -w special for win32 headers');
  105. writeln (' -x handle SYS_TRAP of PalmOS header files');
  106. halt (0);
  107. end;
  108. Procedure ProcessOptions;
  109. Var
  110. cp : string;
  111. I : longint;
  112. Function GetNextParam (const Opt,Name : String) : string;
  113. begin
  114. if i=paramcount then
  115. begin
  116. writeln ('Error : -',Opt,' : ',name,' expected');
  117. halt(1);
  118. end
  119. else
  120. begin
  121. GetNextParam:=paramstr(i+1);
  122. inc(i);
  123. end;
  124. end;
  125. begin
  126. if paramcount=0 then
  127. Usage;
  128. inputfilename:='';
  129. outputfilename:='';
  130. LibFileName:='';
  131. UnitName:='';
  132. CompactMode:=false;
  133. UseLib:=false;
  134. UseName:=false;
  135. StripComment:=false;
  136. StripInfo:=false;
  137. UsePPointers:=false;
  138. UseCTypesUnit := false;
  139. EnumToCOnst:=false;
  140. usevarparas:=false;
  141. palmpilot:=false;
  142. includefile:=false;
  143. packrecords:=false;
  144. createdynlib:=false;
  145. i:=1;
  146. while i<=paramcount do
  147. begin
  148. cp:=paramstr(i);
  149. if cp[1]='-' then
  150. begin
  151. case cp[2] of
  152. 'c' : CompactMode:=true;
  153. 'C' : UseCTypesUnit := true;
  154. 'e' : EnumToConst :=true;
  155. 'd' : UseLib :=true;
  156. 'D' : begin
  157. UseLib :=true;
  158. usename :=true;
  159. end;
  160. 'i' : includefile:=true;
  161. 'l' : LibFileName:=GetNextParam ('l','libname');
  162. 'o' : outputfilename:=GetNextParam('o','outputfilename');
  163. 'P' : createdynlib:=true;
  164. 'p' : begin
  165. if (cp[3] = 'r') then
  166. begin
  167. PackRecords := true;
  168. end
  169. else
  170. UsePPointers:=true;
  171. end;
  172. 's' : stripcomment:=true;
  173. 'S' : begin
  174. stripcomment:=true;
  175. stripinfo:=true;
  176. end;
  177. 't' : PrependTypes:=true;
  178. 'T' : begin
  179. PrependTypes:=true;
  180. RemoveUnderscore:=true;
  181. end;
  182. 'u' : UnitName:=GetNextParam ('u','unitname');
  183. 'v' : usevarparas:=true;
  184. 'w' : begin
  185. Win32headers:=true;
  186. UseLib:=true;
  187. usename:=true;
  188. usevarparas:=true;
  189. LibFileName:='kernel32';
  190. end;
  191. 'x' : palmpilot:=true;
  192. else
  193. Writeln ('Illegal option : ',cp);
  194. end
  195. end
  196. else
  197. begin { filename }
  198. if inputfilename<>'' then
  199. begin
  200. writeln ('Error : only one filename supported. Found also :',cp);
  201. halt(1);
  202. end;
  203. inputfilename:=MaybeExtension(cp,'h');
  204. if outputfilename='' then
  205. outputfilename:=ForceExtension (inputfilename,'pp');
  206. end;
  207. inc(i);
  208. end;
  209. If inputfilename='' then
  210. Usage;
  211. if UnitName='' then
  212. begin
  213. i:=pos('.',outputfilename)-1;
  214. if i<=0 then
  215. UnitName:=outputfilename
  216. else
  217. UnitName:=Copy(OutputFileName,1,i);
  218. end;
  219. end;
  220. end.