! 'FR_Do'     F-BASIC Compile & Run      Written by Roy M. Nuzzo

! Compile and save as 'FR' in the 'TBDo' drawer.
! This is a 'Do' program called from within the True BASIC editor.
! Save the file to the 'FB:' directory.
! At the command window type "do FR, filename"  <no quotes> then enter.
! F-BASIC is case sensitive so use correct case.
! The True BASIC editor will launch FB:FB with the debugger option.
! If the file screws up, the debugger leaves a text file read by
! this Do program.
! The Do program returns to the editor with the line number that failed.
! 
! At the command window type "to <linenumber>"

EXTERNAL

sub FBasicCompile(line$(),FileName$)
    LIBRARY "{TBLibrary}AmigaLib*"

    let FileName$ = Trim$(FileName$)


    if FileName$ = "" then
       ! TRY NAME OF CURRENTLY LOADED FILE
       ask name FileName$
       when error in
         open #100: name "FB:" & FileName$, organization TEXT, CREATE OLD
         close #100
       use
         close #100
         cause error 1, "Use: Do FB, filename"
       end when
    end if


    when error in

         when error in
           call CLI("Delete FB:" & FileName$ & ".EXT")
         use
         end when

         call CLI("FB " & FileName$ & " opt-d")
         sound 1000,.01

         let ErrNum$ = " No Err."
         let count = 0

         WHEN ERROR IN
           open #100: name "FB:" & FileName$ & ".EXT", organization TEXT, CREATE OLD
            set #100: POINTER BEGIN
           
           do while more #100
              Line input #100: s$
              let count = count +1
           loop

           let ErrNum$ = " Err at " & STR$(count) & ".  Resave after correcting."
           sound 3000,.01

         USE
         END WHEN
         close #100

         call CLI("FB:" & FileName$ & ".bin")
    use
         cause error 1, Extext$ & ErrNum$
         exit sub
    end when

    cause error 1, "Done." & ErrNum$
end sub

