USES
sysutils,dos;


VAR

mprog,mpas,mbase,temp,dummy   : AnsiString;
bppath,bpopt,fpcpath,fpcopt   : AnsiString;
fcfg	: text;
Function LTrimBP( s : String) : String;
VAR
i,l : Integer;
a : AnsiString;
begin
a := s;
L := Length(a);
IF L > 0 THEN
  BEGIN
      For i := 1 to L DO
        BEGIN
            IF Byte(a[i]) > 32 THEN
              BEGIN
                  IF i > 1 THEN
                    BEGIN
                        DELETE(a,1,i-1);
                        BREAK;
                    END
                  ELSE
                      BEGIN
                        BREAK;
                    END;
              END;
        END;
  END
ELSE
    BEGIN
      a := '';
  END;
LTrimBP := a;
END;
Function ExtractBP(ss : String;cc : String) : String;
VAR
fcxdb : Byte;
begin
fcxdb := Pos(cc,ss);
ExtractBP := LeftStr(ss,fcxdb-1);
END;
PROCEDURE OpenReadBP(VAR fh : Text; name : String);
begin
Assign(fh,name);
Reset(fh);
END;
FUNCTION SnipFirstWord(Var s : String) : String;
VAR
i,L	: Integer;
a	: Ansistring;
begin
s := LTrimBP(s);
L := Length(s);
IF L > 0 THEN
  BEGIN
      FOR i := 1 to L DO
        BEGIN
            IF Byte(s[i]) < 33 THEN
              BEGIN
                  a := LeftStr(s,i-1);
                  Delete(s,1,i-1);
                  s := LTrimBP(s);
                  BREAK;
              END;
        END;
  END;
SnipFirstWord := a;
END;

begin




mprog := Paramstr(1);


mbase := ExtractBP(mprog,'.');
mpas := mbase + '.pas';
Writeln ( mprog,' ',mpas);
IF FileExists('rbpcfg.dat') then
  BEGIN
      OpenReadBP(fcfg,'rbpcfg.dat');
      While not eof(fcfg) DO
        BEGIN
            Readln(fcfg,temp);
            dummy := SnipFirstWord(temp);
            IF UpCase(dummy) = 'BP' THEN
              BEGIN
                  bppath := temp;
              END;
            IF UpCase(dummy) = 'BPOPT' THEN
              BEGIN
                  bpopt := temp;
              END
            ELSE
                BEGIN
                  bpopt := '';
              END;
            IF UpCase(dummy) = 'FPC' THEN
              BEGIN
                  fpcpath := temp;
              END;
            IF UpCase(dummy) = 'FPCOPT' THEN
              BEGIN
                  fpcopt := temp;
              END
            ELSE
                BEGIN
                  fpcopt := '';
              END;
      END;
      Close(fcfg);
      
      {BPOPT = MBASE + ' ' + BPOPT }
      BPOPT := mprog;
      Writeln ( bppath,' ',bpopt);
      Exec(bppath,bpopt);
      
      FPCOPT := FPCOPT + MPAS;
      Writeln ( fpcpath,' ',fpcopt);
      Exec(fpcpath,fpcopt);
  END;

END.
