unit Scripts;

interface

uses Windows, SysUtils;

type
  TParamList = array of string;

function RemoveComment(s: string): string;
function RemoveCommentASM(s: string): string;
function ExtractParamList(s: string): TParamList;
function GetNextCommand(var f: text): TParamList;
function GetNextCommandASM(var f: text): TParamList;

function Stri(x: longint): string;
function Strf(x: single): string;
function Vali(s: string): longint;
function Valf(s: string): single;

implementation

function RemoveComment;
begin
  if Pos('//', s) = 0 then result := s
                      else result := Copy(s, 1, Pos('//', s) - 1);
end;

function RemoveCommentASM;
begin
  if Pos('#', s) = 0 then result := s
                     else result := Copy(s, 1, Pos('#', s) - 1);
end;

function ExtractParamList;
var
  count, i, j: integer;
begin
  s := s + ' ';
  j := Pos(#9, s);
  while j <> 0 do
  begin
    Delete(s, j, 1);
    Insert(' ', s, j);
    j := Pos(#9, s);
  end;
  j := Pos('  ', s);
  while j <> 0 do
  begin
    Delete(s, j, 1);
    j := Pos('  ', s);
  end;
  if s[1] = ' ' then Delete(s, 1, 1);
  count := 0;
  for i := 1 to length(s) do
    if s[i] = ' ' then inc(count);
  SetLength(result, count+1);
  j := 0; result[0] := '';
  for i := 1 to length(s) do
    if s[i] = ' ' then
    begin
      inc(j);
      result[j] := '';
    end else result[j] := result[j] + s[i];
end;

function GetNextCommand;
var
  s: string;
begin
  repeat
    readln(f, s);
    result := ExtractParamList(UpperCase(RemoveComment(s)));
  until result[0] <> '';
end;

function GetNextCommandASM;
var
  s: string;
begin
  repeat
    readln(f, s);
    result := ExtractParamList(UpperCase(RemoveCommentASM(s)));
  until result[0] <> '';
end;

function Stri;
begin
  Str(x, result);
end;

function Strf;
begin
  Str(x, result);
end;

function Vali;
var
  c: integer;
begin
  Val(s, result, c);
end;

function Valf;
var
  c: integer;
begin
  Val(s, result, c);
end;

end.
