'---------------------------------------------------------------------------
'
'                        BASIC Linker
'
'
'                 Copyright 1987 by Brian Zupke
'
'
'    This program creates an executable BASIC program from an object
'  module source library.  Object modules are indicated by the '.sub'
'  extension on the module name.
'
'
  DIM ModulesUsed$(40)
  DIM SHARED TRUE,FALSE,NoError
'
'  constants:
'
  TRUE = -1
  FALSE = 0
'
'  Trap I/O errors
'
  ON ERROR GOTO ProcessError
  NoError = TRUE
'
'  Set program name, disk pathnames, and Compress flags.
'
  CALL GetLinkerInfo.SUB(ProgramName$,LibraryPathname$,ProgramPathname$,Compress)
'
'  Open output file
'
   OPEN ProgramPathname$+ProgramName$+".EXE" FOR OUTPUT AS #2  len = 4096
   IF NoError THEN
'
'  Linke modules to create an executeable program.
'
      CALL LinkModules.SUB(ProgramName$,ModulesUsed$(),Used,ProgramCreated)
'
'  Report results
'
      IF ProgramCreated THEN
         PRINT "Link Complete - Program saved as ";ProgramName$;".EXE"
      ELSE
         PRINT "Link Failed"
      END IF
   ELSE
      PRINT "Unable to open output file - Link Failed"
   END IF
   CLOSE 2
   END
'
'
'  Process I/O errors only.
'
'
ProcessError:
  IF ERR = 53 OR ERR = 61 OR ERR = 64 OR ERR = 68 OR ERR = 70 THEN
    NoError = FALSE
    IF ERR = 70 THEN
      PRINT "Disk write-protected!"
    ELSEIF ERR = 61 THEN
      PRINT "Disk FULL!"
    ELSE
      PRINT "Unable to access file."
    END IF
    RESUME NEXT
  ELSE
    ON ERROR GOTO 0
  END IF

