         PCC      0
*
*M*      MAILBX   BUILD 'MAILBOX' FILES IN USER'S ACCOUNTS
*
*
*P*      NAME:    MAILBX
*P*
*P*      PURPOSE: INFORM USERS OF SYSTEM ACTION TAKEN WITH REGARD TO
*P*               FILE MAINTENANCE.  THE MESSAGE GENERALLY CONSISTS OF
*P*               THE REASON A SYSTEM BACKUP FAILED OR A COMPLETION
*P*               MESSAGE CONCERNING SOMETHING THE USER HAS REQUESTED.
*P*      DESCRIPTION:  THE MAILBX ROUTINE FORMATS A MESSAGE CONTAINING
*P*               THE CURRENT DATE AND TIME AND THE ACCOUNT NAME WHICH
*P*               IS REQUESTING THE MAILBOX BE BUILT; THE REST OF THE
*P*               MESSAGE IS PART OF THE INPUT.  THE MESSAGE IS WRITTEN
*P*               INTO THE SPECIFIED ACCOUNT BY ADDING A RECORD TO AN
*P*               EXISTING 'MAILBOX' FILE IN THE ACCOUNT OR INTO A NEW
*P*               ONE IF NONE CURRENTLY EXISTS.  THE MESSAGE IS ALSO
*P*               OPTIONALLY PRINTED ON THE LINE PRINTER.
*P*
         PAGE
         SYSTEM   SIG7
         SYSTEM   BPM
*X*      DEF      F:MAIL            DCB USED TO CREATE AND WRITE THE
*,*                                 MAILBOX FILE IN A USER'S ACCOUNT
         DEF      FMAILBX           ENTRY POINT TO BYPASS M:TIME CAL
*,*                                 (THE TIME HASN'T CHANGED SINCE LAST
*,*                                 CALL TO MAILBOX)
         DEF      MAIL              DEF FOR MAILBX PROCEDURE PATCHING
         DEF      MAILBOX           MAIN ENTRY POINT TO MAILBOX ROUTINE
         DEF      MAILD             DEF FOR MAILBX DATA PATCHING
         DEF      NOPRINT           LOCATION WHICH GOVERNS LINE PRINTER
*,*                                 ACTION: 0 => PRINT, NON-0 => NOT
*
         REF      J:ACCN            JIT LOCATION OF RUNNING ACCOUNT
*,*                                 USED TO LOCATE MAILBOX FILE
         REF      JULIAN            CONVERTS M:TIME TIME INTO JULIAN TIME
         PAGE
*        DEFINE STANDARD REGISTERS
R0       EQU      0
R1       EQU      1
R2       EQU      2
R3       EQU      3
R4       EQU      4
R5       EQU      5
R6       EQU      6
R7       EQU      7
SR1      EQU      8
SR2      EQU      9
SR3      EQU      10
SR4      EQU      11
D1       EQU      12
D2       EQU      13
D3       EQU      14
D4       EQU      15
         PAGE
F:MAIL   DSECT    1
F:MAIL   M:DCB    (FILE,'MAILBOX'),;
                  (KEYED),(DIRECT),(KEYM,7),;
                  (INOUT),(SAVE),;
                  (ERR,ML:ERR),(ABN,ML:ABN)
         PAGE
MAILD    CSECT    0
         DEF      MAILD:            XDELTA PATCHING DEF
MAILD:   RES
ENVIR    DATA     %+1
         GEN,16,16 16,0
         RES      16
MSGBUF   RES      28
OPENFPT  DATA     X'14000000'+F:MAIL
         DATA     X'C7480009'
         DATA     ML:ERR            ERR RETURN
         DATA     ML:ABN            ABN RETURN
         DATA     2                 KEYED
         DATA     2                 DIRECT
INOUT    DATA     4                 INOUT USUAL,OUT SOMETIMES
         DATA     2                 SAVE
         DATA     7                 KEYM
         DATA     X'2010202'        ACCOUNT WHERE MAILBOX
ACCOUNT  TEXT     ':SYS    '         IS TO BE BUILT.
MAXSIZ   EQU      80                20 WORD MESSAGE LIMIT
KEYBUF   RES      2
NOPRINT  DATA     0                 IF NONZERO, NO LP OUTPUT
SENDER   EQU      J:ACCN
BLANK    EQU      X'40'
         PAGE
*
*D*      NAME:    MAILBOX
*D*      ENTRY:   FMAILBX
*D*
*D*      REGISTERS:  ALL ARE PRESERVED
*D*
*D*      CALL:    LI,SR3   FPT
*D*               BAL,SR4  MAILBOX
*D*
*D*      INPUT:   FPT    => ADDRESS OF TEXTC MESSAGE (NO INDIRECT)
*D*               FPT+1  => ADDRESS OF RECIPIENT ACCOUNT NAME
*D*               NOPRINT = 0 => PRINT MESSAGE ON LINE PRINTER
*D*                       = 1 => SUPPRESS LINE PRINTER LISTING
*D*                                 NOPRINT IS A DEF'ED WORD IN MAILD
*D*               D4 (R15) = 0 => SUPPRESS FILE BUILDING
*D*                        = 1 => BUILD MAILBOX FILE IN RECIPIENT ACCT
*D*
*D*      INTERFACE:  JULIAN
*D*
*D*      ENVIRONMENT:  MAPPED, SLAVE OR MASTER, C0 PRIVILEGE
*D*
*D*      DESCRIPTION:  ALL REGISTERS ARE SAVED UPON ENTRY IN THE STACK
*D*               'ENVIR'; AN M:TIME CAL IS THEN ISSUED TO OBTAIN THE
*D*               CURRENT TIME AND JULIAN IS CALLED TO CONVERT THIS
*D*               INTO A JULIAN FORMATTED DATE ('00YY0DDD','HHMM0000').
*D*               THIS DATE IS USED AS A KEY TO WRITE THE MAILBOX FILE;
*D*               IF ENTRY IS AT FMAILBX, THE PREVIOUS KEY IS INCRE-
*D*               MENTED TO MAKE IT UNIQUE FOR EACH WRITE.
*D*               THE MESSAGE IS THEN PUT TOGETHER; IT HAS THE FORM:
*D*               'HH:MM MON DD BY BUILDER' FOLLOWED BY TEXT MESSAGE
*D*               INPUT TO MAILBOX (FPT ABOVE); 'BUILDER' IS THE
*D*               NAME OF THE ACCOUNT BUILDING THE MAILBOX, USUALLY
*D*               :SYS.  THE 'BUILDER' FOR THE LINE PRINTER MESSAGE IS
*D*               THE INPUT RECIPIENT ACCOUNT (FPT+1 ABOVE).  THUS,
*D*               TWO DIFFERENT MESSAGES ARE BUILT.  (IF THE INPUT
*D*               MESSAGE IS TOO LONG, I.E. > THAN 80 CHARACTERS, THE
*D*               ROUTINE DOES NOT BUILD A FILE IN THE USER'S ACCOUNT.)
*D*               IF D4 (REGISTER 15) = 0, THE MAILBOX FILE IS NOT BUILT;
*D*               OTHERWISE, IT IS OPENED IN THE RECIPIENT'S ACCOUNT
*D*               AND THE APPROPRIATE MESSAGE ADDED TO THE FILE.
*D*               (IF THE FILE DOES NOT ALREADY EXIST, A NEW ONE IS BUILT)
*D*               IF NOPRINT = 0, THE LINE PRINTER MESSAGE IS PRINTED;
*D*               OTHERWISE, THE ROUTINE EXITS AFTER CLOSING
*D*               THE F:MAIL DCB (IF IT WAS OPEN) AND PULLING ALL REGS.
         CSECT    1
MAIL     EQU      %
MAILBOX  EQU      %
         DEF      MAILBX:           XDELTA PATCHING DEF
MAILBX:  RES
         LCI      0
         PSM,R0   ENVIR
         M:TIME   MSGBUF+1
         LI,SR3   MSGBUF+1
         BAL,SR4  JULIAN
         LI,R6    7                 7 BYTES FOR KEY
         STB,R6   SR1               TWO WORD DATE/TIME IS KEY- SR1,SR2
         STW,SR1  KEYBUF
         STW,SR2  KEYBUF+1
         B        CMAILBX
FMAILBX  EQU      %                 ENTRY FOR NO TIME UPDATE
         MTW,1    KEYBUF+1          MAKE KEY UNIQUE
         LCI      0
         PSM,R0   ENVIR
CMAILBX  EQU      %
         LW,SR3   ENVIR+12
         LW,SR4   ENVIR+13
         LW,R4    L(C' BY ')
         STW,R4   MSGBUF+4
         LW,R4    SENDER
         STW,R4   MSGBUF+5
         LW,R4    SENDER+1
         STW,R4   MSGBUF+6
         LW,R4    *SR3              LOCATION OF MSG TO R4
         LB,R7    *R4               BYTE 0 IS BYTE COUNT OF MSG
         CI,R7    MAXSIZ
         BG       EXIT              MSG TOO LONG
         AI,7     1
         LI,R6    6*4               6 WORD FIXED PREFIX
         AW,R6    R7                ADD MSG LENGTH FOR RECORD LNG
         SLS,R4   2                 BYTE ADDRESS
         LI,R5    MSGBUF+7
         SLS,R5   2                 BYTE ADDRESS
         STB,R7   R5                BYTE 0 IS CHARACTER COUNT
         MBS,R4   0
         LI,R5    BLANK
         STB,R5   MSGBUF+7
         AI,SR3   1                 LOCATE RECIPIENT
         LW,4     *SR3              PICK UP ACCT POINTER
         LW,R5    *R4               FIRST WORD OF ACCT
         XW,R5    ACCOUNT
         AI,R4    1
         LW,R7    *R4
         XW,R7    ACCOUNT+1
         LW,D4    ENVIR+17          WAS MAILBOX ADDITION REQUESTED
         BEZ      EXIT              NO
OPEN     EQU      %
         LI,D3    4
         STW,D3   INOUT
         CAL1,1   OPENFPT
         M:PFIL   F:MAIL,(EOF)
WRIT     M:WRITE  F:MAIL,(BUF,MSGBUF+1),(SIZE,*R6),;
                  (ERR,ML:ERR),(ABN,ML:ABN),;
                  (KEY,KEYBUF),(NEWKEY)
EXIT     EQU      %
         MTW,0    NOPRINT
         BNEZ     EXIT05
         LW,4     ACCOUNT
         STW,4    MSGBUF+5
         LW,4     ACCOUNT+1
         STW,4    MSGBUF+6
         LW,R4    ='    '
         STW,R4   MSGBUF
         AI,R6    3
         STB,R6   MSGBUF
         M:PRINT  (MESS,MSGBUF)
EXIT05   EQU      %
         LH,R0    F:MAIL            IS DCB OPEN?
         CI,R0    X'20'
         BAZ      XIT1              NO, DON'T CLOSE
CLOSE    M:CLOSE  F:MAIL,(SAVE)
XIT1     EQU      %
         LCI      0
         STW,R5   ACCOUNT
         STW,R7   ACCOUNT+1
         PLM,R0   ENVIR
         B        *SR4
SLP      GEN,8,24 X'F',60           1 MINUTE SLEEP
         PAGE
**
**   ERROR AND ABNORMAL RETURNS
**
ML:ERR   EQU      %
         B        EXIT
ML:ABN   EQU      %
         LB,R4    SR3
         CI,R4    3                 NON EXISTENT FILE
         BNE      LP1
         LI,D3    2
         STW,D3   INOUT             OPEN FILE OUTPUT
         CAL1,1   OPENFPT
         B        WRIT
LP1      CI,R4    X'16'             KEY ALREADY EXISTS
         BNE      LP2
         AWM,R1   KEYBUF+1
         B        WRIT
LP2      CI,R4    X'14'             MAYBE BUSY
         BNE      EXIT
         LI,R1    1
         LB,R4    SR3,R1
         SLS,R4   -1                7 BIT SUB CODE
         CI,R4    1
         BNE      EXIT              NOT BUSY
         CAL1,8   SLP               SLEEP A MINUTE
         AI,R2    1
         BGZ      EXIT
         B        OPEN
         END

