1	!	CRUN	Fake entrance for C programs &
	! &
	! CRUN is intended to be installed as a (non-privileged) CCL &
	! command.  It is executed by a statement such as &
	! &
	!	CRUN FOO parameter list &
	! &
	! when run, it will chain to FOO at line 30000 with core &
	! common set to "FOO parameter list".  This is useful &
	! for C programs that want to run this way (but which should &
	! not take up CCL table space).  Line 30000 is used so that &
	! BASIC-PLUS programs can insert a GOTO statement there. &
	! see INIT.MAC in the run-time library for an example of its use. &
	! INIT.MAC accepts any line number greater than 29000.
	! &
	! Note: CRUN may be installed using any CCL command name. &
	! The following installation is recommended: &
	! &
	!	UTILITY CCL CR-UN=$CRUN.*;30000
	! &
	! CRUN maintains a search list defined in line 110.
	&

10	EXTEND
100	! &
	! Define search list for accounts: &
	!
110	DATA	"SY:@", "C:", "SY:$", "PUB:", "" &

1000	PRINT "?Please use the CRUN command" &

1010	GOTO 32767 &

30000	! &
	!	CCL entrance &
	! &

30010	text$ = SYS(CHR$(7%)) &
	\ mcrname$ = "CRUN" &
	\ header$ = "" &
	\ i% = INSTR(1%, text$, " ") &
	\ IF i% THEN &
	    mcrname$ = left(text$, i%-1%) &
	    \ j% = INSTR(i%+1%, text$ + " ", " ") &
	    \ IF j% THEN &
		prog$ = MID(text$, i%+1%, j%-i%) &
		\ junk$ = SYS(CHR$(8%) + RIGHT(text$, i%+1%)) &

30020	IF j% = 0% THEN &
	  PRINT "?"; mcrname$; '-E-bad entrance, core common = "'; &
		text$; '"' & 
	  \ GOTO 32767 &

30030	IF LEN(prog$) = 0% THEN &
	  PRINT "?"; mcrname$; "-E-no program given" &
	  \ GOTO 32767 &

30050	! PRINT "Chaining to '"; prog$; "' with '"; right(text$, i%+1%); &
	!	"' in common, "; i%; "i, "; j%; "j" &

30100	ON ERROR GOTO 30900 &
	\ JUNK$ = SYS(CHR$(6%) + CHR$(-21%))	! Drop privileges &
	\ CHAIN header$+prog$ 30000%		! Signal "chain" entry &

30900	error.code% = ERR &
	\ IF LEN(header$) = 0% THEN		! If it's the first time, &
		RESUME 30990 UNLESS ERR = 5%	! Only allow "not found" &
		\ RESUME 30920			! Try the search list &

30910	RESUME 30920				! Allow all errors &

30920	READ header$ &
	\ GOTO 30100 IF LEN(header$) &
	\ error.code% = 5%			! Really couldn't find it &

30990	PRINT "?"; mcrname$; "-E-Error chaining to '"; PROG$; "' -- "; &
		CVT$$(RIGHT(SYS(CHR$(6%)+CHR$(9%)+CHR$(error.code%)),3%),4%) &

32767	END &

