REM   "FIX" -- PROGRAM TO MANUFACTURE "DO" FILE TO RUN EDITOR,
REM            AND THEN INVOKE THE BASIC COMPILER, FOLLOWED BY ASSEMBLER
REM PROGRAM INVOCATION
REM     .FIX <PROG> [ WITH <FILE> ]
REM
REM          WHERE "PROG" IS NAME OF BASIC PROGRAM,
REM          AND "FILE" IS NAME OF OPTIONAL ASSEMBLY LANGUAGE ADDITION
REM     REVISION HISTORY:
REM     FIX 1.0 3/24/80
REM            1ST VERSION
REM     FIX 1.0A 1/29/81
REM            Creates JUNK.TMP, ASMLOG.TMP to override old versions,...
REM            thereby recovering virtually all the disk space held.
REM     FIX 1.0B 4/24/82
REM            Creates filenames of form: "filename.DO" in order to allow
REM            use under SDOS/MT 1.x (single directory SDOS)
REM            Added operator prompting and self-id message
REM            Set up to hunt for SEDIT or EDIT, in that order of preference
REM
     DIM VERSION$/"Fix v1.0b"/
     DIM COMMANDLINE$(120),BASICSOURCE$(50),ASMSOURCE$(50)
     DIM MAINNAME$(50)
     DIM EDITOR$(20)
     DIM CREATELOG$/:7,:E/

     ! FIND OUT WHAT USER WANTS
     IF COL(0)>1
     THEN
         ! SOPHISTICATED USER, READ INPUT LINE AND PARSE
         INPUT "" COMMANDLINE$
         PRINT VERSION$
     ELSE
         ! DUMB USER, GIVE HIM PROMPTS TO HELP HIM OUT
         PRINT VERSION$ \ ! LET HIM KNOW WHAT WE ARE
         INPUT "Name of BASIC program to compile: " BASICSOURCE$
         INPUT "Name of Assembly file to include: (default=NONE) " ASMSOURCE$
         COMMANDLINE$=BASICSOURCE$
         IF ASMSOURCE$<>""
         THEN LET COMMANDLINE$=COMMANDLINE$ CAT " with " CAT ASMSOURCE$
         PRINT "Next time, you can type:"
         PRINT "     .fix ";COMMANDLINE$
     FI
     ! RIP APART THE COMMAND LINE
     LET I=FIND(COMMANDLINE$," ")
     IF I=0
     THEN BASICSOURCE$=COMMANDLINE$
     ELSE BASICSOURCE$=LEFT$(COMMANDLINE$,I-1)
     LET I=FIND(BASICSOURCE$,".")
     IF I=0
     THEN LET BASICSOURCE$=BASICSOURCE$ CAT ".BAS"
     ! FIND PART OF FILENAME THAT DOES NOT INCLUDE THE EXTENSION
     FOR I=LEN(BASICSOURCE$) TO 1 STEP -1 UNTIL BASICSOURCE$[I,1]="." DO ! NADA
     LET MAINNAME$=BASICSOURCE$[1,I-1]
     REM RECOVER DISK SPACE CURRENTLY HELD BY MAINNAME.TMP FILES
     CREATE #1,MAINNAME$ CAT ".TMP"\CLOSE #1
     CREATE #1,MAINNAME$ CAT ".SYM"\CLOSE #1
     REM NOW CONSTRUCT A DO FILE TO FORCE WHAT WE WANT DONE
     CREATE #1,MAINNAME$ CAT ".DO"
     REM FIGURE OUT WHICH EDITOR TO USE...
     IF ERROR WHEN OPEN #2,"SEDIT"
     THEN
         ! USE CONVENTIONAL EDITOR
         EDITOR$="EDIT"
         REM PRINT #1,"EDIT" NOT NEEDED BECAUSE WE DO "CHAIN" TO IT!
         PRINT #1,"EB";BASICSOURCE$;"\1A? EICONSOLE:\B23T"
         ! IF EDIT ACCEPTED THE REST OF THE SOURCE LINE AS AN EB FILENAME,
         ! THEN ONE COULD SIMPLY RENAME THE DESIRED EDITOR AS "EDIT"
         ! AND ALL OF THESE SHENANIGANS WOULD BE UNNECESSARY
     ELSE
         ! SEDIT EXISTS, AND IT IS PERFECT FOR EDITING BASIC PROGRAMS.
         ! USE SCREEN EDITOR
         EDITOR$="SEDIT"\CLOSE #2
         PRINT #1,BASICSOURCE$
     FI
     PRINT #1,"COMPILE ";COMMANDLINE$
     CLOSE #1
     REM DO FILE IS BUILT, NOW "DO" IT!
     CLOSE #0
     OPEN #0,MAINNAME$ CAT ".DO"
     DELETE MAINNAME$ CAT ".DO"
     IF ERROR WHEN SYSCALL(CREATELOG$,"CONSOLE:",COMMANDLINE$)
     THEN IF ERR<>1031 THEN ERROR \ ! IGNORE ERROR CAUSED IF LOGGING ACTIVE
     PRINT ".";EDITOR$ \ ! JUST TO MAKE IT LOOK LIKE WE WENT THRU SDOSCMDS
     CHAIN EDITOR$
     PRINT "AAAAIIIIIEEEEE!!!!!"
     END
END
