options.pas 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. {
  2. Copyright (C) <avx-testfile-generator> <Torsten Grundke>
  3. This source is free software; you can redistribute it and/or modify it under
  4. the terms of the GNU General Public License as published by the Free
  5. Software Foundation; either version 2 of the License, or (at your option)
  6. any later version.
  7. This code is distributed in the hope that it will be useful, but WITHOUT ANY
  8. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. details.
  11. A copy of the GNU General Public License is available on the World Wide Web
  12. at <http://www.gnu.org/copyleft/gpl.html>. You can also obtain it by writing
  13. to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  14. MA 02110-1301, USA.
  15. }
  16. {$mode objfpc}
  17. unit options;
  18. interface
  19. type
  20. TOptions = class(TObject)
  21. private
  22. FHelp: boolean;
  23. FX64: boolean;
  24. FOutputFormat: Char;
  25. FPath: string;
  26. public
  27. constructor Create;
  28. procedure LoadParams;
  29. property Help: boolean read FHelp write FHelp;
  30. property OutputFormat: Char read FOutputFormat write FOutputFormat;
  31. property X64: boolean read FX64 write FX64;
  32. property Path: string read FPath write FPath;
  33. end;
  34. implementation
  35. uses SysUtils;
  36. { TOptions }
  37. constructor TOptions.Create;
  38. begin
  39. FHelp := false;
  40. FX64 := false;
  41. FOutputFormat := '?';
  42. FPath := '';
  43. end;
  44. procedure TOptions.LoadParams;
  45. var
  46. i: integer;
  47. sParam: Char;
  48. sValue: String;
  49. IsInvalidParam: boolean;
  50. begin
  51. if ParamCount = 0 then FHelp := true
  52. else FHelp := false;
  53. FX64 := false;
  54. FOutputFormat := 'f'; // default = fpc
  55. FPath := IncludeTrailingBackslash(GetCurrentDir);
  56. for i := 1 to ParamCount do
  57. begin
  58. if copy(ParamStr(i), 1, 1) = '-' then
  59. begin
  60. sParam := copy(ParamStr(i) + ' ', 2, 1)[1];
  61. sValue := copy(ParamStr(i), 3, length(ParamStr(i)));
  62. IsInvalidParam := false;
  63. case sParam of
  64. 'h': FHelp := true;
  65. 'f': if sValue = 'fpc' then FOutputFormat := 'f'
  66. else if sValue = 'nasm' then FOutputFormat := 'n'
  67. else if sValue = 'fasm' then FOutputFormat := 'F'
  68. else if sValue = 'fpcinc' then FOutputFormat := 'I'
  69. else IsInvalidParam := true;
  70. 'p': if sValue = 'x8664' then
  71. begin
  72. Fx64 := true;
  73. end
  74. else IsInvalidParam := true;
  75. 'o': if sValue <> '' then
  76. begin
  77. FPath := IncludeTrailingBackslash(sValue);
  78. end
  79. else
  80. begin
  81. FPath := '';
  82. end;
  83. else begin
  84. FHelp := true;
  85. writeln(format('invalid param "%s"', [ParamStr(i)]));
  86. end;
  87. end;
  88. end
  89. else IsInvalidParam := true;
  90. if IsInvalidParam then
  91. begin
  92. FHelp := true;
  93. writeln(format('invalid param "%s"', [ParamStr(i)]));
  94. end;
  95. end;
  96. end;
  97. end.