uses
  d2type,DEngine,d2tabx86,dt2x86,da2x86,ds2x86,d2Comp,dos;

type


  pD2 = ^tD2;
  tD2 = object
    mem:longint;
    constructor init;
    destructor done;virtual;
    procedure run;
  end;



  constructor tD2.init;
  begin asm mov ax,3; int $10 end;
    mem:=MemAvail;
  End;


  Procedure tD2.Run;



var
  what:string;

Begin
  if paramcount>1 then begin
    if Boolean(Pos('.',ParamStr(2)))then
      Target:=ParamStr(2)
    else
      Target:=ParamStr(2)+'.'
  end else begin
    if Boolean(Pos('.',ParamStr(1)))then
      Target:=Copy(ParamStr(1),1,Pos('.',ParamStr(1)))
    else
      Target:=ParamStr(1)+'.';
  end;
  What:=ParamStr(1);
  if pos('.',what)=0 then what:=what+'.d2';

  Compile (_MOD,True,What);

  c^.Save(Target+DefExt[proctype])

End;


Destructor tD2.done;
Begin
  WriteLn('memory in use ',100.0*(Mem-MemAvail)/Mem:5:2,'% (avail ',mem div 1024,'Kb)');
  TAB.Done;
End;

Procedure Usage;
Begin
  writeln(' D2 Compiler by Eugene N Sazonoff (v.5.2.2.b)');
  writeln(' USAGE: run <source[.d2]> [target[.com|.lib]] ');
  writeln;
End;

var
  D2:pD2;
begin
  If ParamCount>0 Then Begin
    D2:=New(pD2,Init);
    D2^.Run;
    Dispose(D2,Done);
  End Else Begin
    Usage;
  End;
end.
