	.TITLE	DEFINE
	.IDENT	"V1.8"
;
;   Author:	D. Mischler	22-MAY-87
;
;   This module implements the DEFINE and UNDEFINE
;   commands which allow the definition and deletion
;   of symbols.
;

	.PSECT	CODE,I,RO
	.ENABL	LSB
;
;   Define a symbol.
;   Parse command line for symbol name and value.
;
DEFINE::
	CALL	U$FNXT		; Point to symbol name, OK?
	BCS	10$		; No, complain.
	CALL	U$SYMN		; Put symbol name in R2,R3, OK?
	BCS	100$		; No, complain.
	CMPB	#'=,(R0)+	; Is equals sign in place?
	BNE	20$		; No, complain about it's absence.
	MOV	R0,R5		; Save expression string address.
	MOV	R3,-(SP)	; Save symbol name.
	MOV	R2,-(SP)
	CALL	XPRESS		; Evaluate value expression.
	MOV	(SP)+,R2	; Recover symbol name.
	MOV	(SP)+,R3
	BCS	100$		; If evaluation error then complain.
	MOV	#SYMTBL,R0	; Point to symbol table head.
	CALL	S$DEFN		; Define symbol, OK?
	BCS	30$		; No, complain.
	RETURN
;   No symbol name present.
10$:	MOV	#E.SNRQ,R1	; Point to error message.
	BR	100$		; Dump complaint on the user.
;   Missing equals sign.
20$:	MOV	#E.EQMS,R1	; Point to error message.
	BR	100$		; Dump complaint on the user.
;   Allocation failure.
30$:	MOV	#E.MFUL,R1	; Point to error message.
100$:	CALL	ERROR		; Complain.
	RETURN
	.PAGE
;
;   Delete a symbol.
;
UNDEF::
	CALL	U$FNXT		; Point to symbol name, OK?
	BCS	10$		; No, complain.
40$:	MOV	R0,R5		; Save symbol name pointer.
	CALL	U$SYMN		; Put symbol name in R2,R3, OK?
	BCS	100$		; No, complain.
	MOV	#SYMTBL,R4	; Point to root of symbol table.
50$:	MOV	(R4),R1		; Point to next symbol entry, zero?
	BEQ	80$		; Yes, symbol is not defined.
	CMP	S.NAME(R1),R2	; Is first name word OK?
	BNE	60$		; No, try next entry.
	CMP	S.NAME+2(R1),R3	; Is second name word OK?
	BEQ	70$		; Yes, unlink the symbol.
60$:	MOV	R1,R4		; Save backwards link.
	BR	50$		; Try next symbol in table.
;   Delete the symbol.
70$:	MOV	(R1),(R4)	; Unlink target symbol.
	MOV	R1,R2		; Copy symbol block address.
	MOV	R0,-(SP)	; Save command line pointer.
	MOV	#FREMEM,R0	; Point to free memory list header.
	MOV	#S.LEN,R1	; Get symbol block length.
	CALL	$RLCB		; Release memory back to pool.
	MOV	(SP)+,R0	; Recover command line pointer.
	CMPB	#',,(R0)+	; Does a comma follow?
	BEQ	40$		; Yes, try next symbol.
	RETURN
;   Complain because the symbol is not defined.
80$:	MOV	#E.SYNF,R1	; Point to error code.
	MOV	R5,R0		; Get symbol name.
	BR	100$		; Complain.

	.END
