2!		PROGRAM		: BUILD.BAS
5!		VERSION		: V10.1
6!		EDIT		: A
7!		EDIT DATE	: 10-MAY-91
10		EXTEND
11	! &
	&
	&
	!		  C O P Y R I G H T &
	&
	&
  !		      Copyright (C) 1977, 1991 by &
  !	        Digital Equipment Corporation, Maynard, Mass. &
  !	&
  !	&
  !	This software is furnished under a license and may be used and &
  !	copied  only  in accordance with the terms of such license and &
  !	with the  inclusion  of  the  above  copyright  notice.   This &
  !	software  or  any  other copies thereof may not be provided or &
  !	otherwise made available to any other person.  No title to and &
  !	ownership of the software is hereby transferred. &
  !	&
  !	The information in this software is subject to change  without &
  !	notice  and should not be construed as a commitment by Digital &
  !	Equipment Corporation. &
  !	&
  !	DIGITAL assumes no responsibility for the use  or  reliability &
  !	of its software on equipment that is not supplied by DIGITAL. &
  !	&
  !******************************************************************* &

20	! &
	&
	&
	!	M O D I F I C A T I O N    H I S T O R Y &
	&
	&

21	! VER/ED	EDIT DATE	REASON &
	! V9.0-05A	04-Mar-84	(PRL) Add /TYPE:REAL for BP2 builds &
	! V9.0-05B	14-Mar-84	(PRL) Change "create account" questions &
	!				      Fix "Use CSPCOM?" question &
	! V9.0-07A	12-Sep-84	(PRL) Always switch into RT11 because &
	!				      ASSIGN's don't work in DCL &
	! V9.0-09	02-Nov-84	(PRL) Update for multiple privs &
	!				      Convert to use DCL commands &
	!				      Remove useless prompts &
	!				      Remove check/install RT11 &
	! V9.0-12	07-Mar-85	(PRL) Require WWRITE priv to run &
	! V9.0-13	12-Mar-85	(PRL) Require most privs to run &
	! V9.0-14	08-Apr-85	(PRL) Add check for TMPPRV privilege &
	! ================================================================== &
	! V9.1-04	05-Jun-85	(JJT) Add high density support &
	! V9.1-04	20-Jun-85	(PRL) Fix $PROMPT RTS with ...RSX &
	! V9.1-04	05-Aug-85	(JJT) Fix bug when no /DEN specified &
	! V9.1-05	16-Aug-85	(PRL) Clean up some PEEKs &
	!				      Fix privilege error message &
	! V9.4-02	25-Feb-87	(JJT) Don't require SETPAS or GACNT &

300	! &
	&
	&
	!	I / O    C H A N N E L S &
	&
	&
	&
	!     CHANNEL #		USED FOR &
	!	9%		STACK AND SUBSTITUTION STRING STORAGE. &
	!	10%		COMMAND FILE INPUT CHANNEL &
	!	11%		SECONDARY (INDIRECT/PATCH) COMMAND FILES AND COPY &
	!	12%		WORK FILE FOR PASSING INFORMATION BETWEEN PROGRAMS &

400	!	V A R I A B L E    D E F I N I T I O N S &
	&
	&
	&
   	! VARIABLE NAME		USED FOR &
	! &
	! C0		COUNT OF LINES READ FROM KB &
	! C0$		STRING CONTAINING NAME OF COMMAND FILE FOR AUTOED &
	! C1$		UTILITY VARIABLE &
	! CDFL%		PROTECTION CODE FLAG FOR FILENAME IN $END STATEMENT &
	! CMPFLG%	FLAG SET IF USER SELECTS TO HAVE PATCHED FILES &
	! 		COMPILED &
	! CMPPRM$	PROMPT REQUESTING DEV/PPN FOR LIBRARY &
	! CMPQST$	"COMPILE PATCHED FILES?" PROMPT &
	! CRLF$		CARRIAGE RETURN LINE FEED &
	! CRC$		CHR$(13%) &
	! CURRNT$	DEVICE/PPN FOR CURRENT ACCOUNT &
	! D0%		FLAGS INDICATING A DISK DEVICE IN STATUS FLAG &
	! DEVBITS%	AS ABOVE BUT INCLUDES UNDEFINED LOGICAL NAME FLAG &
	! DVST%   	WORK VARIABLE CONTAINING DEVICE STATUS AS RETURNED &
	! 		BY FILE NAME STRING SCAN &
	! E%		VARIABLE SET TO ERROR TYPE CODE &
	! E0%		CHAIN ENTRY FLAG &
	! EXTBITS%	BITS IN STRING SCAN STATUS WORD CONCERNING THE &
	! 		FILENAME EXTENSION &
	! F0%		UTILITY VARIABLE &
	! FLNBITS%	BITS IN STRING SCAN STATUS WORD CONCERNING THE &
	! 		FILENAME &
	! I$		VERSION/EDIT NUMBER &
	! I%		UTILITY VARIABLE &
	! INPDEV$	CURRENT DEVICE/PPN FOR INPUT OF FILES TO PATCH &
	! INPPRM$	PROMPT TO USER FOR ABOVE INPUT &
	! JN$		CURRENT JOB NUMBER &
	! L0$		NAME OF LOG FILE WHICH WILL BE SUPPLIED TO CPATCH &
	! L1$		UTILITY VARIABLE &
	! LIBDEV$	DEVICE/PPN FOR LIBRARY &
	! M0%(30),M1%(30) UTILITY ARRAY USED IN STRING SCANS &
	! MRG1%		UTILITY VARIABLE &
	! N0%		UTILITY VARIABLE &
	! NCMP$		STRING CONTAINING "/NC" &
	! NL$		A NULL STRING CONSTANT &
	! NPG%		PROJECT NUMBER OF CURRENT USER &
	! NPJ%		PROGRAMMER NUMBER OF CURRENT USER &
	! OFLG%		SET TO -1% IF OUTPUT DEVICE FOR PATCHED FILES IS &
	! 		NOT A FILE STRUCTURED DISK &
	! OPTDEV$	DEVICE/PPN OF FILE STRUCTURED DISK FOR TEMPORARY &
	! 		PLACEMENT OF FILE BEING PATCHED.  WILL BE THE SAME &
	! 		AS PRMDEV$ BELOW IF PRMDEV$ IS A FILE STRUCTURED DISK &
	! OPTPRM$	PROMPT TO REQUEST ABOVE DEV/PPN &
	! P0%		UTILITY VARIABLE &
	! PPNBITS%	FLAG BITS IN FILE NAME SCAN STATUS WORD &
	! 		PERTAINING TO PROJECT PROGRAMMER NUMBER &
	! PRMDEV$	DEVICE/PPN OF OUTPUT DEVICE FOR PATCHED FILES &
	! PRV%		USER HAS REQUIRED PRIVILEGES TO CONTINUE &
	! PRTBITS%	FLAG BITS IN FILE NAME SCAN STATUS WORD &
	! 		PERTAINING TO PROTECTION CODE &
	! S0$		FILE NAME STRING SCAN FIP CALL &
	! S0%,S1%	UTILITY VARIABLES &
	! SAVFLG%	SET IF USER WISHES TO SAVE PATCHED SOURCES &
	! SAVQST$	PROMPT ASKING WHETHER OR NOT TO SAVE PATCHED SOURCES &
	! SP%		STACK POINTER TO ARRAY stak$ &
	! STAK$(31)	FILE NAME STACK FOR NESTING INDIRECT COMMAND FILES &
	! SYSDEV$	SYSTEM DEVICE/PPN &
	! SYSPRM$	PROMPT TO REQUEST ABOVE DEVICE/PPN &
	! T0-Tn(% OR $)	TEMPORARY (SCRATCH) VARIABLES &
	! TST0%		UTILITY VARIABLE &
	! W%		UTILITY VARIABLE &

800	! &
	&
	&
	!	F U N C T I O N / S U B R O U T I N E    D E S C . &
	&
	&
	&
	! &
	&
	&
	&
	!	S U B R O U T I N E S &
	&
	&
	! SUBROUTINE	LINES		USED FOR &
	! &
	! INIT		10000-10020	INITIALIZE PROGRAM VARIABLES &
	! &
	&
	&
	&
	!	F U N C T I O N S &
	&
	&
	&
	! FNFLNC$(P$,F%,DFLT$) &
	!		15000-15090	RETURN FILE NAME P$ WITH ALL MISSING &
	!				PARTS OF NAME (EXTENSION ETC.) &
	!				FROM STRING DFLT$.  CHECK STRING &
	!				FOR VALIDITY ACCORDING TO FLAG F% &
	! &
	! FNF$(P0$,D0$,F1%,MRG$) &
	!		15200-15220	INPUT FILE NAME. P0$ IS USED AS A &
	!				PROMPT, DEFAULT RESPONSE IS D0$. &
	!				DEFAULTS FOR ANY FIELDS OF RESPONSE &
	!				WHICH ARE ABSENT (EXTENSION, ETC.) &
	!				ARE TAKEN FROM MRG$ AND THE RESULTING &
	!				STRING IS CHECKED FOR VALIDITY USING &
	!				FNFLNC$ AND FLAG F1% &
	! &
	! FNR$(S1$,S2$,S3$) &
	!		15300-15350	RETURN S1$ WITH ALL OCCURANCES OF &
	!				S2$ REPLACED BY S3$ &
	! &
	! FNSB$(ST0$)	15400-15410	REPLACE LOGICAL DEVICE NAMES AND &
	!				CONTROL CHARACTERS WITH EXPANDED &
	!				VALUES WHEN FORCING DATA DIRECTLY &
	!				TO THE KEYBOARD USING THE $FORCE &
	!				DIRECTIVE (SEE FUNCTION FOR VALUES) &
	! &
	! FNIND%	15500-15570	RETURN NEXT COMMAND IN INDIRECT &
	!				COMMAND FILE. COMMAND IS RETURNED &
	!				IN STRING C0$.  FUNCTION RETURNS &
	!				ERROR INDICATOR &
	! &
	! FNFM$(A0$,A1$,FLG%) &
	!		17300-17395	MERGE FILE NAME STRING A0$ INTO A1$ &
	!				BY INSERTING INTO A1$ ALL PARTS OF A0$ &
	!				WHICH ARE BOTH MISSING FROM A1$ AND &
	!				SELECTED BY BITS IN FLG% &
	! &
	! &
	! FNILN$	17600-17620	INPUT LINE FROM KB: ON CHANNEL 10% &
	!				TRAPPING EOF ERRORS &
	! &

900	! &
	&
	&
	!	D I M E N S I O N    S T A T E M E N T S &
	&
	&
	&
	DIM M0%(30%),M1%(30%) &
	\ DIM #9%, SUBN$(75%)=26%,STAK$(31%)=32%,SUBR$(75%)=26% &

1000	! &
	&
	&
	!	M A I N    C O D I N G    A R E A &
	&
	&
	&
	ON ERROR GOTO 19000 &
	\ I$="V10.1-A" &
	\ BTLV%=0% &
	\ PRINT IF CCPOS(0%) &
		! SET UP STANDARD ERROR TRAP &
		! SET UP VERSION/EDIT NUMBER &
		! RETURN KB TO LEFT MARGIN &
	&
	&
	\ GOTO 1020 IF E0% &
	\ CHANGE SYS(CHR$(12%)) TO M0% &
	\ TAP%=0% &
	\ PKLO$="_SY:" &
	\ IF (M0%(26%) AND 1%) THEN &
	  	PKLO$="_"+CHR$(M0%(23%))+CHR$(M0%(24%)) &
	\	PKLO$=PKLO$+NUM1$(M0%(25%)) IF M0%(26%) &
	\	PKLO$=PKLO$+":" &
	\	IF (STATUS AND 255%)=14% THEN &
			TAP%=-1% &
	\		OPEN PKLO$ FOR INPUT AS FILE 1% &
	\		I%=MAGTAPE(7%,0%,1%) &
	\		I0%=MAGTAPE(12%,0%,1%) &
	\		CLOSE 1% &
	\		PKLO$=PKLO$+"/DEN:" + NUM1$(I0%) &
	\		ON ERROR GOTO 19000 &
	\		IF I0% = 800% THEN &
				PKLO$=PKLO$+"/PAR:" &
	\			PKLO$=PKLO$+"ODD" UNLESS I% AND 2048% &
	\			PKLO$=PKLO$+"EVEN" IF I% AND 2048% &
		! SET UP NAME OF DEVICE FROM WHICH WE WERE RUN. &
	&
		! NOTE : BOTTOM TWO BITS OF BYTE 26 OF RETURNED STRING &
		! ARE CODED AS : &
		!	BIT 0 = 0 => SOURCE DEVICE IS PUBLIC &
		!		1 => SOURCE DEVICE IS PRIVATE &
		!	BIT 1 = 0 => GENERAL SPECIFICATION (IE, _SY:) &
		!		1 => SPECIFIC SPECIFICATION (E.G., _SY0:, _DK0:) &
	&
		! IF DEVICE IS MAGTAPE THEN &
		!	SET UP DENSITY AND PARITY DEFAULTS BASED ON &
		!	 CURRENT SETTINGS OF TAPE DRIVE. &
	&

1020	PRINT "BUILD  ";I$;CHR$(9%);FNE$(0%);CHR$(13%);CHR$(10%) UNLESS E0% &
		! PRINT SYSTEM HEADER FOR A RUN ENTRY &
	&
	\ GOSUB 10000 &
	\ IF NOT PRV% THEN &
		FATLER%=-1% &
	\	GOTO 32700 &
		! DO INITIAL SET UP. &
		! DIE UNLESS USER HAS NEEDED PRIVS &
	&

1040	! &
	&
	&
	&
	!	M A I N   P R O G R A M &
	&
	&
	&
	GOTO 1065 IF E0% &
	\ GOSUB 11045 &
	\ STRTLO$=INDV$+INAC$ &
	\ STRTYP%=INST% &
		! SKIP TO 1065 (I.E. AVOID DIALOG ) IF CHAIN (PBUILD) ENTRY. &
		! GOSUB TO ASK INPUT DEVICE QUESTION. &
	&

1050	LBDV$,SYDV$="_SY:" &
	\ SYDV$=FNF$("Output device","_SY0:",37%,NL$) &
	\ GOTO 1050 IF DVST% AND 255% &

1060	LBAC$="[1,2]" &
	\ GOTO 1060 UNLESS LEN(FNFLNC$(LBDV$+LBAC$,301%,NL$)) AND &
				LEN(FNFLNC$(SYDV$+LBAC$,301%,NL$)) &
		!					301%=1+4+8+32+256 &
	\ CTFL$=INDV$+INAC$+"BUILD.CTL" &
	\ CTFL$=CTFL$+"/MO:2" IF &
				INST%=14% AND TAP% AND (DENSET% = 1600%) &
	\ CTFL$=FNF$("Control File is",NL$,-32755%,INDV$+"$.CTL") &
		!				-32755%=(1+4+8)EQV 32767 &
		! ASK TARGET DEV QUESTION --> SYDV$		. &
		! ASK CMD FILE QUESTION   --> CTFL$. &
		! ADD /MO:2 IF INPUT DEVICE IS TAPE WE CAME FROM TAPE AND &
		!	IT IS 1600 BPI. &
	&

1065	Z$ = SYS(PRIV.ON$) &
	\ OPEN SYDV$+"[0,1]BADB.SYS" FOR INPUT AS FILE 12%, MODE 8192% &
	\ CHANGE SYS(CHR$(12%)) TO M0% &
	\ FORIGN%=M0%(26%) AND 1% &
	\ OPEN LBDV$+"[0,1]BADB.SYS" FOR INPUT AS FILE 12%, MODE 8192% &
	\ CHANGE SYS(CHR$(12%)) TO M0% &
	\ FORIGN%=(M0%(26%) AND 1%) OR FORIGN% &
	\ CLOSE 12% &
	\ Z$ = SYS(PRIV.OFF$) &
	\ RLIB$=LBDV$+LBAC$ &
	\ JMP%=-1% &
	\ RLIB$="_SY:[1,2]" UNLESS &
		LEN(FNFLNC$(RLIB$+"ATPK.*",15%,NL$)) &
	\ JMP%=0% &
	\ T0%=FNSETSB%("LIBDEV",LBDV$) &
	\ T0%=FNSETSB%("SYSDEV",SYDV$) &
	\ T0%=FNSETSB%("LIBACC",LBAC$) &
	\ SYAC$=LBAC$ UNLESS LEN(SYAC$) &
	\ T0%=FNSETSB%("SYSACC",SYAC$) &
	\ T0%=FNSETSB%("SYSTEM",LBDV$+LBAC$) &
	\ T0%=FNSETSB%("RUNLIB",RLIB$) &
	\ T0%=FNSETSB%("SYSDSK",SYDV$+SYAC$) &
	\ GOSUB 1083 &
	\ PADV$=FNFM$(PADV$,NL$,35%) &
	\ T0%=FNSETSB%("PATLOC",PADV$) IF E0% &
	\ OPTDV$=LBDV$+LBAC$ UNLESS LEN(OPTDV$) &
	\ RPIP$=R$+RLIB$+"PIP.SAV" &
		! SET UP GLOBAL SUBS. &
		! THESE CAN NOW BE ACCESSED BY THE SUBSTITUTION BIT. &
		! MTMODE="/MO:2" IF INPUT DEVICE IS MT: &
	&
	\ OPEN IOFL$+"/MO:32" FOR OUTPUT AS FILE 12% &
	\ T0%=FNPRNT%(ASGN$+INMT$+"/MO:1"+CRLF$) IF INST%=14% &
	\ GOTO 1075 IF E0% &
	\ T0%=FNPRNT%(ASGN$+SYDV$+"SYSDSK"+CRLF$) &
	\ T0%=FNPRNT%(ASGN$+LBDV$+"SYSTEM"+CRLF$) &
	\ T0%=FNPRNT%(ASGN$+LBAC$+CRLF$) &
	\ T0%=FNPRNT%(ASGN$+INDV$+IN$+CRLF$) &
		! OPEN OUTPUT FILE. (TENTATIVE) CHANNEL MUST BE CLOSED LAST. &
		! INSTRUCT PK: JOB TO SNAG INPUT DEVICE IF  MT: &
		! SET UP JOB LOGICALS FOR BUILD (SKIP IF PBUILD E0%). &

1075	GOSUB 1085 &
	\ NEWF%=-1% UNLESS E0% &
	\ GOSUB 1087 &
	\ NEWF%=0% UNLESS E0% &
	\ GOTO 2000 &
		! SET UP STACK FOR FIRST INPUT FILE. &
		!	SP%		RESET STACK POINTER. &
		!	STAK$(0%)	PUSH CURRENT INPUT FILE ON STACK. &
		!	C0		SET NUMBER OF LINES READ TO 0 &
		! COPY INPUT FILE TO [P]BLDnn.TMP &
		!	GO BACK AND TRY AGAIN IF COPY FAILED. &
	&

1080	CLOSE 10% &
	\ GOTO 32700 UNLESS NEWF% AND NONW%=0% &
	\ T2$=INDV$+INAC$+".CTL" &
	\ T2$=PADV$+".CMD" IF E0% &
	\ RSP$=CVT$$(FNF$( &
		"Additional Control File is <None>","\",-24576%,NL$),172%) &
		!				-24576=8192 EQV 32767 &
		!				172=4+8+32+128 &
	\ GOSUB 1095 IF COPERR% AND RSP$="\" &
	\ GOTO 32700 IF RSP$="\" &
	\ CTFL$=FNFLNC$(RSP$,-32739%,T2$) &
		!				-32739=(1+4+8+16)EQV 32767 &
	\ GOTO 1080 UNLESS LEN(CTFL$) &
	\ INFSTA%=DVST% AND 255% &
	\ INFSTA%=-14% IF INFSTA%=14% AND COPERR% &
	\ GOTO 1090 IF FNFM$(CTFL$,NL$,1%)=INDV$ &
!	\ IF FNFM$(CTFL$,NL$,1%)<>INDV$ THEN &
	\	PKLO$=INDV$ &
	\	GOSUB 1095 IF COPERR% &
	\	GOSUB 11045 &
	\	INFSTA%=-14% IF INFSTA%=14% &
	\	GOSUB 1083 &
	\	T0%=FNPRNT%(ASGN$+INDV$+IN$+CRLF$) &
	\	T0%=FNPRNT%(ASGN$+INMT$+"/MO:1"+CRLF$) IF INST%=14% &
	\	GOTO 1090 &
		! DON'T ASK FOR ANOTHER INPUT FILE UNLESS IT WAS A NEW FILE. &
		! ASK FOR ANOTHER INPUT FILE WITH PROPER MASH FOR BLD/PBLD. &
		! GET ANSWER DEFAULT IS *** I.E. DONE. &
		! IF INPUT FILE DEVICE<> CURRENT INPUT DEV: RE-ASK INP.DEV &
		!	QUESTION AND RE-SET SUBS ASSIGNMENTS IF IT CHANGED. &
		!	THIS ALLOWS ONE TO BUILD FROM MORE THAN ONE DISK. &
	&

1083	T0%=FNSETSB%(IN$,INDV$+INAC$) &
	\ T0%=FNSETSB%("INPDEV",INDV$) &
	\ T0%=FNSETSB%("MTMODE",NL$) &
	\ T0%=FNSETSB%("MTMODE","/MO:2") IF INST%=14% &
	\ RETURN &

1085	SP%=2% &
	\ STAK$(0%)=CTFL$ &
	\ STAK$(2%)=IOFL$ &
	\ C0=0. &
	\ RETURN &

1087	COPERR%=FNFILCPY%(CTFL$,IOFL$) &
	\ RESUME 1080 IF COPERR% &
	\ OPEN IOFL$ FOR INPUT AS FILE 10% &
	\ RETURN &

1090	GOSUB 1085 &
	\ CTFL$=CTFL$+"/MO:2" IF INFSTA%=14% &
	\ INFSTA%=ABS(INFSTA%) &
	\ GOSUB 1087 &
	\ GOTO 2000 &
		! SET UP STACK FOR FIRST INPUT FILE. &
		!	SP%		RESET STACK POINTER. &
		!	STAK$(0%)	PUSH CURRENT INPUT FILE ON STACK. &
		!	C0		SET NUMBER OF LINES READ TO 0 &
		! COPY INPUT FILE TO [P]BLDnn.TMP &
		!	GO BACK AND TRY AGAIN IF COPY FAILED. &
	&

1095	ON ERROR GOTO 1098 &
	\ OPEN INDV$ AS FILE 10% &
	\ T0%=MAGTAPE(3%,0%,10%) &
		! GET TAPE DRIVE AND REWIND IT &

1097	ON ERROR GOTO 19000 &
	\ RETURN &
		! RESET ERROR TRAP AND RETURN &

1098	RESUME 1097 &
		! IGNORE ANY ERRORS WE GET. &
	&

2000	! &
	!	MAIN GET/PROCESS COMMAND FILE LOOP &
	! &
	GOTO 1080 IF FNIND% &
	\ C$=CVT$$(C0$,164%) &
		!	164=4+32+128 &
	\ GOTO 2010 UNLESS ABORT% &
	\ FATLER%=-1% &
	\ PRINT "?Program aborted"; &
	\ PRINT " - ";SUBR$(0%) IF LEN(SUBR$(0%)) &
	\ RESUME 32700 &
		! INPUT A LINE. &
		! GOTO 2010 UNLESS WE WANT TO ABORT &
		! PRINT ABORT MESSAGE AND ABORT. &
	&
	&

2010	IF ASCII(C$)<>36% THEN &
		GOTO 2020 &
	ELSE &
		P%=1% &
	\	GOTO 2030 IF FNR%("DOPAT",-3%) &
	\	GOTO 2100 IF FNR%("PROMPT",-3%) &
	\	IF FNR%("BOOT",-4%)=0% THEN &
			GOTO 2000 IF BOT% &
		ELSE &
			GOTO 2070 IF BOT% &
	\		GOTO 2080
2015	IF FUNC%<>2% THEN &
		GOTO 2000 IF FNR%("BREAK",-3%) OR FNR%("END",-3%) &
	\	GOTO 2040 IF FNR%("DETACH",-3%) &
	\	GOTO 2050 IF FNR%("PATCH",-3%) OR &
			     FNR%("FORCE",-3%)
2020	GOTO 2050 UNLESS FUNC%=2% OR BOT% &
	\ GOTO 2000 &
		! IF 'PATCHING ONLY' IGNORE EVERYTHING EXCEPT &
		!	$DOPAT &
		!	$PROMPT &
		! &
		! $DOPAT  HANDLED AT 2030 &
		! $PROMPT HANDLED AT 2100 &
		! $BREAK IS A NOOP. &
		! $PATCH/$FORCE HANDLED AT 2050 &
		! $BOOT HANDLED AT 2080 &
		! PRINT LINE TO FILE (NORMAL LINE) UNLESS PATCHING ONLY &
		! GO BACK FOR MORE. &
	&

2030	! &
	!	$DOPAT &
	! &
	GOTO 2000 UNLESS FUNC% &
	\ GOTO 2000 UNLESS FNR%("@",1%) &
	\ DPAT%=SP% &
	\ C0$=" "+RIGHT(C0$,P%+1%) &
	\ P%,E%=0% &
	\ GOSUB 15570 &
	\ WHILE SP%>DPAT% &
	\	GOTO 2000 IF FNIND% &
	\ 	GOSUB 20000 IF SP%>DPAT% &
	\ NEXT &
	\ GOTO 1080 IF FNIND% WHILE FNR%("$BREAK",-4%)=0% UNLESS E% &
	\ GOTO 2000 &
		! $DOPAT &
		! $BREAK &
		! &
		!	SAVE STATE OF STACK &
		!	JUMP INTO 15570 TO GET TO NEW INPUT FILE. &
		!	KEEP GOING TO 20000 UNTIL BACK TO PROPER DEPTH. &
		!	TRASH EVERYTHING UNTIL $BREAK &
		!	GO BACK FOR MORE &
	&
	&
	&
	&
	&
	&

2040	! &
	! &
	!	$DETACH &
	! &
	GOTO 2000 UNLESS DTCH% &
	\ DTCH%=0% &
	\ NONW%=-1% &
	\ GOTO 2020 &
		! CHUCK THIS COMMAND UNLESS REQUESTED TO DETACH. &
		! ELSE CLEAR DETACH REQUESTED FLAG AND &
		! GO PRINT DETACH COMMAND TO FILE (ATPK WILL DETACH &
		! WHEN IT READS IT). &
		! WE DO NOT WANT TO CHANCE GETTING ANOTHER &
		! $DETACH SO DO NOT ASK FOR ANOTHER CONTROL FILE.
2050	! &
	!	$PATCH AND $FORCE &
	! &
	P%=0% &
	\ GOSUB 20000 &
	\ GOTO 2000 &
		! $PATCH AND $FORCE &
		! RESET P% &
		! GOSUB TO PBUILD ROUTINE &
		! GO BACK FOR MORE &
	&
	&
	&

2070	! &
	!	$BOOT &
	! &
	BOT%,E0%=0% &
	\ PRINT "BUILD has rebooted" &
	\ GOTO 2000
2080	GOTO 2000 UNLESS BTLV% < VAL(CVT$$(RIGHT(C$,P%+1%),-1%)) &
	\ PRINT "Please wait";CRLF$;"BUILD rebooting ..." &
	\ CLOSE 10% &
	\ T$="BLDB"+JN$+".TMP" &
	\ OPEN T$ FOR OUTPUT AS FILE 10% &
	\ PRINT #10%,	INDV$;CRLF$; &
			INAC$;CRLF$; &
			SAV.DEV$;CRLF$; &
			OPTDV$;CRLF$; &
			LBDV$;CRLF$; &
			LBAC$;CRLF$; &
			SYDV$;CRLF$; &
			SYAC$;CRLF$; &
			PADV$;CRLF$; &
			CTFL$;CRLF$; &
		"BOOT,";CMPFLG%;",";FUNC%;",";DTCH%;",'"+LOGF$+"'" &
	\ CLOSE 10% &
	\ BOT%=-1% &
	\ GOTO 32700 &

2100	! &
	!	$PROMPT &
	! &
	GOSUB 2110 &
	\ GOTO 2000 &

2110	NEWF%=-1% &
	\ T0%=INSTR(1%,C0$,"_") &
	\ WHILE T0% &
	\	C0$=LEFT(C0$,T0%-1%)+CHR$(ASCII(MID(C0$,T0%+1%,1%)) OR 128%)+ &
			RIGHT(C0$,T0%+2%) &
	\	T0%=INSTR(T0%,C0$,"_") &
	\ NEXT &
	\ GOTO 2200 IF P%=LEN(C$) IF FNR%("PATCH",-3%) &
	\ GOTO 2250 IF P%=LEN(C$) IF FNR%("RTS",-3%) &
	\ GOTO 2400 IF P%=LEN(C$) IF FNR%("PCTSK",-3%) &
	\ GOTO 2155 IF P%=LEN(C$) IF FNR%("ALB:",-3%) &
	\ GOTO 2150 IF P%=LEN(C$) IF FNR%("LB:",-2%) &
	\ RETURN IF P%=LEN(C$) OR FNR%("!",1%) &
	\ GOTO 2300 &
		! $PROMPT &
		! SET FLAG SAYING THIS IS A "NEW STYLE FILE" &
		! SET PARITY ON ANY CHARACTER WHICH IS UNDERSCORE QUOTED &
		! DISPATCH FOR TYPES OF PROMPTS. &
		!	$PROMPT PATCH HANDLED AT 2200 &
		!	$PROMPT RTS   HANDLED AT 2250 &
		!	$PROMPT PCTSK HANDLED AT 2400 &
		!	$PROMPT LB:   HANDLED AT 2150 &
		!	$PROMPT ALB:  HANDLED AT 2155 &
		!	$PROMPT      BUILD COMMENT (INTERNAL) &
		!	$PROMPT (THE NULL PROMPT) NOOP GO BACK &
		!	$PROMPT (GENERAL) HANDLED AT 2300 &

2150	! &
	!	$PROMPT LB: &
	! &
	! FORIGN ONLY &
	GOTO 2185 UNLESS FORIGN%
2155	! &
	! &
	! LOCAL &
	GOTO 2185 IF LB.SET% &
	\ RSP1$=LB$ &
	\ RSP1$=FNFM$(LB$,SYDV$,3%) IF FORIGN% &
	\ RSP$=FNF$("Locate logical 'LB:' on",RSP1$,301%,RSP1$) &
	\ S$=FNFM$(RSP$+"LB",NL$,7%) &
	\ GOTO 2155 IF FNAC%(S$,-1%) &
	\ GOTO 2170 IF FORIGN% &
	\ M0%(I%)=0% FOR I%=0% TO 30% &
	\ M0%(0%)=30% &
	\ M0%(1%)=6% &
	\ M0%(2%)=21% &
	\ M0%(I%)=M1%(I%) FOR I%=5% TO 26% &
	\ CHANGE M0% TO S$ &
	\ ON ERROR GOTO 2190 &
	\ S$=SYS(S$)
2160	M0%(3%)=1% &
	\ CHANGE M0% TO S$ &
	\ S$=SYS(S$) &
	\ S$=NL$
2170	IF FORIGN% THEN &
		T0%=FNPRNT%("DEASSIGN"+CRLF$) &
	\	T0%=FNPRNT%(ASGN$+INMT$+"/MO:1"+CRLF$) IF INST%=14% &
	\	T0%=FNPRNT%(ASGN$+RSP$+"LB"+CRLF$) &

2180	T0%=FNSETSB%("LB",RSP$) &
	\ LB$=RSP$ &
	\ LB.SET%=-1%
2185	ON ERROR GOTO 19000 &
	\ RETURN &

2190	RESUME 2160 IF ERL=2155 &
	\ PRINT FNE$(ERR);" On ADD LOGICAL" &
	\ RESUME 2170 &
	&
	&

2200	! &
	!	$PROMPT PATCH &
	! &
	RETURN IF FUNCSET% &
	\ RSP$=FNF$("Function (Build/Patch, Patch, Build)", &
		"Build/Patch",8192%,NL$) &
	\ RSP$=CVT$$(RSP$,32%) &
	\ FUNC%=-1% &
	\ FUNC%=0% IF RSP$="BUILD" &
	\ FUNC%=1% IF RSP$="BUILD/PATCH" &
	\ FUNC%=2% IF RSP$="PATCH" &
	\ GOTO 2200 IF FUNC%<0% &
	\ FUNCSET%=-1% &
	\ CMPFLG%=-1% IF FUNC% &
	\ RETURN UNLESS FUNC% &
		! $PROMPT PATCH &
		! GO BACK IF ALREADY ASKED. (funcset%) &
		! ASK FUNCTION &
		! REPROMPT UNLESS ANSWER WAS ONE OF 3 LEGAL OPTIONS. &
		! SET FUNCSET% FLAG &
		!	SET CMPFLG% IF PATCHING &
		!	SET FUNCTION SELECTED. &
		!	GO BACK UNLESS PATCHING. &

2210	PADV$=FNF$("Patch file input location","PATCH$:",61%,NL$) &
		!	61%=1%+4%+8%+16%+32% &
	\ IF DVST% AND 255% THEN &
		PRINT "?Patches MUST be on DISK" &
	\	GOTO 2210 &
		! MUST BE PATCHING SO WHERE ARE PATCHES. &
		! PATCHES MUST BE ON DISK. &
	&

2220	T0%=FNSETSB%("PATLOC",PADV$) &
	\ OPTDV$=LBDV$+LBAC$ &
	\ T0%=FNSETSB%("SAVDEV",OPTDV$) &
	\ RETURN &
		! STORE PATCH FILE LOCATION. &
		! (removed) ?SAVE SOURCES? &
		! (removed) ?WHERE? &
		! (removed) SET SAVFLG% (DO THE SAVE) &
		! (removed) SET OFLG% (SAVE IS NOT TO DISK) &
		! OPTDV$ IS OUTPUT DEVICE/ACC WHICH WILL BE PATCHED TO. &
	&

2250	! &
	!	$PROMPT RTS &
	! &
	RETURN IF RTSTYP% &
	\ RSP$=FNF$("Run-Time System",DRTS$,13%,"[0,1].RTS") &
	\ T0%=FNRTS%(RSP$) &
	\ IF T0% THEN &
		GOTO 2250 UNLESS KBM% &
	\	PRINT RTSD$ UNLESS RTSTYP% &
	\	GOTO 2250 UNLESS RTSTYP% &
	\	GOTO 2295 &
		! SKIP THIS IF ALREADY ASKED. &
		! ASK FOR A RUN-TIME SYSTEM (IT MUST BE ON [0,1]) &
		! FNRTS% FIND OUT WHAT WE GOT. &
		! PRINT ERROR IF NOT A KEYBOARD MONITOR KBM%=0% &
		! RTSTYP%=-1% IF ".TSK" EXTENSION. &
		! RTSTYP%= 1% IF ".BAC" EXTENSION. &
		!	ELSE RTSTYP%=0% &
		! RTS NAME --> RTS$ &
		! RTS .EXT --> RTS.EXT$ &
		! CSPCOM WAS ASKED ABOUT IN FNRTS% &
	&
	&

2260	PRINT RSP$;" is not installed" &
	\ GOTO 2250 IF &
	ASCII(CVT$$(FNF$("Attempt to Install "+RSP$,"No",8192%,NL$),-1%))<>89% &
	\	ON ERROR GOTO 2290 &
	\	CHANGE SYS(CHR$(6%)+CHR$(-10%)+CVT$$(RSP$,-1%)) TO M0% &
	\	M0%(1%)=6% &
	\	M0%(2%)=-18% &
	\	M0%(3%)=128% &
	\	M0%(T0%)=0% FOR T0%=11% TO 22% &
	\	CHANGE M0% TO S$ &
	\	S$=SYS(S$) &
	\	ON ERROR GOTO 19000 &
	\	PRINT RSP$;" installed" &
	\	IF FNRTS%(RSP$) THEN &
			IF KBM% AND RTSTYP% THEN &
				GOTO 2295 &
		! RTS WAS NOT INSTALLED SO ASK IF WE SHOULD TRY TO. &
		! IF YES SET UP SYS CALL, DO IT AND INFORM USER. &
		! PERFORM SAME CHECKS AS ABOVE. &

2280	PRINT RTSD$ IF KBM% &
	\		PRINT RSP$;" will be removed" &
	\		ON ERROR GOTO 2290 &
	\		M0%(3%)=4% &
	\		CHANGE M0% TO S$ &
	\		S$=SYS(S$) &
	\		ON ERROR GOTO 19000 &
	\		GOTO 2250 &
		! IF CAN'T USE THE RTS, INFORM USER AND REMOVE THE RTS. &
	&

2290	ON ERROR GOTO 19000 &
	\ PRINT "RTS operation failed" &
	\ PRINT FNE$(ERR) &
	\ RESUME 2250 &
		! SOMETHING FAILED. &

2295	RTS.NM$=FNFM$(RSP$,NL$,4%) &
	\ T0%=FNSETSB%("RTS.NM",RTS.NM$) &
	\ NKBM$,RTSD$,UCSP$=NL$ &
	\ RETURN &
	&

2300	! &
	!	$PROMPT (RANDOM) &
	! &
	T1%=P% &
	\ T0%=INSTR(P%,C0$,",") &
	\ P0$=CVT$$(MID(C0$,P%,T0%-P%),140%) &
		!	140=4+8+128 &
 	\ T1%=INSTR(T0%+1%,C0$,",") &
	\ D0$=MID(C0$,T0%+1%,T1%-T0%-1%) &
	\ T0%=INSTR(T1%+1%,C0$,",") &
	\ F1%=INT(VAL(MID(C0$,T1%+1%,T0%-T1%-1%))) &
	\ T1%=INSTR(T0%+1%,C0$,",") &
	\ MRG$=MID(C0$,T0%+1%,T1%-T0%-1%) &
	\ SUB.NM1$=CVT$$(RIGHT(C0$,T1%+1%),39%) &
		!	39%=1%+2%+4%+32% &
	\ I1%=-1% &
		! "NORMAL" PROMPT COMMAND &
		!	DEFAULT RESPONSE	--> D0$ &
		!	KEYWORD FLAG		--> F1% &
		!	MASH STRING		--> MRG$ &
		!	ACCESS NAME TO STORE	--> SUBN$ &
		! SET I1% TO -1% (WE JUST STARTED A PROMPT). &

2310	RSP$=CVT$$(FNF$(P0$,D0$,F1%,MRG$),429%) &
		!		429%=1%+4%+8%+32%+128%+256% &
	\ GOTO 2380 UNLESS F1% AND 192% &
	\ GOTO 2340 IF F1% AND 64% &
	\ GOTO 1080 IF FNIND% IF I1% &
	\ C$=CVT$$(C0$,164%) &
		!	164%=4%+32%+128% &
	\ T0%=INSTR(0%,C$,"><") &
	\ ON ERROR GOTO 2330 &
	\ T1=INT(VAL(RIGHT(C$,T0%+2%))) &
	\ T0=INT(VAL(LEFT(C$,T0%-1%))) &
	\ RSP$=NUM1$(INT(VAL(RSP$))) &
	\ GOTO 2380 UNLESS VAL(RSP$)<T0 OR VAL(RSP$)>T1 &
		! GO ASK THE QUESTION ANSWER --> RSP$ &
		! GOTO 2380 IF NOT A KNOWN ANSWER OR NUMBER. &
		! GOTO 2340 IF KNOWN ANSWER. &
		! ELSE	MUST BE AN INTEGER SO LETS DO IT. &
		!	GET A LINE (SHOULD BE LIMITS FOR THE INTEGER). &
		!	FORMAT IS  LOW-LIMIT "><" HIGH-LIMIT &
		!	SET ERROR TRAP &
		!	HIGH LIMIT --> T1 &
		!	LOW  LIMIT --> T0 &
		!	PUT USER RESPONSE INTO RSP$ (MAKE IT AN INTEGER.) &
		!	GO TO 2380 IF ANSWER IS IN BOUNDS ELSE GO TO HELPER. &
	&

2320	PRINT VLO$ &
	\ PRINT "Integer from";T0;" to ";T1 &
	\ I1%=0% &
	\ GOTO 2310 &
		! HELPER FOR GET AN INTEGER. &
		! PRINT THE RANGE OF VALID ANSWERS. &
		! CLEAR I1% SO WE KNOW THAT WE HAVE ALREADY INPUT THE BOUNDS. &
		! GOTO 2110 AND RE-PROMPT USER. &

2330	RESUME 2320 IF ERL=2310 &
	\ RESUME 19000 &
		! ERROR TRAP FOR INTEGER ERRORS &
		! RETRY ON ERRORS (ASSUMES USER TYPED AN INVALID INTEGER). &
		! WILL PROBABLY LOOP FOREVER IF LIMITS WERE ILLEGAL. &
	&

2340	IF I1% THEN &
		T1%=-1% &
	\	T2%=NUM.SUB% &
	\	GOTO 1080 IF FNIND% &
	\	T1%=VAL(CVT$$(C0$,-1%)) &
	\	FOR I%=1% TO T1% &
	\		GOTO 1080 IF FNIND% &
	\		C$=CVT$$(C0$,429%) &
		!		429%=1+4%+8%+32%+128%+256% &
	\		T0%=INSTR(0%,C$,"=") &
	\		T0$=LEFT(C$,T0%-1%) &
	\		T1$=RIGHT(C$,T0%+1%) &
	\		PRO.SAV%=-1% &
	\		T0%=FNSETSB%(T0$,T1$) &
	\		PRO.SAV%,ABORT%=0% &
	\	NEXT I% &
		! GET A KNOWN ANSWER &
		! IF FIRST TIME THROUGH (I1%=-1%) THEN &
		! SAVE STATE OF SUBSTITUTION STACK. &
		!	(UNUSED PORTION WILL BE USED AS SCRATCH STORAGE) &
		! GET A LINE.	SHOULD BE # OF POSSIBLE LEGAL ANSWERS. --> T1% &
		! GET EACH POSSIBLE ANSWER &
		! 	USER SPECIFIED	--> T0$ &
		!	STORE		--> T1$ &
		! SET PRO.SAV%	(INSTRUCTS FNSETSB% NOT TO WIPE OUT PRIOR &
		!	OCCURRENCE OF THIS) &
		! STORE BOTH. &
		! LINE HAS FOLLOWING FORMAT: &
		!	USER-RESPONSE=FOOBAR-STRING &
		! WILL BE USED AS FOLLOWS: &
		! IF WHAT USER TYPED MATCHES A "USER-RESPONSE" THEN &
		!	RESPONSE IS LEGAL, STORE ANSWER AFTER &
		!	CHANGING IT TO "FOOBAR-STRING" &
	&

2350	I1%=0% &
	\ I1%=I% IF RSP$=SUBN$(I%) FOR I%=NUM.SUB% TO T2%+1% STEP -1% &
	\ IF RSP$<>SUBN$(I1%) THEN &
		PRINT VLO$ &
	\	PRINT , SUBN$(I%) FOR I%=T2%+1% TO NUM.SUB% &
	\	GOTO 2310 &
		! CLEAR I1% (WE HAVE ALREADY STORED THE LEGAL ANSWERS.) &
		! CHECK USER RESPONSE AGAINST ALL LEGAL ONES. &
		! IF RESPONSE WAS INVALID PRINT THE VALID OPTIONS AND &
		!	RE-PROMPT. &

2360	RSP$=SUBR$(I1%) &
	\	NUM.SUB%=T2% &
		! WE GOT A VALID ANSWER SO SUBSTITUTE THE "FOOBAR-STRING". &
		! RESTORE SUBSTITUTION STACK. &

2380	T0%=FNSETSB%(SUB.NM1$,RSP$) &
	\ RETURN &
		! PERFORM ACTUAL SETTING OF THE SUBSTITUTION. &
		! GO BACK FOR MORE. &
	&
	&

2400	! &
	!	$PROMPT PCTSK (PRE-COMPILED TASKS) &
	! &

2410	PCT%=-1% &
	\ RETURN &
	&
	!	SET PCT% SWITCH AND RETURN &

3100	! &
	&
	&
	!	D O S    S W I T C H &
	&
	&
	E%=-1% IF INST%<>14% OR MTTYP% &
	\ MTTYP%=1% &
	\ GOTO 11050 &
		! THIS WILL GENERATE AN ERROR IF: &
		!	DEVICE IS NOT MAGTAPE; &
		!	A DOS OR ANSI SWITCH HAS ALREADY BEEN PARSED; &
		! OTHERWISE, SET TYPE TO DOS; &
		! GO LOOK FOR MORE. &

3200	! &
	&
	&
	!	A N S I     S W I T C H &
	&
	&
	E%=-1% IF INST%<>14% OR MTTYP% &
	\ MTTYP%=2% &
	\ GOTO 11050 &
		! THIS WILL GENERATE AN ERROR IF: &
		!	DEVICE IS NOT MAGTAPE; &
		!	A DOS OR ANSI SWITCH HAS ALREADY BEEN PARSED; &
		! OTHERWISE, SET TYPE TO ANSI; &
		! GO LOOK FOR MORE. &
	&

3300	! &
	&
	&
	!	D E N S I T Y    S W I T C H &
	&
	&
	E%=-1% IF INST%<>14%  OR  DENSET% &
	\ E%=-1% UNLESS FNR%(":",1%) &
	\ DENSET% = 1% IF FNR%("MINIMUM",3%) &
	\ DENSET% = 32767% IF FNR%("MAXIMUM",3%) UNLESS DENSET% &
	\ GOTO 11050 IF DENSET% &
	\ P%=P%+1% &
	\ DENSET%=FNN% UNLESS E% &
	\ P%=P%-1% &
	\ E%=-1% IF (DENSET% < 1%) OR (DENSET%<>800% AND PARSET%) &
	\ GOTO 11050 &
		! THIS WILL GENERATE AN ERROR IF: &
		!	DEVICE IS NOT MAGTAPE; &
		!	A DENSITY SWITCH HAS ALREADY BEEN PROCESSED; &
		!	DENSITY IS NOT 800 OR 1600; &
		!	A PARITY HAS BEEN SPECIFIED AND DENSITY IS NOT 800. &
		! OTHERWISE, SET DENSITY WORD, GO CHECK FOR MORE SWITCHES &

3400	! &
	&
	&
	!	P A R I T Y    S W I T C H &
	&
	&
	E%=-1% IF INST%<>14% OR PARSET% OR (DENSET% <> 800%) &
	\ PARSET%=1% IF FNR%(":ODD",-3%) &
	\ PARSET%=2% IF FNR%(":EVEN",-3%) UNLESS PARSET% &
	\ E%=-1% UNLESS PARSET% &
	\ MTSTA%=MTSTA% OR ((PARSET% - 1%) AND 1%) OR 8192% &
	\ GOTO 11050 &
		! THIS WILL GENERATE AN ERROR IF: &
		!	DEVICE IS NOT MAGTAPE; &
		!	A PARITY SWITCH HAS ALREADY BEEN PARSED; &
		!	A DENSITY OF 1600 HAS ALREADY BEEN SPECIFIED; &
		!	THE SPECIFIED PARITY IS NEITHER 'ODD' NOR 'EVEN'. &
		! OTHERWISE, SET UP PARITY WORD; &
		! GO LOOK FOR MORE. &
	&

3500	! &
	&
	&
	!	D E T A C H   S W I T C H &
	&
	&
	DTCH%=-1% &
	\ GOTO 11050 &
		! GO LOOK FOR MORE. &

3600	! &
	&
	&
	!	I N P U T   A C C O U N T   S W I T C H &
	&
	&
	T0%=INSTR(P%,C$,"]") &
	\ INAC$=CVT$$(MID(C$,P%+2%,T0%-P%-1%),7%) &
	\ P%=T0% &
	\ P%=LEN(C$)+1% UNLESS T0% &
	\ T0%=FNSETSB%("INPACC",INAC$) &
	\ GOTO 11050 &
		! *** THIS SWITCH IS ONLY FOR DEBUGGING *** &
		! *** IT IS NOT A SUPPORTED SWITCH AND  *** &
		! *** MAY SCREW UP SOME CONTROL FILES *** &
		! ******** DO NOT USE THIS SWITCH ********* &
		! SETS THE VALUE OF THE INPUT ACCOUNT. &
		! GO LOOK FOR MORE. &
	&
	&

10000	! &
	&
	&
	&
	!	I N I T I A L I Z E   V A R I A B L E S &
	&
	&
	&
	&
	NL$="" &
	\ INAC$="[1,2]" UNLESS E0% &
	\ CMPFLG%=-1% UNLESS E0% &
	\ CH6$=CHR$(6%) &
	\ PRIV.OFF$=CH6$+CHR$(-21%)+CHR$(255%) &
	\ PRIV.ON$=CH6$+CHR$(-21%)+CHR$(0%) &
	\ T0$=SYS(PRIV.OFF$) &
	\ T0$=SYS(CH6$+CHR$(14%)+STRING$(6%,0%)+CHR$(1%)) &
	\ CHANGE T0$ TO M0% &
	\ NPJ%=M0%(7%) &
	\ NPG%=M0%(8%) &
	\ GOSUB 10100 &
	\ RETURN UNLESS PRV% &
	\ JN$=RIGHT(NUM1$(100%+(M0%(1%)/2%)),2%) &
	\ OPEN "TMPT"+JN$+".TMP" FOR OUTPUT AS FILE 9%, MODE 288% &
		UNLESS BUFSIZ(9%) &
	\ SUBN$(0%),SUBR$(0%)=NL$ &
	\ IOFL$="BLD"+JN$+".TMP" &
	\ IOFL$="P"+IOFL$ IF E0% AND NOT BOT% &
	\ CR$=CHR$(13%) &
	\ CRLF$=CR$+CHR$(10%) &
	\ T0$=SYS(PRIV.ON$) &

10010	RTS.LST%=SWAP%(CVT$%(MID(SYS(CH6$+CHR$(-12%)),15%,2%))) &
	\ Z% = PEEK(PEEK(RTS.LST%)) 	! Skip over 1st RTS (...RSX) &
	\ WHILE Z% &
	\	Z$ = RAD$(PEEK(Z%+2%))+RAD$(PEEK(Z%+4%)) &
	\	T$=RAD$(PEEK(Z%+6%)) &
	\	IF T$="BAC" OR T$="TSK" THEN &
			DRTS$ = CVT$$(Z$,2%) &
	\		RTS.EXT$ = CVT$$(T$,2%) &
	\		GOTO 10030 &

10020		Z% = PEEK(Z%) &
	\ NEXT &

10030	T0$=SYS(PRIV.OFF$) &
	\ T0$ = MID(SYS(CHR$(6%)+CHR$(26%)),23%,4%) &
	\ RTS$ = "" &
	\ RTS$ = "RT11.RTS" &
			IF "DCL" = CVT$$(RAD$(SWAP%(CVT$%(T0$)))+ &
				RAD$(SWAP%(CVT$%(RIGHT(T0$,3%)))),-1%) &
	\ NKBM$=" is not a keyboard monitor" &
	\ BP2.COM$="_SY:[1,2]BP2IC2.TSK" &
        \ RTSD$="Run-time System file type must be .BAC or .TSK" &
	\ VLO$="Valid options are:" &
	\ S0$=CH6$+CHR$(-23%) &
	\ LB$=FNFM$("LB:",NL$,3%) &
	\ LB$="_SY:[1,1]" IF LB$="LB:" &
	\ SW$="/OBJ/CHA/LIN/NODEB/WOR/TYPE:REAL/NOCRO/NOLIS/FLAG:NODEC"+ &
		CRLF$+"SCRATCH"+CRLF$+"EXIT"+CRLF$ &
	\ R$="RUN " &
	\ COM$="COMPILE " &
	\ ASGN$ = "ASSIGN " &
	\ IN$ = "INPUT" &
	\ RETURN &
		! INITIALIZE THE WORLD &

10100	! &
	!	ENSURE USER HAS REQUIRED PRIVILEGES &
	!	RETURNS PRV% = -1% IF USER HAS REQUIRED PRIVS &
	!		        0% IF USER LACKS ANY REQUIRED PRIV &
	! &
	RESTORE &
\	PRV% = -1% &
\	READ PRV.NAM$ &
\	Z% = 0% &
\	WHILE LEN(PRV.NAM$) &
\		IF NOT FNPRV%(PRV.NAM$) THEN &
			PRV% = 0% &
\			Z% = Z% + 1% &
\			IF Z% = 1% THEN &
				Z$ = PRV.NAM$ &
			ELSE	PRINT "?Additional privileges required:" &
					IF Z% = 2% &
\				PRINT RECORD 32%, "	"; Z$; &
\				PRINT RECORD 32% &
					IF CCPOS(0%) > 72% &
\				Z$ = PRV.NAM$ &

10110		READ PRV.NAM$ &
\	NEXT &
\	PRINT "?"; Z$; " privilege required" &
		IF Z% = 1% &
\	PRINT RECORD 32%, "	"; Z$ &
		IF Z% > 1% &
\	RETURN &

10120	! Define privileges required to run INSTAL: &
	! All except SYSMOD, EXQTA, GACNT, SETPAS, and USER1-USER8 &
	DATA	DATES, &
		DEVICE, &
		GREAD, &
		GWRITE, &
		HWCFG, &
		HWCTL, &
		INSTAL, &
		JOBCTL, &
		MOUNT, &
		PBSCTL, &
		RDMEM, &
		RDNFS, &
		SEND, &
		SHUTUP, &
		SWCFG, &
		SWCTL, &
		SYSIO, &
		TMPPRV, &
		TUNE, &
		WACNT, &
		WREAD, &
		WRTNFS, &
		WWRITE, &
		"" &

11045	! &
	!	ASK FOR 'SOURCE INPUT DEVICE' AND SWITCHES &
	! &
	ON ERROR GOTO 11057 &
	\ PRINT IF CCPOS(0%) &
	\ RSP$=CVT$$(FNF$("Input device",PKLO$,8192%,NL$),39%) &
		! THIS SUBROUTINE ASKS THE SOURCE INPUT DEVICE &
		! QUESTION. &
		! SET ERROR TRAP AND ASK. &

11047	ON ERROR GOTO 11057 &
	\ RSP$=RSP$+PKLO$ IF LEN(RSP$)=0% OR INSTR(1%,RSP$,"=")>=LEN(RSP$) &
	\ T2%=INSTR(1%,RSP$,"=") &
	\ CHANGE SYS(S0$+RIGHT(RSP$,T2%+1%)) TO M1% &
	\ T1%=RECOUNT &
	\ GOTO 11045 IF (M1%(29%)+SWAP%(M1%(30%)) AND 1161%) &
	     OR ((M1%(29%)+SWAP%(M1%(30%)) AND 12288%)<>12288%) &
		OR (M1%(30%) AND 128%) &
		!		1161%=1+8+128+1024 &
		!		12288=4096+8192 &
	\ INDV$="_"+CHR$(M1%(23%))+CHR$(M1%(24%)) &
	\ INDV$=INDV$+NUM1$(M1%(25%)) IF M1%(26%) &
	\ INDV$=INDV$+":" &
	\ GOTO 11045 IF LEN(FNFLNC$(INDV$,37%,NL$))=0% &
		!		37%=1+4+32 &
	\ T0$=RSP$ &
	\ RSP$=INDV$+RIGHT(RSP$,LEN(RSP$)-T1%+1%) &
	\ INST%=STATUS AND 255% &
	\ T2%=0% IF T2%=1% &
	\ LOGF$=FNFLNC$(MID(T0$,0%,T2%-1%),28%,"_SY:BLD"+JN$+ &
		".LOG") IF T2% &
	\ GOTO 11045 IF LEN(LOGF$)=0% AND T2% &
	\ LOGF$=LOGF$+"=" IF T2% &
	\ C$=RSP$ &
	\ T0$,RSP$=NL$ &
	\ P%=LEN(INDV$) &
	\ PARSET%,DENSET%,MTTYP%,MTSTA%,E%=0% &
	\ ON ERROR GOTO 19000 &
		! PUT PKLO$ -->RSP$ IF NULL ANSWER (DEFAULT) &
		! NOTE FORMAT IS: &
		! [LOGFIL=] INPUT LOCATION [/SWITCHES] &
		! CHECK THE INPUT LOCATION (MUST ONLY BE DEV:) &
		! PUT INPUT DEVICE --> INDV$ &
		! SET INST% TO STATUS OF THE INPUT DEVICE (IS IT MT:) &
		! MASH LOG FILE --> LOGF$ IF "=" FOUND &
		! CLEAR ALL SWITCHES AND PREPARE TO PARSE &
		! REMAINING SWITCHES. &

11050	WHILE FNR%("/",1%) AND E%=0% &
	\	GOTO 3100 IF FNR%("DOS",-3%) &
	\	GOTO 3200 IF FNR%("ANSI",-3%) &
	\	GOTO 3300 IF FNR%("DENSITY",-3%) &
	\	GOTO 3400 IF FNR%("PARITY",-3%) &
	\	GOTO 3500 IF FNR%("DETACH",-3%) &
	\	GOTO 3600 IF FNR%("INPACC",-3%) &
	\	E%=-1% &
	\ NEXT &
	\ E%=-1% UNLESS P%>=LEN(C$) &
	\ IF E% THEN &
		PRINT FNE$(67%);" - ";C$ &
	\	GOTO 11045 &
		! WHILE THERE ARE SWITCHES TO PROCESS: &
		!	DISPATCH FOR DOS &
		!	DISPATCH FOR ANSI &
		!	DISPATCH FOR DENSITY &
		!	DISPATCH FOR PARITY &
		!	DISPATCH FOR DETACH &
		!	DISPATCH FOR LIBACC	* NOT SUPPORTED * SEE 3600 &
		!	ERROR IF UNDEFINED SWITCH &
		!	LOOP TILL ALL SWITCHES ARE PROCESSED OR ERROR &
		!	IF ILLEGAL UP SWITCHES PRINT ERROR AND GO REPROMPT. &
	&

11055	RETURN IF INST%<>14% &
	\ ON ERROR GOTO 11057 &
	\	INMT$=NL$ &
	\	INMT$=".DOS" IF MTTYP%=1% &
	\	INMT$=".ANSI" IF MTTYP%=2% &
	\	INMT$=CVT$$(INDV$+INMT$,1%) &
	\	CHANGE SYS(CH6$+CHR$(-10%)+INMT$) TO M0% &
	\	M0%(1%)=6% &
	\	M0%(2%)=10% &
	\	CHANGE M0% TO T0$ &
	\	T0$=SYS(T0$) &
	\	OPEN INDV$ AS FILE 1% &
	\	T0%=MAGTAPE(3%,0%,1%) &
	\	T0%=MAGTAPE(6%,MTSTA%,1%) &
	\	T0% = MAGTAPE(12%,DENSET%+32767%+1%,1%) IF DENSET% &
	\	CLOSE 1% &
	\	RETURN &
		! PREPARE TO SET THE DRIVE. &
	&

11057	PRINT "?Invalid density -"; DENSET% IF ERR = 52% &
\	PRINT FNE$(ERR);" - ";INDV$ IF ERR <> 52% &
	\	RESUME 11045 &
	! TRAP ERRORS FOR MT: SET UP. &
	&

15000	! &
	!	F U N C T I O N   F N F L N C $ &
	! &
	&
	&
	! FUNCTION: FNFLNC$(P$,F%,DFLT$) &
	! &
	! THE STRING P$ IS USED AS A FILE NAME. IF NO &
	! EXTENSION IS PROVIDED ON P$ THEN DFLT$ IS USED &
	! FOR THE EXTENSION.  THE RESULTING STRING IS &
	! CHECKED ACCORDING TO THE SPECIFICATION IN F%. &
	! F% IS INTERPRETTED AS FOLLOWS: &
	! &
	!	BIT	VALUE	MEANING &
	! &
	!	0	1	IF SET, THEN LOOK UP FILE AS &
	!			CHECK FOR CORRECTNESS. &
	! &
	!	1	2	SET MEANS THAT WILD CARD &
	!			CHARACTERS ARE PERMITTED &
	! &
	!	2	4	SET INDICATES THAT A DEVICE MAY &
	!			BE SPECIFIED.  IF CLEAR, NONE IS &
	!			PERMITTED AND _SY: IS ASSUMED. &
	! &
	!	3	8	IF SET, THEN A PPN IS PERMITTED IN &
	!			THE FILE SPECIFICATION. &
	! &
	!	4	16	IF SET, DEV AND/OR PPN SHOULD &
	!			BE EXPANDED TO _SY: AND CURRENT ACCOUNT &
	!			IF THEY ARE MISSING FROM THE &
	!			RESULTING FILE NAME &
	! &
	!	5	32	IF SET, A FILENAME IS NOT PERMITTED. &
	!			I.E. A DEVICE SPECIFIER IS EXPECTED &
	! &
	!	6	64	CHECK FOR A KNOWN ANSWER. &
	! &
	!	7	128	CHECK FOR A NUMBER IN RANGE. &
	! &
	!	8	256	CREATE ACCOUNT IF NOT ALREADY THERE. &
	! &
	!	13	4096	ONLY PRINT THE PROMPT. &
	! &
	!	14	8192	CHECK FOR A RANDOM STRING. &
	! &
	!	15	16384	DO NOT PRINT OR INPUT ANYTHING. &
	! &
	!	16	-32768	DO NOT PRINT DEFAULT. &
	! &
	! IF THE FILE NAME IS VALID, THEN THE STRING IS RETURNED &
	! AS THE FUNCTION VALUE. IF INVALID FOR ANY REASON, &
	! THE NULL STRING IS RETURNED. &
	&
	DEF* FNFLNC$(P$,F%,DFLT$) &
	\ FNFLNC$=NL$ &
	\ MRG1%=31% &
	\ MRG1%=63% IF F% AND 16% &
	\ F0%=0% &
	\ F0%=870% UNLESS F% AND 2% &
	\ F0%=F0%+28672% UNLESS F% AND 4% &
	\ F0%=F0%+128% UNLESS F% AND 8% &
	\ F0%=F0%+25% IF F% AND 32% &
		!	870%=2%+4%+32%+64%+256%+512% &
		!	28672%=4096%+8192%+16384% &
		!	25%=1%+8%+16% &
		! INIT FLAGS FOR STRING CHECK. &
	&
	\ T0$=CVT$$(P$,6%) &
	\ GOTO 15040 IF F% AND 8192% &
	\ IF LEN(T0$)=0% &
		THEN FNFLNC$=NL$ &
		\    GO TO 15070 &

15020	T0$=FNFM$(DFLT$,T0$,MRG1%) &
	\ ON ERROR GOTO 15090 &
	\ IF S1%=0% &
		THEN &
			PRINT IF CCPOS(0%) &
		\	PRINT FNE$(2%);" - ";T0$ &
		\	FNFLNC$=NL$ &
		\	GO TO 15070 &
		! SCAN STRING AND INSERT DEFAULT EXTENSION. &
		! IF A BAD NAME IS GIVEN, RETURN NULL LINE. &

15030	T1$=CVT$$(T0$,32%) &
	\ GO TO 15040 UNLESS (S1% AND F0%) &
		OR (S1% < 0%) &
	\ PRINT IF CCPOS(0%) &
	\ PRINT T0$;" not permitted" &
	\ FNFLNC$=NL$ &
	\ GO TO 15070 &
		! IF FILE NAME CONTAINS ITEMS WHICH ARE &
		! NOT PERMITTED BY THE VALUE OF F%, &
		! RETURN NULL STRING. &

15040	GO TO 15050 IF ((F% AND 1%) <> 0%) &
		   AND (((DVST% AND 256%)=0%) &
			OR ((DVST% AND 512%) <> 0%) &
			OR (DVST% < 0%)) &
		   AND ((DVST% AND 255%) <> 14%) &
	\ FNFLNC$=T0$ &
	\ GO TO 15070 &
		! IF FILE NAME DOES NOT HAVE TO BE &
		! LOOKED UP, RETURN IT. &

15050	T2$=T0$ &
	\ T2$=T0$+"[*,*]" IF (F% AND 32%) AND (F% AND 8%)=0% &
	\ IF F% AND 32% THEN &
		GOTO 15090 IF FNAC%(T2$,F% AND 256%) &
	ELSE &
		M1%(1%)=6% &
	\	M1%(2%)=17% &
	\	M1%(3%),M1%(4%)=255% &
	\	M1%(3%),M1%(4%)=0% IF F% AND 2% &
	\	CHANGE M1% TO T1$ &
	\	T1$=SYS(T1$) &
		! LOOK UP FILE NAME.  IF FOUND (I.E. IF NO &
		! ERROR TRAP OCCURS) RETURN IT. &

15060	FNFLNC$=T0$ &

15070	ON ERROR GOTO 19000 &
	\ FNEND &
		! RESET ERROR HANDLER AND EXIT. &
	&

15080	! &
	&
	&
	&
	!	E R R O R   H A N D L E R :   F N F L N C $ &
	&
	&

15090	E%=ERR &
	\ T2$="?"+T0$+" - "+FNE$(E%) &
!	\ T2$="?File not found: "+T0$ IF E%=5% &
	\ PRINT IF CCPOS(0%) &
	\ PRINT T2$ UNLESS (JMP% AND (E%=5%)) OR (F% AND 32%) &
	\ FNFLNC$=NL$ &
	\ RESUME 15070 &
		! PRINT ERROR MESSAGE AND PROMPT &
		! AND GET INPUT AGAIN. &
	&

15100	! &
	&
	!	F N P R V $ ( priv_name$ ) &
	&
	! FUNCTION: FNPRV$(PRIV$) &
	! &
	! Function to see if job currently has specified privilege &
	! If privileged then return -1%, else return 0% &
	&
	DEF* FNPRV%(PRIV$) = &
		(ASCII(RIGHT(SYS(CHR$(6%)+CHR$(32%)+CHR$(1%)+STRING$(3%,0%)+ &
		PRIV$),3%)) = 0%) &

15200	! &
	&
	&
	&
	!	F U N C T I O N   F N F $ &
	&
	&
	&
	! FUNCTION: FNF$(P0$,D0$,F1%,MRG$) &
	! &
	! FUNCTION TO INPUT A FILE NAME.  STRING P0$ IS ISSUED &
	! AS A PROMPT.  THE STRING D0$ IS THE DEFAULT ONLY IF &
	! A NULL STRING IS ENTERED.  IF A STRING IS ENTERED &
	! MRG$ IS MERGED INTO THE STRING AND THE RESULTANT STRING &
	! IS CHECKED WITH FNFLNC$ ACCORDING TO FLAG F1% &
	&
	DEF* FNF$(P0$,D0$,F1%,MRG$) &

15210	PRINT IF CCPOS(0%) &
	\ P0$=CVT$$(P0$,1%) &
	\ PRINT P0$;" "; UNLESS F1% AND 16384% &
	\ PRINT "<";D0$;"> "; IF LEN(D0$) AND (F1% AND -12288%)=0% &
	\ T0$=NL$ &
	\ ON ERROR GOTO 15230 &
	\ INPUT LINE T0$ UNLESS F1% AND 20480% &
	\ ON ERROR GOTO 19000 &
	\ T0$=CVT$$(T0$,4%) &
	\ T0$=CVT$$(D0$,4%) UNLESS LEN(T0$) &
	\ T0$=CVT$$(T0$,2%) UNLESS F1% AND 8192% &
	\ IF CVT$$(T0$,32%)="BP2COM" THEN PRINT T0$;" not allowed" &
		\ GOTO 15210 &

15215	IF LEN(T0$)=0% THEN &
			GO TO 15210 UNLESS F1% AND 4096% &
		ELSE T0$=FNFLNC$(T0$,F1%,MRG$) UNLESS F1% AND 8192% &
			\    GO TO 15210 UNLESS LEN(T0$) &
			\    FNF$=T0$ &
		! PRINT PROMPT FOR FILE NAME INPUT AND GET &
		! A NAME.  CHECK IF NULL, AND USE D0$ IF SO. &
		! ELSE CHECK FILE NAME. RETURN IF OKAY ELSE &
		! ASK FOR ANOTHER ONE. &

15220	FNEND &

15230	FATLER%=-1% &
	\ RESUME 19000 &
		! ALL ERRORS ARE FATAL &

15300	DEF* FNN% &
	\ FNN%=0% &
	&
	\ Z0%=0% &
	\ ON ERROR GOTO 15320 &
	\ Z%=ASCII(MID(C$,P%,1%))-48% &
		! SET UP THE ACCUMULATOR; &
		! SET UP TO TRAP THE 'INTEGER ERROR'; &
		! GET THE CURRENT BYTE. &
	&
	\ WHILE Z%<10% AND Z%>-1% &
	\	P%=P%+1% &
	\	Z0%=Z0%*10%+Z% &
	\	Z%=ASCII(MID(C$,P%,1%))-48% &
	\ NEXT &
	\ FNN%=Z0% &
		! WHILE CURRENT CHR IS A DIGIT: &
		!	INCREMENT CURRENT POSITION POINTER; &
		!	ADD NEW DIGIT INTO ACCUMULATOR; &
		!	GET NEXT CHR. &
		! LOOP; &
		! SET UP THE FUNCTION VALUE. &

15310	ON ERROR GOTO 19000 &
	\ FNEND &
		! EXIT. &

15320	E%=ERR &
	\ RESUME 15310 &
		! HANDLE THE ERRORS. &
	&

15400	! &
	&
	&
	&
	!	F U N C T I O N   F N P R N T % &
	&
	&
	&
	! FUNCTION: FNPRNT%(S$) &
	! &
	! FUNCTION TO PRINT OUTPUT TO FILE. &
	! STRIPS PARITY, AND ADDS SWITCHES TO COMPILE. &
	&
	DEF* FNPRNT%(S$) &
	\ S$=CVT$$(S$,1%) &
	\ C$=CVT$$(S$,32%+256%) &
	\ P%=0% &
	\ BP$=R$+BP2$+CRLF$ IF RTSTYP%=-1% AND NOT CSP% &
	\ S$=BP$+"SCALE 0"+CRLF$+C$ IF FNR%("OLD",-3%) AND CSP%=0% &
	\ P%,TKB%=0% &
	\ TKB%=INSTR(1%,C$,"/TKB") IF FNR%("COMPILE",-3%) &
	\ P%=0% &
	\ S$=LEFT(C$,TKB%-1%)+RIGHT(C$,TKB%+4%) IF TKB% &
	\ TKB%=TKB%<>0% &
	\ TKB%=-1% IF TKB%=0% AND (RTSTYP%=-1% AND NOT CSP%) &
	\ S$=CSP$ UNLESS FNCSPCOM%(S$) 	IF CSP% &
!	\ S$=CVT$$(S$,4%)+SW$ &
!			IF RTSTYP%<0% AND NOT CSP% UNLESS TKB% &
	\ S$=CSP$ UNLESS FNCSPCOM%(S$) IF (TKB%  AND RTSTYP%<0%) &
							AND NOT(CSP%) &
	\ IF NOT(CSP% OR TKB%) THEN &
		IF FNR%("COMPILE",-3%) THEN &
			T1%=INSTR(P%,C$,"/") &
	\		T1%=T1%-1% if T1% &
	\		T1%=LEN(C$)-(LEN(C$)-LEN(CVT$$(C$,4%))) UNLESS T1% &
!	\	S$=LEFT(C$,T1%) &
!				+CRLF$+"SCRATCH"+CRLF$+'EXIT'+CRLF$ &
!					 IF RTSTYP%<0% &
	\		P%=0% &
	\		IF RTSTYP%>0% THEN &
				T1%=INSTR(1%,C$,"/TSK") &
	\			S$=LEFT(C$,T1%-1%)+RIGHT(C$,T1%+4%) IF T1% &
		! CHECK FOR A NULL STRING. &
		! IF NON NULL TRIM PARITY BIT AND ADD SWITCHES &
		! THEN DO THE OUTPUT. &

15410	PRINT #12%,S$; UNLESS (CSP% OR TKB%) AND P% &
	\ CSP$,CSP1$,CSP2$=NL$ UNLESS (CSP% OR TKB%) AND P% &
	\ FNEND &
		! PRINT IT AND GO HOME. &
		! NOTE P% HAS THE VALUE OF FNCSPCOM% &

15500	! &
	&
	&
	&
	!	F U N C T I O N   F N I N D % &
	&
	&
	&
	! FUNCTION: FNIND% &
	! &
	! FUNCTION TO INPUT COMMANDS FROM A COMMAND FILE. &
	! EACH INPUT LINE IS RETURNED AS A COMMAND. IF THE &
	! INPUT LINE BEGINS WITH &
	! AN "@" CHARACTER IT INDICATES TO OBTAIN THE COMMANDS &
	! FROM THE FILE WHOSE NAME FOLLOWS THE "@" CHARACTER, &
	! PROVIDED WE CAN FIND THE FILE AND IT IS ON DISK OR /MO:1 &
	! &
	! &
	! THE COMMAND IS RETURNED IN C0$.  THE FUNCTION RETURNS &
	! THE FOLLOWING POSSIBLE VALUES. &
	! &
	!	VALUE	MEANING &
	! &
	!	 0	CORRECT COMMAND WAS READ. &
	! &
	!	 1	"@" OCCURRED WITH AN INVALID FILE &
	!		NAME. &
	! &
	!	 2	EOF WAS READ.  ONLY RETURNED &
	!		IF AN EOF OCCURS IN LAST LEVEL &
	!		OF INDIRECT COMMANDS. &
	&
	DEF* FNIND% &

15510	T0$=FNILN$ &
	\ GO TO 15530 UNLESS LEN(T0$) &
	\ C0$=T0$ &
	\ T0%=INSTR(1%,C0$,"_") &
	\ WHILE T0% &
	\	C0$=LEFT(C0$,T0%)+CHR$(ASCII(MID(C0$,T0%+1%,1%)) OR 128%)+ &
			RIGHT(C0$,T0%+2%) &
	\	T0%=INSTR(T0%+1%,C0$,"_") &
	\ NEXT &
	\ T0%=INSTR(1%,C0$,"~") &
	\ WHILE T0% &
	\	P%=T0% &
	\	P%=P%+FNDOSUB%(P%) &
	\	T0%=INSTR(P%,C0$,"~") &
	\ NEXT &
	\ C$=C0$ &
	\ P%=0% &
	\ T0%=FNR%("@",1%) &
	\ IF T0%=0% &
		THEN FNIND%=0% &
		\    GO TO 15550 &
		! IF EOF, GO TO POP CODE. IF INDIRECT &
		! GO TO PUSH CODE. ELSE EXIT. &

15520	GOSUB 15570 &
	\ GOTO 15510 UNLESS T0% &
	\ GOTO 15550 &

15530	 IF SP%=2% &
		THEN FNIND%=2% &
		\    C0$=NL$ &
		\    GO TO 15550 &
		! IF EOF AT LOWEST LEVEL THEN JUST RETURN AN &
		! EOF. &

15540	CLOSE 10% &
	\ C0=0. &
	\ SP%=SP%-2% &
	\ OPEN STAK$(SP%) AS FILE 10% &
	\ T0$=FNILN$ FOR I%=1% UNTIL I% > VAL(STAK$(SP%+1%)) &
	\ GO TO 15510 &
		! POP THE STACK.  IF EOF BROUGHT USER BACK TO &
		! LOWEST LEVEL, THEN RETURN EOF, ELSE TRY TO &
		! INPUT ANOTHER COMMAND &

15550	GOTO 15560 IF FUNC% OR NEWF% &
	\ C0$="^C"+CRLF$ IF ASCII(C0$)=94% AND LEN(CVT$$(C0$,-1%))=1% &
	\ I%=INSTR(1%,C0$,"?:") &
	\ IF I% THEN C0$=LEFT(C0$,I%-1%)+INDV$+RIGHT(C$,I%+2%) &
	\ GOTO 15550 &
		! THIS LINE IS IN FOR COMPATIBILITY ONLY. &
		! IT IS SKIPPED UNLESS THIS IS AN OLD STYLE BUILD FILE &
		! I.E. NOT PROMPTS HAVE BEEN MADE. &
		! CHANGE ^ TO ^C IF THAT IS ALL THAT IS ON THE LINE. &
		! REPLACE ALL OCCURRENCES OF "?:" BY THE INPUT DEVICE &
		! ONLY IF THIS IS AN OLD STYLE BUILD FILE. &

15560	C$=CVT$$(C0$,289%) &
		!	289%=1%+32%+256% &
	\ P%=0% &
	\ FNEND &
	&

15570	T0$=CVT$$(RIGHT(C0$,P%+1%),38%) &
	\ T0$=FNFM$(".CMD",T0$,8%) &
	\ JMP%=-1% &
	\ T0$=FNFLNC$(T0$,29%,STAK$(SP%-(2% AND SP%=2%))) &
	\ JMP%=0% &
	\ IF LEN(T0$)=0% OR ((DVST% AND 255%) AND (M1%(17%) AND 2%)=0%) &
		THEN C$=C0$ &
		\ T0%=-1% &
		\ RETURN &
		! GET FILE NAME FOR INDIRECT.  IF INVALID &
		! SET ERROR CODE 1% AND RETURN. &

15580	C0$=T0$ &
	\ STAK$(SP%+1%)=NUM1$(C0) &
	\ C0=0. &
	\ CLOSE 10% &
	\ SP%=SP%+2% &
	\ STAK$(SP%)=C0$ &
	\ STAK$(SP%+1%)="0" &
	\ OPEN C0$ AS FILE 10% &
	\ T0%=0% &
	\ RETURN &
		! PUSH CURRENT FILE STATUS ON THE STACK, &
		! SET UP A NEW STACK FRAME WITH DEFAULT DEVICE &
		! LOGFILE, ETC. AND OPEN THE NEW INPUT FILE. &
	&

15600	DEF* FNR%(S$,L%) &
	\ FNR%=0% &
	\ CHK.END%=L%<0% &
	\ L%=ABS(L%) &
	! FUNCTION:	KEYWORD MATCHING ROUTINE. MATCHES A STRING IN &
	!		THE COMMAND STRING C$ STARTING AT POSITION P%+1% &
	!		TO THE DUMMY STRING S$. A MATCH IS MADE WHEN THE &
	!		MINIMUM NUMBER OF CHARACTERS ARE MATCHED. THIS &
	!		MINIMUM NUMBER IS HELD IN THE DUMMY VARIABLE &
	!		L%. &
	! PARAMETERS:	S$	STRING TO MATCH TO. &
	!		L%	MINIMUM LENGTH OF MATCH. &
	!			CHK.END IS SET IF L%<0% &
	! GLOBAL &
	! VARIABLES &
	! AFFECTED:	P%	POSITION POINTER POINTS TO THE LAST &
	!			CHARACTER MATCHED SUCCESSFULLY. &
	! LOCAL &
	! VARIABLES &
	! USED:		Z%	TEMPORARY CHARACTER POINTER. &
	!		Z$	CHARACTER MATCHING VARIABLE FOR &
	!			PROCESSING BEYOND THE MINIMUM LENGTH. &
	!		CHK.END% CHECK TERMINATION CHARACTER IF SET. &
	! RETURNS:	NUMBER OF CHARACTERS SUCCESSFULLY MATCHED. &
	! ERRORS:	NONE EXPECTED. &

15610	Z%=ASCII(MID(C$,P%+1%,1%)) &
	\ IF Z%=32% OR Z%=9% THEN &
		P%=P%+1% &
	\	GOTO 15610 &
		! SKIP PAST BLANKS AND TABS. &

15620	IF MID (S$,1%,L%)=MID(C$,P%+1%,L%) THEN Z%=L% &
	ELSE GOTO 15650 &
		! SEARCH FOR MINIMUM MATCH. &

15630	Z$=MID(C$,P%+Z%+1%,1%) &
	\ GOTO 15640 UNLESS Z$==MID(S$,Z%+1%,1%) &
	\ Z%=Z%+1% IF LEN(Z$) &
	\ GOTO 15630 IF LEN(Z$) &
		! SEARCH FOR MORE MATCHING CHARACTERS. &

15640	L%=ASCII(MID(C$,P%+Z%+1%,1%)) &
	\ GOTO 15650 UNLESS (L%=9% OR L%=32% OR L%=47% OR L%=10% OR L%=58% OR &
			L%=13% OR L%=61%) IF CHK.END% AND P%+Z%<LEN(C$) &
	\ P%=P%+Z% &
	\ FNR%=Z% &
		! RETURN WITH P% POINTING TO THE LAST SUCCESSFULLY &
		! MATCHED CHARACTER. FUNCTION WILL RETURN AS THE NUMBER &
		! OF CHARACTERS MATCHED. &

15650	FNEND &
	&
	&
	&

15700	DEF* FNSETSB%(SUBN$,RSP$) &
	\ SB0%=0% &
	\ ABORT%=-1% IF SUBN$="ABORT" AND RSP$="YES" &
	\ SUBR$(0%)=RSP$ IF SUBN$="ABORTS" &
	\ SUBN$(0%)=SUBN$ IF SUBN$="ABORTS" &
	\ GOTO 15710 IF SUBN$="ABORTS" &
	\ NONW%=-1% IF NUM.SUB%>50% &
	\ IF LEN(SUBN$)>26% OR LEN(RSP$)>26% OR NUM.SUB%>76% &
	THEN	FNSETSB%=-1% &
	ELSE &
		SB0%=SB1% IF SUBN$=SUBN$(SB1%) &
				FOR SB1%=1% TO NUM.SUB% UNLESS PRO.SAV% &
	\	NUM.SUB%=NUM.SUB%+1% UNLESS SB0% &
	\	SB0%=NUM.SUB% UNLESS SB0% &
	\	SUBN$(SB0%)=SUBN$ &
	\	SB1%=INSTR(1%,RSP$,",") &
	\	WHILE SB1% &
	\		RSP$=LEFT(RSP$,SB1%-1%)+ &
				CHR$(172%)+	RIGHT(RSP$,SB1%+1%) &
		!		172%=44+128 &
	\		SB1%=INSTR(SB1%,RSP$,",") &
	\	NEXT &
	\	SUBR$(SB0%)=RSP$
15710	 FNEND &
		! SB0% AND SB1% ARE ONLY TEMP VARIABLES. &

15750	DEF* FNDOSUB%(P%) &
	\ FNDOSUB%=1% &
	\ SB0%=INSTR(P%,C0$,":") &
	\ IF (SB0%-P%>7%) OR SB0%=0% THEN &
		GOTO 15780 &
	ELSE &
		SUBN$=CVT$$(MID(C0$,P%+1%,SB0%-P%-1%),32%) &
	\	SB3%,FNDOSUB%=0% &
	\	WHILE SUBN$<>SUBN$(SB3%) AND SB3%<=NUM.SUB% &
	\	SB3%=SB3%+1% &
	\	NEXT &
	\	IF SB3%>NUM.SUB% THEN &
			GOTO 15770 &
		ELSE &
		SB1%=0% &
	\	SB1%=INSTR(SB0%+2%,C0$,"/") IF ASCII(MID(C0$,SB0%+1%,1%))=47% &
	\	SB0%=SB1% IF SB1% &
	\	C0$=LEFT(C0$,P%-1%)+SUBR$(SB3%)+RIGHT(C0$,SB0%+1%) &
	\	GOTO 15780
15770	C0$=LEFT(C0$,P%-1%)+RIGHT(C0$,SB0%+1%) &
	\ C$=C0$ &
	\ P%=P%-1% &
	\ SB0%=FNR%("/",1%) &
	\ IF SB0% THEN &
		SB1%=INSTR(P%+1%,C0$,"/") &
	\	IF SB1%>P% THEN &
			C0$=LEFT(C0$,P%-1%)+MID(C0$,P%+1%,SB1%-P%-1%)+ &
				RIGHT(C0$,SB1%+1%)
15780	FNEND &
		! SB0%, SB1% AND SB3% ARE ONLY TEMP VARIABLES. &
	&
	&
	&
	&
	&

15900	&
	&
	&
	!	F U N C T I O N    F N C S P C O M &
	&
	DEF* FNCSPCOM%(C$) &
	\ P%=0% &
	\ CSP$=C$ &
	\ C$=CVT$$(C$,188%) &
		!	188=4%+8%+16%+32%+128% &
	\ IF FNR%("OLD",-3%) THEN &
		CSP1$=RIGHT(C$,P%+1%) &
	\	GOTO 15990 &

15910	IF FNR%("APPEND",-3%) THEN &
		CSP1$=CSP1$+","+RIGHT(C$,P%+1%) &
	\	GOTO 15990 &

15920	GOTO 15990 UNLESS FNR%("COMPILE",-3%) &
	\ T1%=INSTR(P%,C$,"/") &
	\ CSP3$='APP '+RIGHT(CSP1$,3%) &
		UNLESS CSP1$=NL$ OR CSP% &
	\ T0$=RIGHT(C$,P%+1%) &
		UNLESS T1% &
	\ T0$=MID(C$,P%+1%,T1%-(P%+1%)) &
		IF T1% &
	\ T0$=FNFM$(CSP1$,T0$,4%) &
	\ CSP2$,C$=RIGHT(C$,T1%) &
		IF T1% &
	\ P%=0% &
	\ OBJ%=INSTR(1%,C$,"/OBJ") &
	\ P%=OBJ%-1% &
		IF OBJ% &
	\ CSP2$=LEFT(C$,OBJ%-1%)+RIGHT(C$,P%+1%) &
		IF FNR%("/OBJECT",-4%) &
	\ T1%=INSTR(1%,C$,"/TSK") &
	\ CSP2$=LEFT(C$,T1%-1%)+RIGHT(C$,T1%+4%) &
		IF T1% &
	\ T2$=FNFM$(T0$,NL$,16%) &
	\ T1%=VAL(MID(T2$,2%,LEN(T2$)-2%)) &
		IF LEN(T2$) &
	\ T2$="<"+NUM1$(T1% OR 64%)+">" &
		IF LEN(T2$) &
	\ T2$=FNFM$(T0$,".TSK"+T2$,55%) &
	\ RENM%=S1% AND 1024% &
	\ P%=-1% &
	\ T0$=FNFM$(T0$,".OBJ",7%) &
	\ IF CSP% AND PCT% THEN &
		CSP1$ = FNFM$(CSP1$,".TSK",39%) &
	\	DVST% = DVST% AND 255% &
	\	PRINT #12%,RPIP$;CRLF$; &
			   T2$;"/RTS:RSX"; &
	\	PRINT #12%,"/MO:64"; &
			IF DVST% = 0% &
	\	PRINT #12%,"=";CSP1$; &
	\	PRINT #12%,"/RW:NO"; &
			IF DVST% = 14% &
	\	PRINT #12%,CRLF$;T2$;"/MO:64=";FNFM$(T2$,NL$,47%); &
			IF DVST% <> 0% &
	\	PRINT #12%,CRLF$;"^Z" &
	\	GOTO 15990 &

15930	PRINT #12%,R$;RLIB$;"CSPCOM.TSK";CRLF$; &
		   CVT$$(T0$+"/OBJ="+CSP1$,2%)+CRLF$;"^Z" &
			IF CSP% &
	\ GOTO 15990 &
		IF (OBJ% AND CSP%) &
			UNLESS TKB% &
	\ PRINT #12%,CSP3$ &
		UNLESS CSP1$=NL$ OR CSP% &
	\ PRINT #12%,COM$;T0$;CSP2$;SW$ &
		IF TKB% AND NOT CSP% &
			UNLESS OBJ% &
	\ PRINT #12%,COM$;CSP2$;T0$;SW$ &
		IF (TKB% AND OBJ%) AND NOT CSP% &
	\ GOTO 15990 &
		IF OBJ% &
	\ PRINT #12%,R$;RLIB$;"TKB.TSK" &
	\ PRINT #12%,CVT$$(FNFM$(T0$,".TSK",7%)+"/FP="+T0$+","+ &
		   LB$+LIB2$+".OLB/LB",2%);CRLF$;"/" &
			IF TKB% AND NOT CSP% &
	\ PRINT #12%,CVT$$(FNFM$(T0$,".TSK",7%)+"/FP="+T0$+","+ &
		   LB$+LIB$+".OLB/LB",2%);CRLF$;"/" &
			UNLESS TKB% AND NOT CSP% &
	\ PRINT #12%,"UNITS=12";CRLF$; &
		   "ASG=SY:5:6:7:8:9:10:11:12";CRLF$; &
		   "//" &
	\ PRINT #12%,RPIP$;CRLF$; &
	           T0$;'/DE:NO';CRLF$;"^Z" &
	\ PRINT #12%,RPIP$;CRLF$; &
		   T2$;"/RE";CRLF$;"^Z" &
			IF RENM% &

15990	FNCSPCOM%=P% &
	\ FNEND &
	&
	&

16000	DEF* FNAC%(ACC$,CREACT%) &
		! FUNCTION TO VERIFY EXISTENCE OF AN ACCOUNT &
		! AND OPTIONALLY CREATE ACCOUNT (WITH USERS CONSENT). &
	\ ACC$ = CVT$$(ACC$,1%) &
	\ FNAC%=-1% &
	\ ON ERROR GOTO 16010 &
	\ CHANGE SYS(S0$+ACC$) TO M1% &
	\	M1%(1%)=6% &
	\	M1%(2%)=25% &
	\	M1%(3%),M1%(4%)=0% &
	\	CHANGE M1% TO A1$ &
	\	A1$=SYS(A1$) &
	\ ON ERROR GOTO 19000 &
	\ FNAC%=0% &
	\ GOTO 16050 &

16010	IF ERR<>5% OR CREACT%=0% THEN &
		PRINT FNE$(ERR);" - account ";ACC$ &
	\	RESUME 16050 &

16015	PRINT "%Account ";ACC$;" does not exist - create it <No>"; &
	\ INPUT RSP1$ &
	\ RESUME 16050 UNLESS ASCII(CVT$$(RSP1$,-1%))=89% &
	\ RESUME 16020 &

16020	M1%(1%)=6% &
	\ M1%(2%),M1%(3%),M1%(4%),M1%(13%),M1%(14%),M1%(28%)=0% &
	\ M1%(7%)=M1%(5%) &
	\ M1%(8%)=M1%(6%) &
	\ M1%(5%),M1%(6%)=0 &
	\ M1%(I%)=0% FOR I%=9% TO 12% &
	\ M1%(27%)=16% &
	\ CHANGE M1% TO A1$ &
	\ ON ERROR GOTO 16030 &
	\ A1$=SYS(A1$) &
	\ ON ERROR GOTO 19000 &
	\ PRINT "Account ";ACC$;" created" &
	\ FNAC%=0% &
	\ GOTO 16050 &

16030	PRINT "?Account ";ACC$;" not created";CRLF$;FNE$(ERR) &
	\ RESUME 16050 &

16050	FNEND &
	&
	&

16900	! &
	&
	&
	!	F U N C T I O N  F N R T S % &
	&
	! RETURNS -1% IF FOUND. &
	! RETURNS 0% IF NOT FOUND. &
	&
	DEF* FNRTS%(RTS.NM$) &
	\ RTS.NM$ = CVT$$(RTS.NM$,1%) &
	\ FNRTS%,RTSTYP%=0% &
	\ CHANGE SYS(S0$+RTS.NM$) TO M1% &
	\ Z$=SYS(PRIV.ON$) &
	\ RTS.LNK%=PEEK(RTS.LST%)
16920	GOTO 16960 UNLESS RTS.LNK% &
	\ GOTO 16940 IF PEEK(RTS.LNK%+2%)=M1%(7%)+SWAP%(M1%(8%)) AND &
		PEEK(RTS.LNK%+4%)=M1%(9%)+SWAP%(M1%(10%)) &
	\ RTS.LNK%=PEEK(RTS.LNK%) &
	\ GOTO 16920
16940	RTS.EXT$=CVT$$(RAD$(PEEK(RTS.LNK%+6%)),2%) &
	\ FNRTS%=-1% &
	\ KBM%=(PEEK(RTS.LNK%+30%) AND 256%)<>0% &
	\ Z$=SYS(PRIV.OFF$) &
	\ IF NOT KBM% THEN &
		PRINT RTS.NM$;NKBM$ &
	ELSE &
		RTSTYP%=(RTS.EXT$="TSK") &
	\	RTSTYP%=1% IF RTS.EXT$="BAC" &
	\ IF RTSTYP% AND KBM% THEN &
		RTS$=RSP$ &
	\	T0%=FNSETSB%("DEXT","."+RTS.EXT$) &
	\	IF RTSTYP%<0% THEN &
			UCSP$ = "Use CSPCOM" &
	\		UCSP$ = "Use pre-compiled tasks" IF PCT% &
	\		CSP%=ASCII(CVT$$(FNF$(UCSP$,"YES",8192%,NL$),-1%))=89% &
	\		BP2$=CVT$$(FNF$('BASIC-PLUS-2 compiler',BP2.COM$,13%,BP2.COM$),172%) &
				IF RTSTYP%<0% AND NOT CSP% &
	\		T0%=FNSETSB%("CSPCOM","YES") &
	\		T0%=FNSETSB%("CSPCOM","NO") UNLESS CSP% &
	\		LIB2$=MID(BP2$,INSTR(1%,BP2$,']')+1%,3%)+'OTS' &
	\		LIB$="CSPCOM" &
	\		LIB$=FNFM$(RTS.NM$,NL$,4%) UNLESS CSP% &
	\		T0%=FNSETSB%("OLB",LIB$) &
	&
		! &
		! RTSTYP%=0	IF NOT BP OR BP2 (RSX) &
		! 	  =1	IF BP (BASIC-PLUS) &
		!	 =-1	IF BP2 &
		! KBM%	-1% IF KEYBOARD MONITOR ELSE 0 &
		! ASK IF SHOULD USE CSPCOM (DEFAULT IS YES ONLY IF &
		!	THINK WE ARE GOING TO USE "BP2COM") &
		! CSP%  -1% IF WANT TO USE CSPCOM ELSE 0 &

16960	Z$=SYS(PRIV.OFF$) &
	\ FNEND &
	! MAKE SURE PRIVS DROPPED BEFORE EXITING &
	! RETURNS 0 IF RTS NOT INSTALLED (ELSE -1%) &

17300	! &
	&
	&
	&
	!	F U N C T I O N   F N F M $ &
	&
	&
	&
	! FUNCTION: FNFM$(A0$,A1$,FLG%) &
	! &
	! FUNCTION TO MERGE FILE NAME A0$ INTO A1$. &
	! STRING A1$ IS THE TARGET STRING.  A0$ IS &
	! MERGED INTO A1$ FILLING IN ALL COMPONENTS &
	! MISSING FROM A1$ AS SELECTED BY THE FLAG &
	! WORD FLG%.  THE MEANING OF THE BITS ARE: &
	! &
	!	BIT AND VALUE		MEANING &
	! &
	!	0 ((FLG% AND 1%) <> 0%) &
	! &
	!		COPY DEVICE FROM A0$ IF IT &
	!		IS MISSING FROM A1$ &
	! &
	!	1 ((FLG% AND 2%) <> 0%) &
	! &
	!		COPY PPN SPECIFICATION FROM A0$ &
	!		IF MISSING FROM A1$ &
	! &
	!	2 ((FLG% AND 4%) <> 0%) &
	! &
	!		COPY FILE NAME IF MISSING &
	! &
	!	3 ((FLG% AND 8%) <> 0%) &
	! &
	!		COPY EXTENSION IF MISSING &
	! &
	!	4 ((FLG% AND 16%) <> 0%) &
	! &
	!		COPY PROTECTION CODE IF MISSING &
	!		AND/OR MODE: &
	! &
	!	5 ((FLG% AND 32%) <> 0%) &
	! &
	!		FILL IN "_SY:" FOR DEVICE IF NO &
	!		DEVICE IN EITHER STRING, AND &
	!		CURRENT ACCOUNT FOR PPN IF NO &
	!		PPN IN EITHER STRING. &
	! &
	! IN ALL CASES, M1% CONTAINS STRING SCAN OF RESULTING &
	! STRING "CHANGE"D TO INTEGER ARRAY.  S1% CONTAINS &
	! THE FLAG WORD AND DVST% CONTAINS STATUS.  IF &
	! EITHER A0$ OR A1$ IS A BAD STRING, THAT STRING &
	! IS RETURNED AS THE FUNCTIONS VALUE AND S1%=0% &
	&
	DEF* FNFM$(A0$,A1$,FLG%) &
	\ A0$ = CVT$$(A0$,1%) &
	\ A1$ = CVT$$(A1$,1%) &
	\ FNFM$=NL$ &
	\ ON ERROR GO TO 17395 &
	\ T0%=0% &
	\ CHANGE SYS(S0$+A0$) TO M0% &
	\ S0%=M0%(29%)+SWAP%(M0%(30%)) &
	\ TST0%=STATUS &
	\ TST0%=0% IF (S0% < 0%) OR (S0% AND 4096%)=0% &
	\ T0%=1% &
	\ CHANGE SYS(S0$+A1$) TO M1% &
	\ REC%=RECOUNT &
	\ S1%=M1%(29%)+SWAP%(M1%(30%)) &
	\ DVST%=STATUS &
	\ DVST%=0% IF (S1% < 0%) OR (S1% AND 4096%)=0% &
		! SCAN THE 2 FILE NAMES &
	&
	\ IF (FLG% AND 1%) AND (S1% AND 4096%)=0% &
		THEN M1%(I%)=M0%(I%) FOR I%=23% TO 26% &
		\    S1%=S1% OR (S0% AND -4096%) &
		\    DVST%=TST0% &
		\    IF (S1% AND 4096%)=0% AND (FLG% AND 32%) &
			THEN M1%(23%)=ASCII("S") &
			\    M1%(24%)=ASCII("Y") &
			\    M1%(25%),M1%(26%)=0% &
			\    S1%=S1% OR 12288% &
		!			12288=(4096%+8192%) &
		! FILL IN DEVICE FIELD IF LEFT OUT OF TARGET &
		! STRING.  FORCE DEFAULT "_SY:" IF NO DEVICE &
		! IN EITHER STRING AND FORCE DEFAULT BIT IS SET. &
		! DEVBITS%=-4096% = 4096%+8192%+16384%+32767%+1% &
	&

17320	IF (FLG% AND 2%) AND (S1% AND 128%)=0% &
		THEN M1%(I%)=M0%(I%) FOR I%=5% TO 6% &
		\    S1%=S1% OR (S0% AND 896%) &
		\    IF (S1% AND 128%)=0% AND (FLG% AND 32%) &
			THEN M1%(5%)=NPJ% &
			\    M1%(6%)=NPG% &
			\    S1%=S1% OR 128% &
		! FILL IN PPN.  SET TO CURRENT ACCOUNT IF NONE &
		! IN TARGET STRING. &
		! PPNBITS%=896%	= 128%+256%+512% &
	&

17330	IF (FLG% AND 4%) AND (S1% AND 1%)=0% &
		THEN M1%(I%)=M0%(I%) FOR I%=7% TO 10% &
		\    S1%=S1% OR (S0% AND 7%) &
		! COPY FILE NAME IF SELECTED. &
		! FLNBITS%=7%	= 1%+2%+4% &
	&

17340	IF (FLG% AND 8%) AND (S1% AND 8%)=0% &
		THEN M1%(I%)=M0%(I%) FOR I%=11% TO 12% &
		\    S1%=S1% OR (S0% AND 120%) &
		! FILL IN EXTENSION BITS. &
		! EXTBITS%=120%	= 8%+16%+32%+64% &
	&

17350	IF (FLG% AND 16%) AND (S1% AND 1024%)=0% &
		THEN M1%(I%)=M0%(I%) FOR I%=21% TO 22% &
		\    S1%=S1% OR (S0% AND 3072%) &
		! PROTECTION CODE &
		! PRTBITS%=3072% = 1024%+2048% &
	&

17360	A0$=NL$ &
	\ IF S1% AND 4096% THEN &
		     A0$="_"+CHR$(M1%(23%))+CHR$(M1%(24%)) &
		\    A0$=A0$+NUM1$(M1%(25%)) IF M1%(26%)=255% &
		\    A0$=A0$+":" &
		! IF COMPOSITE NAME CONTAINS A DEVICE SPEC, &
		! THEN BUILD DEVICE SPEC INTO FILE NAME. &

17365	A0$=A0$+"["+NUM1$(M1%(6%))+","+NUM1$(M1%(5%))+"]" &
		IF M1%(5%)+M1%(6%) &
	\ IF S1% < 0% THEN &
		A0$=NL$ &
		\ A0$=A0$+RAD$(M1%(I%)+SWAP%(M1%(I%+1%))) &
			FOR I% = 23% TO 25% STEP 2% &
		\ A0$=A0$+":" &

17370	T0%=9% &
	\ T0%=11% IF S1% AND 8% &
	\ FOR I%=7% TO T0% STEP 2% &
	\	A0$=A0$+"." IF I%=11% &
	\	A0$=A0$+RAD$(M1%(I%)+SWAP%(M1%(I%+1%))) &
	\ NEXT I% &
		! CONVERT RAD 50 FILE NAME TO ACTUAL FILE NAME &

17380	A0$=A0$+"/MO:"+NUM1$((M1%(17%)+SWAP%(M1%(18%))) AND 32767%) IF &
		((M1%(27%)+SWAP%(M1%(28%))) AND 2%) AND (FLG% AND 16%)<>0% &
		! INCLUDE MODE IF A MODE SPECIFIED. &
	&
	\ A0$=CVT$$(A0$,6%) &
	\ A0$=A0$+"<"+NUM1$(M1%(22%))+">" IF S1% AND 1024% &
		! FILL IN PROTECTION CODE IF ONE WAS &
		! INCLUDED. &

17390	ON ERROR GO TO 19000 &
	\ GOTO 17395 IF REC% UNLESS EXTRA% &
	\ M1%(29%)=S1% AND 255% &
	\ M1%(30%)=SWAP%(S1%) AND 255% &
	\ A0$=A0$+RIGHT(A1$,LEN(A1$)+1%-REC%) IF REC% &
	\ FNFM$=A0$ IF S1% &
	\ FNEND &

17395	FNFM$=A0$ IF T0%=0% &
	\ FNFM$=A1$ IF T0% &
	\ REC%,S1%=0% &
	\ RESUME 17390 &
	&

17500	! &
	&
	&
	&
	!	F U N C T I O N   F N F I L C P Y % &
	&
	&
	&
	! FUNCTION: FNFILCPY%(A0$,A1$) &
	! &
	! FUNCTION TO COPY FILE A0$ TO A1$ &
	&
	DEF* FNFILCPY%(A0$,A1$) &
	\ ON ERROR GO TO 17520 &
	\ CLOSE 10%,11% &
	\ PRINT CRLF$;"*** Copying file ";A0$;" to ";A1$;" ***";CRLF$ &
	\ OPEN A0$ FOR INPUT AS FILE 11% &
	\ GOTO 17510 IF STATUS AND 8192% &
	\ OPEN A1$ FOR OUTPUT AS FILE 10% &
	\ WHILE -1% &
	\	GET #11% &
	\	I%=RECOUNT &
	\	WHILE I%<512% &
	\		FIELD #11%, I% AS C$, 1% AS C$ &
	\		LSET C$=CHR$(0%) &
	\		I%=I%+1% &
	\	NEXT &
	\	PUT #10%+SWAP%(11%) &
	\ NEXT &
		! OPEN FILES AND COPY IN BLOCK MODE. &
		! IF INPUT IS KB: DO INPUTS AND PRINTS. &

17510	OPEN A1$ FOR OUTPUT AS FILE 10% &
	\ WHILE -1% &
	\	INPUT LINE #11%, C$ &
	\	PRINT #10%, C$; &
	\ NEXT &
		! INPUT FILE IS CHARACTER ORIENTED (KB:) SO &
		! USE INPUT LINES AND PRINT. &

17520	CLOSE 10%,11% &
	\ IF ERR=11% &
		THEN FNFILCPY%=0% &
		ELSE PRINT "?Can't copy ";A0$;" to ";A1$;CRLF$;FNE$(ERR) &
		\    FNFILCPY%=-1% &

17530	RESUME 17540 &

17540	ON ERROR GO TO 19000 &
	\ FNEND &
	&

17600	! &
	&
	&
	&
	!	F U N C T I O N   F N I L N $ &
	&
	&
	&
	! FUNCTION: FNILN$ &
	! &
	! INPUT A LINE FROM KB: TRAPPING EOF'S. &
	! INPUT IS EXPLICITLY FROM CHANNEL 10. &
	&
	DEF* FNILN$ &
	\ C0=C0+1. &
	\ ON ERROR GO TO 17610 &
	\ INPUT LINE #10,T0$ &
	\ FNILN$,C$=T0$ &
	\ GO TO 17620 &

17610	FNILN$=NL$ &
	\ RESUME 17620 IF ERR=11% &
	\ GOTO 19000 &

17620	ON ERROR GO TO 19000 &
	\ FNEND &
	&

17700	! &
	&
	&
	&
	!	F U N C T I O N   F N E $ &
	&
	&
	&
	! FUNCTION: FNE$ &
	! &
	! EXTRACT AN ERROR MESSAGE &
	&
	DEF* FNE$(E8%)=CVT$$(RIGHT(SYS(CHR$(6%)+CHR$(9%)+CHR$(E8%)),3%),4%) &
	&

19000	! &
	&
	&
	!	E R R O R    H A N D L I N G &
	&
	&
	&
	Z$ = SYS(PRIV.OFF$) &
	\ GOTO 32700 IF ERR=11% &
	\ PRINT IF CCPOS(0%) &
	\ PRINT "??Program failure in BUILD";CRLF$; &
			FNE$(ERR);" at line ";NUM$(ERL) &
	\ FATLER%=-1% &
	\ RESUME 32700 &
		! TEMPORARY DUMMY ERROR HANDLER &
	&

20000	! HANDLE ALL PBUILD SPECIFIC SUBSTITUTIONS AND COMMANDS. &
	P%=0% &
	\ RETURN IF FNR%("$END",-4%) &
	\ GOTO 20145 IF FNR%("$PROMPT",-4%) &
	\ GOTO 20140 IF FNR%("$BOOT",-5%) OR BOT% &
	\ GOTO 20085 IF FNR%("$PATCH",-4%) &
		! &
	\ GOTO 20000 IF (FNIND% OR -1%) IF FNR%("$FORCE",-4%) &
	\ C0$=CVT$$(C0$,4%) &
	\ T0%=FNPRNT%(C0$+CRLF$) &
	\ RETURN &
		! HANDLE ALL TEXT TO BE FORCED TO &
		! KEYBOARD AFTER SUBSTITUTING &
		! FOR INPUT, OUTPUT, SYSTEM, AND LIB &
		! DEVICES. &

20085	C0$=FNFM$(".BAS",CVT$$(RIGHT(C0$,P%+1%),38%),31%) &
	\ C1$=FNFLNC$(C0$,29%,INDV$+INAC$) &
	\ C0$=FNFM$(C0$,NL$,12%) &
	\ L1$=FNFLNC$(C0$,28%,OPTDV$) &
	\ PRINT "?Check source input Dev:[ppn]" UNLESS LEN(C1$) &
	\ FATLER%=-1% UNLESS LEN(C1$) &
	\ GOTO 32700 IF FATLER% &
	\ T0%=FNPRNT%(R$+RLIB$+"CPATCH"+CRLF$) &
	\ T0%=FNPRNT%(L1$+"="+C1$+CRLF$) &
		! LOOK FOR PATCH HEADER IN COMMAND FILE. &
		! WHEN FOUND: &
		! C0$=MERGED INPUT FILE SPEC WITH ".BAS" IF NO .EXT WAS FOUND. &
		! L1$=MERGED INPUT FILE SPEC WITH  OUTPUT DEV/ACC  AS NEEDED. &
		! C1$=MERGED INPUT FILE SPEC WITH  INPUT DEV/ACC  AS NEEDED. &
		! (FN)PRINT "RUN CPATCH" &
		! THEN FORCE THE FILE TO &
		! PATCH. &

20090	GOTO 20150 IF FNIND% &
	\ GOTO 20090 IF ASCII(C0$)=33% &
	\ GO TO 20100 IF FNR%("$END",-4%) OR FNR%("$FORCE",-4%) &
	\ EXTRA%=-1% &
	\ C0$=FNFLNC$(CVT$$(C0$,38%),29%,STAK$(SP%-(2% AND SP%=2%))) &
					IF E0% OR NOT NEWF% &
	\ C0$=FNFLNC$(CVT$$(C0$,38%),29%,PADV$) &
					UNLESS E0% OR NOT NEWF% &
	\ EXTRA%=0% &
	\ T0%=FNPRNT%(L0$+C0$+CRLF$) &
	\ GO TO 20090 &
		! GET NEXT PATCH FILE NAME AND FORCE TO &
		! KEYBOARD AFTER MASHING IT WITH EITHER &
		! THE CURRENT INPUT FILE (PBUILD) &
		! OR THE SPECIFIED PATCH FILE LOCATION (BUILD). &

20100	T0%=FNPRNT%("^Z"+CRLF$) &
	\ T0%=FNPRNT%("^Z"+CRLF$) &
	\ C0$=CVT$$(RIGHT(C0$,5%),38%) &
	\ LCMP.FLG%=(INSTR(1%,C0$,"/NC")<>1%) &
	\ C0$=RIGHT(C0$,4%) UNLESS LCMP.FLG% &
		! EXIT CPATCH, CHECK TO SEE IF &
		! NO COMPILE SWITCH IS PRESENT. &
		! SET LOCAL COMPILE FLAG TO SHOW IF IT WAS FOUND. &
		! LCMP.FLG%=0%   MEANS DO NOT COMPILE (/NC) &
		! LCMP.FLG%=-1%  MEANS DO THE COMPILE (/NC WAS NOT FOUND) &
	&
!	\ C0$=FNFM$(SYDV$+SYAC$,RIGHT(C0$,3%),31%) &
!		IF INSTR(1%,C0$,"S:")=1% &
!	\ C0$=FNFM$(LBDV$+LBAC$,RIGHT(C0$,3%),31%) &
!		IF INSTR(1%,C0$,"L:")=1% &
	\ IF LCMP.FLG% AND CMPFLG% &
		THEN 	T0%=FNPRNT%("OLD "+L1$+CRLF$) &
	\    T0$=FNFM$(C1$,LBDV$+LBAC$,63%) &
		\   C0$,T0$=FNFM$(T0$,C0$,55%) &
		\ T0%=FNPRNT%(COM$+T0$+CRLF$) &
		! MASH S: OR L: INTO OUTPUT LOCATION IF NEEDED. &
		! IF SOURCE PROGRAM IS TO BE COMPILED &
		!	(LOCAL COMPILE FLAG AND GLOBAL COMPILE FLAG BOTH SET) &
		! FORM THE COMPILE FILE NAME AND FORCE &
		! COMMANDS TO KB. &

20120	IF SAVFLG% AND &
	(	(NOT(LCMP.FLG%) AND OPTDV$<>LBDV$+LBAC$) OR &
		(OPTDV$<>SAV.DEV$)	) &
	THEN &
		C0$=FNFM$(L1$,LBDV$+LBAC$,63%) &
		\ C0$=FNFM$(L1$,SAV.DEV$,63%) UNLESS OPTDV$=SAV.DEV$ &
		\ T0%=FNPRNT%(RPIP$+CRLF$+ &
			C0$+"="+L1$+CRLF$+ &
			"^Z"+CRLF$) &
	! IF FILE IS TO BE SAVED AND &
	! /NC SWITCH WAS FOUND AND FILE NOT IN LIBRARY THEN PUT IN LIB. &
	! OR FILE IS TO BE SAVED BUT IS NOT ON SAV DEVICE PUT IT ON SAV.DEV$ &

20130	T0%=FNPRNT%(RPIP$+CRLF$+ &
			L1$+"/DE:NO"+CRLF$+ &
			"^Z"+CRLF$) UNLESS &
		(SAVFLG% AND OPTDV$=SAV.DEV$) OR NOT(LCMP.FLG%) &
	\ T0%=FNPRNT%(RPIP$+CRLF$+ &
			FNFM$(C1$,".BAK",63%)+"/DE:NO"+CRLF$+ &
			"^Z"+CRLF$) IF C1$=L1$ &
	\ RETURN &
		! KILL PATCHED COPY UNLESS &
		! SAVING PATCHED SOURCES AND FILE WAS &
		!	PATCHED INTO THE SAVE LOCATION, OR &
		!  "/NC" WAS FOUND. &
		! &
		! KILL .BAK FILE IF WE PATCHED IN PLACE. &

20140	GOTO 2080 IF NOT BOT% &
	\ RETURN UNLESS P% &
	\ BOT%,E0%=0% &
	\ PRINT "BUILD has rebooted" &
	\ RETURN &

20145	GOSUB 2110 &
	\ RETURN &

20150	IF T0% <> 1% THEN &
		CLOSE 10% &
		\ RETURN &
		! ON EOF IN COMMAND FILE, REATTACH &
		! AND GET NEW COMMAND FILE. &
		! OTHER ERROR, GO TO ERROR HANDLER. &

20160	PRINT IF CCPOS(0%) &
	\ PRINT "?File name error" &
	\ GO TO 32700 &
		! PRINT ERROR MESSAGE AND EXIT. &
	&

31000	! &
	&
	&
	!	C H A I N    E N T R Y  (P B U I L D    O N L Y) &
	&
	! CORE COMMON: &
	!	FILE SPEC OF FILE CONTAINING ALL INFO GATHERED BY PBUILD. &
	! &

31010	E0%=2% &
	\ GOSUB 10000 &
	\ IF NOT PRV% THEN &
		FATLER%=-1% &
	\	GOTO 32700 &
		! SHOW WE CAME FROM PBUILD &
		! GO INITIALIZE EVERYTHING &
		! IF NOT PRIV'D, SET FATAL ERROR AND EXIT &

31020	Z$ = SYS(PRIV.OFF$) &
	\ C$=CVT$$(SYS(CHR$(7%)),39%) &
	\ OPEN C$ FOR INPUT AS FILE 10% &
	\ KILL C$ &
	\ PKLO$="_SY:" &
	\ FUNC%=1% &
	\ FUNCSET%=-1% &
	\ INPUT LINE #10%,C$ &
	\ INDV$,RSP$=CVT$$(C$,39%) &
	\ GOSUB 11047 &
	\ INPUT LINE #10%,C$ &
	\ INAC$=CVT$$(C$,39%) &
	\ INPUT LINE #10%,C$ &
	\ SAV.DEV$=CVT$$(C$,39%) &
	\ INPUT LINE #10%,C$ &
	\ OPTDV$=CVT$$(C$,39%) &
	\ T0%=FNSETSB%("SAVDEV",OPTDV$) &
	\ SAVFLG%=-1% IF LEN(SAV.DEV$) &
	\ OFLG%=-1% IF SAV.DEV$<>OPTDV$ &
	\ INPUT LINE #10%,C$ &
	\ LBDV$=CVT$$(C$,39%) &
	\ LBDV$=FNFM$("_SY:",LBDV$,1%) &
	\ INPUT LINE #10%,C$ &
	\ LBAC$=CVT$$(C$,39%) &
	\ LBAC$=FNFM$("[1,2]",LBAC$,2%) &
	\ INPUT LINE #10%,C$ &
	\ SYDV$=CVT$$(C$,39%) &
	\ SYDV$=FNFM$("_SY0:",SYDV$,1%) &
	\ INPUT LINE #10%,C$ &
	\ SYAC$=CVT$$(C$,39%) &
	\ SYAC$=FNFM$("[1,2]",SYAC$,2%) &
	\ INPUT LINE #10%,C$ &
	\ C$=CVT$$(C$,39%) &
	\ T0%=INSTR(1%,C$,"=") &
	\ L0$=LEFT(C$,T0%) &
	\ PADV$=RIGHT(C$,T0%+1%) &
	\ INPUT LINE #10%,C$ &
	\ CTFL$=CVT$$(C$,39%) &
	\ INPUT #10%,C$,CMPFLG%,FUNC%,DTCH%,LOGF$ &
	\ NEWF%=-1% IF LEN(C$) &
	\ BOT%=(C$="BOOT") &
	\ CLOSE 10% &
	\ GOTO 1000 &
	&
	&

32700	! &
	&
	&
	&
	!	E X I T &
	&
	&
	&
	! NORMAL EXIT &
	&
	CLOSE -9% &
	\ GOTO 32767 IF FATLER% &
	\ T0$="BUILD" &
	\ T0$="P"+T0$ IF E0% &
	\ T0%=FNPRNT%(CRLF$) FOR T1%=1% TO 3% &
	\ T0%=FNPRNT%("!*** "+T0$+" Complete ***"+CRLF$) UNLESS BOT% &
	\ CLOSE 10%,11%,12% &
	\ LOGF$=NL$ IF BOT% &
	\ IOFL$=IOFL$+"/DET" IF DTCH% AND NOT BOT% &
	\ IOFL$=IOFL$+"/RTS:"+RTS$ IF LEN(RTS$) &
	\ IOFL$=IOFL$+"/CHA:"+RLIB$+"BUILD;31000=/"+T$+"/" IF BOT% &
		! NORMAL EXIT ON CONTROL Z FOR &
		! LOG OR COMMAND FILE NAME. &

32710	Z$=SYS(CHR$(8%)+"ATPK "+LOGF$+IOFL$+"/LOG/DEL/TIM") &
	\ Z$=SYS(PRIV.ON$) &
	\ CHAIN RLIB$+"ATPK" LINE (30000% OR NOT 32767%) &
		! LOAD CORE COMMON WITH ATPK COMMAND &
		! REGAIN TEMP PRIVS &
		! CHAIN TO ATPK WITH PRIV BIT SET &

32767	END
