         PAGE
R0       EQU      0
R1       EQU      1
VERSION EQU       2                 1=BPM, 2=UTS
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    'COPYTO'
COPYTO   DSECT    1
PLSECT   CSECT    1
         SYSTEM   SIG7
*
* COPYTO          -COPY- AND -TO- COMMAND EXECUTIVE
*
* INPUT
*        D1       COMMAND ACTION CODE
*        D2       MAXIMUM ERROR SEVERITY
*        CMBX     COMMAND BUFFER INDEX OF NEXT ARGUMENT
*        PREVACT  PREVIOUS COMMAND ACTION CODE
*        TERM     TERMINATOR OF LAST ARGUMENT TRANSLATED
* OUTPUT
*        INSWT    FIRST INPUT FILE SWITCH
*        TOSWT    DEFINED -TO- SWITCH
*
         REF      COPYTRAN,TRANSACT,BLDCB,ERROR
         REF      REVARG,RELPAGES,RDWRT
         REF      CLOSEI,CLOSEO
         REF      CMBX,INSWT,PREVACT
         REF      TERM,TOSWT
         REF      TOVER
         REF      BREAK
         REF      FILE
         REF      DEVICE
         REF      M:EI
         DO1      VERSION=2
         REF      FPTPROMT
         DEF      COPYSF
         DEF      COPYSF2
         REF      PRNTBUF
         REF      MAXCMBX
         REF      CLRARG
         REF      J:JIT,TOARG
         REF      M:UC
         REF      COPYSTDF
         REF      ALL8,ALL9
         REF      SFCNT
         REF      IOERR
         REF      FILTRAN
         REF      DEV%IN
*
         USECT    COPYTO
         LCI      7                 SAVE REGISTERS
         PSM,R5   *R7
*
         LI,R6    0                 INITIALIZE COUNT AT 1ST  ACTION VERB
         LI,SR1   0                 CLEAR 'TO' CMBX
         LI,SR2   0                 CLEAR 'COPY' CMBX
*
SCAN1    CI,D1    2                 COPY COMMAND
         BE       SCAN2             YES
         LW,SR1   CMBX,R7           SAVE CMBX OF -TO- DEVICE
         LI,R1    0                 CLEAR DEFINED -TO- SWITCH
         STW,R1   TOSWT,R7
         STW,R1   INSWT,R7          CLEAR FIRST INPUT FILE SWITCH
         B        SCAN3
*
SCAN2    LW,SR2   CMBX,R7           SAVE CMBX OF FIRST -COPY- DEVICE
*
SCAN3    LI,R1    1                 SET ARG. LEVEL TO DEVICE
SCAN4    BAL,SR4  COPYTRAN          TRANSLATE DEVICE/FILE
*
         CI,D2    3                 TEST ERROR SEVERITY
         BE       RETURN
*
         LW,R4    TERM,R7
         CI,D1    2                 -COPY- COMMAND
         BNE      SCANEND           NO
         CI,R1    0                 ANOTHER DEVICE/FILE FOLLOW
         BNE      SCAN4             YES
*
SCANEND  CI,R4    X'15'             END OF COMMAND
         BE       TO1               YES-END OF COMMAND
         CI,R4    X'40'             BLANK TERMINATOR
         BE       NXCMD1            YES-END OF INPUT OR OUTPUT
ERR17    EQU      %
         LI,R1    17                ERROR 17
         BAL,SR4  ERROR
         B        RETURN
*
NXCMD1   CI,R6    0                 EDIT NUMBER OF ACTION VERBS
         BNE      ERR17
NXCMD2   LI,R6    1                 SET SECOND ACTION VERB
         BAL,SR4  TRANSACT          TRANLATE SECOND COMMAND ACTION VERB
         LW,R2    D1                NO SUCH VERB
         BEZ      ERR32             YES
         AW,R2    PREVACT,R7        COPY-TO
         CI,R2    3
         BE       SCAN1             YES
         CI,R2    14                COPY-OVER
         BE       SCAN1             YES
ERR32    LI,R1    32                ERROR 32
         BAL,SR4  ERROR
         B        RETURN
         PAGE
TO1      CI,D2    1                 TEST ERROR SEVERITY
         BG       RETURN
         STW,D1   TOVER,R7          SAVE TO OR OVER OUTPUT ACTION VERB
         CI,SR1   0                 -TO- COMMAND PRESENT
         BE       COPY1             NO-JUST COPY
*
         STW,SR1  CMBX,R7           TRANSLATE OUTPUT DEVICE/FILE
         LI,D1    1                 SET AT -TO- VERB(FOR COMBINE)
         LI,R1    1                 SET AT DEVICE
         BAL,SR4  COPYTRAN          GO-TRANSLATE -TO- DEVICE
TO11     EQU      %
         LI,R1    1                 SET DEFINED -TO- SWITCH
         STW,R1   TOSWT,R7
         STW,R1   INSWT,R7          SET NEW OUTPUT FILE
*
         BAL,SR4  REVARG            SAVE -TO- ARGUMENT TABLE
*
COPY1    CI,SR2   0                 -COPY- COMMAND
         BE       RETURN            NO-JUST -TO- COMMAND
         STW,R0   2,R7              RESET HEADER PRINTED FLAG
         LW,R2    TOSWT,R7          TEST FOR DEFINED -TO-
         BNEZ     COPY2
         LI,R1    20
         MTW,0    J:JIT
         BGEZ     ERR32+1           ERROR IF BATCH MODE
         BAL,SR4  CLRARG            NO DEFINED OUTPUT
         LI,R1    8                 SET DEVICE CODE FOR 'ME'
         STW,R1   DEVICE,R7
         B        TO11
COPYSF   LCI      7                 ENTRY FOR STD FILE COPY
         PSM,R5   *R7
         LI,SR2   PRNTBUF+PRNTBUF+PRNTBUF+PRNTBUF+80
         STW,SR2  MAXCMBX,R7        SET SCAN LIMIT
         LI,SR2   PRNTBUF+PRNTBUF+PRNTBUF+PRNTBUF+1
COPY2    LI,D1    2                 SET AT COPY VERB(FOR COMBINE)
         LI,R1    1                 SET AT DEVICE
COPY3    STW,SR2  CMBX,R7           CMBX OF CURRENT INPUT DEVICE/FILE
         BAL,SR4  COPYTRAN          GO-TRANSLATE CURRENT INPUT DEV/FILE
         LW,R5    R1                SAVE NEXT ARG LEVEL 1-DEV,2-FILE,0--
         LW,R1    DEVICE,R7
         BNEZ     %+2          PCL DEVICE.
         LW,R1    DEV%IN,R7    SYSTEM INPUT DEVICE.
         CI,R1    7                 IS DEVICE ANS TAPE
         BE       COPY9-1           YES
*
         LI,R1    2                 SET FPARAM BIT FOR BLDCB
         MTW,0    FILE,R7           INPUT FILE TYPE
         BNEZ     COPY9             YES
         MTW,0    COPYSTDF,R7
         BNEZ     COPYSF3           COPYSTD COPY
         LI,R1    0
COPY9    LW,SR2   CMBX,R7           SAVE CMBX OF NEXT INPUT DEV/FILE
         BAL,SR4  BLDCB
         CI,D2    3
         BE       COPYEND           DONT CONTINUE IF SEVERITY 3 ERROR
         LW,R1    INSWT,R7          NEW OUTPUT FILE
         BNEZ     COPY7             YES
         MTW,0    COPYSTDF,R7
         BEZ      COPY4             NOT STANDARD FILE COPY
COPY7    STW,R0   INSWT,R7          CLEAR NEW OUTPUT FILE
*
         BAL,SR4  REVARG            BRING UP -TO- ARGUMENTS
*
         LI,R1    1                 BUILD OUTPUT DCB
         BAL,SR4  BLDCB
         BAL,SR4  REVARG            BRING BACK COPY ARGUMENTS
         CI,D2    1                 TEST ERROR SEVERITY
         BG       COPYEND
COPY4    EQU      %
         MTW,0    COPYSTDF,R7
         BNEZ     COPY8             COPYSTD COMMAND
         MTW,0    J:JIT
         BGEZ     COPY6             BATCH MODE
         DO       VERSION=2
         LI,R6    8
         CW,R6    DEVICE,R7         INPUT FROM TERMINAL
         BE       COPY5             YES
         CW,R6    TOARG,R7          OUTPUT TO TERMINAL
         BE       COPY6             YES
         MTW,0    2,R7              HAS MESSAGE BEEN PRINTED
         BNEZ     COPY6             YES - SKIP
         CAL1,1   WRTCOPY           WRITE '..COPYING'
         MTW,1    2,R7              SET FLAG MESSAGE PRINTED
         B        COPY6
         FIN
COPY8    LW,R6    TOARG,R7
         CI,R6    8                 IS OUTPUT TO TERMINAL
         BE       %+3               YES
         CI,R6    9                 TO PRINTER
         BNE      COPY6             NO
         LI,R6    COPY6             RETURN ADDR
         B        ALL8              GO PRINT FILE NAME
COPY5    EQU      %
         DO1      VERSION=2
         CAL1,1   FPTPRMT           SET PROMPT CHAR TO '.'
COPY6    BAL,SR4  RDWRT             COPY M:EI TO M:EO
         DO       VERSION=2
         LW,R6    DEVICE,R7
         CI,R6    8                 TERMINAL INPUT
         BNE      COPYEND           NO
         CAL1,1   FPTPROMT          RESET PROMPT CHAR TO '<'
         FIN
*
COPYEND  EQU      %
*
         BAL,SR4  CLOSEI            CLOSE CURRENT INPUT FILE
         DO1      VERSION=2
         CAL1,1   OPENPR            REMOVE PASSWORD
*
         CI,D2    1                 TEST ERROR SEVERITY
         BG       RETURN2
         MTW,0    COPYSTDF,R7       IS THIS A STANDARD FILE COPY
         BEZ      %+3               NO
         BAL,SR4  CLOSEO            CLOSE OUTPUT
         MTW,1    SFCNT             INC STD FILE COUNT
*
COPYSF2  EQU      %
         MTW,0    BREAK             BREAK SET
         BNEZ     RETURN            YES
         CI,R5    0                 ANOTHER DEVICE/FILE
         BEZ      RETURN            NO-RETURN
         LW,R1    R5                YES-SET 1-DEVICE, 2-FILE
         B        COPY3             GO PROCESS IT
*
RETURN   BAL,SR4  RELPAGES          GO-RELEASE EXCESS RD/WR BUFFER SPACE
         BAL,SR4  CLOSEO            GO CLOSE OUTPUT
*
         LCI      7                 RESTORE REGISTERS
         PLM,R5   *R7
         B        *SR4
*
RETURN2  MTW,0    COPYSTDF,R7
         BEZ      RETURN            NOT COPYSTD
         LW,SR3   IOERR,R7
         LB,R1    SR3               GET ERR OR ABN CODE
         CI,R1    3                 FILE NOT EXISTENT
         BE       %+3               YES
         CI,R1    X'14'             ACCESS PROBLEM
         BNE      RETURN            NO - SOME OTHER ERROR
         LI,D2    0                 ZERO ERROR FLAGS
         STW,R0   IOERR,R7
         LI,R1    TXCNTF
         LB,R2    TXCNTF
         B        ALL9              GO PRINT FILE NAME
COPYSF3  STW,SR2  CMBX,R7           BACK UP TO DEVICE CODE
         LI,R1    3
         STW,R1   DEVICE,R7         SET CODE FOR DC
         BAL,SR4  FILTRAN           TREAT DEV CODE AS FILE NAME
         LI,R1    2
         B        COPY9
TXCNTF   TEXTC    'CAN NOT FIND OR ACCESS FILE
'
         DO       VERSION=2
         USECT    PLSECT
FPTPRMT  GEN,8,16,8      X'2C',0,'.'
OPENPR   GEN,8,24 X'14',M:EI
         DATA     X'E000'
         DATA     0
         DATA     X'03010002'
         DATA     0,0
WRTCOPY  GEN,8,24 X'11',M:UC
         DATA     X'34000000'
         DATA     COPYMSG
         DATA     10
         DATA     0
COPYMSG  TEXT     '..COPYING
'
         USECT    COPYTO
         FIN
         END

