unit fx;
interface
Function  valu(q:string):Integer;
Procedure Print(S : String);
Procedure Println(S : String);
function  direxist(d:string): boolean;
procedure printxy(x,y:byte;s:string);
function  yn(s:boolean):string;
Function Padstring(Outp : String;Number : Byte): String;
implementation
uses dos,crt;

Function Padstring(Outp : String;Number : Byte): String;
Var X : Byte;
Begin
 For X := 1 to (Number - Length(Outp)) do Outp := Outp + ' ';
 Padstring := Outp;
End;

function yn(s:boolean):string;
begin
if s=true then YN:='Yes' ELSE
               YN:='No ';
end;

procedure printxy(x,y:byte;s:string);
begin
gotoxy(x,y);
print(S);
end;

function direxist(d:string): boolean;
  var
    f   : file;
    attr: word;
    len : byte;
  begin
    len:= length(d);
    if (d[len] = '\') then         {if d has a trailing slash...         }
      dec(d[0]);                   {remove the trailing slash.           }
    d:= d + '\.';                  {add '\.' to d                        }
    assign(f,d);                   {assign d to f                        }
    getfattr(f,attr);              {get the attribute word               }
    direxist := ((attr and directory)=directory);
                                   {return true if attr is directory     }
  end;

Function valu(q:string):Integer;
Var i,s,pu:Integer;
    r:Real;
Begin
 valu:=0;
 If Length(q)=0 Then exit;
 If Not(q[1] In ['0'..'9','-']) Then exit;
 If Length(q)>5 Then exit;
 Val(q,r,s);
 If s<>0 Then exit;
 If (r<=32767.0) And (r>=-32767.0) Then valu:=Round(r)
End;

Procedure print(S : String);
Var X,Code : Byte;
    Error  : Integer;
    Total : Byte;
Begin
Total := Length(S);
For X := 1 to Total do
 Begin
  If S[X] <> '|' then Write(S[X])

   Else
         if s[x+1]='B' then begin
                          textbackground(valu(s[x+2]));
                          inc(x,2);
                          end
                          else
 Begin
         Val(Copy(S,X + 1,2),Code,Error);
         If Error>0 then Write(S[X])
                     Else Begin
                            If Code<16 then Textcolor(Code)
                             Else Textbackground(Code-16);
                            If X + 2 > total then Inc(X,1) else Inc(X,2);
                           End;
        End;
 End;
End;

Procedure Println(S : String);
begin
print(s+#10+#13);
end;

begin
end.