         PAGE
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
         TITLE    'GETARG'
GETARG   DSECT    1
         SYSTEM   SIG7
* GET ARGUMENT
*
* INPUT
*
*        CMBX     COMMAND BUFFER INDEX FOR CURRENT ARGUMENT
*        MAXCMBX  MAXIMUM COMMAND BUFFER INDEX
*
* OUTPUT
*
*        CMBX     COMMAND BUFFER INDEX FOR NEXT ARGUMENT
*        ARGBUFF  ARGUMENT BUFFER
*        TERM     TERMINATION CHARACTER
*        NCHAR    NUMBER OF CHARACTERS IN ARGUMENT BUFFER
*
*
         REF      CMBX,MAXCMBX,ARGBUFF,TERM,NCHAR
         REF      ARGBUF4,ERROR
         REF      #DELIM
         REF      DEVICE
         REF      DEL%CT
*
         USECT    GETARG
         LCI      7                 SAVE REGISTERS
         PSM,R5   *R7
*
         LW,R6    CMBX,R7           GET COMMAND BUFFER INDEX
         LI,R5    ARGBUF4+1         INITIALIZE -ARGBUF- INDEX
         LI,SR1   0                 TURN OFF BLANK DELIMITER SWITCH
         LI,SR2   0                 TURN OFF IGNORE CHARACTER SWITCH
         LI,SR3   0                 TURN OFF CHAR STRING IND
         LI,R1    16                CLEAR ARGUMENT BUFFER
         LW,R2    =C'    '
         LI,R3    ARGBUFF-1
         AW,R3    R7
         STW,R2   *R3,R1
         BDR,R1   %-1
         LW,D4    #DELIM,R7         GET DELIM FLAG
         LI,D3    ARGBUF4+32
*
P5       CW,R6    MAXCMBX,R7        TEST FOR MAXIMUM COMMAND INDEX
         BL       P10
P7       EQU      %
         LI,R4    X'15'             SET END OF COMMAND
         B        RETURN2
*
P10      LB,R4    *R7,R6            GET NEXT CHARACTER
         AI,R6    1                 INCREMENT COMMAND BUFFER INDEX
         CI,D4    17                ARE WE SCANNING A CHAR STRING
         BE       P15               YES - SKIP BLANK TESTING
         CI,R4    X'15'
         BE       RETURN2           STOP ON CR IN BATCH
         CI,R4    X'0D'
         BE       P7
*
         CI,R4    X'40'             TEST FOR BLANK
         BNE      P11          SIGNIFICANT CHARACTER.
         CI,D1    3            CHECK FOR DELETE COMMAND.
         BNE      P12          NOT DELETE.
         MTW,1    DEL%CT,R7    UPDATE DELETE BLANK COUNT.
         B        P12
P11      EQU      %
         CI,D1    3            CHECK IF DELETE COMMAND.
         BNE      P11A         NO
         LW,R1    DEL%CT,R7    CHECK DELETE COMMAND FOR BLANKS.
         CI,R1    1
         BLE      P11A
         LI,R1    17
         BAL,SR4  ERROR
         LI,R1    0
         STW,R1   DEL%CT,R7
         B        RETURN
P11A     EQU      %
         CI,R4    X'05'             TEST FOR TAB CHARACTER
         BNE      P15
         LI,R4    X'40'             CHANGE TAB TO BLANK
P12      EQU      %
         CI,SR1   0                 TEST BLANK DELIMITER SWITCH
         BE       P5
         LI,SR1   0                 TURN OFF BLANK DELIMITER SWITCH
         LI,SR2   1                 TURN ON IGNORE CHARACTER SWITCH
         B        P5
*
P15      LW,R2    R4                GET DELIMITER FLAG FOR CHARACTER
         LI,R3    0
         SLD,R2   -5
         SLS,R3   -27
         AW,R2    D4                SELECT DELIMITER TABLE
         LW,R1    DELIMIT,R2
         SLS,R1   0,R3
         CI,R1    0                 TEST FOR DELIMITER
         BL       RETURN
P17      EQU      %
         CI,SR2   0                 TEST IGNORE CHARACTER SWITCH
         BE       P20
         LI,R4    X'40'             SET DELIMITER TO BLANK
         AI,R6    -1                DECREMENT COMMAND BUFFER INDEX
         B        RETURN2
*
P20      CW,R5    D3                TEST FOR MAXIMUM ARGUMENT LENGTH
         BL       P25
         BG       P25+1             ERROR ALREADY REPORTED
         STW,R6   CMBX,R7           UPDATE CMBX FOR ERROR MESSAGE
         LI,R1    1                 SET ERROR FLAG (ERROR 01)
         BAL,SR4  ERROR             ERROR 01
         B        P25+1
*
P25      STB,R4   *R7,R5            PACK CHARACTER IN ARGUMENT BUFFER
         AI,R5    1                 INCREMENT CHARACTER COUNT
         LI,SR1   1
         B        P5
*
RETURN   LW,R1    #DELIM,R7
         CI,R1    12                ARE WE SCANNING A FID
         BNE      RETURN2           NO
         CI,R4    X'7D'             IS DELIM A QUOTE
         BNE      RETURN2           NO
         CI,R5    ARGBUF4+1         HAVE WE STORED A CHARACTER
         BNE      RETURN3           YES
         CI,D4    17                ARE WE PAST INITIAL QUOTE
         BE       RETURN4           YES
         LI,D4    17                SET DELIM MODE TO SCAN FOR QUOTES
         STB,D4   SR3               INDICATE CHAR STRING
         B        P5
RETURN3  CI,D4    17                ARE WE SCANNING '--'
         BE       RETURN4           YES
         BG       RETURN5           END OF HEX STRING
         CI,R5    ARGBUF4+2         IS 2ND CHAR A QUOTE
         BNE      P17               NO
         LI,R1    ARGBUF4+1
         LB,R1    *R7,R1            GET FIRST CHAR
         CI,R1    X'E7'             IS IT AN X
         BNE      RETURN5           NO
         LI,D4    22                SET DELIM MODE FOR HEX SCAN
         LI,D3    ARGBUF4+64        SET MAX ARGUMENT LENGTH
         B        P17
RETURN5  LI,D4    0                 NOT CHAR STRING OR HEX
         B        P17
RETURN4  CW,R6    MAXCMBX,R7        TEST FOR END OF COMMAND
         BL       %+3               NO
         LI,R4    X'15'             SET TERMINATOR
         B        RETURN2
         LB,R4    *R7,R6
         AI,R6    1
         CI,R4    X'7D'             IS DOUBLE QUOTE IN CHAR STRING
         BE       P17               YES - STORE AND CONTINUE
         AI,R6    -1
         LI,D4    0                 END OF CHAR STRING
         LW,R2    DEVICE,R7
         CI,R2    7                 IS DEVICE ANS TAPE
         BNE      P5                NO
         LI,D4    6                 SET # DELIM MODE
         B        P5                GO SCAN FOR DELIMITER
RETURN2  STW,R4   TERM,R7           SAVE DELIMITER
         STW,R6   CMBX,R7           SAVE COMMAND BUFFER INDEX
         AI,R5    -ARGBUF4-1        SAVE CHARACTER COUNT
         STW,R5   NCHAR,R7
         LI,R1    ARGBUF4
         STB,R5   *R7,R1
         LW,D3    SR3               SAVE CHAR STRING IND
         LCI      7                 RESTORE REGISTERS
         PLM,R5   *R7
         LC       D3                INDICATE IF CHAR STRING
         B        *SR4
*                   BLANK .(  );    / ,   #
DELIMIT  DATA     0,0,X'80140006',X'40100000',0,0,0,0
         DATA     X'80140006',X'C0100014',0,0,0,0
         DATA         X'80140006',X'40100004',0,0,0,0
         DATA     X'00000004',0,0,0,0
         DATA     X'00000004',0,0,0,0
         END
