options.pas 7.5 KB

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