1 ! PATCH.BAS [1,200]:
	 ! UTILITY PROGRAM - OVERLAYS A FILE ON ALL BASIC PROGRAMS IN THE ACCOUNT:
	 ! THAT HAVE BOTH A .BAS AND .BAC VERSION:
	 ! BOTH VERSIONS ARE UPDATED WITH THE OVERLAY
2 ! :
	 ! 	BONNIE KAPLAN			5-OCT-78:
  ! 
3 ! :
	 ! ASSUMES THAT EVERY BAC FILE HAS A CORRESPONDING BAS FILE:
	 ! THE BAS FILE IS OVERLAID AND THEN RECOMPILED WITHOUT COMMENTS
4 ! :
	 ! MODIFIED FROM COMPILE.BAS [1,200]
5 ! 
100	 ! INITIALIZATIONS
110 DIM R$[132]V				: ! RECORD
120 DIM BS$[4], BP$[4]				: ! FILE EXTENSIONS
122 BS$=".BAS"
124 BP$=".BAP"
130 DIM F$[12]V					: ! FILE NAME
140 DIM Q$[1]					: ! QUOTES
145 Q$=CHR$(34)			: ! ** CHR$(34) IS A CALL FOR A " (QUOTE)
150	 ! WHAT FILE IS THE OVERLAY FILE ?
160 DIM O$[26]V					: ! NAME OF OVERLAY FILE
170 INPUT LINE "NAME OF OVERLAY FILE.  (INCLUDE EXTENSION IF NOT .BAS) "; O$
180 IF POS(O$,".")=0 THEN O$=O$+".BAS"
190 IF LEN(O$)>26 THEN  PRINT "FILE NAME TOO LONG (9.3)" : GOTO 170
200	 ! CREATE SORTED DIRECTORY FILE SO CAN FIND *.BAC
210 S=0:
    CALL "SPAWNB" ("PIP *.BAC/PU", S):
    IF S<0 THEN  PRINT "PIP PURGE ERROR" : STOP 	: ! ELIMINATE ALL BUT ONE VERSION OF BAC FILES
220 S=0:
    CALL "SPAWNB" ("SRX SRX.DAT=", S):
    IF S<0 THEN  PRINT "SRX ERROR" : STOP 
230 PRINT : PRINT "PROGRAMS BEING OVERLAID AND RECOMPILED:" : PRINT 
300	 ! FIND *.BAC SECTION
310 OPEN #3, "SRX.DAT/EN:900"
320 INPUT LINE #3, R$
330 P=POS(R$,".BAC")
340 IF P=0 THEN 320				: ! GO THRU FILE UNTIL FIND *.BAC
400	 ! RECOMPILE EACH BAC FILE:
	 ! :
	 ! THE PROGRAM AND ITS OVERLAY SECTION ARE MERGED USING PIP.  TWO:
	 ! COPIES OF THE MERGE ARE CREATED, ONE TO BE SAVED .BAS AND ONE:
	 ! TO BE SAVED .BAC  (THE .BAC VERSION IS FIRST DONE AS .BAP):
	 ! 
410 F$=LEFT(R$,P-1)				: ! GET FILE NAME (P SET IN SECTION 300)
420 PRINT F$
430 S=0:
	 CALL "SPAWNB" ("PIP "+F$+BP$ + "=" + F$ + BS$ + "," + O$, S):
	 IF S<0 THEN  PRINT "PIP ERROR - CREATE .BAP (TEMP) VERSION" : STOP :
	 ! COPY THE BAS VERSION AND THE OVERLAY INTO ONE FILE NAMED .BAP
435 S=0 :
	 CALL "SPAWNB" ( "PIP " + F$+BS$+ "/NV = " + F$+BP$, S):
	 IF S<0 THEN  PRINT "PIP ERROR - CREATE NEW .BAS VERSION" : STOP :
	 ! COPY VERSION WITH OVERLAY INTO .BAS FILE ALSO
440 OPEN #4, F$+BS$+"/AP/LN:132"
443 PRINT #4, "SAVE : EXIT" : ! ADD SAVE "PROGRAM" AND EXIT
446 CLOSE 4
450 S=0 :
	 CALL "SPAWNB" ("B11 " + F$+BS$, S) :
	 IF S<0 THEN  PRINT "B11 ERROR - FIRST READ-IN " : STOP :
	 ! WILL READ IN AND SAVE PATCHED VERSION
460 OPEN #4, F$+BP$+"/AP/LN:132"
463 PRINT #4, "SAVE " + Q$ + "/CO" + Q$ + ": EXIT" : ! ADD SAVE "/CO" : EXIT TO COPIED BAS VERSION
466 CLOSE 4
470 S=0 :
	 CALL "SPAWNB" ("B11 " + F$+BP$ + "/RT", S) :
	 IF S<0 THEN  PRINT "B11 ERROR - SECOND (/RT) READ-IN" : STOP :
	 ! WILL READ IN AND SAVE PATCHED VERSION IN COMPILED FORM
500	 ! CONTINUE UNTIL REACH END OF BAC SECTION
510 INPUT #3, R$
520 P=POS(R$,".BAC")
530 IF P=0 THEN 900
540 GOTO 400
900	 ! HAVE NOW DONE ALL RECOMPILATIONS.  CLEAN UP
910 S=0:
    CALL "SPAWNB" ("PIP *"+BP$+";*/DE", S):
    IF S<0 THEN  PRINT "PIP PURGE ERROR - TEMP FILES" : STOP 
920 S=0:
    CALL "SPAWNB" ("PIP *.BAC/PU", S):
    IF S<0 THEN  PRINT "PIP BAC PURGE ERROR" : STOP 
930 S=0:
    CALL "SPAWNB" ("PIP SRX.DAT;*/DE", S):
    IF S<0 THEN  PRINT "PIP DELETE ERROR - SRX.DAT" : STOP 
940 S=0 :
	 CALL "SPAWNB" ( "PIP *"+BS$+"/PU", S):
	 IF S<0 THEN  PRINT "PIP PURGE ERROR - BAS FILES" : STOP 
1000	 ! CLOSE FILES - END PROGRAM
1010 EXIT 
