perm filename SNDMSG.MAC[1,LMM]1 blob sn#087017 filedate 1974-02-07 generic text, type T, neo UTF8
;<SUSSMAN>SNDMSG.MAC;12    31-JAN-74 12:56:50	EDIT BY SUSSMAN
; TTYTRB - TROUBLE REPORTS TO PAIGE
; CHANGE MESSAGE HEADING FORM - SEE RFC 561
;<SUSSMAN>SNDMSG.MAC;11    25-JAN-74 10:12:52	EDIT BY SUSSMAN
; IMPROVE USER LIST ERROR MESSAGES
; HANDLE RUBOUT SAME IN HOST AS IN USER
; REDESIGN HANDLING OF "@<HOST>" - WAS BUGGY
;<SUSSMAN>SNDMSG.MAC;10    22-JAN-74 18:58:15	EDIT BY SUSSMAN
; TTYTRB REPORTS TO STROLLO, NOT TROUTMAN.
; GTJFN FOR MESSAGE.TXT REQUIRES OLD FILE.
; SEVERAL CHANGES IN USER LIST INPUT -
;  1)EOL FROM INSERTED FILE WON'T TERMINATE USER LIST, ONLY EOL FROM TTY
;  2)LEADING AND TRAILING BLANKS IGNORED IN ALL FIELDS (USER NAME,
;    HOST NAME, GROUP NAME)
;  3)AFTER SUCCESSFUL $, CONTINUES NORMAL INPUT - I.E. EDITING
;    CHARS WORK, ETC.
;  4)BETTER ALGORITHM FOR LINE CONTINUE WHEN EOL FOLLOWS ",".
;<SUSSMAN>SNDMSG.MAC;9    15-JAN-74 17:03:17	EDIT BY SUSSMAN
; FIXED GROUP NAMES IN USER LIST AND CC TO WORK AS BEFORE.
;<SUSSMAN>SNDMSG.MAC;8    14-JAN-74 16:13:51	EDIT BY SUSSMAN
; ↑B REQUIRES CONFIRMATION IF AT TOP LEVEL.
; FIX PATHOLOGICAL-CASE BUGS
;<SUSSMAN>SNDMSG.MAC;7    11-JAN-74 17:59:12	EDIT BY SUSSMAN
; Some improved messages
;<SUSSMAN>SNDMSG.MAC;6     9-JAN-74 13:20:28	EDIT BY SUSSMAN
; CHANGE ADDMSG TO ALLOW TEXT PASSED VIA JFN (FOR INSTAL)
;<SUSSMAN>SNDMSG.MAC;5     9-JAN-74 10:40:49	EDIT BY SUSSMAN
; ADD ↑O MESSAGE, FIX UNMATCHED PUSH-POP AT BADUS1
;<SUSSMAN>SNDMSG.MAC;4     4-JAN-74 16:35:03	EDIT BY SUSSMAN
; NEW ENTRY POINT TIPGRP - GRIPE FOR TIP USERS
;<SUSSMAN>SNDMSG.MAC;3     3-JAN-74 17:48:20	EDIT BY SUSSMAN
; CHANGE ADDMSG TO ALLOW SUBJECT PASSED IN AC'S
;  (FOR USE BY INSTAL)
;<SUSSMAN>SNDMSG.MAC;2     3-JAN-74 16:37:19	EDIT BY SUSSMAN
; OUTPUT SUPPRESSION VIA ↑O INTERRUPT FOR LOGGED-IN USERS
;<SOURCES>SNDMSG.MAC;32    21-NOV-73 11:06:38	EDIT BY JOHNSON
; INCORPERATED CHANGES MADE BY DENNIS TING AT UTAH-10.  ALL ARE UTAH
; SPECIFIC CHANGES CONTROLLED BY ASSBEMBLY SWITCH "UTAHSW".
;<SOURCES>SNDMSG.MAC;31     9-NOV-73 16:48:09	EDIT BY JOHNSON
; PUT IN CODE TO INITIALLY SET UP ENTRY VECTOR AND SSAVE AS
; <SUBSYS>SNDMSG.SAV
; FIX ↑X MESSAGE.  MAKE TPSMSG USE SNDMSG CODE.  MAKE @ BE ALWAYS
; VALID WITH SPATCR AN OPTIONAL EXTRA @ CHAR.
;<SOURCES>SNDMSG.MAC;30     9-NOV-73 11:44:38	EDIT BY PLUMMER
; Change help msg to say copy is on MESSAGE.COPY, not  .TXT
;<SOURCES>SNDMSG.MAC;27    29-AUG-73 11:40:36	EDIT BY CLEMENTS
;<SOURCES>SNDMSG.MAC;26    23-AUG-73 16:03:49	EDIT BY CLEMENTS
; EOF CHECK IN WAITOK
;<SOURCES>SNDMSG.MAC;24    11-JUN-73 09:53:39	EDIT BY TOMLINSON
; Queue local messages if necessary
;<SOURCES>SNDMSG.MAC;23    31-MAY-73 09:10:35	EDIT BY TOMLINSON
; Fixed AC2 clobbered in QUEUE+several before PMAP to unmap FLAG page
;<JOHNSON>SNDMSG.MAC;24    16-MAY-73 14:52:43	EDIT BY JOHNSON
;<JOHNSON>SNDMSG.MAC;23    16-MAY-73 14:23:53	EDIT BY JOHNSON
;<JOHNSON>SNDMSG.MAC;22    16-MAY-73 14:11:54	EDIT BY JOHNSON
; CHANGE ADDMSG TO NOT RELEASE JFN AND TO SIGNAL SUCCESS.
; OUTPUT TIME ZONE WITH TIME IN HEADING.
;<TOMLINSON>SNDMSG.MAC;100013     8-MAY-73 19:42:48	EDIT BY TOMLINSON
; Change MESSAGE.COPY back to ;T
;<TOMLINSON>SNDMSG.MAC;21     7-MAY-73 12:01:06	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;20     7-MAY-73 10:40:18	EDIT BY TOMLINSON
; FIXED ALTMODE FAILURE AND CHANGED MESSAGE.COPY TO NOT TMP
;<TOMLINSON>SNDMSG.MAC;7     3-MAY-73 17:38:21	EDIT BY TOMLINSON
; Added multics hand-holding logic
;<TOMLINSON>SNDMSG.MAC;1     2-MAY-73 17:22:51	EDIT BY TOMLINSON
; Added MAILER.FLAGS setting
;<SOURCES>SNDMSG.MAC;19    21-MAR-73 10:41:32	EDIT BY JOHNSON
;<JOHNSON>SNDMSG.MAC;4    19-MAR-73 23:09:45	EDIT BY JOHNSON
;<JOHNSON>SNDMSG.MAC;3    19-MAR-73 22:37:49	EDIT BY JOHNSON
;<JOHNSON>SNDMSG.MAC;2    19-MAR-73 22:31:32	EDIT BY JOHNSON
; ADD CODE FOR ADDMSG (TO ADD A MESSAGE TO A GIVEN FILE).
;<SOURCES>SNDMSG.MAC;18    14-MAR-73 17:24:43	EDIT BY TOMLINSON
; FIXED UP LINE BUFFERING FOR USER LIST
;<SOURCES>SNDMSG.MAC;13    14-MAR-73 11:26:37	EDIT BY TOMLINSON
; MOVED HOST RECOGNITION TO INPUT TIME
;<SOURCES>SNDMSG.MAC;12    13-MAR-73 09:03:31	EDIT BY TOMLINSON
; FIXED LEFT OVER QUEUE INTERRUPT PROBLEM AND 0 USERS PROBLEM
;<SOURCES>SNDMSG.MAC;11     7-MAR-73 14:11:41	EDIT BY CLEMENTS
;<CLEMENTS>SNDMSG.MAC;1     7-MAR-73 12:36:29	EDIT BY CLEMENTS
;<SOURCES>SNDMSG.MAC;10     5-MAR-73 10:58:41	EDIT BY TOMLINSON
; MADE MESSAGE.COPY HAVE 770000 PROTECTION
;<SOURCES>SNDMSG.MAC;9    16-FEB-73 13:37:55	EDIT BY JOHNSON
; ADDED ENTRY AND CODE FOR TPSMSG (SNDMSG FOR NON-LOGGED USERS).
; FIXED BUG IN RECOVERY FROM BAD USER NAME.
;<SOURCES>SNDMSG.MAC;8    14-FEB-73 20:11:40	EDIT BY TOMLINSON
; FIXED MESSAGE.COPY FAILURE
;<SOURCES>SNDMSG.MAC;7    13-FEB-73 16:05:15	EDIT BY TOMLINSON
; BACKSPACE OVER LF ALSO DELETES THE CR
;<SOURCES>SNDMSG.MAC;6    13-FEB-73 15:51:43	EDIT BY TOMLINSON
; ADDED ,<CR> FOR LINE CONTINUATION OF USER NAME LIST
;<SOURCES>SNDMSG.MAC;5    14-DEC-72 13:38:31	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;5    14-DEC-72 13:32:11	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;4    14-DEC-72 13:15:17	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;3    14-DEC-72 13:03:17	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;2    14-DEC-72 12:52:46	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;1    14-DEC-72 12:15:12	EDIT BY TOMLINSON
; ADDED TTYTRB ENTRY AND CODE
;<SOURCES>SNDMSG.MAC;4     8-DEC-72 11:51:48	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;2     8-DEC-72 11:37:21	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;1     8-DEC-72 11:09:11	EDIT BY TOMLINSON
; ERRORS DURING FILE INPUT -- FLUSH FILE, RUBOUT NOT CANCEL INPUT
;<SOURCES>SNDMSG.MAC;3     6-DEC-72 15:17:22	EDIT BY CHIPMAN
;<TOMLINSON>SNDMSG.MAC;39     6-DEC-72 15:14:18	EDIT BY CHIPMAN
;<TOMLINSON>SNDMSG.MAC;38    13-NOV-72 22:39:13	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;37    13-NOV-72 22:24:06	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;36    13-NOV-72 21:51:19	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;35    13-NOV-72 21:49:07	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;34    13-NOV-72 20:25:30	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;33    13-NOV-72 20:16:53	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;32    13-NOV-72 20:16:05	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;31    13-NOV-72 19:12:13	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;30    13-NOV-72 18:47:19	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;29    12-NOV-72 16:36:29	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;28    12-NOV-72 16:28:53	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;24    12-NOV-72 12:28:45	EDIT BY TOMLINSON

;<TOMLINSON>SNDMSG.MAC;23	11-OCT-72  8:54:39 EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;22    11-OCT-72  8:47:20	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;21     9-OCT-72 13:01:40	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;20     8-OCT-72 12:25:41	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;19     8-OCT-72 12:13:30	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;18     8-OCT-72 12:04:48	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;17     6-OCT-72 10:16:12	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;16     6-OCT-72  9:38:19	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;15     6-OCT-72  9:33:23	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;14     6-OCT-72  9:30:14	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;13     6-OCT-72  9:21:12	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;12     6-OCT-72  9:18:32	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;11     6-OCT-72  8:57:57	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;10     6-OCT-72  8:42:36	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;9     4-OCT-72 20:03:21	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;8     4-OCT-72 20:00:15	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;7     4-OCT-72 18:14:48	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;6     4-OCT-72 17:18:39	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;5     4-OCT-72 17:12:17	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;4     4-OCT-72 17:05:21	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;3     4-OCT-72 15:52:07	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;2     4-OCT-72 15:22:19	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;1     4-OCT-72 14:59:30	EDIT BY TOMLINSON
;<SOURCES>SNDMSG.MAC;2     4-OCT-72 14:09:03	EDIT BY TOMLINSON
; BUG FIXES TO INSERT FILE LOGIC
;<TOMLINSON>SNDMSG.MAC;1     4-OCT-72 14:03:44	EDIT BY TOMLINSON
;<SOURCES>SNDMSG.MAC;1     4-OCT-72 13:55:29	EDIT BY TOMLINSON
; SEND OVER NETWORK VIA FTP MAIL
;<TOMLINSON>SNDMSG.MAC;23     4-OCT-72 12:17:17	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;22     4-OCT-72 12:00:35	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;21     4-OCT-72 10:54:32	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;19     4-OCT-72 10:35:39	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;18     4-OCT-72 10:27:28	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;17     4-OCT-72 10:23:27	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;16     4-OCT-72 10:01:41	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;15     4-OCT-72  9:59:23	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;14     4-OCT-72  9:40:51	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;13     4-OCT-72  0:11:05	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;12     3-OCT-72 23:56:29	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;11     3-OCT-72 23:55:46	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;10     3-OCT-72 23:29:49	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;9     3-OCT-72 23:11:08	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;7     3-OCT-72 22:51:07	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;5     3-OCT-72 22:32:55	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;4     3-OCT-72 22:29:39	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;3     3-OCT-72 22:26:00	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.MAC;2     3-OCT-72 22:20:42	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.FAI;5     3-OCT-72 22:20:09	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.FAI;4     3-OCT-72 17:43:30	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.FAI;3     3-OCT-72 17:37:45	EDIT BY TOMLINSON
;<SOURCES>SNDMSG.FAI;5    26-SEP-72  9:07:32	EDIT BY TOMLINSON
; SAY "THANK YOU"
;<SOURCES>SNDMSG.FAI;4    25-JUL-72  8:42:42	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.FAI;2    25-JUL-72  8:32:07	EDIT BY TOMLINSON
;<TOMLINSON>SNDMSG.FAI;1    25-JUL-72  8:31:01	EDIT BY TOMLINSON

	TITLE	SNDMSG
	SUBTTL	R.S.Tomlinson
	SEARCH	STENEX

OPDEF	ESOUT[JSYS 313]

; Accumulators

F=0
A=1
B=2
C=3
D=4
X=5
PTR=6
EPTR=7
Y=10
BPTR=11
FLG=12
SF=15
R=16
P=17

; Flags in F

QUIETF==400000
COMMAF==200000
BUFFUL==100000
STHSTF==1000
BLANKF==400
NCFRMF==200		; NEED TO CONFIRM GENERAL DELIVERY
FRSTCH==100		; FIRST CHARACTER SEEN BY INSTR
AMBIGF==40		;IN HOST NAME RECOGNIZER
MATCHF==20		; ..
NUMF==10
RAISEF==4
FULLF==2
USEATF==1

; FLAGS IN FLG

NTLOGF==400000
RVRSF==200000
SUBJF==100000
TEXTF== 40000

; Parameters

NFILS==10		; Number of input files open at once
NUSRS==500		; NUMBER OF USERS
NDIST==↑D20		; MAXIMUM NUMBER OF DISTRIBUTION LISTS
NHSTTB==1000		;SPACE FOR HOST NAME TABLES
PDLL==100		;LENGTH OF STACK
MAXMSG==↑D250000	; MAXIMUM MESSAGE SIZE

;MACRO TO SKIP IF CHAR IN AC ARG IS NEITHER "@" NOR, IF NOTLGF IS SET,
; THE CHAR IN SPATCR.
DEFINE	SKPNAT	(ARG)
<	TRNE	FLG,NTLOGF		;;IS NTLOGF SET?
	 CAME	ARG,SPATCR		;;YES.  IS IT THE SPECIAL CHAR?
	CAIN	ARG,"@"			;;IS IT "@"
>



ENTVEC:	JRST SNDMSG
	JRST GRIPE
	JRST TTYTRB
	JRST TPSMSG
	JRST ADDMSG
	JRST TIPGRP
EVECL==.-ENTVEC

; MAIN ROUTINE FOR SNDMSG

SNDMSG:	MOVE P,PDP
	MOVE PTR,[POINT 7,STRING-1,34]
	SETZ	FLG,		;CLEAR  FLG
	SETOM	SPATCR		; SET TO NO SPECIAL AT CHAR.

; JRST TO HERE FROM TPSMSG (WITH NTLOGF SET AND SPATCR SET UP).
SNDMS1:	PUSHJ P,INIPSI		; INITIALIZE PSI SYSTEM
	PUSHJ P,INITIM		; INITIALIZE TIMER FORK
	PUSHJ P,INITTY		; INITIALIZE TTY MODES
	PUSHJ P,INILH		; INITIALIZE LOCAL HOST STUFF
	PUSHJ P,GETUSR		; GET LIST OF USERS
	PUSHJ P,GETSBJ		; GET SUBJECT
	PUSHJ P,GETTXT		; GET TEXT OF MESSAGE
	SKIPL X,NUSERS
	 JRST [	PUSHJ P,GETUSR
		JRST .-1]

; SEND TO ALL USERS

SNDLUP:	SETZM REPLY
	PUSHJ P,MAKHED		; GENERATE HEADING
	SKIPE HOST(X)		; LOCAL?
	 JRST SNDNET		; NO
	PUSHJ P,OPNMSG		; OPEN MESSAGE.TXT
	 JRST QUEUE
	PUSHJ P,OUTMRK		; OUTPUT DATE AND TIME STAMP
	PUSHJ P,OUTMSG		; PUT OUT MESSAGE
	CLOSF
	 JFCL
	HRROI B,[ASCIZ / -- ok/]
	JRST ENDSND

; Send message via network FTP MAIL facility

SNDNET:	TRZ F,NCFRMF
	MOVE A,TIMFRK
	FFORK
	MOVEM P,SAVEP
	MOVEI B,TIMER
	SFORK
	RFORK
	PUSHJ P,DOICP
	 JRST CANT
	 JRST QUEUE
	PUSHJ P,WAITOK
	 JRST QUEUE
REMAIL:	MOVE A,SJFN
	HRROI B,[ASCIZ /MAIL /]
	SETZ C,
	SOUT
	MOVE B,USRTAB(X)
	SOUT
	HRROI B,[ASCIZ /
/]
	SOUT
	MOVEI B,21
	MTOPR
WATMR1:	PUSHJ P,WAITOK
	 JRST WATMRF
	CAMN C,GENDLV
	 JRST [	HRROI A,REPLY
		PSOUT
		TRO F,NCFRMF
		JRST WATMR1]
	CAME C,GOMAIL
	 JRST WATMR1
	TRNE F,NCFRMF
	 JRST [	MOVE A,TIMFRK
		FFORK
		SETZM REPLY
		HRROI A,[ASCIZ /Is general delivery ok for user /]
		PSOUT
		MOVEI A,101
		PUSHJ P,OUTUSR
		HRROI A,[ASCIZ /? /]
		PSOUT
		MOVEI A,100
		RFMOD
		TRO B,77B23
		SFMOD
		PBIN
		CAIE A,"Y"
		CAIN A,"y"
		 JRST WATMRG
		CAIE A,"N"
		CAIN A,"n"
		 JRST DONT
		JRST .]
WATMRG:	MOVE A,TIMFRK
	FFORK
	SETOM MONITV
	MOVEI B,MONITR
	SFORK
	RFORK
	PUSHJ P,OUTMSG
	HRROI B,[ASCIZ /.
/]
	SETZ C,
	SOUT
	MOVEI B,21
	MTOPR

WATMR2:	AOSE MONITV
	 JRST CANT		; MESSAGE REJECTED
	MOVE A,TIMFRK
	WFORK
	FFORK
	SKIPLE MONITV
	 JRST CANT
	MOVE A,SJFN
	CLOSF
	 JFCL
	MOVE A,RJFN
	 CLOSF
	 JFCL
	HRROI B,[ASCIZ / -- ok/]
	SETZM REPLY
	JRST ENDSND

WATMRF:	CAMN C,NEDLOG
	 JRST MITMUL
	HRLZ D,MNQCOD
	JUMPGE D,CANT
WATMRL:	CAMN C,QCODES(D)
	 JRST QUEUE
	AOBJN D,WATMRL
	JRST CANT

MITMUL:	HRROI B,[ASCIZ /USER NETML
/]
	PUSHJ P,SWTOK		; TRY TO LOGIN
	 JFCL
	CAME C,NEDPAS		; SPECIAL REQUEST FOR PASSWORD
	 JRST CANT		; WELL... WE TRIED
	HRROI B,[ASCIZ /PASS NETML
/]
	PUSHJ P,SWTOK
	 JFCL
	CAME C,LOGOK
	 JRST CANT
	JRST REMAIL

; TRY TO QUEUE THE MESSAGE

QUEUE:	MOVE A,TIMFRK
	FFORK
	PUSHJ P,OPNQUE
	 JRST CANT
	PUSHJ P,OUTMSG
	MOVE A,SJFN
	CLOSF
	 JFCL
	PUSHJ	P,MLFLG
	JRST	QUEUE1
	HRROI B,[ASCIZ / -- queued/]
	JRST ENDSND

QUEUE1:	HRROI B,[ASCIZ / -- queued (unable to set flag for immediate processing)/]
	JRST ENDSND

;SET MAILER FLAG
MLFLG:	HRROI B,[ASCIZ /<SYSTEM>MAILER.FLAGS;1/]
	MOVSI A,(1B2)
	GTJFN
	POPJ	P,
	PUSH P,A
	MOVEI B,1B19+1B20+1B25
	OPENF
	 JRST [	POP P,A
		RLJFN
		 JFCL
		POPJ	P,]
	HRLZS A
	MOVE B,[400000,,FLAGPG]
	MOVSI C,140000
	PMAP
	GJINF
	MOVE C,B
	IDIVI C,44
	MOVSI A,400000
	MOVN D,C+1
	ROT A,(D)
	IORM A,FLAGPG*1000(C)
	SETO A,
	MOVE B,[400000,,FLAGPG]
	PMAP
	POP P,A
	CLOSF
	 JFCL
	AOS	0(P)
	POPJ	P,

; DONT SEND

DONT:	HRROI B,[ASCIZ / -- didn't/]
	JRST ENDSND

; CAN'T SEND MESSAGE

CANT:	MOVE A,TIMFRK
	FFORK
	HRROI B,[ASCIZ / -- can't/]
ENDSND:	PUSH P,B
	MOVEI A,101
	MOVEI 2,37
	BOUT
	PUSHJ P,OUTUSR
	POP P,B
	SETZ C,
	SOUT
	HRROI B,[ASCIZ / --/]
	SETZ C,
	SKIPE REPLY
	SOUT
	HRROI B,REPLY
	SOUT
	SETO A,
	CLOSF
	 SETO A,
	RLJFN
	 JFCL
	AOBJN X,SNDLUP

;KEEPS A COPY OF ALL MESSAGES SENT TO MESSAGE.SAVE IF IT EXISTS
	PUSHJ P,OPNSVD	;OPEN MESSAGE.SAVE
	 JRST ENDS.1	;MESSAGE.SAVE DOES NOT EXIST
	PUSHJ P,MAKHED	;MAKE MESSAGE HEADING ("TO" INSTEAD OF "CC")
	PUSHJ P,OUTMRK	;OUTPUT DATE AND SIZE STAMP
	PUSHJ P,OUTMSG	;OUTPUT THE MESSAGE
	CLOSF		;CLOSE MESSAGE.SAVE
	 JFCL
ENDS.1:

	HALTF
	JRST SNDMSG

; MAIN GRIPE CODE

GRIPE:	MOVE P,PDP
	MOVE PTR,[POINT 7,STRING-1,34]
	RESET
	SETZ	FLG,		;CLEAR  FLG
	SETOM	SPATCR		; SET TO NO SPECIAL AT CHAR.
	PUSHJ	P,INIPSI
	PUSHJ P,INITTY
GRIPE1:	HRROI A,[ASCIZ /
Griping on subject of /]
	PSOUT
	MOVEI A,[XWD 501000,1
		XWD 100,101
		0

		POINT 7,[ASCIZ /SYSTEM/]
		POINT 7,[ASCIZ /GENERAL/]
		POINT 7,[ASCIZ /GRIPES/]
		0
		0
		0
		0]
	SETZ B,
	GTJFN
	 JRST [	HRROI A,[ASCIZ /
No gripe file for that subject, use subsys name or "general"
/]
		PSOUT
		JRST GRIPE1]
	MOVEM A,SJFN
	PUSHJ P,GETTXT
	TRZ	F,USEATF	;MAKIHD-DONT INCLUDE SITE IN "FROM"
	PUSHJ P,MAKIHD
	PUSHJ P,MAKEHD
	MOVE A,SJFN
	MOVE B,[7B5+1B22]
	OPENF
	 JRST [	HRROI A,[ASCIZ /
Can't open that file.  Message saved on MESSAGE.COPY/]
		PSOUT
		HALTF
		JRST GRIPE]
	PUSHJ P,OUTMRK
	PUSHJ P,OUTMSG
	MOVE A,SJFN
	CLOSF
	 JFCL
	HRROI A,[ASCIZ /
Thank you for your constructive criticism./]
	PSOUT
	HALTF
	JRST GRIPE

; MAIN CODE FOR GRIPE FOR NON-LOGGED USERS (I.E.TIP USERS)
; SITE NUMBER IN AC1
; USER NAME IN AC10-14 (UP TO 24 CHARS)

TIPGRP:	MOVE	P,PDP
	MOVE	PTR,[POINT 7,STRING-1,34]
	PUSHJ	P,TIPUSE
	SETZM	SPATCR
	RESET
	PUSHJ	P,INITTY
	SETZM	HOSTN	;SET TO NO HOST TABLES
	SETZM	HSTNAM	;FOR USE BY MAKIHD IN "FROM.."
	HRROI	A,QMSG6
	PSOUT
	MOVE	A,[600001,,0]	;OUTPUT USE, NEW FILE
	HRROI	B,[ASCIZ/[--UNSENT-MAIL--].NCC⊗@BBN;P770000/]
	GTJFN
	JRST	[HRROI	A,[ASCIZ/
CAN'T GET GRIPE FILE.
PLEASE TRY AGAIN LATER.
/]
		 PSOUT
		 HALTF
		 JRST TIPGRP]
	MOVEM	A,SJFN
	MOVE	B,[70000,,20000]
	OPENF
	JRST	[HRROI	A,[ASCIZ/
CAN'T OPEN GRIPE FILE.
PLEASE TRY AGAIN LATER.
/]
		 PSOUT
		 MOVE	A,SJFN
		 RLJFN
		 JFCL
		 HALTF
		 JRST TIPGRP]
	PUSHJ	P,GETSBJ
	PUSHJ	P,GETTXT
	TRO	F,USEATF	;SET FLAG SO MAKIHD WILL
	PUSHJ	P,MAKIHD	;INCLUDE SITE IN "FROM.."
	PUSHJ	P,MAKHSB
	PUSHJ	P,MAKEHD
	PUSHJ	P,OUTMSG
	MOVE	A,SJFN
	CLOSF
	JFCL
	PUSHJ	P,MLFLG	;SET MAILER FLAGS
	JFCL		;IGNORE FAILURE TO SET FLAGS
	HRROI	A,[ASCIZ /
Thank you for your constructive criticism.
/]
	PSOUT
	HALTF
	JRST TIPGRP

; DO TTY TROUBLE REPORT

TTYTRB:	MOVE P,PDP
	MOVE PTR,[POINT 7,STRING-1,34]
	RESET
	SETZ	FLG,		;CLEAR  FLG
	SETOM	SPATCR		; SET TO NO SPECIAL AT CHAR.
	PUSHJ	P,INIPSI
	PUSHJ P,INITTY
	MOVEI X,[POINT 7,TTYMAN]-USRTAB
	PUSHJ P,OPNMSG
	 JRST [	HRROI A,[ASCIZ /
TROUBLE FILE NOT AVAILABLE/]
		ESOUT
		HALTF
		JRST TTYTRB]


		HRROI A,[ASCIZ /
LOCATION OF TERMINAL: /]

	PSOUT
	PUSHJ P,GETSB0
	HRROI A,[ASCIZ /
DESCRIBE TROUBLE: /]
	PSOUT
	PUSHJ P,GETTX0
	TRZ	F,USEATF	;MAKIHD-DONT INCLUDE SITE IN "FROM"
	PUSHJ P,MAKIHD
	SETZ C,
	HRROI B,[ASCIZ /
LOC'N:/]
	SOUT
	SKIPN B,SUBJCT
	HRROI B,[ASCIZ /NOT STATED/]
	SOUT
	PUSHJ P,MAKEHD
	PUSHJ P,OUTMRK
	PUSHJ P,OUTMSG
	MOVE A,SJFN
	CLOSF
	 JFCL
	HRROI A,[ASCIZ /
THANK YOU FOR REPORTING YOUR DIFFICULTY.
IT WILL BE INVESTIGATED SHORTLY.
/]
	PSOUT
	HALTF
	JRST TTYTRB

; NAME OF TTY REPAIR MAN


TTYMAN:	ASCIZ /PAIGE/


; MAIN CODE FOR SNDMSG FOR NON-LOGGED USERS (IE TIP USERS)
; Site number in AC1
; User name in AC10-AC14 (up to 24 chars)

TPSMSG:	MOVE	P,PDP
	MOVE	PTR,[POINT 7,STRING-1,34]
	PUSHJ	P,TIPUSE
	MOVEI	A,"%"		;USE % AS SPECIAL AT CHAR
	MOVEM	A,SPATCR
	HRROI	A,QMSG5
	PSOUT			; GIVE SPECIAL MESSAGE.
	HRROI	A,QMSG6
	PSOUT
	JRST	SNDMS1		;CONTINUE AS FOR REGULAR ENTRANCE.

TIPUSE:	MOVEM	A,SITEN		;SITE ADDR OF USER IN AC 1
	MOVEM	PTR,FROMNM		;get user name.
	MOVE	A,PTR
	MOVE	B,[POINT 7,10]
	SETZ	C,
	SOUT
	MOVE	PTR,A			;PUT NEW PTR BACK
	IDPB	C,PTR			;AND PUT IN ZERO BYTE.
	PUSHJ	P,GETSIT	; GET SITE NAME
	MOVEI	FLG,NTLOGF		;SET TO "NOT-LOGGED"
	POPJ	P,

;GET SITE NAME

GETSIT:	MOVE	A,PTR
	MOVEM	A,SITE
	MOVE	B,SITEN
	MOVEI	C,10
	CVHST
	 NOUT			;USE NUMBER IF NAME NOT KNOWN
	 JFCL
	MOVEM	A,PTR
	IBP	PTR
	POPJ	P,



; ADD A MESSAGE TO A GIVEN FILE.
; AC1 - OUTPUT JFN (OF MESSAGE FILE).
; AC2 - B(0)=1 => ADD MESSAGE AT FRONT OF FILE.
;     - B(1)=1 => SUBJECT IN AC7-AC16 (UP TO 39 CHARS)
;     - B(2)=1 => TEXT ON FILE - SEE AC3
;AC3 - INPUT JFN OF TEXT IF B(2) IN AC2 SET
; ON SUCCESS HALTS WITH JFN IN AC1 (CLOSED BUT NOT RELEASED).
; ON FAILURE, HALTS WITH AC1 NOT CONTAINING JFN.
ADDMSG:	MOVEM	SAVACS	;SAVE AC0
	MOVE	[XWD 1,SAVACS+1]	;SAVE AC1-AC17
	BLT	SAVACS+17
	MOVE P,PDP
	MOVE PTR,[POINT 7,STRING-1,34]
	MOVEM A,SJFN		;SAVE OUTPUT JFN.
	SETZ FLG,
	TLNE	B,400000		;SKIP IF NORMAL OUTPUT.
	 TRO FLG,RVRSF		;OUTPUT AT FRONT OF FILE.
	TLNE	B,200000	;SUBJECT PASSED?
	JRST	[TRO	FLG,SUBJF	;SET FLAG
		 MOVEM	PTR,SUBJCT	;STORE SUBJECT
		 MOVE	A,PTR		;COPY IT FROM SAVED AC'S
		 MOVE	B,[POINT 7,SAVACS+7]
		 SETZ	C,
		 SOUT
		 CAMN	PTR,A	;INDICATE NULL SUBJECT
		 SETZM	SUBJCT
		 MOVE	PTR,A
		 IDPB	C,PTR
		 JRST	.+1]
	MOVE	B,SAVACS+2	;GET PASSED FLAGS
	TLNE	B,100000	;TEXT PASSED?
	JRST [	TRO FLG,TEXTF	;SET FLAG
		MOVEM	PTR,MSG	;STORE TEXT
		MOVE	A,SAVACS+3 ;JFN
		MOVE	B,[7B5+1B19] ;READ
		OPENF
		 JRST [	SETO	A,	;OPENF SHOULDN'T FAIL
			JRST	ADDHLT ]
		MOVE	B,PTR	;PLACE TO COPY TO
		SETZ	C,
		SIN
		MOVE	PTR,B
		IDPB	C,PTR
		HRLI	A,(1B0)	;DON'T RELEASE JFN
		CLOSF		;CLOSE INPUT FILE
		JFCL
		PUSHJ	P,GTXTE
		JRST	.+1 ]
	SETOM	SPATCR		; SET TO NO SPECIAL AT CHAR.
	TRNE	FLG,SUBJF
	TRNN	FLG,TEXTF
	PUSHJ	P,INIPSI
	PUSHJ P,INITTY		;INITIALIZE TTY PARAMS.
	TRNN	FLG,SUBJF	;SKIP SUBJECT IF GIVEN ALREADY
	PUSHJ P,GETSBJ		;GET SUBJECT.
	TRNN	FLG,TEXTF	;SKIP TEXT IF GIVEN ALREADY
	PUSHJ P,GETTXT		;GET MESSAGE TEXT.
	TRZ	F,USEATF	;MAKIHD-DONT INCLUDE SITE IN "FROM"
	PUSHJ P,MAKIHD		;INITIAL PART OF HEADING.
	PUSHJ P,MAKHSB		;SUBJECT.
	PUSHJ P,MAKEHD		;END OF HEADING.
	MOVE A,SJFN
	MOVE B,[7B5+1B22]
	TRNE FLG,RVRSF
	 MOVE B,[7B5+1B19+1B20+1B26]	;R W AND WAIT IF BUSY.
	OPENF
	 JRST [	HRROI A,[ASCIZ /
CAN'T OPEN THAT FILE.  MESSAGE SAVED ON MESSAGE.COPY./]
		PSOUT
		SETO A,		; MARK FAILURE.
		JRST ADDHLT ]
	TRNN FLG,RVRSF
	 JRST ADDMS1		;APPEND MESSAGE.
	MOVEM PTR,ENDPTR	;ADD MESSAGE AT BEGINNING.
	MOVE A,SJFN
	MOVE B,ENDPTR
	MOVNI C,300000
	SIN			;READ WHAT IS THERE ALREADY.
	MOVEM C,OLDCNT		;SAVE COUNT.
	SETZ B,0
	SFPTR			;BACK TO START.
	 JFCL
ADDMS1:	PUSHJ P,OUTMRK		;OUTPUT TIME STAMP.
	PUSHJ P,OUTMSG		;OUTPUT MESSAGE.
	MOVE A,SJFN
	TRNN FLG,RVRSF
	 JRST ADDMS2		;JUST CLOSE IT.
	MOVE B,ENDPTR		;FIRST WRITE OLD CONTENTS.
	MOVNI C,300000
	SUB C,OLDCNT		;GET NEGATIVE BYTE COUNT.
	SOUT
ADDMS2:	HRLI	A,(1B0)		; DO NOT RELEASE JFN.
	CLOSF
	 JFCL
	MOVE	A,SJFN		; SUCCESS.
ADDHLT:	HALTF
	JRST	.-1


; USER NAME INSTRUCTIONS

QMSG1:	ASCIZ /
Type user names of the form <user name>@<host name>.  Separate names
with comma, end with carriage return.  Typing just @<host name>
causes that host to apply to subsequent users.  Typing @<null string>
refers to the local host.  Each user's message will indicate to whom
else the message was sent unless a named distribution list is
stated by using <distribution name>:.  E.g. TENEX-users:Tomlinson,... .
If one or more distribution list names are specified, they are used
in place of the user names.  Control-B (STX) may be used to substitute
the contents of a file for typed input.
/
; MESSAGE TYPING INSTRUCTIONS

QMSG2:	ASCIZ /
Your message should be typed in and be terminated with control-Z (SUB).
/

QMSG7:	ASCIZ /
A copy of the text of the message will be saved on the file
MESSAGE.COPY;nnn;S if you need to send it again.
/
QMSG3:	ASCIZ /
Use the following control characters to edit:
A (SOH)	character delete
B (STX)	inserts the following file
H (BS)	also character delete
Q (DC1)	line delete
R (DC2)	retype current line or item
S (DC3) retypes entire text or all items
W (ETB) deletes last word
X (CAN)	cancels entire item (start over) - ignored during text input
Z (SUB)	terminates input
/

; Subject instructions

QMSG4:	ASCIZ /
The subject should be a one line summary of the message or a null string
ended with carriage return.
/
QMSG5:	ASCIZ	/
In the following % may be used instead of @ wherever necessary.
/

QMSG6:	ASCIZ /
↑C (Control C) may be used to abort a message.
/

QMSG8:	ASCIZ /
↑O (CONTROL O) WILL SUPPRESS TYPEOUT.
/

; INTERRUPT STUFF

LEVTAB:	RETPC1
	RETPC1
	RETPC1

CHNTAB:	XWD 1,TIMOUT
	XWD	1,SUPOUT
	REPEAT ↑D34,<0>

TIMOUT:	MOVE A,[POINT 7,REPLY]
	HRROI B,[ASCIZ /timed-out/]
	SETZ C,
	SOUT
	MOVE P,[XWD 10000,QUEUE]
	MOVEM P,RETPC1
	MOVE P,SAVEP
	DEBRK

TIMER:	MOVEI A,↑D30000
	DISMS
	MOVEI A,777777
	MOVSI B,(1B0)
	IIC
	HALTF

MONITR:	MOVEI P,PDL2-1
	PUSHJ P,WAITOK
	 JRST MONITF
	 CAIE C,↑D256
	 JRST MONITR
	HALTF

MONITF:	AOSE MONITV
	 HALTF
	PUSHJ P,WAITOK
	JRST .-1
	JRST .-2

;TYPE (OUTPUT TO PRIMARY OUTPUT FILE) THE STRING IN A
TYPOUT:	MOVE	R,[XWD 10000,TYPSKP]
	MOVEM	R,SUPRET
	PSOUT
TYPSKP:	SETZM	SUPRET
	POPJ	P,

;HANDLE ↑O INTERRUPT - SUPPRESS TTY OUTPUT
SUPOUT:	PUSH	P,A	;SAVE A,B
	PUSH	P,B
	MOVEI	A,101	;IF OUTPUT BUFFER EMPTY, DO NOTHING
	SOBE
	SKIPA
	JRST	SUPDON
	MOVEI	A,101	;CLEAR PRIMARY OUTPUT BUFFER
	CFOBF
	MOVEI	A,17	;TYPE ↑O(EOL)
	PBOUT
	MOVEI	A,37
	PBOUT
SUPDON:	SKIPN	SUPRET	;SPECIAL DEBREAK ADDRESS?
	JRST	SUPEND	;NO, JUST DISMISS
	MOVE	R,SUPRET;YES, CLOBBER IT INTO RETURN PC
	MOVEM	R,RETPC1
SUPEND:	POP	P,B	;RESTORE A,B
	POP	P,A
	DEBRK		;DISMISS INTERRUPT

; INITIALIZE PSI SYSTEM

INIPSI:	RESET			; RESET THE WORLD
	MOVEI A,400000		; INITIALIZE INTERRUPT SYSTEM
	MOVE B,[XWD LEVTAB,CHNTAB]
	SIR
	EIR
	MOVSI B,(1B0+1B1)
	AIC			; TURN ON CHANNELS 0&1
	MOVE	A,[XWD 17,1]
	TRNN	FLG,NTLOGF	;IF LOGGED-IN USER,
	ATI			;ASSIGN ↑O TO CHANNEL 1
	SETZM	SUPRET
	HRROI	A,QMSG8		;TYPE ↑O MESSAGE
	TRNN	FLG,NTLOGF	;IF APPROPRIATE
	PSOUT
	POPJ P,

; INITIALIZE TIMER FORK

INITIM:	MOVSI A,(1B0+1B1)
	CFORK			; GET A FORK TO DO TIMING
	 HALTF
	MOVEM A,TIMFRK		; REMEMBER FORK HANDLE
	POPJ P,

; INITIALIZE TTY STUFF

INITTY:	MOVEI A,100		; PRIMARY INPUT
	MOVEM A,INFIL		; IS INITIAL INPUT FILE
	MOVE B,[BYTE (2) 1,0,0,1,1,1,1,2,0,3,3,3,3,3,1,1,1,0]
	MOVE C,[BYTE (2) 0,0,1,1,1,0,0,1,1,0,1,1,1,3]
	SFCOC			; NO ECHO ON CONTROL-A,B,H,Q,R,S,W,X ALT
	TRZ F,QUIETF		; TURN ON RESPONSES
	MOVE SF,[XWD -NFILS,FILSTK-1]	; INIT FILE STACK
	POPJ P,

; INITIALIZE LOCAL HOST THINGS

INILH:	MOVE A,[SIXBIT /LHOSTN/]
	SYSGT			; GET LOCAL HOST NUMBER
	MOVEM A,LHOSTN
	MOVE A,PTR
	MOVEM A,LHOST		; GET STRING FOR LOCAL HOST
	MOVE B,LHOSTN		; NUMBER
	MOVEI C,10
	CVHST			; CONVERT TO STRING
	 NOUT			; IF FAILS, USE NUMERIC HOST
	 JFCL
	MOVEM A,PTR		; REST OF STRINGS GO AFTER THIS
	IBP PTR			; SKIP OVER NULL
	MOVEI A,HSTTAB		;INITIAL FREE SPACE POINTER
	MOVEM A,HSTFRE		; ..
	MOVE A,['HOSTN ']
	MOVEI B,HOSTN
	PUSHJ P,SYSGET		;GET THE NUMBERS OF ALL HOSTS
	MOVE A,['HSTNAM']	;AND THE NAMES IN ASCIZ
	MOVEI B,HSTNAM
	PUSHJ P,SYSGET
	POPJ P,

; GET USER LIST

GETUSR:	HRROI A,[ASCIZ /
Type ? for help
Users: /]
	PSOUT			; PROMPT
	MOVSI A,-NDIST
	MOVEM A,XDIST		; POINTER FOR STORING DISTRIBUTION NAMES
	MOVSI X,-NUSRS		; ALLOW ONLY NUSRS USERS
	SETZM	DEFHST
	TRO F,FULLF		; BREAK ON PUNCT
	TRO	F,BLANKF	;IGNORE LEADING AND TRAILING BLANKS
	MOVEM PTR,BPTR
RULUP:	MOVEM PTR,USRTAB(X)	; SAVE BEGINNING OF STRING
	TRZ	F,STHSTF
	PUSHJ P,INSTR		; GET USER/HOST NAME
GETUS0:	 JRST [	MOVE PTR,BPTR
		JRST GETUSR]
RULUP1:	CAIN A,"?"		; TERMINATOR = ??
	 JRST [	HRROI A,QMSG1	; YES, PRINT INSTRUCTIONS
		PUSHJ	P,TYPOUT
		HRROI A,QMSG3
		PUSHJ	P,TYPOUT
		JRST RULUP]	; AND DO IT AGAIN
	CAIN A,":"		; DISTRIBUTION LIST?
	 JRST [	SKIPL B,XDIST
		 JRST [	HRROI A,[ASCIZ / Too many group names /]
			JRST BADUS1 ]
		MOVE C,USRTAB(X)
		MOVEM C,DIST(B)
		ADD B,[1,,1]
		MOVEM B,XDIST
		IDPB A,EPTR	; KEEP TERMINATOR
		MOVE PTR,EPTR
		JRST RULUP]
	CAIN A,177		; ABORTED?
RUBOUT:	 JRST [	MOVE PTR,USRTAB(X)	; YES, RESTORE PTR
		HRROI A,[ASCIZ /XXX /]	; AND ACKNOWLEDGE ABORTION
		PSOUT
		JRST RULUP]	; AND LOOP
	CAMN EPTR,PTR		; NULL STRING TYPED?
	 JRST [	SKPNAT A		; YES, @ TERMINATOR?
		 JRST [	TRO  F,STHSTF	;YES, READ STRING AS
			JRST RUL6 ]	; PERMANENT HOST
		CAIE A,37	; NO, EOL TERMINATOR
		 JRST [	HRROI A,[ASCIZ / Null user /]
			JRST BADUS1 ]
		IDPB A,EPTR
		MOVEM	EPTR,PTR
		JRST USREOL ]	; YES, DONE COLLECTING USER NAMES
	CAIE A,33
	JRST RUL1
	MOVSI A,400000
	MOVE B,USRTAB(X)	; GET BACK TO BEGINNING OF STRING
	STDIR
	 JRST [	SKIPE DEFHST	; IF WE ARE TALKING ABOUT ANOTHER HOST
		 JRST .+1	; JUST CALL IT AMBIGUOUS
		HRROI A,[ASCIZ / No such local user /]
		JRST BADUS1]	; IF THIS HOST, CALL IT BAD
USRAMB:	JRST [	MOVEI A,7
		PBOUT
		JRST USRMOR ]
	MOVE A,EPTR		; POINTER TO TAIL
	MOVEM B,EPTR		; PASS OVER TAIL
	PSOUT			; PRINT TAIL
USRMOR:	PUSHJ P,INSTRC	;GET MORE INPUT
	 JRST GETUS0
	JRST RULUP1

RUL1:	SKPNAT A		; @ TERMINATOR?
	 JRST	RUL6		;YES.  READ FOREIGN SITE NAME.
	SKIPE DEFHST
	 JRST RUL2		; SKIP CHECK IF OTHER HOST
	MOVE B,USRTAB(X)
	MOVEM A,C		; SAVE CHARACTER.
	SETZ A,
	STDIR
	 JRST [	HRROI A,[ASCIZ / No such local user /]
		JRST BADUS1 ]
	 JRST [	HRROI A,[ASCIZ / Ambiguous local user /]
		JRST BADUS1]
	MOVE A,C		; RESTORE CHARACTER.
RUL2:	SKPNAT A		; USER AT FOREIGN SITE WANTED?
	 JRST RUL6		; YES, READ WHERE
	MOVE B,DEFHST
	MOVEM B,HOST(X)		; REMEMBER DEFAULT
RUL63:	IDPB A,EPTR		; STORE THE TERMINATOR FOR RETYPE
	MOVEM EPTR,PTR		; KEEP THE STRING
	CAIE A,","
	CAIN A,37
	SKIPA
	JRST [	HRROI A,[ASCIZ / Bad terminator /]
		JRST BADUS1 ]
	TRZE	F,STHSTF
	JRST [	MOVE	B,HOST(X)	;STORE HOST AS DEFAULT
		MOVEM	B,DEFHST
		JRST	.+2 ]		;RE-USE SAME SLOT
	AOBJP X,RUL3
	CAIN A,","
	JRST	RULUP	;COMMAS - CONTINUE GETTING USERS
USREOL:	MOVE	A,INFIL	;EOL
	CAIE	A,100	;FROM PRIMARY INPUT?
	JRST	RULUP	;NO, DON'T TERMINATE USER LIST
	MOVE	A,EPTR	;DON'T TERMINATE IF EOL PRECEDED BY COMMA
	BKJFN		;BACK UP
	JFCL
	CAMN	A,BPTR	;IF NO PREVIOUS CHARS, EOL TERMINATES
	JRST	RUL3
	LDB	B,A	;GET PREVIOUS CHAR
	CAIN	B,","
	JRST	RULUP	;COMMA PRECEDED EOL
RUL3:	HLRE A,X
	ADDI A,NUSRS
	MOVNS A
	HRLZM A,NUSERS
	HLRE	A,XDIST
	ADDI	A,NDIST
	MOVNS	A
	HRLZM	A,DISTL
	SETZ C,
	MOVE A,BPTR
DPNULL:	ILDB B,A
	SKPNAT B
	 DPB C,A
	CAIN B,","
	 DPB C,A
	CAIE B,12
	CAIN B,15
	 DPB C,A
	CAIE B,":"
	CAIN B,37
	 DPB C,A
	JUMPN B,DPNULL
	POPJ P,

RUL6:	IDPB A,EPTR		; STORE THE TERMINATOR FOR RETYPE
	MOVEM EPTR,PTR		; KEEP THE STRING
	PUSHJ P,GETHST		; GET HOST NAME
	 JRST GETUS0		; ABORT ALL
	 JRST RUBOUT		; FLUSH WHOLE USER SPEC
	 JRST BADUS1		; FAILURE
	MOVEM B,HOST(X)		; SAVE HOST
	JRST RUL63

GETHST:	PUSH P,PTR		; SAVE START POINT
GETHS0:	PUSHJ P,INSTR		; GET STRING
	 JRST POP1		; GET OUT
	CAIN A,177
	 JRST [	POP P,PTR
		JRST SKPRET]
	CAMN EPTR,PTR
	 JRST [	SETZM 0(P)	; NULL STRING, USE LOCAL
		JRST GETHS1]
	PUSH P,A		; SAVE TERMINATOR
	MOVE A,-1(P)		; WHERE TO WRITE RECOGNIZED STRING
	MOVE B,A		; IS ALSO SOURCE
	SETZ C,
	PUSHJ P,HSTSOU		; PERFORM RECOGNITION
	TRNE F,AMBIGF		; AMBIGUOUS?
	 JRST [	POP P,A		; GET TERMINATOR
		CAIN A,33	; ALTMODE?
		 JRST [	MOVEI A,7
			PBOUT	; DING
			JRST HSTMOR ]
		HRROI A,[ASCIZ / Ambiguous host name /]
		POP P,PTR
		JRST SK2RET]
	TRNN F,MATCHF		; Match found?
	 JRST [	HRROI A,[ASCIZ / No such host /]
		SUB P,[1,,1]
		POP P,PTR
		JRST SK2RET]
	MOVE B,EPTR		; Save where tail starts
	MOVEM A,EPTR		; Update EPTR
	POP P,A			; Get terminator
	CAIE A,33		; ALTMODE?
	 JRST GETHS1
	MOVEI A,101
	SETZ C,
	SOUT
HSTMOR:	PUSHJ	P,INSTRC	;GET MORE INPUT
	JRST	GETHS0+1
	JRST	GETHS0+2
GETHS1:	POP P,B
SK3RET:	AOS 0(P)
SK2RET:	AOS 0(P)
SKPRET:	AOS 0(P)
CPOPJ:	POPJ P,

POP1:	SUB P,[1,,1]
	POPJ P,


BADUSR:	HRROI A,[ASCIZ / /]
BADUS1:	PUSH P,A
	MOVE PTR,USRTAB(X)
	MOVE A,INFIL
	CAIE A,100
	 JRST [	PUSHJ P,ENDFIL
		POP P,A
		HRROI A,[ASCIZ / FILE INPUT TERMINATED/]
		JRST .+2]
	POP P,A
	ESOUT
	SETZ C,
	MOVE A,PTR
	IDPB C,A
	MOVEI A,37
	PBOUT
	MOVE A,BPTR
	PUSHJ	P,TYPOUT
	JRST RULUP

; GET SUBJECT LINE

GETSBJ:	HRROI A,[ASCIZ /
Subject: /]
	PSOUT
GETSB0:	MOVEM PTR,BPTR
	MOVEM PTR,SUBJCT
GETSB1:	TRO F,FULLF
	TRZ	F,BLANKF	;NO SPECIAL TREATMENT OF BLANKS
	PUSHJ P,INSTR
GETSB2:	 JRST [	MOVE PTR,BPTR
		JRST GETSBJ]
	CAIN A,"?"
	 JRST [	HRROI A,QMSG4
		PUSHJ	P,TYPOUT
		JRST GETSB1]
	CAIN A,177
	 JRST [	HRROI A,[ASCIZ /XXX/]
		PSOUT
		JRST GETSB1]
	CAIE A,37
	 JRST [	IDPB A,EPTR
		PUSH P,[GETSB2]
		JRST INSTRC]	; CONTINUE GATHERING STRING
	CAMN PTR,EPTR
	 SETZM SUBJCT		; MARK NULL SUBJECT THIS WAY
	MOVEM EPTR,PTR
	IBP PTR
	POPJ P,

; GET THE TEXT OF A MESSAGE

GETTXT:	HRROI A,[ASCIZ /
Message (? for help):
/]
	PSOUT
GETTX0:	MOVEM PTR,MSG
	MOVEM	PTR,BPTR
	TRZ	F,FULLF
	TRZ	F,BLANKF	;NO SPECIAL TREATMENT OF BLANKS
	PUSHJ P,INSTR
GETTX:	 JRST GETTXT
	CAIN A,177
	 JRST [	PUSH P,[GETTX]
		JRST INSTRC]
	CAIN A,"?"
	 JRST [	HRROI A,QMSG2
		PUSHJ	P,TYPOUT
		HRROI A,QMSG7
		TRNN	FLG,NTLOGF
		PUSHJ P,TYPOUT
		HRROI A,QMSG3
		PUSHJ	P,TYPOUT
		JRST GETTXT]
	MOVEI A,37
	PBOUT
	LDB A,EPTR		; IS THERE A LF
	CAIE A,12		; AT THE END?
	 JRST [	MOVE A,EPTR	; NO
		HRROI B,[ASCIZ /
/]
		SETZ C,
		SOUT		; PUT ONE THERE
		MOVEM A,EPTR
		JRST .+1]
	MOVEM EPTR,PTR
	IBP PTR
	PUSH P,[1]
GMCLP:	MOVSI A,(1B0!1B1!1B5!1B17)
	HRR A,0(P)
	HRROI B,[ASCIZ /MESSAGE.COPY;P770000/]
	GTJFN
	 JRST [	AOS A,0(P)
		CAIG A,100
		 JRST GMCLP
		POP P,A
		JRST NOCOPY]
	MOVEM A,0(P)
	MOVE B,[XWD 70000,100000]
	OPENF
	 JRST [	POP P,A
		RLJFN
		 JFCL
		JRST NOCOPY]
	MOVE B,MSG
	SETZ C,
	SOUT
	POP P,A
	CLOSF
	 JFCL
	JRST	GTXTE
NOCOPY:	HRROI	A,[ASCIZ /
Unable to save message on MESSAGE.COPY -
/]
	PSOUT
	MOVEI	A,101
	HRLOI	B,400000
	SETZ	C,
	ERSTR
	JFCL
	JFCL
GTXTE:	MOVE A,MSG
	PUSHJ P,CNTMSG		; COUNT LENGTH OF MESSAGE
	MOVEM B,MSGLEN		; SAVE
	POPJ P,

; OPEN MESSAGE.TXT FILE

OPNMSG:	MOVE A,[POINT 7,FILNAM]
	MOVEI B,"<"
	IDPB B,A
	MOVE B,USRTAB(X)
	SETZ C,
	SOUT
	HRROI B,[ASCIZ />MESSAGE.TXT;1;A220100/]
	SOUT
	HRROI B,FILNAM
	MOVSI A,501001
	GTJFN
	 POPJ P,
	MOVEM A,SJFN
	MOVE B,[7B5+1B22]
	OPENF
	 JRST [	MOVE A,SJFN
		RLJFN
		 JFCL
		POPJ P,]
	AOS 0(P)
	POPJ P,

;OPEN MESSAGE.SAVE FILE
OPNSVD:	HRROI B,[ASCIZ /MESSAGE.SAVE /]
	MOVSI A,(1B2!1B17)
	GTJFN
	 POPJ P,0
	MOVEM A,SJFN
	MOVE B,[7B5!1B22!1B26]
	OPENF
	 JRST [MOVE A,SJFN	;CAN'T OPEN MESSAGE.SAVE
		RLJFN
		 JFCL
		POPJ P,0]
	AOS 0(P)
	POPJ P,0	;SUCCESSFUL, NORMAL RETURN

; OPEN UNDELIVERABLE FILE
OPNUND:	MOVE	A,PTR
	HRROI	B,[ASCIZ '/UNDELIVERABLE-MAIL/.']
	JRST	OPNQU2

; OPEN QUEUE FILE

OPNQUE:	MOVE A,PTR
	HRROI B,[ASCIZ /[--UNSENT-MAIL--]./]
OPNQU2:	SETZ C,
	SOUT
	MOVE B,USRTAB(X)
	MOVEI D,"V"-100
OPNQUL:	ILDB C,B
	CAIL C,"A"
	CAILE C,"Z"
	 JRST [	CAIL C,"0"
		CAILE C,"9"
		 IDPB D,A
		JRST .+1]
	IDPB C,A
	JUMPN C,OPNQUL
	MOVEI B,"@"
	DPB B,A
	SKIPE B,HOST(X)
	PUSHJ P,HSTSOU		;COMPLETE HOST NAME THEN SOUT
	HRROI B,[ASCIZ /;P770000/]
	SOUT
	MOVE B,PTR
	MOVSI A,400001
	GTJFN
	 POPJ P,
	MOVEM A,SJFN
	MOVE B,[70000,,100000]
	OPENF
	 JRST [	MOVE A,SJFN
		RLJFN
		 JFCL
		POPJ P,]
	AOS 0(P)
	POPJ P,

; OUTPUT USER NAME AT SITE STRING

OUTUSR:	SETZ C,
	MOVE B,USRTAB(X)
	SOUT
	SKIPN HOST(X)
	 POPJ P,
	HRROI B,[ASCIZ / at /]
	SOUT
	MOVE B,HOST(X)
	PUSHJ P,HSTSOU		;COMPLETE HOST NAME THEN SOUT
	POPJ P,

; DO ICP TO FTP

DOICP:	MOVE A,PTR
	HRROI B,[ASCIZ /NET:0./]
	SETZ C,
	SOUT
	MOVE B,HOST(X)
	PUSHJ P,HSTSOU		;COMPLETE HOST NAME THEN SOUT
	MOVN B,FTPSKT
	MOVEI C,8
	NOUT
	 HALT
	HRROI B,[ASCIZ /;T/]
	SETZ C,
	SOUT
	MOVE B,PTR
	MOVSI A,1
	GTJFN
	 POPJ P,		; NO SKIP -- NO SUCH HOST
	AOS 0(P)		; AT LEAST ONE SKIP FROM HERE
	MOVEM A,SJFN
	MOVE B,[XWD 400000,200000]
	OPENF
	 POPJ P,
	BIN
	MOVEM B,FSKT
	CLOSF
	 JFCL
	MOVE A,PTR
	HRROI B,[ASCIZ /NET:2./]
	SETZ C,
	SOUT
	MOVE B,HOST(X)
	SOUT
	MOVN B,FSKT
	MOVEI C,10
	NOUT
	 JFCL
	HRROI B,[ASCIZ /;T/]
	SETZ C,
	SOUT
	MOVE B,PTR
	MOVSI A,1
	GTJFN
	 POPJ P,
	MOVEM A,SJFN
	MOVE B,PTR
	MOVSI A,1
	GTJFN
	 POPJ P,
	MOVEM A,RJFN
	MOVE B,[XWD 103400,200000]
	OPENF
	 POPJ P,
	MOVE A,SJFN
	MOVE B,[XWD 103400,100000]
	OPENF
	 POPJ P,
	AOS 0(P)
	POPJ P,

;HSTSOU - HOST SOUT ROUTINE - COMPLETES HOST NAMES AND DOES SOUT

HSTSOU:	SKIPE HOSTN		;DID THE TABLES READ OK?
	SKIPN HSTNAM		; ..
	JRST SOUTPJ		;NO. JUST SOUT AS IT STANDS
	PUSH P,A		;DESTINATION STRING
	PUSH P,B		;SOURCE STRING TO RECOGNIZE
	PUSH P,C		;COUPLE AC'S FOR TEMPS
	PUSH P,D		; ..
	PUSH P,X		;WILL USE AS COUNTER THRU TABLE
	TRZ F,AMBIGF!MATCHF	;INITIALIZE NOT AMBIGUOUS OR MATCHED
	MOVE X,HOSTN		;POINTER TO HOST NUMBERS AND NAME OFFSET
HSOUL2:	MOVE B,0(X)		;GET A HOST NAME
	ADD B,HSTNAM		;POINT TO TEXT STRING
	HRLI B,440700		;BYTE PTR
	MOVE A,-3(P)		;USER'S NAME
HSOUL1:	ILDB C,A		;CHAR FROM USER
	ILDB D,B		;CHAR FROM TABLE
	CAIG C,172		;USER MAY BE LOWER CASE
	CAIGE C,141
	SKIPA			;NOT
	TRZ C,40		;LOWER. MAKE UPPER.
	CAME C,D		;CHARACTERS MATCH?
	JRST HSOUT1		;NO
	JUMPN C,HSOUL1		;YES. LOOP UNLESS TO END OF STRINGS
HSOUTM:	TRZ F,AMBIGF		; INDICATE SUCCESS FOR INTERESTED CALLER
	TRO F,MATCHF
	MOVE B,0(X)		;EXACT MATCH
	ADD B,HSTNAM		;POINT TO STRING IN TABLE
	HRLI B,440700
	MOVEM B,-3(P)		;PUT IT IN AC B ON STACK
HSOUTR:	POP P,X			;RESTORE ACS
	POP P,D
	POP P,C
	POP P,B
	POP P,A
SOUTPJ:	SOUT
	POPJ P,0

HSOUT1:	JUMPN C,HSOUT2		;IF NOT END OF USER STRING, NO MATCH.
	SKIPL 0(X)		;SERVER BIT ON FOR THIS HOST?
	JRST HSOUT2		;NO. DONT RECOGNIZE IT.
	TROE F,MATCHF		;YES. IT'S A MATCH. FIRST?
	TRO F,AMBIGF		;NO. LOSES. AMBIGUOUS.
	MOVEM X,HSOUTX		;STASH THE INDEX OF THE MATCH
HSOUT2:	AOBJN X,HSOUL2		;MOVE ON TO NEXT HOST NAME
	MOVE B,HSOUTX		;TRIED ALL. POINT TO ANY MATCH
	MOVE B,0(B)
	ADD B,HSTNAM
	HRLI B,440700		;STRING POINTER, MAYBE TO A NAME.
	TRNE F,MATCHF		;A MATCH?
	TRNE F,AMBIGF		;AND NOT AMBIGUOUS?
	SKIPA			;NOT A WIN
	MOVEM B,-3(P)		;WINS. PUT IT ON STACK FOR SOUT
	JRST HSOUTR		;AND RESTORE ACS, SOUT, RETURN.

; SEND A LINE AND WAIT FOR RESPONSE FROM FTP

SWTOK:	MOVE A,SJFN
	SETZ C,
	SOUT
	MOVEI B,21
	MTOPR
	JRST WAITOK

; GET A RESPONSE FROM FTP

WAITOK:	MOVE A,RJFN
	TRZ F,NUMF
	SETZ C,
NINLP:	BIN
	CAIL B,200
	 JRST NINLP
	CAIG B,"9"
	CAIGE B,"0"
	 JRST NINDUN
	TRO F,NUMF
	IMULI C,↑D10
	ADDI C,-60(B)
	JRST NINLP

NINDUN:	SKIPA D,[POINT 7,REPLY]
NINDU1:	BIN
	JUMPE B,[GTSTS
		TLNE B,1000
		POPJ P,
		JRST NINDU1]
	IDPB B,D
	CAIE B,12
	 JRST NINDU1
	TRNN F,NUMF		; ANY NUMBER INPUT?
	 JRST WAITOK		; NO, GET ANOTHER
	SETZ B,
	IDPB B,D
	CAIL C,↑D400
	CAIL C,↑D600
	AOS 0(P)
	POPJ P,

; GENERATE FIRST PART OF HEADING

MAKIHD:	MOVE A,PTR
	MOVEM A,HEAD
	HRROI B,[ASCIZ /Date: /]
	SETZ C,
	SOUT
	MOVSI C,(1B5!1B7!1B10!1B12!1B13); IN FORM "15 MAY 1973 1346-EDT"
	SETO B,
	ODTIM
	HRROI B,[ASCIZ /
From: /]
	SETZ C,
	SOUT
	TRNE	FLG,NTLOGF	; IS USER LOGGED IN?
	 JRST	MAKIH1		;NO, USE FROM NAME.
	PUSH P,A
	GJINF
	MOVE B,A
	POP P,A
	DIRST
	 JFCL
	JRST	MAKIH2
MAKIH1:	MOVE	B,FROMNM	;USE FROM NAME
	SOUT
MAKIH2:	TRNN	F,USEATF	;INCLUDE "AT..."?
	POPJ	P,		;NO, JUST RETURN
	HRROI B,[ASCIZ / at /]; SAY WHAT HOST IT'S FROM
	SETZ C,
	SOUT
	MOVE B,LHOST
	TRNE	FLG,NTLOGF	;IS USER LOGGED IN?
	 MOVE	B,SITE		;NO, USE SITE NAME.
	PUSHJ P,HSTSOU		;COMPLETE HOST NAME THEN SOUT
	POPJ	P,

; PUT SUBJECT LINE INTO HEADING

MAKHSB:	SKIPN SUBJCT
	 POPJ P,
	HRROI B,[ASCIZ /
Subject: /]
	SETZ C,
	SOUT
	MOVE B,SUBJCT
	SOUT
	POPJ P,

; MAKE HEADING FOR SNDMSG

MAKHED:	TRZ	F,USEATF	;ASSUME NOT USING HOST NAME
	TRNN	FLG,NTLOGF	; IF THIS IS A NON-LOGGED USER OR
	SKIPE HOST(X)		; IF THIS IS TO A DIFFERENT HOST
	TRO	F,USEATF	;USE HOST NAME
	PUSHJ P,MAKIHD		; GENERATE INITIAL PART OF HEADING
	PUSHJ	P,MAKHSB
	SKIPGE Y,DISTL		; PRINT DISTRIBUTION LIST IF ANY
	 JRST DOCC
	MOVE Y,NUSERS

	JUMPG X,[HRROI B,[ASCIZ /
TO:   /]
		JRST DOCC1]	;X IS GREATER THAN 0 AFTER MESSAGE HAS
				;BEEN SENT TO ALL USERS AND WE ARE
				;MAKING A COPY FOR MESSAGE.SAVE.
				;MAKE A LIST OF ALL PERSONS RECEIVING
				; THE MESSAGE.

	CAML Y,[-1,,0]
	JRST ENDHED
DOCC:	HRROI B,[ASCIZ /
cc:   /]

DOCC1:				;OUTPUT 'TO:	' FOLLOWED BY USER LIST

	SETZ C,
	SOUT
	PUSH P,A
	TRZ F,COMMAF
CCLUP:	SKIPGE	DISTL
	JRST	CCLUP1
	CAMN Y,X
	JRST CCNXT
CCLUP1:	PUSH P,A
	HRROI B,[ASCIZ /, /]
	TROE F,COMMAF
	SOUT
	SKIPGE DISTL
	 JRST [	MOVE B,DIST(Y)
		SOUT
		JRST CCCHKE]
	EXCH X,Y
	PUSHJ P,OUTUSR
	EXCH X,Y
CCCHKE:	HRRZ B,A
	SUBI B,@-1(P)
	CAILE B,↑D12
	 JRST [	POP P,A
		HRROI B,[ASCIZ /,
cc:   /]
	SKIPLE	X
	HRROI	B,[ASCIZ /,
      /]
		TRZ F,COMMAF
		SOUT
		MOVEM A,0(P)
		JRST CCLUP]
	SUB P,[XWD 1,1]
CCNXT:	AOBJN Y,CCLUP
	SUB P,[XWD 1,1]
ENDHED:	PUSHJ P,MAKEHD		; DO THE END OF THE HEADING
	POPJ P,

; FINISH UP HEADING

MAKEHD:	HRROI B,[ASCIZ /

- - - -
/]
	SETZ C,
	SOUT
	MOVEM A,PTR
	IBP PTR
	MOVE A,HEAD
	PUSHJ P,CNTMSG		; GET ITS LENGTH
	MOVEM B,HEDLEN
	POPJ P,

; OUTPUT DATE AND SIZE STAMP

OUTMRK:	MOVE A,SJFN
	SETO B,
	MOVSI C,(1B17)
	ODTIM
	MOVEI B,","
	BOUT
	MOVE B,MSGLEN
	ADD B,HEDLEN
	ADDI B,9
	MOVEI C,12
	NOUT
	 JFCL
	MOVEI B,15
	BOUT
	MOVEI B,12
	BOUT
	POPJ P,

; OUTPUT MESSAGE

OUTMSG:	MOVE A,SJFN
	MOVE B,HEAD
	MOVN C,HEDLEN
	SOUT
	MOVE B,MSG
	MOVN C,MSGLEN
	SOUT
	HRROI B,[ASCIZ /-------
/]
	SETZ C,
	SOUT
	POPJ P,

; COUNT LENGTH OF MESSAGE

CNTMSG:	SETZ B,
	ILDB C,A
	JUMPE C,CPOPJ
	AOJA B,.-2

; Collect string
; If fullf = 1, then string is terminated by control-Z
; otherwise it is terminated by any punctuation (@ , eol altmode now)
; Initial ? always returns, rubout always returns

INSTR:	TRZ F,BUFFUL
	MOVE EPTR,PTR
INSTRC:	MOVEI A,100
	RFMOD
	TRZ B,77B23
	TRO B,16B23
	SFMOD
	TRZ F,FRSTCH

RLUP:	PUSHJ P,.BIN
	TRNE	FLG,NTLOGF		;IS USER LOGGED IN?
	 JRST	[ CAIE	A,"C"-100	;NO CHECK FOR ↑C
		   JRST	.+1		;NONE. GO ON.
		  PBOUT
		  HALTF			;FOUND ONE. EXIT.
		  JRST	RLUP		;ON CONT GO ON.
		]
	CAIE A,"H"-100
	CAIN A,"A"-100
	 JRST [	CAMN EPTR,PTR
		 JRST DING
		MOVEI A,"\"
		PBOUT
		LDB A,EPTR
		PBOUT
		PUSH P,A
		MOVE A,EPTR
		BKJFN
		 0
		MOVE EPTR,A
		POP P,A
		CAIN A,12
		 JRST .
		JRST RLUP]
	CAIN A,"Q"-100
	 JRST [	CAMN EPTR,PTR
		JRST DING
		MOVEI A,"←"
		PBOUT
		MOVEI A,37
		PBOUT
		PUSHJ P,BKLIN
		MOVEM A,EPTR
		JRST RLUP]
	CAIN A,"W"-100
	 JRST [	CAMN PTR,EPTR
		 JRST DING
		PUSHJ P,BKWORD
		MOVEI A,"←"
		PBOUT
		JRST RLUP]
	CAIN A,"R"-100
	 JRST [	MOVEI A,37
		PBOUT
		PUSHJ P,BKLIN
		PUSHJ	P,TYPOUT
		JRST RLUP]
	CAIN A,"S"-100
	 JRST [	MOVEI A,37
		PBOUT
		SETZ B,
		PUSH P,EPTR
		IDPB B,EPTR
		POP P,EPTR
		MOVE A,BPTR
		PUSHJ	P,TYPOUT
		JRST RLUP]
	TRNE	F,BLANKF	;IF FLAG ON,
	 JRST [	CAIN A," "	; SKIP LEADING BLANKS
		CAME PTR,EPTR
		JRST .+1
		JRST	RLUP ]
	CAMN PTR,EPTR
	CAIE A,"?"
	CAIN A,177
	 JRST ENDIN
	CAIN A,"Z"-100
	JRST ENDIN
	TRNE F,FULLF
	 JRST [	CAIN A,15
		 JRST RLUP	; IGNORE
		CAIN A,"X"-100
		 JRST [	HRROI A,[ASCIZ /←←←
/]
			PSOUT
			POPJ P,]
		CAIN A,12
		 MOVEI A,37	; LF BECOMES EOL
		CAIE A,","
		CAIN A,37
		 JRST ENDIN
		CAIE A,33
		CAIN A,":"
		 JRST ENDIN
		SKPNAT A
		 JRST ENDIN
		JRST DEPBYT]
DEPBYT:	TRNN F,FULLF
	TROE F,FRSTCH
	 JRST RLUPS
	PUSH P,A
	MOVEI A,100
	RFMOD
	TRZ B,1B20+1B22		; STOP WAKING ON PUNC AND FORMAT CTRLS
	SFMOD
	POP P,A
RLUPS:	HRRZ B,EPTR
	CAIL B,ESTRING-25
	 JRST [	TROE F,BUFFUL
		 JRST RLUP
		HRROI A,[ASCIZ /
String buffer full.  Finish input soon or you will lose.
/]
		ESOUT
		JRST RLUP]
	CAIL A,140
	CAILE A,177
	 JRST NOTLWR
	TRNE F,RAISEF
	 TRZ A,40
NOTLWR:	CAIN A,37
	 JRST [	MOVEI A,15
		IDPB A,EPTR
		MOVEI A,12
		JRST .+1]
	IDPB A,EPTR
	PUSH P,EPTR
	SETZ A,
	IDPB A,EPTR
	POP P,EPTR
	JRST RLUP

BKWORD:	MOVE A,EPTR
BKWRL1:	LDB B,A
	PUSHJ P,INVCHK
	 JRST BKWRD1
	CAME A,PTR
	BKJFN
	 JRST BKWRDN
	JRST BKWRL1

BKWRD1:	CAME A,PTR
	BKJFN
	 JRST BKWRDN
	LDB B,A
	PUSHJ P,INVCHK
	 JRST BKWRD1
BKWRDN:	MOVEM A,EPTR
	SETZ B,
	IDPB B,A
	POPJ P,

INVCHK:	CAILE B," "
	CAIL B,177
	AOS 0(P)
	POPJ P,
BKLIN:	MOVE A,EPTR
	SETZ B,
	IDPB B,A
	MOVE A,EPTR
BKLINL:	CAMN A,PTR
	 POPJ P,
	BKJFN
	 0
	LDB B,A
	CAIE B,37
	CAIN B,12
	POPJ P,
	JRST BKLINL

BKBLNK:	PUSH	P,A
	MOVE	A,EPTR
BKBL1:	CAMN	A,PTR
	JRST	BKBL2
	LDB	B,A
	CAIN	B," "
	BKJFN
	JRST	BKBL2
	JRST	BKBL1
BKBL2:	MOVEM	A,EPTR
	POP	P,A
	POPJ	P,

DING:	MOVEI A,7
	PBOUT
	JRST RLUP

ENDIN:	TRNE	F,BLANKF	;IF FLAG ON,
	PUSHJ	P,BKBLNK	; BACK UP OVER TRAILING BLANKS
	SETZ B,
	MOVE C,EPTR
	IDPB B,C
	AOS 0(P)
	POPJ P,

; BYTE INPUT FROM MULTI-FILES

.BIN:	PUSH P,B
	MOVE A,INFIL
	BIN
	JUMPE B,[GTSTS
		TLNN B,1000
		 JRST .-1
		PUSHJ P,ENDFIL
		POP P,B
		JRST .BIN]
	CAIN B,"B"-100
	 JRST NEWFIL
	MOVE A,B
	POP P,B
	POPJ P,

SYSGET:	PUSH P,A		;PRESERVE AC'S
	PUSH P,B
	SETZM 0(B)		;IN CASE FAILS, CLEAR ANSWER.
	SYSGT
	JUMPE B,BAPOPJ		;RETURN IF NO TABLE
	MOVE A,HSTFRE		;POINT TO FREE SPACE
	HLL A,B			;PUT IN COUNT
	MOVEM A,@0(P)		;THATS THE ANSWER
	PUSH P,B		;NOW GET DATA. SAVE POINTER
	HLLZ X,B		;AOBJN COUNTER
SYSGTL:	MOVSI A,(X)		;ENTRY NUMBER IN TABLE
	HRR A,0(P)		;TABLE NUMBER
	GETAB
	  JRST SYSGTF		;FAILED!!
	AOS C,HSTFRE		;MOVE ON DOWN THE FREE SPACE
	CAILE C,HSTTAB+NHSTTB	;OVERFLOW TABLE?
	JRST SYSGTF		;YES.
	MOVEM A,-1(C)		;NO. STORE DATUM
	AOBJN X,SYSGTL		;COUNT THRU TABLE
SYSGTY:	POP P,(P)		;PEEL STACK
BAPOPJ:	POP P,B
	POP P,A
	POPJ P,0

SYSGTF:	SETZM @-1(P)		;FAILURE. CLOBBER ANSWER.
	JRST SYSGTY		;AND RETURN

; POP FILE STACK

ENDFIL:	CLOSF
	 JFCL
	POP SF,INFIL
	CAMN SF,[XWD -NFILS,FILSTK-1]
	 TRZ F,QUIETF
	HRROI A,[ASCIZ /EOF)/]
	TRNN F,QUIETF
	 PSOUT
	POPJ P,

; SET NEW INPUT FILE, PUSH FORMER

NEWFIL:	PUSH SF,INFIL
	TRNE	FLG,NTLOGF		;IS USER LOGGED IN?
	 JRST	[ HRROI	A,[ASCIZ /(File capability not available non-logged-in users.)/]
		  PSOUT
		  JRST	NONEWF  ]
	HRROI A,[ASCIZ /(Insert file: /]
	TRNN F,QUIETF
	PSOUT
	MOVSI A,(1B2!3B17)
	MOVEI B,100
	CAMN	B,INFIL	;REQUIRE CONFIRMATION IF TTY INPUT
	OR	A,[1B4]
	CAME B,INFIL
	 SKIPA B,[377777]
	 MOVEI B,101
	HRL B,INFIL
	GTJFN
	 JRST [	HRROI A,[ASCIZ / ?)/]
		TRNN F,QUIETF
		PSOUT
		JRST NONEWF]
	MOVEM A,INFIL
	MOVE B,[XWD 70000,200000]
	OPENF
	 JRST [	MOVE A,INFIL
		RLJFN
		 JFCL
		HRROI A,[ASCIZ / can't open)/]
		TRNN F,QUIETF
		PSOUT
		JRST NONEWF]
	HRROI A,[ASCIZ /.../]
	TRNN F,QUIETF
	PSOUT
	TRO F,QUIETF
	POP P,B
	JRST .BIN

NONEWF:	POP SF,INFIL
	POP P,B
	JRST .BIN

NEDLOG:	↑D504	; NEED TO LOG IN
NEDPAS:	↑D330	; NEED PASSWORD
LOGOK:	↑D230	; SUCCESSFUL LOGIN FOR MULTICS
GENDLV:	↑D950
GOMAIL:	↑D350
QCODES:	BLOCK 5	; CODES IMPLYING QUEUEING
MNQCOD:	0	; NEG OF NUMBER OF REPLY CODES THAT IMPLY QUEUEING
FTPSKT:	3
PDP:	IOWD PDLL,PDL

LIT
; INITIAL ENTRY POINT TO SET UP ENTRY VEC AND SSAVE TO
; <SUBSYS>SNDMSG.SAV

IF2, <
PRINTX *****
PRINTX Remember to run SNDMSG initially once to set up ENTVEC  and to
PRINTX SSAVE itself as <SUBSYS>SNDMSG.SAV
PRINTX *****
>

INITIT:	RESET
	HRROI	A,[ASCIZ /
Setting up entry vector./]
	PSOUT
	MOVE	B,[EVECL,,ENTVEC]
	MOVEI	A,400000
	SEVEC
	HRROI	A,[ASCIZ /
SSAVEing myself as <SUBSYS>SNDMSG.SAV/]
	PSOUT
	HRLZI	A,(1B0+1B1+1B17)	;OUTPUT USE, NEW FILE.
	HRROI	B,[ASCIZ /<SUBSYS>SNDMSG.SAV/]
	GTJFN
	 JRST	[MOVE B,A
		 MOVEI A,37
		 PBOUT
		 MOVEI A,101
		 HRLI B,400000
		 SETZ C,
		 ERSTR
		  JFCL
		  JFCL
		 HRROI A,[ASCIZ /
Can't get JFN for <SUBSYS>SNDMSG.SAV
/]
		 PSOUT
		 HALTF
		 HALTF
		]
	HRLI	A,400000
	MOVE	B,[-1000,,1B18+1B20+1B22+0]	;EVERYTHING.
	SETZ	C,			;  READ, EXECUTE, COPY ON WRITE.
	SSAVE
	HRRZS	A
	CLOSF
	 JFCL
	HRROI	A,[ASCIZ /
Done.  Thank you.
/]
	PSOUT
	HALTF
	JRST	.-1


; MASSIVE RE-ORGANIZATION

; VARIABLES

LOC 10000

FLAGPG==./1000
	BLOCK 1000

SAVACS:	BLOCK 20	;TO SAVE ACCUMULATORS
MONITV:	BLOCK 1
PDL2:	BLOCK 4
PDL:	BLOCK PDLL
FILSTK:	BLOCK NFILS
INFIL:	BLOCK 1
MSG:	BLOCK 1
MSGLEN:	BLOCK 1
HEAD:	BLOCK 1
HEDLEN:	BLOCK 1
SUBJCT:	BLOCK 1
DEFHST:	BLOCK 1
XDIST:	BLOCK 1
DISTL:	BLOCK 1
DIST:	BLOCK NDIST
HOST:	BLOCK NUSRS
USRTAB:	BLOCK NUSRS
FILNAM:	BLOCK NFILS
NUSERS:	BLOCK 1
TIMFRK:	BLOCK 1
SAVEP:	BLOCK 1
RETPC1:	BLOCK 1
SUPRET:	BLOCK 1
LHOSTN:	BLOCK 1
LHOST:	BLOCK 1
FSKT:	BLOCK 1
RJFN:	BLOCK 1
SJFN:	BLOCK 1
ENDPTR:	BLOCK 1
OLDCNT:	BLOCK 1
SPATCR:	BLOCK 1
SITEN:	BLOCK 1
SITE:	BLOCK 1
FROMNM:	BLOCK 1
HSTFRE:	BLOCK 1		;SPACE COUNTER INTO HSTTAB
HOSTN:	BLOCK 1		;POINTER TO HOST NUMBERS AND BITS
HSTNAM:	BLOCK 1		;POINTER TO HOST ASCII STRINGS
HSOUTX:	BLOCK 1		;TEMP FOR HSTSOU ROUTINE
REPLY:	BLOCK 100
HSTTAB:	BLOCK NHSTTB	;SPACE FOR HOST NAMES AND NUMBERS
STRING:	BLOCK MAXMSG/5
ESTRING:

RELOC

	END	INITIT