options.pas 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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.15';
  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. RemoveUnderscore : Boolean;
  33. usevarparas : boolean; { generate var parameters, when a pointer }
  34. { is passed }
  35. includefile : boolean; { creates an include file instead of a unit }
  36. palmpilot : boolean; { handling of PalmOS SYS_CALLs }
  37. { Helpers }
  38. Function ForceExtension(Const HStr,ext:String):String;
  39. Function MaybeExtension(Const HStr,ext:String):String;
  40. { Options }
  41. Procedure ProcessOptions;
  42. Implementation
  43. {*****************************************************************************
  44. Helpers
  45. *****************************************************************************}
  46. Function ForceExtension(Const HStr,ext:String):String;
  47. {
  48. Return a filename which certainly has the extension ext
  49. (no dot in ext !!)
  50. }
  51. var
  52. j : longint;
  53. begin
  54. j:=length(Hstr);
  55. while (j>0) and (Hstr[j]<>'.') do
  56. dec(j);
  57. if j=0 then
  58. j:=255;
  59. ForceExtension:=Copy(Hstr,1,j-1)+'.'+Ext;
  60. end;
  61. Function MaybeExtension(Const HStr,ext:String):String;
  62. {
  63. Return a filename which certainly has the extension ext
  64. (no dot in ext !!)
  65. }
  66. var
  67. j : longint;
  68. begin
  69. j:=length(Hstr);
  70. while (j>0) and (Hstr[j]<>'.') do
  71. dec(j);
  72. if j=0 then
  73. MaybeExtension:=Hstr+'.'+Ext
  74. else
  75. MaybeExtension:=Hstr;
  76. end;
  77. {*****************************************************************************
  78. Options
  79. *****************************************************************************}
  80. Procedure Usage;
  81. begin
  82. writeln ('Usage : ',paramstr(0),' [options] filename');
  83. writeln (' Where [options] is one or more of:');
  84. writeln (' -d Use external;');
  85. writeln (' -D use external libname name ''func_name'';');
  86. writeln (' -e change enum type to list of constants');
  87. writeln (' -c Compact outputmode, less spaces and empty lines');
  88. writeln (' -i create include files (no unit header)');
  89. writeln (' -l libname Specify the library name for external');
  90. writeln (' -o outputfilename Specify the outputfilename');
  91. writeln (' -p Use "P" instead of "^" for pointers');
  92. writeln (' -s strip comments from inputfile');
  93. writeln (' -S strip comments and don''t write info to outputfile.');
  94. writeln (' -t Prepend typedef type names with T');
  95. writeln (' -T Prepend typedef type names with T, and remove _');
  96. writeln (' -u unitname Specify the name of the unit.');
  97. writeln (' -v replace pointer parameters by call by');
  98. writeln (' reference parameters');
  99. writeln (' -w special for win32 headers');
  100. writeln (' -x handle SYS_TRAP of PalmOS header files');
  101. halt (0);
  102. end;
  103. Procedure ProcessOptions;
  104. Var
  105. cp : string;
  106. I : longint;
  107. Function GetNextParam (const Opt,Name : String) : string;
  108. begin
  109. if i=paramcount then
  110. begin
  111. writeln ('Error : -',Opt,' : ',name,' expected');
  112. halt(1);
  113. end
  114. else
  115. begin
  116. GetNextParam:=paramstr(i+1);
  117. inc(i);
  118. end;
  119. end;
  120. begin
  121. if paramcount=0 then
  122. Usage;
  123. inputfilename:='';
  124. outputfilename:='';
  125. LibFileName:='';
  126. UnitName:='';
  127. CompactMode:=false;
  128. UseLib:=false;
  129. UseName:=false;
  130. StripComment:=false;
  131. StripInfo:=false;
  132. UsePPointers:=false;
  133. EnumToCOnst:=false;
  134. usevarparas:=false;
  135. palmpilot:=false;
  136. includefile:=false;
  137. i:=1;
  138. while i<=paramcount do
  139. begin
  140. cp:=paramstr(i);
  141. if cp[1]='-' then
  142. begin
  143. case cp[2] of
  144. 'c' : CompactMode:=true;
  145. 'e' : EnumToConst :=true;
  146. 'd' : UseLib :=true;
  147. 'D' : begin
  148. UseLib :=true;
  149. usename :=true;
  150. end;
  151. 'i' : includefile:=true;
  152. 'l' : LibFileName:=GetNextParam ('l','libname');
  153. 'o' : outputfilename:=GetNextParam('o','outputfilename');
  154. 'p' : UsePPointers:=true;
  155. 's' : stripcomment:=true;
  156. 'S' : begin
  157. stripcomment:=true;
  158. stripinfo:=true;
  159. end;
  160. 't' : PrependTypes:=true;
  161. 'T' : begin
  162. PrependTypes:=true;
  163. RemoveUnderscore:=true;
  164. end;
  165. 'u' : UnitName:=GetNextParam ('u','unitname');
  166. 'v' : usevarparas:=true;
  167. 'w' : begin
  168. Win32headers:=true;
  169. UseLib:=true;
  170. usename:=true;
  171. usevarparas:=true;
  172. LibFileName:='kernel32';
  173. end;
  174. 'x' : palmpilot:=true;
  175. else
  176. Writeln ('Illegal option : ',cp);
  177. end
  178. end
  179. else
  180. begin { filename }
  181. if inputfilename<>'' then
  182. begin
  183. writeln ('Error : only one filename supported. Found also :',cp);
  184. halt(1);
  185. end;
  186. inputfilename:=MaybeExtension(cp,'h');
  187. if outputfilename='' then
  188. outputfilename:=ForceExtension (inputfilename,'pp');
  189. end;
  190. inc(i);
  191. end;
  192. If inputfilename='' then
  193. Usage;
  194. if UnitName='' then
  195. begin
  196. i:=pos('.',outputfilename)-1;
  197. if i<=0 then
  198. UnitName:=outputfilename
  199. else
  200. UnitName:=Copy(OutputFileName,1,i);
  201. end;
  202. end;
  203. end.
  204. {
  205. $Log$
  206. Revision 1.4 2000-03-27 21:39:20 peter
  207. + -S, -T, -c modes added
  208. * crash fixes
  209. * removed double opening of inputfile
  210. }