options.pas 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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., 59 Temple Place - Suite 330, Boston,
  14. MA 02111-1307, 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 IsInvalidParam := true;
  69. 'p': if sValue = 'x8664' then
  70. begin
  71. Fx64 := true;
  72. end
  73. else IsInvalidParam := true;
  74. 'o': if sValue <> '' then
  75. begin
  76. FPath := IncludeTrailingBackslash(sValue);
  77. end
  78. else
  79. begin
  80. FPath := '';
  81. end;
  82. else begin
  83. FHelp := true;
  84. writeln(format('invalid param "%s"', [ParamStr(i)]));
  85. end;
  86. end;
  87. end
  88. else IsInvalidParam := true;
  89. if IsInvalidParam then
  90. begin
  91. FHelp := true;
  92. writeln(format('invalid param "%s"', [ParamStr(i)]));
  93. end;
  94. end;
  95. end;
  96. end.