;<PUP>PUPDEF.MAC;34    13-JAN-83 14:34:08    EDIT BY TAFT
; Change ASSIGN to .ASSIGN
;<PUP>PUPDEF.MAC;33    26-SEP-82 15:14:24    EDIT BY TAFT
; Add Desired-Property property and X.prop indices.
; Add New-enumerate command
; Define MOVX and TX-- macros
;<PUP>PUPDEF.MAC;32    12-SEP-80 11:28:29    EDIT BY TAFT
; Add SNDSTL
;<PUP>PUPDEF.MAC;31    28-NOV-79 11:14:18    EDIT BY TAFT
; Add FTP/Mail flags to mark type table
;<PUP>PUPDEF.MAC;30     2-SEP-79 15:58:49    EDIT BY TAFT
;<PUP>PUPDEF.MAC;29    11-APR-79 17:31:43    EDIT BY TAFT
; Put Sender property in its right alphabetical sequence, dummy
;<PUP>PUPDEF.MAC;28    18-MAR-79 19:18:28    EDIT BY TAFT
; Put back Sender property
;<PUP>PUPDEF.MAC;27    24-MAY-78 18:12:41    EDIT BY TAFT
; Add New-Store mark
;<PUP>PUPDEF.MAC;26    15-SEP-77 11:19:01    EDIT BY TAFT
; Fix [Mailbox-exception] command to take sub-codes
;<PUP>PUPDEF.MAC;25     1-SEP-77 15:52:10    EDIT BY TAFT
; Revise property and mark tables for updated Mail Transfer Protocol
;<PUP>PUPDEF.MAC;24     3-JUN-77 11:04:13    EDIT BY TAFT
; Remove "Sender" and "Distribution" properties
;<PUP>PUPDEF.MAC;23     2-JUN-77 21:33:43    EDIT BY TAFT
; Add "Size" and "Author" properties
; Add "Rename" command mark
;<PUP>PUPDEF.MAC;22    15-APR-77 10:03:57    EDIT BY TAFT
; Add SERVF
;<PUP>PUPDEF.MAC;21    31-MAR-77 20:16:42    EDIT BY TAFT
; Add marks and properties for Mail Transfer Protocol
;<PUP>PUPDEF.MAC;20    19-MAR-77 20:24:21    EDIT BY TAFT
; Add "delete" mark type
; Add date properties
;<PUP>PUPDEF.MAC;18    18-MAR-77 17:05:38    EDIT BY TAFT
; Move mark and property definitions here from PFUDEF.MAC.
; Add some common flag bits.
;<PUP>PUPDEF.MAC;16    10-MAR-77 14:24:40    EDIT BY TAFT
; Divide into two definitions files:
; PUPDEF.MAC contains definitions common to PUPSRV and PUPFTP
; PSVDEF.MAC contains stuff specific to PUPSRV
;<PUP>PUPDEF.MAC;14    20-OCT-76 13:27:17    EDIT BY TAFT
; Add defs for net directory server
;<PUP>PUPDEF.MAC;13     2-OCT-76 23:16:30    EDIT BY TAFT
; Add defs for gateway info server
;<PUP>PUPDEF.MAC;11    30-JUN-76 18:04:45    EDIT BY TAFT
; Revise storage assignment macros
; Add defs for event report server

; Copyright 1979 by Xerox Corporation

	UNIVERSAL PUPDEF -- DEFINITIONS COMMON TO PUPSRV AND PUPFTP
	SUBTTL E. A. Taft / September, 1975


; Standard Accumulator assignments

	F=0		; Flags

	A=1		; General scratch
	B=2
	C=3
	D=4

	P1=10		; Permanent -- saved by callees
	P2=11
	P3=12
	P4=13

	P=17		; Stack


; Flag assignments common to PUPSRV and PUPFTP

DEBUGF==1B0		; In debug mode
ENABLF==1B1		; We are enabled as wheel/operator
SERVF==1B2		; On if we are server, off if user

RAISEF==1B18		; Raise lower-case input


; Macro to declare storage PC's to be used in a module

DEFINE USEVAR(LSVAR,LSPVAR) <
	DEFINE LS(LOC,SIZE<1>) <.ASSIGN LOC,LSVAR,SIZE>
	DEFINE LSP(LOC,SIZE<1>) <.ASSIGN LOC,LSPVAR,↑O1000*<SIZE>>
	DEFINE GS(LOC,SIZE<1>) <.ASSIGN LOC,GSVAR,SIZE>
	DEFINE GSP(LOC,SIZE<1>) <.ASSIGN LOC,GSPVAR,↑O1000*<SIZE>>
>

; Definitions needed to append items to a list and then extract
;  them all for assembly in a single place

DEFINE APPEND(DEF,ITEM) <
	DEFINE DEF(XX,MORE) <XX DEF,<ITEM,MORE>>
>
DEFINE EXPAND(DEF,OP) <
	DEFINE OPMAC(A,ITEM) <IRP ITEM <IFNB <ITEM>,<OP>>>
	DEF(OPMAC)
	PURGE OPMAC
>

DEFINE UUO(OP,DISP) <
	UUON==UUON+1
	OPDEF OP [<UUON>B8]
IFB <DISP>,<UUOS(APPEND,%'OP)>
IFNB <DISP>,<UUOS(APPEND,DISP)>
>

APPEND(UUOS)	;INIT DISPATCH LIST
UUON==0		;INIT UUO NUMBERS


; UUOs used in PUPSRV and PUPFTP

	UUO PRINT	; Print character specified in eff adr
	UUO UTYPE	; Type message on TTY
	UUO UDTYPE	; Type message on TTY iff debugging
	UUO UWRITE	; Write message on arbitrary designator
	UUO UFTPM	; Send FTP reply message

; UUOs used only in PUPSRV

	UUO ULOG	; Log a message
	UUO UELOG	; Log to both file and TTY

; UUOs used only in PUPFTP

	UUO UERROR	; Type error message, clear input buffer
	UUO UNOISE	; Print noise words if Escape hit
	UUO UPROMP	; Type text and also append to cmd buffer


; Macros to call the above UUOs

DEFINE LOG(STRING) <ULOG [ASCIZ \STRING\]>
DEFINE ELOG(STRING) <UELOG [ASCIZ \STRING\]>
DEFINE TYPE(STRING) <UTYPE [ASCIZ \STRING\]>
DEFINE DTYPE(STRING) <UDTYPE [ASCIZ \STRING\]>
DEFINE NOISE(STRING) <UNOISE [ASCIZ \(STRING) \]>
DEFINE PROMPT(STRING) <UPROMP [ASCIZ \STRING\]>
DEFINE ERROR(STRING,NPOP<0>) <UERROR NPOP,[ASCIZ \STRING\]>
DEFINE WRITE(AC,STRING) <
	IFNB <STRING>,<UWRITE AC,[ASCIZ \STRING\]>
	IFB <STRING>,<UWRITE A,[ASCIZ \AC\]>
>
DEFINE FTPM(TYPE,CODE,STRING,NPOP<0>,EOCF) <
	ZZ==0
	IFNB <EOCF>,<ZZ==1>
	UFTPM [<MK'TYPE>B7+<CODE>B15+<ZZ>B16+<NPOP>+1
		ASCIZ \STRING\]
>

; FTP-related definitions common to server and user

USRSTL==↑D39		; Maximum name/password/acct string lengths
NAMSTL==↑D<2*39+1+2*39>	; Name.Extension length (with possible ↑Vs)
SFNSTL==USRSTL+2+NAMSTL+7  ; Server-Filename string length
SNDSTL==↑D100		; Sender property string length

PQUOTE=="'"		; Quote character in property lists
EOL==37			; Tenex EOL character (internal use only)


; Property list names and assignments
; Calls are of the form
;	X internal mnemonic , property name , storage
; The internal mnemonic must be 4 characters or less.
; Entries must be sorted alphabetically by property name.
; "Storage" is the maximum number of words needed to store
;  the property (default 1).
; Offsets in a property list are assigned to P.' mnemonic.
; Dispatches to process received properties are PP' mnemonic.

DEFINE PNAMES <
	X AUTH,<AUTHOR>,USRSTL/5+1
	X BYTE,<BYTE-SIZE>
	X CNAM,<CONNECT-NAME>
	X CPSW,<CONNECT-PASSWORD>,USRSTL/5+1
	X CDAT,<CREATION-DATE>
	X DPRP,<DESIRED-PROPERTY>
	X DEVI,<DEVICE>,USRSTL/5+1
	X DIRE,<DIRECTORY>,USRSTL/5+1
	X EOLC,<END-OF-LINE-CONVENTION>
	X MLBX,<MAILBOX>,0
	X NAMB,<NAME-BODY>,NAMSTL/5+1
	X RDAT,<READ-DATE>
	X SNDR,<SENDER>,SNDSTL/5+1
	X SFIL,<SERVER-FILENAME>,SFNSTL/5+1
	X SIZE,<SIZE>
	X TYPE,<TYPE>
	X UACT,<USER-ACCOUNT>,USRSTL/5+2
	X UNAM,<USER-NAME>
	X UPSW,<USER-PASSWORD>,USRSTL/5+1
	X VERS,<VERSION>
	X WDAT,<WRITE-DATE>
>


; Assign offsets and indices for individual properties in a property list

DEFINE X(SYM,NAME,SIZE<1>) <
	P.'SYM==PLSIZE
	PLSIZE==PLSIZE+SIZE
	X.'SYM==PLINDX
	PLINDX==PLINDX+1
>
	PLSIZE==0
	PLINDX==0

	PNAMES

; Must be able to hold all Desired-Property flags in one word
IFG PLINDX-↑D36,<PRINTX More than 36 property names defined>

; Mark type assignments
; Calls are of the form
;	XN internal mnemonic , mark type , name string , flags
; or	XS internal mnemonic , mark type , name string , flags
; The internal mnemonic must be 4 characters or less.
; Mark type must be octal.  Entries must be in order of Mark type.
; Mark types are assigned to MK' mnemonic.
; Dispatches to process received Marks are C.' mnemonic.
; The XS macro declares the Mark to have sub-codes.

; Flag assignments
;	B0			; Command has subcommands
	NFETCH==1B1		; Do not pre-fetch command text
	OKRETR==1B2		; Command ok during Retrieve
	OKSTOR==1B3		; Command ok during Store
	NOTFTS==1B4		; Not allowed in FTP server
	NOTMLS==1B5		; Not allowed in Mail server

DEFINE MARKS <
	XN RETR, 1,<Retrieve>
	XN STOR, 2,<Store>,NOTMLS
	XS YES,  3,<Yes>,OKRETR+OKSTOR
	XS NO,   4,<No>,OKRETR+OKSTOR
	XN FILE, 5,<Here-is-file>,NFETCH+OKSTOR
	XN EOC,  6,<End-of-command>,NFETCH+OKRETR+OKSTOR
	XN COMM, 7,<Comment>,OKRETR+OKSTOR
	XS VERS,10,<Version>
	XN NSTO,11,<New-store>,NOTMLS
	XN ENUM,12,<Enumerate>,NOTMLS
	XN PLST,13,<Here-is-property-list>
	XN NENU,14,<New-enumerate>,NOTMLS
	XN ABOR,15,<Abort>,OKRETR+OKSTOR
	XN DELE,16,<Delete>,NOTMLS
	XN RENA,17,<Rename>,NOTMLS
	XN SMAI,20,<Store-mail>,NOTFTS
	XN RMAI,21,<Retrieve-mail>,NOTFTS
	XN FMAI,22,<Flush-mail>,NOTFTS
	XS MBEX,23,<Mailbox-exception>,NOTFTS
>


; Assign the Mark type symbols

DEFINE XN(SYM,TYPE,NAME,FLAGS) <
	MK'SYM==TYPE
	NMARKS==NMARKS+1
>
DEFINE XS(SYM,TYPE,NAME,FLAGS) <
	MK'SYM==TYPE
	NMARKS==NMARKS+1
>

	NMARKS==0
	MARKS

; MOVX and TX-- instructions, ripped off from MACSYM.MAC

DEFINE MOVX (AC,MSK)<
   ..MX1==MSK			;;EVAL EXPRESSION IF ANY
	..MX2==0		;;FLAG SAYS HAVEN'T DONE IT YET
	IFE <..MX1>B53,<
	  ..MX2==1
	  MOVEI AC,..MX1>	;;LH 0, DO AS RH
	IFE ..MX2,<		;;IF HAVEN'T DONE IT YET,
	IFE <..MX1>B17,<
	  ..MX2==1
	  MOVSI AC,(..MX1)>>	;;RH 0, DO AS LH
	IFE ..MX2,<		;;IF HAVEN'T DONE IT YET,
	IFE <<..MX1>B53-↑O777777>,<
	  ..MX2==1
	  HRROI AC,<..MX1>>>	;;LH -1
	IFE ..MX2,<		;;IF HAVEN'T DONE IT YET,
	IFE <<..MX1>B17-↑O777777B17>,<
	  ..MX2==1
	  HRLOI AC,(..MX1-↑O777777)>> ;;RH -1
	IFE ..MX2,<		;;IF STILL HAVEN'T DONE IT,
	  MOVE AC,[..MX1]>	;;GIVE UP AND USE LITERAL
	PURGE ..MX1,..MX2>

;THIS DOUBLE IRP CAUSES ALL COMBINATIONS OF MODIFICATION AND TESTING
;TO BE DEFINED

DEFINE ..DOTX (M,T)<
	IRP M,<
	IRP T,<
	  DEFINE TX'M'T (AC,MSK)<
		..TX(M'T,AC,<MSK>)>>>>

	..DOTX (<N,O,Z,C>,<,E,N,A>) ;DO ALL DEFINITIONS
	PURGE ..DOTX

;..TX
;ALL TX MACROS JUST CALL ..TX WHICH DOES ALL THE WORK

DEFINE ..TX(MT,AC,MSK)<
   ..TX1==MSK			;;EVAL EXPRESSION IF ANY
	..TX2==0		;;FLAG SAYS HAVEN'T DONE IT YET
	IFE <..TX1&↑O777777B17>,<
	  ..TX2==1		;;LH 0, DO AS RH
	  TR'MT AC,..TX1>
	IFE ..TX2,<		;;IF HAVEN'T DONE IT YET,
	IFE <..TX1&↑O777777>,<
	  ..TX2==1		;;RH 0, DO AS LH
	  TL'MT AC,(..TX1)>>
	IFE ..TX2,<		;;IF HAVEN'T DONE IT YET,
	  IFE <<..TX1>B53-↑O777777>,< ;;IF LH ALL ONES, 
	    ..TX3 (MT,AC)>>	;;TRY Z,O,C SPECIAL CASES
	IFE ..TX2,<		;;IF STILL HAVEN'T DONE IT,
	  TD'MT AC,[..TX1]>	;;MUST GIVE UP AND USE LITERAL
	PURGE ..TX1,..TX2>

;SPECIAL CASE FOR LH ALL ONES

DEFINE ..TX3 (MT,AC)<
	IFIDN <MT><Z>,<		;;IF ZEROING WANTED
	  ..TX2==1
	  ANDI AC,↑-..TX1>	;;CAN DO IT WITH ANDI
	IFIDN <MT><O>,<		;;IF SET TO ONES WANTED
	  ..TX2==1
	  ORCMI AC,↑-..TX1>	;;CAN DO IT WITH IORCM
	IFIDN <MT><C>,<		;;IF COMPLEMENT WANTED
	  ..TX2==1
	  EQVI AC,↑-..TX1>>	;;CAN DO IT WITH EQV


	END