options.pas 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. 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 (' -s strip comments from inputfile');
  95. writeln (' -S strip comments and don''t write info to outputfile.');
  96. writeln (' -t Prepend typedef type names with T');
  97. writeln (' -T Prepend typedef type names with T, and remove _');
  98. writeln (' -u unitname Specify the name of the unit.');
  99. writeln (' -v replace pointer parameters by call by');
  100. writeln (' reference parameters');
  101. writeln (' -w special for win32 headers');
  102. writeln (' -x handle SYS_TRAP of PalmOS header files');
  103. halt (0);
  104. end;
  105. Procedure ProcessOptions;
  106. Var
  107. cp : string;
  108. I : longint;
  109. Function GetNextParam (const Opt,Name : String) : string;
  110. begin
  111. if i=paramcount then
  112. begin
  113. writeln ('Error : -',Opt,' : ',name,' expected');
  114. halt(1);
  115. end
  116. else
  117. begin
  118. GetNextParam:=paramstr(i+1);
  119. inc(i);
  120. end;
  121. end;
  122. begin
  123. if paramcount=0 then
  124. Usage;
  125. inputfilename:='';
  126. outputfilename:='';
  127. LibFileName:='';
  128. UnitName:='';
  129. CompactMode:=false;
  130. UseLib:=false;
  131. UseName:=false;
  132. StripComment:=false;
  133. StripInfo:=false;
  134. UsePPointers:=false;
  135. EnumToCOnst:=false;
  136. usevarparas:=false;
  137. palmpilot:=false;
  138. includefile:=false;
  139. packrecords:=false;
  140. i:=1;
  141. while i<=paramcount do
  142. begin
  143. cp:=paramstr(i);
  144. if cp[1]='-' then
  145. begin
  146. case cp[2] of
  147. 'c' : CompactMode:=true;
  148. 'e' : EnumToConst :=true;
  149. 'd' : UseLib :=true;
  150. 'D' : begin
  151. UseLib :=true;
  152. usename :=true;
  153. end;
  154. 'i' : includefile:=true;
  155. 'l' : LibFileName:=GetNextParam ('l','libname');
  156. 'o' : outputfilename:=GetNextParam('o','outputfilename');
  157. 'p' : begin
  158. if (cp[3] = 'r') then
  159. begin
  160. PackRecords := true;
  161. end
  162. else
  163. UsePPointers:=true;
  164. end;
  165. 's' : stripcomment:=true;
  166. 'S' : begin
  167. stripcomment:=true;
  168. stripinfo:=true;
  169. end;
  170. 't' : PrependTypes:=true;
  171. 'T' : begin
  172. PrependTypes:=true;
  173. RemoveUnderscore:=true;
  174. end;
  175. 'u' : UnitName:=GetNextParam ('u','unitname');
  176. 'v' : usevarparas:=true;
  177. 'w' : begin
  178. Win32headers:=true;
  179. UseLib:=true;
  180. usename:=true;
  181. usevarparas:=true;
  182. LibFileName:='kernel32';
  183. end;
  184. 'x' : palmpilot:=true;
  185. else
  186. Writeln ('Illegal option : ',cp);
  187. end
  188. end
  189. else
  190. begin { filename }
  191. if inputfilename<>'' then
  192. begin
  193. writeln ('Error : only one filename supported. Found also :',cp);
  194. halt(1);
  195. end;
  196. inputfilename:=MaybeExtension(cp,'h');
  197. if outputfilename='' then
  198. outputfilename:=ForceExtension (inputfilename,'pp');
  199. end;
  200. inc(i);
  201. end;
  202. If inputfilename='' then
  203. Usage;
  204. if UnitName='' then
  205. begin
  206. i:=pos('.',outputfilename)-1;
  207. if i<=0 then
  208. UnitName:=outputfilename
  209. else
  210. UnitName:=Copy(OutputFileName,1,i);
  211. end;
  212. end;
  213. end.
  214. {
  215. $Log$
  216. Revision 1.4 2004-09-08 22:21:41 carl
  217. + support for creating packed records
  218. * var parameter bugfixes
  219. Revision 1.3 2004/08/13 02:35:30 carl
  220. + bugfixes with C++ comments, they are now placed above the definition
  221. * some bugfixes with the _label reserved word.
  222. Revision 1.2 2002/09/07 15:40:34 peter
  223. * old logs removed and tabs fixed
  224. }