unit uParam;

interface

uses Classes;

procedure ParamParse(P: PChar; Params: TStrings);

implementation

function GetParamStr(P: PChar; var Param: string): PChar;
var
  Len: Integer;
  Buffer: array[0..4095] of Char;
begin
  while True do
  begin
    while (P[0] <> #0) and (P[0] <= ' ') do Inc(P);
    if (P[0] = '"') and (P[1] = '"') then Inc(P, 2) else
    if (P[0] = #39) and (P[1] = #39) then Inc(P, 2) else Break;
  end;
  Len := 0;
  while (P[0] > ' ') and (Len < SizeOf(Buffer)) do
    if P[0] = '"' then
    begin
      Inc(P);
      while (P[0] <> #0) and (P[0] <> '"') do
      begin
        if P[0] = '\' then
        begin
          Inc(P);
          if P[0] = #0 then Break;
        end;
        Buffer[Len] := P[0];
        Inc(Len);
        Inc(P);
      end;
      if P[0] <> #0 then Inc(P);
    end else
    if P[0] = #39 then
    begin
      Inc(P);
      while (P[0] <> #0) and (P[0] <> #39) do
      begin
        if P[0] = '\' then
        begin
          Inc(P);
          if P[0] = #0 then Break;
        end;
        Buffer[Len] := P[0];
        Inc(Len);
        Inc(P);
      end;
      if P[0] <> #0 then Inc(P);
    end else
    begin
      Buffer[Len] := P[0];
      Inc(Len);
      Inc(P);
    end;
  SetString(Param, Buffer, Len);
  Result := P;
end;

procedure ParamParse(P: PChar; Params: TStrings);
var
  S: string;
begin
  while True do
  begin
    P := GetParamStr(P, S);
    if S = '' then Break;
    Params.Add(S);
  end;
end;

end.
