{$N+,A+,G+,F+,D-,E-,L-,R-,S-,Q-,Y-,I-}
unit utils;

interface

function toASCIIZ(dest : PChar; str : string) : PChar;
function StrLower(Str: string): string;
function checkparam(str:string):boolean;
function check_s3m_in_params:byte;


implementation

function toASCIIZ(dest : PChar; str : string) : PChar;
var
    spos, slen : integer;
    i : integer;

begin
    spos := 0;                          { string position = 0 }
    slen := ord(str[0]);                { string length }
    { copy string to ASCIIZ conversion buffer: }
    while spos < slen do
    begin
        dest[spos] := str[spos+1];
        spos := spos + 1;
    end;
    dest[spos] := chr(0);               { put terminating 0 to end of string }
    toASCIIZ := dest;
end;


function StrLower(Str: string): string;
var
n,o:byte;
c:char;
begin
     if length(str)=0 then exit;
     for n:=1 to length(str) do begin
       c:=str[n];
       o:=ord(c);
       if (o>=65) and (o<=90) then c:=chr(o+32);
       strLower[n]:=c;
     end;
     strLower[0]:=char(n);
end;

function checkparam(str:string):boolean;
var n:byte;
begin
  str:=strlower(str);
  if paramcount>0 then
  for n:=1 to paramcount do
     if strlower(paramstr(n))=str then begin checkparam:=true; exit; end;
checkparam:=false;
end;

function check_s3m_in_params:byte;
var n,m,l:byte;
c:char;
s:string;
begin
  if paramcount>0 then
  for n:=1 to paramcount do
    begin
      s:=strlower(paramstr(n));
      l:=length(s);
      for m:=1 to l do
        begin
          if (s[m]='.') and (m+3<=l) then
              if (s[m+1]='s') and (s[m+2]='3') and (s[m+3]='m')
                then begin check_s3m_in_params:=n; exit; end;
        end;
    end;
  check_s3m_in_params:=0;
end;

end.