options.pas 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. var
  19. inputfilename, outputfilename : string; { Filenames }
  20. LibFileName, unitname : string; { external library name }
  21. UseLib, { Append external to implementation ? }
  22. UseName, { Append 'libname name 'funcname ' }
  23. UsePPOinters, { Use P instead of ^ for pointers }
  24. EnumToConst, { Write enumeration types as constants }
  25. Win32headers, { allows dec_specifier }
  26. stripcomment, { strip comments from inputfile }
  27. PrependTypes : Boolean; { Print T in front of type names ? }
  28. usevarparas : boolean; { generate var parameters, when a pointer }
  29. { is passed }
  30. includefile : boolean; { creates an include file instead of a unit }
  31. palmpilot : boolean; { handling of PalmOS SYS_CALLs }
  32. Procedure ProcessOptions;
  33. Implementation
  34. Procedure Usage;
  35. begin
  36. writeln ('Usage : ',paramstr(0),' [options] filename');
  37. writeln (' Where [options] is one or more of:');
  38. writeln (' -o outputfilename Specify the outputfilename');
  39. writeln (' -l libname Specify the library name for external.');
  40. writeln (' -u unitname Specify the name of the unit.');
  41. writeln (' -t Prepend typedef type names with T');
  42. writeln (' -p Use "P" instead of "^" for pointers.');
  43. writeln (' -d Use external;');
  44. writeln (' -D use external libname name ''func_name'';');
  45. writeln (' -e change enum type to list of constants.');
  46. writeln (' -s strip comments from inputfile.');
  47. writeln (' -v replace pointer parameters by call by');
  48. writeln (' reference parameters');
  49. writeln (' -w special for win32 headers');
  50. writeln (' -i create include files (no unit header)');
  51. writeln (' -x handle SYS_TRAP of PalmOS header files');
  52. halt (0);
  53. end;
  54. Function ForceExtension(Const HStr,ext:String):String;
  55. {
  56. Return a filename which certainly has the extension ext
  57. (no dot in ext !!)
  58. }
  59. var
  60. j : longint;
  61. begin
  62. j:=length(Hstr);
  63. while (j>0) and (Hstr[j]<>'.') do
  64. dec(j);
  65. if j=0 then
  66. j:=255;
  67. ForceExtension:=Copy(Hstr,1,j-1)+'.'+Ext;
  68. end;
  69. Procedure ProcessOptions;
  70. Var cp : string;
  71. I : longint;
  72. Function GetNextParam (const Opt,Name : String) : string;
  73. begin
  74. if i=paramcount then
  75. begin
  76. writeln ('Error : -',Opt,' : ',name,' expected');
  77. halt(1);
  78. end
  79. else
  80. begin
  81. GetNextParam:=paramstr(i+1);
  82. inc(i);
  83. end;
  84. end;
  85. begin
  86. if paramcount=0 then
  87. Usage;
  88. inputfilename:='';
  89. outputfilename:='';
  90. LibFileName:='';
  91. UnitName:='';
  92. UseLib:=False;
  93. UseName:=FAlse;
  94. StripComment:=False;
  95. UsePPointers:=False;
  96. EnumToCOnst:=False;
  97. usevarparas:=false;
  98. palmpilot:=false;
  99. includefile:=false;
  100. i:=1;
  101. while i<=paramcount do
  102. begin
  103. cp:=paramstr(i);
  104. if cp[1]='-' then
  105. case cp[2] of
  106. 'o' : outputfilename:=GetNextParam('o','outputfilename');
  107. 't' : PrependTypes := True;
  108. 'p' : UsePPointers := True;
  109. 'e' : EnumToConst := True;
  110. 'd' : UseLib := True;
  111. 'D' : begin
  112. UseLib := True;
  113. usename := True;
  114. end;
  115. 's' : stripcomment:=true;
  116. 'l' : LibFileName:=GetNextParam ('l','libname');
  117. 'u' : UnitName:=GetNextParam ('u','unitname');
  118. 'v' : usevarparas:=true;
  119. 'i' : includefile:=true;
  120. 'w' : begin
  121. Win32headers:=true;
  122. UseLib:=true;
  123. usename:=true;
  124. usevarparas:=true;
  125. LibFileName:='kernel32';
  126. end;
  127. 'x' : palmpilot:=true;
  128. else
  129. Writeln ('Illegal option : ',cp);
  130. end
  131. else
  132. begin { filename }
  133. if inputfilename<>'' then
  134. begin
  135. writeln ('Error : only one filename supported. Found also :',cp);
  136. halt(1);
  137. end;
  138. inputfilename:=cp;
  139. if outputfilename='' then
  140. outputfilename:=ForceExtension (inputfilename,'pp');
  141. end;
  142. inc(i);
  143. end;
  144. If inputfilename='' then Usage;
  145. if UnitName='' then
  146. begin
  147. i:=pos('.',outputfilename)-1;
  148. if i<=0 then
  149. UnitName:=outputfilename
  150. else
  151. UnitName:=Copy(OutputFileName,1,i);
  152. end;
  153. end;
  154. end.
  155. {
  156. $Log$
  157. Revision 1.3 2000-02-09 16:44:15 peter
  158. * log truncated
  159. Revision 1.2 2000/01/07 16:46:05 daniel
  160. * copyright 2000
  161. }