perm filename MAIL[MLI,LSP] blob sn#052959 filedate 1975-06-03 generic text, type T, neo UTF8
COMMENT ⊗   VALID 00002 PAGES 
RECORD PAGE   DESCRIPTION
 00001 00001
 00002 00002	% LAP-defined functions:  (SEND JOB), (WRCV), (SRCV), (SKPME), (SKPHIM JOB), (SLEEP <integer>) %
 00010 ENDMK
⊗;
% LAP-defined functions:  (SEND JOB), (WRCV), (SRCV), (SKPME), (SKPHIM JOB), (SLEEP <integer>) %


EXPR SEND_MAIL (JOB, LETTER);					% SEND_MAIL(<atom>, <string>) %
	% Sends LETTER (an sexpression) to JOB (a symbolic name).
	Returns T if mail sent successfully;  otherwise NIL %
	BEGIN  NEW P, I, LOC;
	IF ¬JOB_EXISTS(JOB) THEN RETURN NIL;			% The job doesn't exist! %
	P ← (IF STRP LETTER THEN LETTER ELSE STR LETTER).PNAME;	% Make sure the mail is a string %
    A;	WHILE MAIL_IS_WAITING(JOB) DO SLEEP(1);			% Wait until the job's mailbox is empty %
	FOR I ON P FOR LOC ← ?!SEND_MAILBOX?! TO ?!SEND_MAILBOX?! + 31 DO	% Fill the mailbox, %
		DEPOSIT(LOC, EXAMINE MAKNUM(CAR I, 'FIXNUM));			% 5 letters at a time %
	IF NULL SEND(JOB) THEN RETURN NIL ELSE			% Mail couldn't be delivered %
	IF NULL I THEN						% Mail completely sent %
		IF LOC THEN RETURN T
		ELSE WHILE MAIL_IS_WAITING(JOB) DO SLEEP(1)	% Make sure a null word is sent %
			ALSO RETURN SEND(JOB)
	ELSE P ← CDR I ALSO GO A;				% More mail to send %
	END;


EXPR GET_MAIL (SEXP);  RECEIVE_MAIL(SEXP, T);			% Uses SRCV %
	% Returns the mail (SEXP=T => s-expression, SEXP=NIL => string) if some is in the mailbox;
	otherwise NIL %


EXPR WAIT_FOR_MAIL (SEXP);  RECEIVE_MAIL(SEXP, NIL);		% Uses WRCV %
	% Returns the mail (SEXP=T => as an s-expression, SEXP=NIL => as a string)
	if some is in the mailbox; otherwise enters a wait state until the mailbox is filled %


EXPR RECEIVE_MAIL (SEXP, FN);
	% Empties the mailbox using function FN (T => SRCV, NIL => WRCV).
	Returns the letter as a string or s-expression, depending on SEXP (T => s-expression, NIL => string).
	The letter must be a series of ascii characters beginning and ending with the double-quote (") %
	BEGIN  NEW DONE, PNAME, PLOC;
	IF ¬FILL_MAILBOX(FN) THEN RETURN NIL;			% Nothing in the mailbox (only with SRCV) %
	PNAME ← ?!MAILBOX?!.PNAME;
    A;	FOR NEW MLOC ← ?!RECEIVE_MAILBOX?! TO ?!RECEIVE_MAILBOX?! + 31 FOR PLOC ON PNAME DO
		IF DEPOSIT(MAKNUM(CAR PLOC,'FIXNUM), EXAMINE MLOC) = 0 THEN DONE ← T
	UNTIL DONE;
	IF DONE THEN RETURN
		BEGIN  NEW L;
		L ← EXPLODE ?!MAILBOX?!;
		RETURN READLIST IF SEXP & CAR L EQ '?" THEN REVERSE CDR REVERSE CDR L ELSE L;
		END;
	FILL_MAILBOX(NIL);					% More mail coming; use WRCV UUO to get it %
	PNAME ← CDR PLOC;
	GO A;
	END;


EXPR MAIL_INIT ();						% Initializes the mail system %
	BEGIN
	?!SEND_MAILBOX?!{0} ← MAKNUM('SEND.SUBR, 'FIXNUM) + 1;		% Mailbox for sending mail %
	?!RECEIVE_MAILBOX?!{0} ← MAKNUM('FILL_MAILBOX.SUBR, 'FIXNUM) + 1;	% Mailbox for receiving mail %
	?!MAILBOX?!{0} ←	"11111222223333344444555556666677777888889999900000%
			%11111222223333344444555556666677777888889999900000%	300 word printname
			%11111222223333344444555556666677777888889999900000%	for getting the mailbox
			%11111222223333344444555556666677777888889999900000%	into LISP.
			%11111222223333344444555556666677777888889999900000%
			%11111222223333344444555556666677777888889999900000%	The maximum number of
			%11111222223333344444555556666677777888889999900000%	characters that may be sent
			%11111222223333344444555556666677777888889999900000%	at one time is 1500.
			%11111222223333344444555556666677777888889999900000%
			%11111222223333344444555556666677777888889999900000%
			%11111222223333344444555556666677777888889999900000%
			%11111222223333344444555556666677777888889999900000%
			%11111222223333344444555556666677777888889999900000%
			%11111222223333344444555556666677777888889999900000%
			%11111222223333344444555556666677777888889999900000%
			%11111222223333344444555556666677777888889999900000%
			%11111222223333344444555556666677777888889999900000%
			%11111222223333344444555556666677777888889999900000%
			%11111222223333344444555556666677777888889999900000%
			%11111222223333344444555556666677777888889999900000%
			%11111222223333344444555556666677777888889999900000%
			%11111222223333344444555556666677777888889999900000%
			%11111222223333344444555556666677777888889999900000%
			%11111222223333344444555556666677777888889999900000%
			%11111222223333344444555556666677777888889999900000%
			%11111222223333344444555556666677777888889999900000%
			%11111222223333344444555556666677777888889999900000%
			%11111222223333344444555556666677777888889999900000%
			%11111222223333344444555556666677777888889999900000%
			%11111222223333344444555556666677777888889999900000";
	END;


_EOF_