***********************************************************************
*M*      GHOST    TO DECODE :GHOST CC AND BUILD EDIT-TYPE M:GHOST FILE
***********************************************************************
*
         SYSTEM   SIG7FDP
         SYSTEM   BPM
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
         REF      P2ABRT,P2ERR
         REF      M:TM
         REF      PRNTP2SI
         REF      LOGIT
         REF      READSTRG
         REF      SYNTAX,COREALLOC,MODGEN,WRITELM
         REF      FETCHBUF
         REF      GETPGPTR
         REF      GETPGS
         DEF      GHOST
DYN      CNAME
         PROC
LF       EQU      %-DYNAM
         GEN,1,15,16  AF(1),AF(2),AF(3)
         PEND
FOP      CNAME
         PROC
         GEN,1,7,8    AF(1),AF(2),AF(3)
         PEND
         PAGE
*
*        CARD FORMAT AND KEYWORD
*
KWDTBLO  EQU      %
         DATA     KWDTBL
         FOP      0,0,3             0    FIND '('
         FOP      0,9,11            1    NXT STRING MUST BE ALPHA-NUM
         FOP      0,1,19            2    STOR IF SO IN D.W. TABLE
         FOP      0,15,6            3    SEARCH FOR COMMA
         FOP      0,11,11           4    NXT STTRING MUST BE ALPHA-NUM
         FOP      0,1,19            5    STOR IF SO IN D.W. TABLE
         FOP      0,17,6            6    LOOK FOR COMMA
         FOP      0,17,11           7    NXT STRING MUST BE ALPHA-NUM
         FOP      0,1,18            8    STOR IN WD TBL AT 1,R5
         FOP      1,0,8             9    LOOK FOR ),( STRING
         FOP      0,1,1             10   GO TO 1
         FOP      0,15,6            11   LOOK FOR COMMA
         FOP      0,1,21            12   INCREMENT TBL PTR BY 1
         FOP      0,1,21            13   INCREMENT TBL PTR BY 1
         FOP      0,7,1             14   GO TO 7
         FOP      0,1,21            15   INCREMENT TBL PTR BY 1
         FOP      0,1,21            16   INCR TBL PTR BY 1
         FOP      0,1,21            17   INCR. TBL PTR BY 1
         FOP      0,9,1             18   GO TO 9
         FOP      0,0,0             19   ROUND OFF TO WORD BOUNDARY
KWDTBL   EQU      %-KWDTBLO
         DATA     0                 NO DEFAULTS
KWDPTR   GEN,15,17  0,KWDTBLO
*
*  SKELETON DYNAMIC DATA FOR SYNTAX
*
DYNAM    EQU      %
GNAMTOP  DATA     0
GNAMPTR  DATA     0
#DYNAM   EQU      %-DYNAM
         PAGE
*
*        OTHER    DATA
*
PRIERR#  DATA     0
         BOUND    8
PRIOLIM  DATA     X'C3F0'           LOWER PRIORITY LIMIT =  C0
         DATA     X'C6C5'           UPPER PRIORITY LIMIT =  FE
GHOSTNM  TEXT     'GHOS'
STOFCC   DATA     0
X1FF     DATA     X'1FF'
EDITKEY  DATA     X'03000000'
BUF      DO1      20
         TEXT     '    '
         PAGE
GHOST    LW,R1    FETCHBUF,R3       SEE IF THERE IS AN ACTUAL COMMAND
         CW,R1    GHOSTNM
         BNE      READSTRG
         LI,R2    GETPGPTR+1        GET 1 PAGE FOR PROCESSING GHOST CC
         BAL,R1   GETPGS
         LW,SR2   GETPGPTR,R3       ADDRESS OF END OF PAGE
         STW,SR2  DYNAM             STORE IT IN TABLE FOR USE BY SYNTAX
         EOR,SR2  X1FF              CALCULATE START OF PAGE
         STW,SR2  DYNAM+1
         STW,SR2  STOFCC            SAVE START OF DYNAM AREA
         LI,R2    DYNAM
         LI,R1    #DYNAM
         LW,R4    KWDPTR
         BAL,SR4  SYNTAX
         AI,R5    1
         M:OPEN   M:TM,(ERR,ERR),(ABN,ABN),(FILE,'M:GHOST'),;
                  (DIRECT),(OUT),(SAVE),(KEYED)
*                                   NAME AND ACCOUNT ENTRIES
         LW,R1    STOFCC            R1 POINTS TO THE CURRENT ENTRY IN
*                                   IN THE DYNAMIC AREA
MUVENTRY LI,R6    0                 R6 CONTROLS STORING INTO THE BUFFER
         LI,R2    1000              EDIT KEY ADDEND TO PRODUCE 1.0 LINE
         AWM,R2   EDITKEY
         LI,R2    0                 R2 CONTROLS NAME/ACCT/PRIOR POSITIONING
MAINLOOP LI,R7    0                 R7 USED TO CHK FOR 1ST BLANK IN
GETBYTE  LB,R4    *R1,R7            GET CURRENT BYTE IN NAME OR ACCT
         CI,R4    ' '               ENTRY AND CHK FOR 1ST BLANK
         BE       ACCTCHK
         STB,R4   BUF,R6            OTHERWISE STORE IT IN BUFFER
         AI,R7    1
         AI,R6    1
         B        GETBYTE
ACCTCHK  AI,R2    1
         CI,R2    2                 IF IT'S 2, IT IS A PRIOR ENTRY
         BE       PRIOR
         MTW,2    R1                MOVE PTR TO ACCT ENTRY
         LW,R4    *R1               SEE IF ANY SPECIFIED
         BEZ      PRIOR             BRANCH IF NOT
         LI,R4    '.'               NEED TO INSERT PERIOD BETWEEN
         STB,R4   BUF,R6            FILE NAME AND ACCT #
         AI,R6    1
         B        MAINLOOP
PRIOR    MTW,2    R1                MOVE PTR TO PRIORITY ENTRY
         LW,SR2   *R1               CHECK IF THERE IS ANY PRIORITY
         BEZ      WRITIT            OTHERWISE FINISHED WITH RECORD
         LI,SR1   '('               NEED TO INSERT LEFT PAREN
         STB,SR1  BUF,R6
         SLS,SR2  -16               MOVE PRIORITY INTO POSITION
         CLM,SR2  PRIOLIM
         BCS,9    ERRPRIO
STORPRIO EQU      %
         AI,R6    2
         STB,SR2  BUF,R6
         AI,R6    -1
         SLS,SR2  -8
         STB,SR2  BUF,R6
         AI,R6    2
         AI,SR1   X'10'             CONVERT LEFT PAREN TO RIGHT PAREN
         STB,SR1  BUF,R6
WRITIT   MTW,1    R1
         M:WRITE  M:TM,(ERR,ERR),(ABN,ABN),(BUF,BUF),(SIZE,80),;
                       (KEY,EDITKEY),(ONEWKEY)
         CW,R1    *R5               CHECK FOR ALL THRU
         BGE      CLOSE
BLANKBUF STD,R0   SR1               SAVE R0
         LI,R1    0
         LI,R0    X'4050'          BLANK TO BE MOVED AND SIZE OF MOVE
         SLD,R0   -8
         AI,R1    BA(BUF)
         SCS,R0   -8                POSITION BLANK
         MBS,0    0                 MOVE THE BLANK INTO 80 BUFFER CHAR
         LD,R0    SR1               RESTORE REGISTER R0 AND R1
         B        MUVENTRY
ERRPRIO  MTW,0    PRIERR#
         BNEZ     GETDEFLT
         MTW,1    PRIERR#
         LI,D3    ERRPMSG
         BAL,SR4  LOGIT
GETDEFLT LW,SR2   PRIOLIM
         B        STORPRIO
CLOSE    LW,R1    M:TM
         CW,R1    =X'200000'
         BAZ      %+2
         M:CLOSE  M:TM,(SAVE)
         LW,1     =X'9000001'
         CAL1,8   1
         B        READSTRG
ERR      EQU      %
ABN      EQU      %
         LB,SR1   SR3
         SLD,SR1  -4
         SCS,SR2  4
         LI,SR4   CONVNO1
CONVIOER CI,SR1   10
         BL       CONVNO
         AI,SR1   X'B7'             CONVERT CHARACTER TO EBCDIC
         B        *SR4
CONVNO   AI,SR1   X'F0'             CONVERT TO EBCDIC NUMBER
         B        *SR4
CONVNO1  XW,SR1   SR2
         BAL,SR4  CONVIOER
         LI,R1    2
         STB,SR2  ERRMSG+3,R1
         LI,R1    1
         STB,SR2  ERRMSG+3,R1
         LI,D3    ERRMSG
         BAL,SR4  LOGIT
         B        CLOSE
ERRMSG   TEXTC    '****I/O ERR    WHILE WRITING M:GHOST FILE'
ERRPMSG  TEXTC    '***** PRIORITY VALUES MUST LIE BETWEEN C0 AND',;
                  ' FE. VALUES OUTSIDE THE RANGE ARE DEAULTED TO C0'
PATCH    RES      50
         END

