{
- Copyright (C) 2010-2014 MegaBrutal
+ Copyright (C) 2010-2015 MegaBrutal
This unit is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
TArgumentParser = class
- constructor Create(RawArguments: TStringArray; AllowedPrefixes: TStringArray = []);
+ constructor Create(RawArguments: array of string; AllowedPrefixes: array of string);
destructor Destroy; override;
private
Arguments: array of TArgument;
- procedure ParseArgument(Arg: string; const AllowedPrefixes: TStringArray);
+ procedure ParseArgument(Arg: string; const AllowedPrefixes: array of string);
public
function GetArgument(ID: integer): TArgument;
function IsPresent(ArgumentName: string): boolean;
function GetValue(ArgumentName: string; DefValue: string = ''): string;
- function ValidateArguments(ValidArguments: TStringArray): integer;
+ function ValidateArguments(ValidArguments: array of string): integer;
end;
const
{ MgSMTP version: }
- VERSION_STR = '0.9s';
+ VERSION_STR = '0.9t';
{ Architecture: }
{$IFDEF CPU64}
{ Unit-private functions/prodecures: }
+function InStringArray(const S: string; const SA: array of string): boolean;
+var i: integer;
+begin
+ i:= 0;
+ while (i < Length(SA)) and (SA[i] <> S) do Inc(i);
+ Result:= i < Length(SA);
+end;
+
function MakeTimeOffsetStr(TimeOffset: integer): string;
var CorrS: string; CorrI: integer;
begin
end;
end;
+function CmdlineToStringArray: TStringArray;
+var i: integer;
+begin
+ SetLength(Result, ParamCount);
+ for i:= 1 to ParamCount do
+ Result[i-1]:= ParamStr(i);
+end;
+
function UnixTimeStamp(DateTime: TDateTime): TUnixTimeStamp;
begin
{Result:= Trunc((DateTime - EncodeDate(1970, 1 ,1)) * 24 * 60 * 60);}
{ Object constructors/destructors: }
-constructor TArgumentParser.Create(RawArguments: TStringArray; AllowedPrefixes: TStringArray = []);
+constructor TArgumentParser.Create(RawArguments: array of string; AllowedPrefixes: array of string);
var i: integer;
begin
for i:= 0 to Length(RawArguments) - 1 do
{ Object methods: }
-procedure TArgumentParser.ParseArgument(Arg: string; const AllowedPrefixes: TStringArray);
+procedure TArgumentParser.ParseArgument(Arg: string; const AllowedPrefixes: array of string);
var i, n: integer; found: boolean;
begin
{ Strip prefix if present. }
Result:= DefValue;
end;
-function TArgumentParser.ValidateArguments(ValidArguments: TStringArray): integer;
+function TArgumentParser.ValidateArguments(ValidArguments: array of string): integer;
{ Returns -1 if all arguments are valid. Otherwise, returns the ID of the first
invalid parameter. }
var i: integer;
begin
i:= 0;
- while (i < Length(Arguments)) and (Arguments[i] in ValidArguments) do
+ while (i < Length(Arguments)) and InStringArray(Arguments[i].Option, ValidArguments) do
Inc(i);
- if i < Length(Arguments) then
+ if i >= Length(Arguments) then
Result:= -1
else
Result:= i;