{$A+,B-,D+,E-,F-,G-,I-,L+,N-,O-,P-,Q-,R-,S-,T-,V+,X+,Y+}
{$M 16384,0,65535}
unit flprsprt;

interface

Function upstring(name:string):string;
Function GetOpt(look:string):string;
Function IntToStr(I: LongInt): String;    { Convert any integer type to a string }
Function StrToInt(s:String):LongInt;    { Convert any string to integer }
Function FileExists(filename:String):Boolean;
Procedure fatalerror(s:String);
Procedure blip(freq,duration:word);
Procedure PrintHeader(progname,progdesc,progvers:string;progdate:longint);


implementation

uses
  crt;

Function FileExists(filename:String):Boolean;
Var
  f:File;
Begin
  Assign(f,filename);
  {$I-}
  Reset(f);
  {$I+}
  FileExists:=(IOResult = 0);
End;

Procedure blip(freq,duration:word);
begin
  sound(freq);
  delay(duration);
  nosound;
end;

Function upstring(name:string):string;
var
  foo:string;
  loop:byte;
begin
  for loop := 1 to Length(name) do
    foo[loop] := UpCase(name[loop]);
  foo[0]:=name[0];
  upstring:=foo;
end;

Function GetOpt(look:string):string;
const
  gotit:boolean=false;
var
  loop:byte;
  foo:string;
begin
  look:=upstring(look);
  for loop:=1 to paramcount do begin
    {grab param}
    foo:=upstring(paramstr(loop));
    {delete leading switch, if present}
    if (foo[1]='/') or (foo[1]='-')
      then delete(foo,1,1);
    {compare}
    if foo[1]=look[1]
      then gotit:=true
      else gotit:=false;
    if gotit then break;
  end;
  if gotit
    then begin
      delete(foo,1,1);
      GetOpt:=foo;
    end
    else GetOpt:=#0;
end;

Function IntToStr(I: LongInt): String;    { Convert any integer type to a string }
Var
  S: String[11];
Begin
  Str(I, S);
  IntToStr := S;
End;

Function StrToInt(s:String):LongInt;    { Convert any string to integer }
Var
  i:LongInt;
  foo:Integer;
Begin
  Val(S,i,foo);
  strtoint := i;
End;

Procedure fatalerror(s:String);
{allows a means of reporting errors and stopping the system}
Begin
  asm
    mov  ax,03h
    int  10h
  end;
  TextColor(lightRed);
  WriteLn('Fatal error: ',s);
  Halt;
End;

Procedure PrintHeader(progname,progdesc,progvers:string;progdate:longint);
const
  spacer=' ³ ';
{prints a standard welcome header for the utilities}
begin
  Writeln(progname,spacer,progdesc,spacer,'Version ',progvers,spacer,progdate);
  Writeln('Written by trixter@oldskool.org for the Flopper Project.');
  writeln('Use /? for available command-line options.');
end;

end.