*M*      GOOSE    GHOST STARTUP PROGRAM FOLLOWING RECOVERY
*
*P*      NAME:    GOOSE
*P*
*P*      PURPOSE: TO RESTART SYSGEN OR INSTALLATION SPECIFIED
*P*               GHOST JOBS FOLLOWING A GENERAL SYSTEM RECOVERY.
*P*      DESCRIPTION:  GHOST1, FOLLOWING THE STARTUP OF SYSTEM
*P*               DEFAULT GHOSTS, DOES A LOAD-AND-TRANSFER-CONTROL
*P*               TO THE GOOSE PROCESSOR.  GOOSE THEN OPENS THE
*P*               M:GHOST FILE IN :SYS AND PERFORMS GJOB START
*P*               MONITOR CALLS TO INITIATE GHOST JOBS SPECIFIED
*P*               IN THE FILE.
*P*      REFERENCES:  SYSTEM MANAGEMENT REFERENCE MANUAL
*P*
*D*      NAME:    GOOSE
*D*
*D*      CALL:    M:LDTRC FROM GHOST1 FOLLOWING RECOVERY OR RAD BOOT
*D*      INTERFACE:   T:GJOB
*D*      ENVIRONMENT:   MASTER MODE, MAPPED
*D*      INPUT:   M:GHOST FILE, :SYS ACCOUNT
*D*      OUTPUT:  THE GHOST JOBS CONTAINED IN THE M:GHOST FILE ARE
*D*               INITIALIZED AND ENTERED.
*D*      DESCRIPTION:  THE M:GHOST FILE IS OPENED AND A RECORD READ;
*D*               SYNTAX IS CHECKED FOR THE FOLLOWING ERRORS:
*D*                  1.  GHOST NAME NOT MORE THAN 7 CHARACTERS
*D*                  2.  ACCOUNT NAME NOT MORE THAN 8 CHARACTERS
*D*                  3.  PRIORITY IN THE RANGE X'C0' - X'FF'
*D*               THE ENTRY IS CONVERTED IN THE REGISTERS AS FOLLOWS:
*D*                                 R0-R1 <= TEXTC GHOST NAME
*D*                                 R8-R9 <= TEXT ACCOUNT
*D*                                 R15 <= HEX PRIORITY
*D*               A CALL IS THEN MADE TO THE MONITOR 'T:GJOB' ROUTINE
*D*               TO INITIATE THE GHOST; IF THE GJOB TABLES ARE FULL,
*D*               THE OPERATOR WILL BE NOTIFIED OF THE SITUATION AND
*D*               THE NAMES OF THE GHOST JOBS GOOSE WAS UNABLE TO START.
         PCC      0
         SYSTEM   SIG7P
*
*        ALL DEFS IN GOOSE FOLLOW
*
         DEF      GOOSE             DEF FOR PATCHING GOOSE PROCEDURE
         DEF      GOOSED            DEF FOR PATCHING GOOSE DATA
         DEF      PATCH             PATCH AREA FOR GOOSE PROCESSOR
*
*        ALL REFS IN GOOSE FOLLOW
*
         REF      M:EI              DCB USED TO READ M:GHOST FILE
         REF      M:LL              DCB USED TO PRINT IN DEBUG MODE
         REF      NEWQ              VERIFY THAT GOOSE WAS LOADED WITH
*,*                                 CORRECT MONITOR REFERENCES
         REF      SL:GPRIO          DEFAULT PRIORITY OF GHOST JOBS
         REF      SYSACCT           DEFAULT ACCOUNT OF GHOST JOBS
         REF      T:GJOB            MONITOR ROUTINE TO INITIATE GHOSTS
         SPACE    2
R0       EQU      0
R1       EQU      1
R2       EQU      2
R3       EQU      3
R4       EQU      4
R5       EQU      5
R6       EQU      6
R7       EQU      7
R8       EQU      8
R9       EQU      9
R10      EQU      10
R11      EQU      11
R12      EQU      12
R13      EQU      13
R14      EQU      14
R15      EQU      15
         PAGE
GOOSED   CSECT    0
BUFFER   RES      21
PATCH    RES      50
DEBUG    PZE
         PAGE
GOOSE    CSECT    1
         CAL1,6   SYS
         CI,R10   NEWQ
         BNE      BADMNSTK
         CAL1,1   OPNGHOST
GOOSE1   EQU      %
         LI,R6    GOOSE2            EXIT ADDRESS FOR READFILE
READFILE EQU      %
         LD,R0    BLBUF             BLANK FILL THE BUFFER
         MBS,R0   3
         CAL1,1   READGHST
         LH,R4    M:EI+4            ARS OF DCB (RECORD SIZE)
         SLS,R4   -1
         STB,R4   BUFFER
         B        0,R6              RETURN TO CALLER
*
GOOSE2   EQU      %
         MTW,0    DEBUG
         BEZ      %+2
         CAL1,2   PRINT
         LD,R8    0BLANK
         LW,R15   SL:GPRIO
         LI,R3    1
         LB,R10   BUFFER,R3
         BAL,R5   CHKDLIM
         BNEZ     ERROR             FIRST CHAR CAN'T BE A DELIMITER
         B        GETGHST1
GETGHOST EQU      %
         AI,R3    1
         LB,R10   BUFFER,R3
         BAL,R5   CHKDLIM
         BNEZ     1STDLIM-1,R2      GOT A DELIMITER
GETGHST1 EQU      %
         STB,R10  R0,R3             BUILD GHOST NAME IN R0, R1
         STB,R3   R0                COUNT OF GHOST NAME
         CI,R3    8
         BL       GETGHOST
         B        ERROR             GHOST NAME TOO LONG
1STDLIM  EQU      %
         B        BLANKDLM
         B        GETACCT           . => ACCOUNT SPECIFIED
         B        GETPRIO           ( => PRIORITY SPECIFIED
         B        ERROR             ) => SYNTAX ERROR
*
GETACCT  EQU      %
         LI,R4    -8                ACCOUNT INDEX
         AI,R3    1                 BUMP BUFFER POINTER
         LB,R10   BUFFER,R3         GET NEXT CHARACTER
         BAL,R5   CHKDLIM
         BNEZ     ERROR             2 DELIMITERS IN A ROW
         B        GETACCT2
GETACCT1 EQU      %
         AI,R3    1                 BUMP PAST THE DELIMITER
         LB,R10   BUFFER,R3
         BAL,R5   CHKDLIM
         BNEZ     2NDLIM-1,R2       GOT A DELIMITER
GETACCT2 EQU      %
         STB,R10  R10,R4            NEGATIVE INDEXING INTO R8,R9
         BIR,R4   GETACCT1
         AI,R3    1
         LB,R10   BUFFER,R3
         BAL,R5   CHKDLIM
         BEZ      ERROR             ACCOUNT TOO LONG
         B        2NDLIM-1,R2       CHECK THE DELIMITER
2NDLIM   EQU      %
         B        BLANKDLM
         B        ERROR             SECOND . ENCOUNTERED
         B        GETPRIO           ( => PRIORITY SPECIFIED
         B        ERROR             ) => SYNTAX ERROR
GETPRIO  EQU      %
         LI,R4    -2
         LI,R12   0
         AI,R3    1
         LB,R10   BUFFER,R3
         BAL,R5   CHKDLIM
         BNEZ     ERROR             2 DELIMITERS IN A ROW
         B        GETPRIO2
GETPRIO1 EQU      %
         AI,R3    1
         LB,R10   BUFFER,R3
         BAL,R5   CHKDLIM
         BNEZ     ERROR             MUST HAVE TWO CHARACTERS
GETPRIO2 EQU      %
         LI,R7    15
         CB,R10   HEX,R7            CONVERT EBCDIC TO HEX
         BE       %+2
         BDR,R7   %-2
         STB,R7   R13,R4            NEGATIVE INDEXING INTO R12
         BIR,R4   GETPRIO1
         AI,R3    1
         LB,R10   BUFFER,R3
         CI,R10   ')'               TAIL END DELIMITER
         BNEZ     ERROR
         SLD,R12  -8
         SLS,R13  4
         SLD,R12  4                 SET UP PRIO AS ONE BYTE
         CI,R12   X'C0'
         BL       ERROR
         CI,R12   X'FF'
         BG       ERROR
         LW,R15   R12
BLANKDLM EQU      %
         CI,R10   ' '               BLANK MEANS COUNT IS ONE HIGH
         BNE      %+2
         AI,R3    -1
         CB,R3    BUFFER            IS THIS THE ENTIRE RECORD?
         BNEZ     ERROR             NO, RECORD IS TOO LONG
         MTB,0    R8
         BNEZ     %+2
         LD,R8    SYSACCT           PICK UP :SYS AS ACCT IF NONE THERE
         BAL,R10  T:GJOB
         BCS,6    GOOSE1            GHOST ALREADY IN TABLES
         BCR,8    GOOSE1            NEW GHOST STARTED
*
*        FALL THROUGH => GHOST TABLE SLOTS OR USER TABLES FULL
*
         LI,R2    SLOTFULL          TELL THE OPERATOR
*
*O*      MESSAGE: GHOST OR USER TABLES FULL...UNABLE TO START GHOSTS:
*O*               A LIST OF GHOSTS WHICH CANNOT BE STARTED FOLLOWS.
*O*      ACTION:  NONE.  MESSAGE FOR INFORMATION ONLY.
*O*      MEANING: THE NUMBER OF GHOST USERS NEEDS TO BE INCREASED THE
*O*               NEXT TIME A SYSTEM IS GENERATED.
*
         CAL1,2   TYPE
         LI,R2    BUFFER
         CAL1,2   TYPE
         BAL,R6   READFILE
         B        %-3
*
CHKDLIM  EQU      %
         LI,R2    4
         CB,R10   DELIMS,R2
         BE       %+2
         BDR,R2   %-2
         CI,R2    0                 SET CONDITION CODES FOR DELIMITERS
         B        0,R5               AND EXIT
*
DELIMS   TEXT     '  .()'           NULL,BLANK,PERIOD,OPAREN,CPAREN
HEX      TEXT     '0123456789ABCDEF'
*
ERROR    EQU      %
         MTB,1    BUFFER            BUMP COUNT ONE FOR ? ERROR
         LI,R5    '?'               QUESTION MARK FOR ERROR MESSAGE
         LB,R4    BUFFER
         STB,R5   BUFFER,R4
         LI,R2    BUFFER
         CAL1,2   TYPE              TELL THE OPERATOR THE BAD GUY
         B        GOOSE1             AND GO TO THE NEXT ENTRY
         PAGE
OPNERR   EQU      %
         LB,R4    R10
         CI,R4    3                 FILE DOES NOT EXIST
         BE       DONE
         CI,R4    10
         BE       *R8               IGNORE CLOSE OF CLOSED DCB
         CAL1,3   SNAP
DONE     EQU      %
         CAL1,1   CLSGHOST          CLOSE AND SAVE THE FILE
         CAL1,9   1
         SPACE    5
READERR  EQU      %
         LB,R4    R10
         CI,R4    5
         BE       DONE
         CI,R4    6
         BE       DONE
         CAL1,3   SNAP
         B        DONE
BADMNSTK EQU      %
         LI,R2    BADSTK
*
*O*      MESSAGE: GOOSE LOADED WITH WRONG MONSTK...MUST RELOAD
*O*      ACTION:  NONE.  MESSAGE FOR INFORMATION ONLY
*O*      MEANING: THIS VERSION OF GOOSE WAS LOADED WITH INVALID
*O*               MONITOR REFERENCES.  IT MUST BE RELOADED.
*
         CAL1,2   TYPE
         B        DONE
         PAGE
         BOUND    8
0BLANK   DATA     X'404040'
         TEXT     '    '
BLBUF    DATA     X'40'
         GEN,8,24 80,BA(BUFFER)
         SPACE    2
OPNGHOST GEN,8,24 X'14',M:EI
         DATA     X'F7400009'
         DATA     OPNERR
         DATA     OPNERR
         DATA     BUFFER
         DATA     80
         DATA     1,1,1,2           CONSEC,SEQUEN,IN,SAVE
         DATA     X'01010202'
         TEXTC    'M:GHOST'
         SPACE    2
READGHST GEN,8,24 X'10',M:EI
         DATA     X'F4000000'
         DATA     READERR
         DATA     READERR
         DATA     BUFFER
         DATA     80
         DATA     1                 BTD INTO BUFFER
         SPACE    2
CLSGHOST GEN,8,24 X'15',M:EI
         PZE      *0
         DATA     2
         SPACE    2
SYS      GEN,8,24 8,0
         SPACE    2
TYPE     GEN,8,24 2,0
         PZE      *0
         PZE      *R2
         SPACE    2
PRINT    GEN,8,24 1,0
         PZE      *0
         DATA     BUFFER
SNAP     DATA     0
         TEXT     'GOOSDOWN'
         DATA     BUFFER
         DATA     GOOSE
         NOP
         B        DONE
         SPACE    2
BADSTK   TEXTC    'GOOSE LOADED WITH WRONG MONSTK...MUST RELOAD'
SLOTFULL TEXTC    'GHOST OR USER TABLES FULL...UNABLE TO START GHOSTS:'
         END      GOOSE

