* $Id: spitbol.sno,v 1.3 2002/01/14 21:13:21 phil Exp $
*
* Emulate SPITBOL functions
* Phil Budne <phil@ultimate.com>
* September 13, 1997

* SPITBOL lacks QUICKSCAN mode;
	&FULLSCAN = 1

* rename I/O functions
	OPSYN("MB_INPUT", "INPUT")
	OPSYN("MB_OUTPUT", "OUTPUT")
	OPSYN("MB_ENDFILE", "ENDFILE")
	OPSYN("MB_REWIND", "REWIND")
	OPSYN("MB_SET", "SET")

	DEFINE("INPUT(n,u,fn)")
	DEFINE("OUTPUT(n,u,fn)")
	DEFINE("ENDFILE(u)")
	DEFINE("REWIND(u)")
	DEFINE("SET(u,o,w)")
	DEFINE("MB_UNIT(u)i")
* map spitbol unit to snobol unit number
	MAP_UNITS = TABLE()

* host functions
	DEFINE("SYSTEM()")
	DEFINE("PARM()")
	DEFINE("EXECUTE(STR)")
	DEFINE("GETARG(N)")
	DEFINE("FIRSTARG()")
	DEFINE("SHELLVAR(STR)")
							:(EDEFNS)

* map SPITBOL unit (can be any type?) to a unique integer;
MB_UNIT	MB_UNIT = DIFFER(MAP_UNITS<u>) MAP_UNITS<u>	:S(RETURN)
* don't map integers from 1 .. 20 (never returned by IO_FINDUNIT)
	i = CONVERT(u,"INTEGER")			:F(MB_UNI1)
	LT(i,1)						:S(MB_UNI1)
	GT(i,20)					:S(MB_UNI1)
	MB_UNIT = i					:(RETURN)
MB_UNI1	MB_UNIT = MAP_UNITS<u> = IO_FINDUNIT()		:F(FRETURN)S(RETURN)

* XXX error if unit in use!
* XXX process filename for []'ed I/O options? !-style piping?
INPUT	MB_INPUT(n,MB_UNIT(u),,fn)			:S(RETURN)F(FRETURN)
OUTPUT	MB_OUTPUT(n,MB_UNIT(u),,fn)			:S(RETURN)F(FRETURN)

SET	SET = MB_SET(MB_UNIT(u),o,w)			:S(RETURN)F(FRETURN)
REWIND	MB_REWIND(MB_UNIT(u))				:S(RETURN)F(FRETURN)

* XXX clear out array/table entries??
ENDFILE	MB_ENDFILE(MB_UNIT(u))				:S(RETURN)F(FRETURN)

****************
* host functions

SYSTEM	SYSTEM = HOST()					:S(RETURN)F(FRETURN)
PARM	PARM = HOST(0)					:S(RETURN)F(FRETURN)
EXECUTE	EXECUTE = HOST(1,STR)				:S(RETURN)F(FRETURN)
GETARG	GETARG = HOST(2,N)				:S(RETURN)F(FRETURN)
FIRSTARG FIRSTARG = HOST(3)				:S(RETURN)F(FRETURN)
SHELLVAR SHELLVAR = HOST(4,STR)				:S(RETURN)F(FRETURN)

EDEFNS

*	DEFINE("SETEXIT()")
*SETEXIT						:(RETURN)
