*COMDECK COMCKER
CC    COMCKER - KERMIT SYMBOL DEFINITIONS.
C 
C     THIS COMDECK CONTAINS ALL SYMBOL DEFINITIONS NEEDED BY KERMIT.  IT
C     CONTAINS ITEMS FOUND IN SEVERAL DIFFERENT AREAS IN THE TEXAS
C     VERSION OF KERMIT, AND CLEANS UP USAGE CONFLICTS AMONG THE VARIOUS
C     PARAMETER VALUES.  THIS COMDECK SHOULD BE *CALLED INTO EVERY
C     KERMIT MODULE.
C 
      IMPLICIT INTEGER (A - Z)
  
CC    KERMIT SITE DEFINITIONS.
C 
C     CHARACTER SET INFORMATION.
C 
C     IPC641 = IP.C64.1 (FROM IPTEXT).
C     IPC642 = IP.C64.2 (FROM IPTEXT).
C     IPC63 = IP.C63 (FROM IPTEXT). 
C     IPCSET = IP.CSET = CHARACTER SET IN USE AT YOUR SITE. 
C     N.B.  IPCSET IS IGNORED IF UT2D = 1.
C 
      PARAMETER (IPC641=0, IPC642=1, IPC63=2) 
      PARAMETER (IPCSET=IPC63)
  
CC    O.S. DEFINITIONS.  SET YOUR O.S. TO 1, ALL OTHERS TO 0. 
C 
      PARAMETER (UT2D=1, NOS=0, NOSBE=0, SCOPE=0) 
  
CC    SITE DEFINITIONS.  USED FOR SITES WITH NON-STANDARD OPSYS.
C 
      PARAMETER (UTEXAS=1, UARIZ=0) 
  
CC    FILE I/O DEFINITIONS. 
C 
      PARAMETER (STDIN=1, STDOUT=2) 
  
CC    ASCII CHARACTER DEFINITIONS.
C 
      PARAMETER (SOH=1, TAB=9, LF=10, CR=13, BLANK=32, MINUS=45)
      PARAMETER (QMARK=63, DEL=127, NEL=O"0205", NULL=O"4000", EOF=-1)
  
CC    MISCELLANEOUS.
C 
      PARAMETER (OK=1, ERROR=-2, ON=1, OFF=0, YES=1, NO=0)
  
CC    PROTOCOL DEFINITIONS. 
C 
      PARAMETER (UNKNOWN=0, FULLDUP=1, HALFDUP=2) 
      PARAMETER (NONE=0, EVEN=1, ODD=2, MARK=3, SPACE=4)
      PARAMETER (MAXINIT=20, MAXTRY=5)
      PARAMETER (MAXPACK=94, MYTIME=10, MYPAD=0, MYPADCH=0) 
      PARAMETER (MYEOL=13, MYQUOTE=35, QUOT8CH=78, MYCKTYP=49)
      PARAMETER (PREFXCH=126) 
  
CC    PACKET TYPES. 
C 
      PARAMETER (A=65, B=66, C=67, D=68, E=69, F=70, G=71, L=76, N=78)
      PARAMETER (R=82, S=83, Y=89, Z=90)
  
CC    PACKET ERROR DEFINITIONS
C 
      PARAMETER (TOOMANY=O"1000", INVALID=O"2000", SEQERR=O"4000")
      PARAMETER (LCLFILE=O"10000", NOTLCL=O"20000", INVFN=O"40000") 
      PARAMETER (SRVCMD=O"100000")
      PARAMETER (SENDING=O"100", READING=O"200")
      PARAMETER (INITERR=1, FILERR=2, DATAERR=4, EOFERR=O"10")
      PARAMETER (BRKERR=O"20")
  
  
CCCC  KERMIT SAVED COMMON BLOCK HEADER
C 
C     ALL COMMON BLOCKS TO BE SAVED WHEN EXECUTING MONITOR
C     COMMANDS MUST BE PLACED BETWEEN /HEADER/ AND /TRAILER/
C 
      COMMON /HEADER/ HEADER
  
  
CCCC  KERMIT COMMAND PROCESSOR COMMON BLOCK.
C 
      COMMON /KERMCMD/ AUTORET, DSKCSET, RDELAY 
  
  
CCCC  KERMIT PACKET DESCRIPTION COMMON BLOCK. 
C 
C     DO NOT ALLOCATE ANY STORAGE BETWEEN PACKSIZ AND SNDSYNC!
  
C     ALLOCATE STORAGE FOR WHAT I WANT. 
  
      COMMON /PACKET/ PACKSIZ, TIMEOUT, NPAD, PADCH, EOLCH, QUOTECH,
     +                QUOTE8, CHKTYP, RPREFIX, RESERVE(2), SYNC,
  
C     ALLOCATE STORAGE FOR WHAT PARTNER WANTS.
  
     +                SPKSIZ, STIMOUT, SPAD, SPADCH, SPEOL, SPQUOTE,
     +                S8QUOTE, SCHKTYP, SREPEAT, UNUSED(2), SNDSYNC 
  
  
CCCC  KERMIT PROTOCOL COMMON BLOCK. 
C 
      COMMON /PROTO/ PACKET(MAXPACK), RECPACK(MAXPACK), 
     +   FILESTR(MAXPACK),
     +   PSIZE, PACKNUM, NUMTRY, MAXRTRY, MAXRINI, STATE, IFD, OFD, FFD,
     +   DELAYFP, SAVEDPX,
  
C     STORAGE FOR STATISTICS. 
  
     +   ABORTYP, STARTIM, ENDTIM, SCHCNT, RCHCNT, SCHOVRH, RCHOVRH 
  
  
CCCC  DEBUG COMMON BLOCK. 
C 
      PARAMETER (DBGOFF=0, DBGSTAT=1, DBGPACK=2, DBGALL=3)
      COMMON /DEBUG/ DEBUG, DEBUGFD, DEBUGFN(8) 
  
  
CCCC  ASCII STRING MESSAGE COMMON BLOCK DEFINTIONS. 
C 
      INTEGER ERRMSG(MAXPACK) 
  
      COMMON /MSG/ ERRMSG 
  
  
CCCC  KERMIT SAVED COMMON BLOCK TRAILER 
C 
      COMMON /TRAILER/ TRAILER
  
  
CCCC  FILE I/O COMMON BLOCK DEFINITIONS.
C 
      PARAMETER (MAXFILE=5) 
  
C     CIO RELATED PARAMETERS. 
C 
C     CIORD = CIO READ FUNCTION CODE. 
C     CIOWT = CIO WRITE FUNCTION CODE.
C     CIOBUFL = CIO BUFFER LENGTH (MUST BE .GT. PRU SIZE OF DEVICE).
C     FETL = FET LENGTH IN WORDS. 
C     MAXWD = LINE SIZE IN WORDS; MUST BE AN EVEN NUMBER. 
C     NORMAL = FLAG TO EXITPGM THAT THIS IS A NORMAL EXIT.
  
      BOOLEAN CIORD, CIOWT
      PARAMETER (CIORD = O"10", CIOWT = O"14")
      PARAMETER (ASCIIIO = 43, NOSBIT = 42, CIOODD = O"2")
      PARAMETER (CIOBUFL=129, FETL=6, MAXWD=32) 
  
      PARAMETER (CLOSED=0, RD=1, WR=2, CREATE=3)
      PARAMETER (NOPAR=0, EVEPAR=1, ODDPAR=2, MRKPAR=3, SPCPAR=4) 
      PARAMETER (DSKDPC=0, DSKNOS8=1, DSKUT8=2, DSKIMAG=4)
      PARAMETER (DSKASCI = DSKNOS8 .OR. DSKUT8) 
  
      CHARACTER*10 FNAME(MAXFILE) 
      COMMON /FILEIOC/ FNAME
  
      BOOLEAN FCHBUF(MAXWD,MAXFILE) 
      BOOLEAN FETS(0:FETL - 1,MAXFILE), CIOBUFF(CIOBUFL,MAXFILE)
      INTEGER FMODE(MAXFILE), FNWDS(MAXFILE), FWPTR(MAXFILE), 
     +        FWSHFT(MAXFILE) 
      LOGICAL FEOF(MAXFILE), CTDEV(MAXFILE), RAWMODE, BINMODE 
      LOGICAL NORMAL
      COMMON /FILEIO/ FMODE, FWPTR, FNWDS, FEOF, FWSHFT,
     +   CTDEV, RAWMODE, BINMODE, PARITY, DUPLEX, NORMAL
      COMMON /FETCOM/ FETS, CIOBUFF, FCHBUF 
C     COMMON // CIOBUFF, FCHBUF 
  
  
CCCC  MESSAGE COMMON BLOCK. 
C 
      CHARACTER*37 VERSION
      CHARACTER*15 AMBIG
      CHARACTER*38 NOMATCH
      CHARACTER*24 FOLLOW 
      CHARACTER*53 NODIGIT
      CHARACTER*31 MISSING
      CHARACTER*33 CONFMSG
      CHARACTER*19 NOTCONF
      CHARACTER*42 HLPDLFP
      CHARACTER*37 HLPDBFN
      CHARACTER*24 HLPPLEN
      CHARACTER*34 HLPPADL
      CHARACTER*74 HLPASCH
      CHARACTER*29 HLPIPRC
      CHARACTER*21 HLPPRTR
      CHARACTER*43 HLPTIMO
      CHARACTER*19 HLPSNFN
      CHARACTER*41 HLPRDEL
  
      COMMON /MESSAGE/ VERSION, AMBIG, NOMATCH, FOLLOW, NODIGIT,
     +   MISSING, CONFMSG, NOTCONF, 
     +   HLPASCH, HLPDLFP, HLPDBFN, HLPPLEN, HLPPADL, HLPIPRC, HLPPRTR, 
     +   HLPTIMO, HLPSNFN, HLPRDEL
  
  
CCCC  CHARACTER CONVERSION TABLES.
C 
C     DPCTBL = ASCII TO DISPLAY CODE TABLE. 
C     LASCII = DISPLAY CODE TO LOWER CASE ASCII.
C     UASCII = DISPLAY CODE TO UPPER CASE ASCII.
  
      BOOLEAN DPCTBL(0:127), LASCII(0:63), UASCII(0:63) 
      COMMON /CHARCOM/ DPCTBL, LASCII, UASCII 
*COMDECK KERMCOM  SAME AS COMCKER, BUT TURNS OFF LISTING. 
C$    LIST(S=0) 
C 
C     THE FOLLOWING C$ LINES ARE HERE INSTEAD OF COMCKER BECAUSE
C     FTN5 FLAGS THEM AS ERRORS IN A BLOCK DATA MODULE (GRRRR). 
C 
C$    COLLATE(FIXED)
C$    DO(OT=0)
*CALL COMCKER 
C$    LIST(S=1) 
*DECK KERMIT
*IF DEF,OVCAP 
          IDENT  KERMIT 
          LCC    OVERLAY(0,0,OV=8)
          LDSET  LIB
          LDSET  LIB=KERMLIB/AZLIB/FTN5LIB
          LDSET  OMIT=SYSERR.  SAVES 2000B+ WORDS 
          ENTRY  KERMIT 
          SYSCOM B1 
 KERMIT   TITLE  KERMIT - MICRO COMPUTER FILE EXCHANGE/KERMIT PROTOCOL. 
          COMMENT MICRO COMPUTER FILE EXCHANGE/KERMIT PROTOCOL. 
 KERMIT   SPACE  4,10 
*****     KERMIT - MICRO COMPUTER FILE EXCHANGE/KERMIT PROTOCOL.
* 
*         KERMIT IS A FILE SHIPPING PROGRAM USED BY MICRO COMPUTERS TO
*         TRANSFER FILES TO/FROM ANOTHER COMPUTER.  IT WAS ORIGINALLY 
*         DEVELOPED BY COLUMBIA UNIVERSITY FOR THEIR DECSYSTEM-20, AND
*         ADAPTED BY THE UNIVERSITY OF TEXAS FOR THEIR CYBER AND UT2D 
*         OPERATING SYSTEM. 
 KERMIT   SPACE  4,10 
***       MICRO COMPUTER FILE INTERCHANGE/KERMIT PROTOCOL.
* 
*         THIS VERSION IS FOR USE UNDER NOS/BE.  IN CASE YOU ARE
*         WONDERING, KERMIT STANDS FOR (K)L10 (E)RROR-FREE (R)ECIPROCAL 
*         (M)ICROPROCESSOR (I)NTERCHANGE OVER (T)TY LINES.  (X) 
*         INDICATES A LETTER IN THE ACRONYM.  A KL-10 (AKA KL-20) IS A
*         DIGITAL EQUIPMENT CORPORATION 36 BIT CPU. 
 KERMIT   SPACE  4,10 
**        INTERNAL DOCUMENTATION. 
* 
*         DUE TO THE NASTY HABIT INTERCOM HAS OF SWAPPING OUT JOBS THAT 
*         GO INTO TERMINAL INPUT WAIT, KERMIT'S FIELD LENGTH MUST BE
*         KEPT TO A MINIMUM.  SINCE KERMIT DOES ASCII I/O, IT CANNOT
*         USE FORTRAN READ AND WRITE STATEMENTS.  THUS, AN EASY WAY TO
*         SAVE MEMORY IS TO KICK OUT MOST FTN5LIB MODULES.  THIS IS 
*         COMPLICATED BY SOME NEEDED MODULES CALLING 'SYSERR.', WHICH 
*         IN TURN DRAGS IN ABOUT 3000B WORDS OF OTHER STUFF.  FOR THIS
*         REASON, I HAVE INCLUDED AN 'LDSET OMIT=SYSERR.' IN THIS 
*         MODULE.  THUS, SHOULD SOME ERROR CONDITION ARISE THAT 
*         WOULD CAUSE ICHAR, CHAR, XOVCAP, OR WHOEVER TO CALL 'SYSERR.',
*         AN ERROR MODE 1 AT WILL HAPPEN IN THE ROUTINE MAKING THE
*         CALL.  SINCE THIS SHOULD NOT OCCUR, I AM WILLING TO LIVE
*         WITH THE USER HOSTILE DIAGNOSTIC.  FOR DEBUGGING PURPOSES,
*         THE LDSET MAY BE COMMENTED OUT SO YOU GET THE FTN5 ERROR
*         DIAGNOSTIC. 
* 
*         I ALSO USED OVCAPS INSTEAD OF SEGMENTING KERMIT SO THE CORE 
*         IMAGE CAN BE INSTALLED IN NUCLEUS, WITH THE OVCAPS IN SYSOVL. 
*         CDC HAS NOT YET ANSWERED A PSR WE SUBMITTED REGARDING FDL.OCR 
*         NOT LOOKING IN SYSOVL FOR CAPS FOR NUCLEUS PROGRAMS.  THUS, 
*         WITHOUT OUR SUGGESTED CODE, OVCAPS WILL NEED TO BE IN NUCLEUS 
*         ALSO. 
* 
*         EACH OVCAP HAS A COMPASS FRONT-END SO THAT THE COMMENT FIELD
*         OF THE BINARY HAS USEFUL INFORMATION IN IT.  THIS IS USEFUL 
*         WHEN YOU ITEMIZE A DEADSTART TAPE.  ALSO, MAKING THE MAIN 
*         BE IN COMPASS GETS RID OF A CALL TO 'Q5NTRY=' WHICH ALSO
*         SAVES SOME MEMORY.
 KERMIT   TITLE  MAIN PROGRAM.
**        MAIN PROGRAM. 
  
  
 KERMIT   SB1    1
          IF     DEF,ACTR,1 
          SA1    ACTR        GET CONTROL CARD PARAMETER COUNT 
          IF     DEF,RA.ACT,1 
          SA1    RA.ACT      GET CONTROL CARD PARAMETER COUNT 
          SX1    X1 
          ZR     X1,KERMIT1  IF NO PARAMETERS 
          MESSAGE (=C* KERMIT - TOO MANY PARAMETERS.*),,RCL 
          ABORT  ,ND,S
  
 KERMIT1  RJ     =XKERMAIN   CALL THE REAL WORKHORSE
          ENDRUN
  
          END    KERMIT 
      SUBROUTINE KERMAIN
*ENDIF
*IF -DEF,OVCAP
      PROGRAM KERMIT
*ENDIF
  
CCC   KERMIT - A CYBER FILE TRANSFER PROGRAM USING THE KERMIT PROTOCOL
C 
C     THIS PROGRAM MAY NOT BE SOLD FOR PROFIT.
C 
C     MODIFICATIONS:
C 
C     2.0   4/17/84  JIM KNUTSON, UNIVERSITY OF TEXAS AT AUSTIN 
C        FIX FILENAME PACKET TO SEND UPPERCASE FILE NAMES ONLY. 
C        CLEANUP ERROR PACKET HANDLING (ADDED TO STATE TABLE HANDLERS). 
C        FIX RETRY COUNTS TO USE PROPER NUMBER. MODIFY CHARACTER TABLES.
C        MERGE RIC ANDERSON'S NOS/BE CODE.  TRY TO ORGANIZE THE 
C        SOURCE A LITTLE BETTER.  ADDED PUSH AND ! COMMANDS.
C        ADD READ DELAY FOR PERFORMANCE TUNING.  CHANGED NEL BACK TO
C        205B.  THE BINARY DATA-MODE IGNORES NEL THOUGH.
C        UT2D REQUIRES THE NEL BE A 205B.  CHANGED CHARACTER TABLES 
C        TO USE OCTAL CONSTANTS FOR NON-REPRESENTABLE CHARACTERS. 
C 
C     1.1   01/21/84  RIC ANDERSON, UNIVERSITY OF ARIZONA AT TUSCON 
C        ADD OVCAPS FOR INSTALLATION IN NUCLEUS.  ADD DISPLAY CODE
C        SUPPORT.  REMOVE GOBS AND GOBS OF FIELD LENGTH.  CHANGED 
C        NEL TO 4012B TO AVOID CONFUSION WITH DATA BYTE.  UPDATED 
C        CHARACTER TABLES FOR 63 AND 64 CHARACTER SETS.  CHANGED
C        PERCENTS IN FPRINTFS TO AT-SIGNS SINCE 63 CHARACTER SET HAS
C        NO PERCENT SIGN. 
C 
C     1.0   10/14/84  JIM KNUTSON, UNIVERSITY OF TEXAS AT AUSTIN
C        ORIGINAL IMPLEMENTATION. 
C 
C     JIM KNUTSON 
C     COMPUTATION CENTER ROOM 1 
C     UNIVERISITY OF TEXAS
C     AUSTIN, TX   78712
C 
C     APRPANET ADDRESS:  KNUTSON@UT-NGP 
C 
C     SPECIAL THANKS TO KING ABLES FOR HIS CONTRIBUTION.
C 
C     MODIFIED FOR NOS/BE BY RIC ANDERSON 
C     UNIVERSITY OF ARIZONA 
C     COMPUTER CENTER 
C     TUCSON, ARIZONA 85721 
C 
C 
C     FUTURE ENHANCEMENTS:
C        8TH BIT QUOTING
C        REPEAT COUNTS
C        WILD CARD SENDS
C        CONDITIONAL CODE GENERATION FOR I/O CHECKS 
C 
C 
C     BUILD SEQUENCE: 
C        BUILD AN UPDATE OPLPL FROM THE SOURCE FILE.
C        CREATE THE COMPILE FILE, CHANGING THE SITE PARAMETER IN THE
C           COMMON DECK COMCKER.  ALSO USE *DEFINES FOR OVCAPS VS.
C           SEGLOAD VERSION AND SITE DEPENDENT COMPASS.  SEE
C           IMPLEMENTATION NOTES. 
C        FOR THE OVCAP VERSION: 
C           FTN5,I,OPT=2. 
C           FTN5,I,OPT=2,B=LIBREL.
C           LIBGEN,P=KERMLIB,F=LIBREL.
C           LOAD,LGO. 
C           NOGO,KERMIT.
C        FOR THE SEGLOAD VERSION: 
C           FTN5,I,OPT=2. 
C           SEGLOAD,I=SEGDEF,B=KERMIT.
C           LOAD,LGO. 
C           NOGO. 
C        LOAD IT WITH THE FOLLOWING SEGLOAD DIRECTIVES: 
C          TREE     KERMIT-(SET,HLPCMD,EXECMD,SERVER-(RECEIVE,SEND))
C SET      INCLUDE  SHOW,STATUS,MATCH,SETVAL
C RECEIVE  INCLUDE  RINIT,RFILE,RDATA 
C SEND     INCLUDE  SINIT,SFILE,SDATA,SEOF,SBREAK 
C KERMIT   GLOBAL   PROTO,PACKET,DEBUG,MESSAGE,FILEIO,FILEIOC 
C          END      KERMIT
C 
C     IMPLEMENTATION NOTES: 
C 
C        THERE ARE NOW TWO VERSIONS AVAILABLE FOR KERMIT.  ONE USES 
C        SEGLOAD THE OTHER USES OVCAPS.  ONLY THE OVCAP VERSION MAY 
C        BE INSTALLED ON THE SYSTEM NUCLEUS (CLD FOR YOU UT2D FANS).
C        THE DEFAULT VERSION YOU GET FROM UPDATE IS FOR SEGLOAD.
C        THE OVCAP VERSION MAY BE OBTAINED BY USING THE UPDATE
C        DIRECTIVE *DEFINE,OVCAP. 
C 
C        THIS VERSION OF KERMIT SHOULD BE PORTABLE TO OTHER CDC SITES 
C        EXCEPT FOR THE ABOVE MENTIONED CONDITIONAL UPDATES AND THE 
C        FOLLOWING CASES. 
C 
C        THE DELAY SUBROUTINE USES SUBROUTINE RTIME TO RETURN THE SYSTEM
C        REAL TIME CLOCK (NUMBER OF JIFS SINCE DEADSTART).  NOS AND 
C        NOS/BE RTIME MACROS ALLEGEDLY RETURN SLIGHTLY DIFFERENT
C        FORMATS OF DATA, SO NOS SITES MAY NEED TO MODIFY DELAY().
C 
C        THE SERVER KNOWS HOW TO LOGOUT ON UT2D AND NOS/BE SITES. 
C        UT2D USES A LOCAL FUNTION CALLED BELLC TO PERFORM THIS.  NOS/BE
C        SITES USE A FUNCTION TO ESSENTIALLY PCC A LOGOUT CONTROL 
C        COMMAND.  SEE SUBROUTINE LOGOUT(). 
C 
C        THE ASCII I/O IS ALSO PROBABLY NOT PORTABLE SINCE
C        CDC DOES NOT REALLY SUPPORT ASCII I/O YET. 
C        ASCII I/O ON UT2D (UNIV. OF TEXAS OP. SYS.) IS DONE BY 
C        SETTING BIT 2**43 IN FET+1.  THE ASCII CHARACTER SET THAT
C        IS USED IS "8 IN 12".  THIS IS 8 BITS OF AN ASCII CHARACTER
C        STORED IN A 12 BIT BYTE.  NULLS ARE REPRESENTED AS 4000B,
C        AND THE NEWLINE CHARACTER (NEL) IS 205B.  THIS IS SLIGHTLY 
C        DIFFERENT FROM THE CDC END-OF-LINE WHICH IS 0000B IN THE 
C        LOW ORDER BYTE OF THE WORD.  CURRENTLY, 0000B BYTES ARE IGNORED
C        SINCE NULLS ARE GUARDED. 
C 
C        THE DISPLAY CODE CHARACTER MAPPINGS FOR UT2D ARE DIFFERENT 
C        THAN THE 64 AND 63 CHARACTER SET (SIGH).  THESE SHOULD 
C        ALREADY BE TAKEN CARE OF IN THE CONDITIONAL COMPILATION. 
C 
C        SITES THAT MODIFY KERMIT TO RUN ON THEIR SYSTEM SHOULD 
C        MODIFY THE APPROPRIATE PARAMETER DEFINITION TO ALLOW 
C        CONDITIONAL COMPILATION FOR THEIR SITE.  TRY TO BE 
C        AS GENERAL AS YOU CAN WHEN MAKING MODS.
C 
C        ****** ABOVE ALL SEND YOUR MODS BACK TO UT ******* 
C 
C     KERMIT I/O CONSIDERATIONS:
C 
C        KERMIT USES TWO MODES OF I/O.  IT DOES CODED I/O WHEN READING
C        FROM THE TERMINAL TO GET COMMANDS.  THIS CAUSES THE FRONT
C        END TO MAP THE CR/LF PAIR INTO A SINGLE NEL CHARACTER. 
C        NORMAL CYBER SITES WILL HAVE THE NEL CHARACTER ADDED FOR 
C        THEM BY THE SUBROUTINE FINDEOL.
C        COMMAND EDITING (BACKSPACE AND CANCEL)  AND PARITY IS TAKEN
C        CAREOF BY THE FRONT-END.  BINARY I/O IS USED WHEN READING
C        AND SENDING PACKETS.  THIS ALLOWS KERMIT TO CONTROL THE
C        PARITY BIT.  OTHER NOS SITES MAY HAVE TO SET TRANSPARENT MODE
C        TO DO THIS.  BINARY I/O ALSO CAUSES NO COMMAND EDITING TO BE 
C        DONE (BACKSPACES ARE TREATED AS REGULAR ASCII CHARACTERS) AND
C        CR/LF IS NOT MAPPED TO NEL. RAWMODE IS A MODE INTERNAL 
C        TO KERMIT THAT CAUSES NO CR/LF <-> NEL MAPPING.
C 
C        KERMIT OPENS TWO FILES (STDIN AND STDOUT) AND CONNECTS 
C        THEM TO THE TERMINAL FOR DOING THE ASCII I/O.  THIS WAS
C        DONE TO PREVENT PROBLEMS WITH TRYING TO BUFFER READS AND 
C        WRITES TO THE SAME FILE.  WHEN READING/WRITING DISK FILES, 
C        KERMIT WILL TRY TO BUFFER 2 DISK SECTORS (128 WORDS) WORTH 
C        OF DATA PER READ/WRITE.  THIS WAS CHANGED FROM THE 8 DISK
C        SECTORS (512 WORDS) SINCE THIS REDUCED WASTED SPACE FOR
C        THE TERMINAL FILES AND HELPED REDUCE FIELD LENGTH. 
C        ALL I/O IS DONE THROUGH INTERFACE ROUTINES TO THE COMPASS
C        I/O MACROS.
C 
C        THE ONLY IMPLEMENTATION DEPENDENT I/O ROUTINES SHOULD BE 
C        THE COMPASS I/O INTERFACE ROUTINES, STTY() AND PERHAPS 
C        THE RTIME() SUBROUTINE.
C        SEE THESE ROUTINES FOR MORE INFO ON WHAT THEY DO.
C 
C     SUBROUTINE ORDERING:
C        MAIN PROGRAM AND INITIALIZATION
C           KERMIT
C           BLKDAT. 
C           EXITPGM 
C           ABTP
C        KERMIT COMMAND SUBROUTINES 
C           EXECMD
C           HLPCMD
C           RCVFILE 
C           SNDFILE 
C           SET 
C           SHOW
C           STATUS
C           DBUGCMD 
C           DMODCMD 
C           SETPACK 
C           DPLXCMD 
C           PARCMD
C        COMMAND PARSING SUBROUTINES
C           MATCH 
C           OUTTBL
C           SETVAL
C           CONFIRM 
C        SERVER SUBROUTINES 
C           SERVER
C           LOGOUT
C        KERMIT RECEIVE STATE PROTOCOL SUBROUTINES
C           RECEIVE 
C           RINIT 
C           RFILE 
C           RDATA 
C        KERMIT SEND STATE PROTOCOL SUBROUTINES 
C           SEND
C           SINIT 
C           SFILE 
C           SDATA 
C           SEOF
C           SBREAK
C        PACKET I/O SUBROUTINES 
C           SNDPACK 
C           RDPACK
C           BUFFILL 
C           BUFEMP
C        STANDARD I/O SUBROUTINES 
C           FOPEN 
C           FCLOSE
C           FFLUSH
C           GETC
C           UNGETC
C           GETWORD 
C           FREAD 
C           FWRITE
C           PUTC
C           PUTSTR
C           PUTINT
C           PUTDAY
C           PUTMNTH 
C           FPRINTF 
C           SPRINTF 
C           DOPRNT
C           STTY
C           GTTY
C        UTILITY SUBROUTINES
C           AS2DPC
C           ASC 
C           DPC2AS
C           CTOI
C           ITOS
C           GETEMSG 
C           CREAT 
C           GETNOW
C           FILCHK
C           RDPARAM 
C           REMOVE
C           STRCPY
C           SLEN
C           SNDPAR
C           SLEEP 
C           DELAY 
C        NOS/BE UTILITY MODULES.
C           ECHOPLX 
C           MAKEFET 
C           CFE 
C           GETREC
C           FINDEOL 
C           EDL 
C           ICHAR 
C           DISPLA
C 
*CALL KERMCOM 
      LOGICAL CFE 
      EXTERNAL EXITPGM
      PARAMETER (TSIZE=11)
      CHARACTER*10 CMD(TSIZE) 
      DATA CMD / 'EXIT', 'HELP', 'PUSH', 'QUIT', 'RECEIVE', 'SEND', 
     +    'SERVER', 'SET', 'SHOW', 'STATUS', '!' /
  
C 
C     INSURE WE ARE AN INTERACTIVE JOB. 
C 
C$    IF (NOSBE .EQ. 1) THEN
      CALL XGJO(IPRIV,IORIG)
      IF(IORIG .NE. 3) THEN 
          CALL REMARK(' KERMIT - INCORRECT JOB ORIGIN.')
          CALL ABTP("ND,S") 
      ENDIF 
C$    ENDIF 
C$    IF (UT2D .EQ. 1)
      CALL JOBINFO(11,IORIG)
      IF ((IORIG.AND.4) .NE. 4) THEN
         CALL REMARK(' KERMIT - INCORRECT JOB ORIGIN.') 
         CALL ABTP("ND,S")
      ENDIF 
C$    ENDIF 
C 
C     IF RUNNING FROM A SYSTEM LIBRARY, SET INFINITE CPU
C     TIME LIMIT FOR THIS JOB STEP. 
C 
C$    IF (NOSBE .EQ. 1) THEN
      IF(IPRIV .EQ. -1) CALL ENTL(O"77777") 
C$    ENDIF 
C 
C     OPEN THE I/O FILES
C 
      IF (FOPEN('STDIN',RD) .NE. STDIN) THEN
         CALL DISPLA(' CANNOT OPEN STANDARD INPUT') 
         CALL ABTP("ND")
      ELSE IF (FOPEN('STDOUT',WR) .NE. STDOUT) THEN 
         CALL DISPLA(' CANNOT OPEN STANDARD OUTPUT')
         CALL ABTP("ND")
      ENDIF 
C 
C     READ IN ENVIRONMENT IF NEEDED 
C 
      IF (CFE('ZZZZKEN')) THEN
         CFD = FOPEN('ZZZZKEN',RD)
         IF (CFD .EQ. ERROR) THEN 
            CALL DISPLA(' CANNOT OPEN TEMP FILE') 
         ELSE 
            CALL FREAD(CFD,HEADER,LOCF(TRAILER)-LOCF(HEADER)) 
            CALL FCLOSE(CFD)
         ENDIF
         CALL RETFILE('ZZZZKEN')
      ENDIF 
C 
C     MAKE SURE THINGS GET FIXED DURING ABORTS
C 
      CALL RECOVR(EXITPGM,O"77",0)
C 
C     PARSE AND EXECUTE ANY COMMANDS
C 
5     CALL FPRINTF(STDOUT,'^KERMIT-170>',0,0,0,0) 
      CALL FFLUSH(STDOUT) 
      CALL FFLUSH(STDIN)
      INDX = MATCH(CMD,TSIZE,.TRUE.)
      IF (INDX .EQ. ERROR .OR. INDX .EQ. 0) GO TO 5 
      IF (INDX .EQ. EOF) THEN 
          NORMAL = .TRUE. 
          CALL EXITPGM
      ENDIF 
      GO TO (10, 20, 30, 10, 40, 50, 60, 70, 80, 90, 100), INDX 
C 
C     THATS ALL FOLKS 
C 
10    NORMAL = .TRUE. 
      CALL EXITPGM
C 
C     GIVE SOME HELP
C 
*IF DEF,OVCAP 
20    CALL XOVCAP('KERMHLP')
      CALL UOVCAP('KERMHLP')
*ENDIF
*IF -DEF,OVCAP
20    CALL HLPCMD 
*ENDIF
      GO TO 5 
C 
C     SAME AS EXIT AND QUIT BUT ALLOWS YOU TO REENTER WITH
C     THE SAME ENVIRONMENT AS BEFORE
C 
30    AUTORET = NO
*IF DEF,OVCAP 
      CALL XOVCAP('KERMXCC')
      CALL UOVCAP('KERMXCC')
*ENDIF
*IF -DEF,OVCAP
      CALL EXECMD 
*ENDIF
      GO TO 5 
C 
C     RECEIVE A FILE
C 
*IF DEF,OVCAP 
40    CALL XOVCAP('KERMRCV')
      CALL UOVCAP('KERMRCV')
*ENDIF
*IF -DEF,OVCAP
40    CALL RCVFILE
*ENDIF
      GO TO 5 
C 
C     SEND A FILE 
C 
*IF DEF,OVCAP 
50    CALL XOVCAP('KERMSND')
      CALL UOVCAP('KERMSND')
*ENDIF
*IF -DEF,OVCAP
50    CALL SNDFILE
*ENDIF
      GO TO 5 
C 
C     ENTER SERVER MODE 
C 
*IF DEF,OVCAP 
60    CALL XOVCAP('KERMSRV')
      CALL UOVCAP('KERMSRV')
*ENDIF
*IF -DEF,OVCAP
60    CALL SERVER 
*ENDIF
      GO TO 5 
C 
C     SET SOME ATTRIBUTES 
C 
*IF DEF,OVCAP 
70    CALL XOVCAP('KERMSET')
      CALL UOVCAP('KERMSET')
*ENDIF
*IF -DEF,OVCAP
70    CALL SET
*ENDIF
      GO TO 5 
C 
C     SHOW CURRENT SETTINGS 
C 
*IF DEF,OVCAP 
80    CALL XOVCAP('KERMSHO')
      CALL UOVCAP('KERMSHO')
*ENDIF
*IF -DEF,OVCAP
80    CALL SHOW 
*ENDIF
      GO TO 5 
C 
C     GIVE THE STATUS OF LAST TRANSFER
C 
*IF DEF,OVCAP 
90    CALL XOVCAP('KERMSTA')
      CALL UOVCAP('KERMSTA')
*ENDIF
*IF -DEF,OVCAP
90    CALL STATUS 
*ENDIF
      GO TO 5 
C 
C     EXEC A CONTROL COMMAND
C 
100   AUTORET = YES 
*IF DEF,OVCAP 
      CALL XOVCAP('KERMXCC')
      CALL UOVCAP('KERMXCC')
*ENDIF
*IF -DEF,OVCAP
      CALL EXECMD 
*ENDIF
      GO TO 5 
      END 
      BLOCK DATA
*CALL COMCKER 
  
  
      DATA FMODE / MAXFILE*CLOSED / 
      DATA FWPTR,FNWDS / MAXFILE*0, MAXFILE*0 / 
      DATA RAWMODE, BINMODE / 2*.FALSE. / 
      DATA PARITY, DUPLEX / NOPAR, FULLDUP /
      DATA DSKCSET / DSKDPC / 
      DATA NORMAL / .FALSE. / 
      DATA IFD, OFD         / STDIN, STDOUT / 
      DATA FFD              / 0 / 
      DATA MAXRTRY, MAXRINI / MAXTRY, MAXINIT / 
      DATA PACKNUM          / 0 / 
      DATA STARTIM, ENDTIM  / 2*0 / 
      DATA SCHCNT , RCHCNT  / 2*0 / 
      DATA SCHOVRH, RCHOVRH / 2*0 / 
      DATA STATE            / C / 
      DATA DELAYFP          / 5 / 
      DATA RDELAY           / 100 / 
      DATA SYNC   , SNDSYNC / 2*SOH / 
      DATA PACKSIZ, SPKSIZ  / 2*MAXPACK / 
      DATA TIMEOUT, STIMOUT / 2*MYTIME  / 
      DATA NPAD   , SPAD    / 2*MYPAD   / 
      DATA PADCH  , SPADCH  / 2*MYPADCH / 
      DATA EOLCH  , SPEOL   / 2*MYEOL   / 
      DATA QUOTECH, SPQUOTE / 2*MYQUOTE / 
      DATA QUOTE8 , S8QUOTE / 2*QUOT8CH / 
      DATA CHKTYP , SCHKTYP / 2*MYCKTYP / 
      DATA RPREFIX, SREPEAT / 2*PREFXCH / 
      DATA DEBUG  , DEBUGFD / DBGOFF, 0 / 
      DATA DEBUGFN          / 75, 69, 82, 77, 76, 79, 71, 0 / 
C                              K   E   R   M   L   O   G
      DATA (ERRMSG(I),I=1,14) / 63, 75, 101, 114, 109, 105, 116, 45, 49,
C                             ?   K    E    R    M    I    T   -   1
     +                       55, 48, 58, 2*32 / 
C                             7   0   : 
      DATA VERSION / '^CYBER-170 ^K^E^R^M^I^T VERSION 2.0\N' /
      DATA AMBIG   / '?^AMBIGUOUS - "' /
      DATA NOMATCH / '?^DOES NOT MATCH SWITCH OR KEYWORD - "' / 
      DATA FOLLOW  / '^ONE OF THE FOLLOWING:\N' / 
      DATA NODIGIT /
     +   '?^INVALID, ^FIRST NONSPACE CHARACTER IS NOT A DIGIT\N' /
      DATA MISSING / '?^INVALID, ^MISSING PARAMETER\N' /
      DATA CONFMSG / '^CONFIRM WITH A CARRIAGE RETURN\N' /
      DATA NOTCONF / '?^NOT CONFIRMED - "' /
      DATA HLPASCH / '^DECIMAL, OCTAL (^B), OR HEXIDECIMAL (^H) CODE FOR
     + ^A^S^C^I^I CHARACTER \N' / 
      DATA HLPDLFP / '^NUMBER OF SECONDS TO DELAY FIRST PACKET\N' / 
      DATA HLPDBFN / '^DEBUG OUTPUT LOGFILE SPECIFICATION\N' /
      DATA HLPPLEN / '^MAXIMUM PACKET LENGTH\N' / 
      DATA HLPPADL / '^NUMBER OF PAD CHARACTERS TO USE\N' / 
      DATA HLPIPRC / '^INITIAL PACKET RETRY COUNT\N' /
      DATA HLPPRTR / '^PACKET RETRY COUNT\N' /
      DATA HLPTIMO / '^NUMBER OF SECONDS TO WAIT BEFORE TIMEOUT\N' /
      DATA HLPSNFN / '^FILENAME TO SEND\N' /
      DATA HLPRDEL / '^MILLISECONDS TO DELAY EACH ^T^T^Y READ\N' /
  
C$    IF (UT2D .EQ. 1)
      DATA DPCTBL/R" ",31*R" ",R" ",R"!",R"""",O"65",R"$",O"71",R"&", 
     +            O"64",R"(",R")",R"*",R"+",R",",R"-",R".",R"/",R"0", 
     +            R"1",R"2",R"3",R"4",R"5",R"6",R"7",R"8",R"9", 
     +            O"63",R";",R"<",R"=",R">",O"75",R"@", 
     +            R"A",R"B",R"C",R"D",R"E",R"F",R"G",R"H",R"I", 
     +            R"J",R"K",R"L",R"M",R"N",R"O",R"P",R"Q",R"R", 
     +            R"S",R"T",R"U",R"V",R"W",R"X",R"Y",R"Z",
     +            R"[",O"76",R"]",O"70",R" ",R" ",
     +            R"A",R"B",R"C",R"D",R"E",R"F",R"G",R"H",R"I", 
     +            R"J",R"K",R"L",R"M",R"N",R"O",R"P",R"Q",R"R", 
     +            R"S",R"T",R"U",R"V",R"W",R"X",R"Y",R"Z",
     +            5*R" "/ 
      DATA LASCII/0,97,98,99,100,101,102,103,104,105,106,107,108,109, 
C                    A  B  C   D   E   F   G   H   I   J   K   L   M
     +            110,111,112,113,114,115,116,117,118,119,120,121,122,
C                   N   O   P   Q   R   S   T   U   V   W   X   Y   Z 
     +            48,49,50,51,52,53,54,55,56,57,
C                  0  1  2  3  4  5  6  7  8  9 
     +            43,45,42,47,40,41,36,61,32,44,46,34,91,93,58, 
C                  +  -  *  /  (  )  $  =     ,  .  "  [  ]  :
     +            39,35,33,38,94,37,60,62,64,63,92,59/
C                  '  #  !  &  ^  <PCT>  <  >  @  ?  \  ; 
      DATA UASCII/0,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81, 
C                    A  B  C  D  E  F  G  H  I  J  K  L  M  N  O  P  Q
     +            82,83,84,85,86,87,88,89,90,48,49,50,51,52,53,54,55, 
C                 R  S  T  U  V  W  X  Y  Z  0  1  2  3  4  5  6  7 
     +            56,57,43,45,42,47,40,41,36,61,32,44,46,34,91,93,58, 
C                 8  9  +  -  *  /  (  )  $  =     ,  .  "  [  ]  : 
     +            39,35,33,38,94,37,60,62,64,63,92,59/
C                   '  #  !  &  ^  <PCT>  <  >  @  ?  \  ;
C$    ELSE
C$      IF(IPCSET .EQ. IPC63) 
        DATA DPCTBL/R" ",31*R" ",R" ",R"!",R"""",O"60",R"$",R" ",R"&",
     +              O"70",R"(",R")",R"*",R"+",R",",R"-",R".",R"/",R"0", 
     +              R"1",R"2",R"3",R"4",R"5",R"6",R"7",R"8",R"9", 
     +              O"63",R";",R"<",R"=",R">",O"71",R"@", 
     +              R"A",R"B",R"C",R"D",R"E",R"F",R"G",R"H",R"I", 
     +              R"J",R"K",R"L",R"M",R"N",R"O",R"P",R"Q",R"R", 
     +              R"S",R"T",R"U",R"V",R"W",R"X",R"Y",R"Z",
     +              R"[",O"75",R"]",O"76",O"65",R"@", 
     +              R"A",R"B",R"C",R"D",R"E",R"F",R"G",R"H",R"I", 
     +              R"J",R"K",R"L",R"M",R"N",R"O",R"P",R"Q",R"R", 
     +              R"S",R"T",R"U",R"V",R"W",R"X",R"Y",R"Z",
     +              R"[",R"\",R"]",R"^",R" "/ 
        DATA LASCII/32,97,98,99,100,101,102,103,104,105,106,107,108,109,
C                       A  B  C   D   E   F   G   H   I   J   K   L   M 
     +              110,111,112,113,114,115,116,117,118,119,120,121,122,
C                     N   O   P   Q   R   S   T   U   V   W   X   Y   Z 
     +              48,49,50,51,52,53,54,55,56,57,
C                    0  1  2  3  4  5  6  7  8  9 
     +              43,45,42,47,40,41,36,61,32,44,46,35,91,93,58, 
C                    +  -  *  /  (  )  $  =     ,  .  %  [  ]  :
     +              34,95,33,38,39,63,60,62,64,92,94,59/
C                    "  #  !  &  '  ?  <  >  @  \  ^  ; 
        DATA UASCII/32,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80, 
C                       A  B  C  D  E  F  G  H  I  J  K  L  M  N  O  P
     +              81,82,83,84,85,86,87,88,89,90,48,49,50,51,52,53,54, 
C                    Q  R  S  T  U  V  W  X  Y  Z  0  1  2  3  4  5  6
     +              55,56,57,43,45,42,47,40,41,36,61,32,44,46,35,91,93, 
C                    7  8  9  +  -  *  /  (  )  $  =     ,  .  %  [  ]
     +              58,34,95,33,38,39,63,60,62,64,92,94,59/ 
C                    :  "  #  !  &  '  ?  <  >  @  \  ^  ;
C$      ELSE
        DATA DPCTBL/R" ",31*R" ",R" ",R"!",R"""",O"60",R"$",O"63",R"&", 
     +              O"70",R"(",R")",R"*",R"+",R",",R"-",R".",R"/",R"0", 
     +              R"1",R"2",R"3",R"4",R"5",R"6",R"7",R"8",R"9", 
     +              O"0",R";",R"<",R"=",R">",O"71",R"@",
     +              R"A",R"B",R"C",R"D",R"E",R"F",R"G",R"H",R"I", 
     +              R"J",R"K",R"L",R"M",R"N",R"O",R"P",R"Q",R"R", 
     +              R"S",R"T",R"U",R"V",R"W",R"X",R"Y",R"Z",
     +              R"[",O"75",R"]",O"76",O"65",R"@", 
     +              R"A",R"B",R"C",R"D",R"E",R"F",R"G",R"H",R"I", 
     +              R"J",R"K",R"L",R"M",R"N",R"O",R"P",R"Q",R"R", 
     +              R"S",R"T",R"U",R"V",R"W",R"X",R"Y",R"Z",
     +              R"[",R"\",R"]",R"^",R" "/ 
        DATA LASCII/58,97,98,99,100,101,102,103,104,105,106,107,108,109,
C                    :  A  B  C   D   E   F   G   H   I   J   K   L   M 
     +              110,111,112,113,114,115,116,117,118,119,120,121,122,
C                     N   O   P   Q   R   S   T   U   V   W   X   Y   Z 
     +              48,49,50,51,52,53,54,55,56,57,
C                    0  1  2  3  4  5  6  7  8  9 
     +              43,45,42,47,40,41,36,61,32,44,46,35,91,93,37, 
C                    +  -  *  /  (  )  $  =     ,  .  %  [  ]  <PCT>
     +              34,95,33,38,39,63,60,62,64,92,94,59/
C                    "  #  !  &  '  ?  <  >  @  \  ^  ; 
        DATA UASCII/58,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80, 
C                    :  A  B  C  D  E  F  G  H  I  J  K  L  M  N  O  P
     +              81,82,83,84,85,86,87,88,89,90,48,49,50,51,52,53,54, 
C                    Q  R  S  T  U  V  W  X  Y  Z  0  1  2  3  4  5  6
     +              55,56,57,43,45,42,47,40,41,36,61,32,44,46,35,91,93, 
C                    7  8  9  +  -  *  /  (  )  $  =     ,  .  %  [  ]
     +              37,34,95,33,38,39,63,60,62,64,92,94,59/ 
C                <PCT>  "  #  !  &  '  ?  <  >  @  \  ^  ;
C$      ENDIF 
C$    ENDIF 
      END 
      SUBROUTINE EXITPGM
  
CCC   EXITPGM - EXIT THE PROGRAM
C 
*CALL KERMCOM 
C 
C     SET COMPLETE BIT IN ALL FETS, IN CASE WE DIED IN MID-CIO CALL.
C 
      IF(.NOT. NORMAL) THEN 
          DO 10 I = 1, MAXFILE
              FETS(0,I) = OR(FETS(0,I),1) 
10        CONTINUE
      ENDIF 
  
      CALL STTY('RAW',OFF)
      CALL STTY('BINARY',OFF) 
      IF (SAVEDPX .NE. HALFDUP) CALL STTY('DUPLEX',FULLDUP) 
      CALL FCLOSE(STDIN)
      CALL FCLOSE(STDOUT) 
      IF (DEBUGFD.NE.0) CALL FCLOSE(DEBUGFD)
      CALL ENDRUN 
  
      END 
      SUBROUTINE ABTP(TYPE) 
  
CC    ABTP - ABORT PROGRAM. 
C 
C     THIS SUBROUTINE SHOULD NOT RETURN.
C 
*CALL KERMCOM 
      BOOLEAN TYPE
C$    IF (UT2D .EQ. 1) THEN 
      CALL ABORT
C$    ELSE
      CALL ABORT(TYPE)
C$    ENDIF 
      RETURN
      END 
*IF DEF,OVCAP 
          IDENT    KERMXCC
          ENTRY    KERMXCC
          LCC      OVCAP. 
          LDSET    NOEPT=UNLFILE
KERMXCC   TITLE    KERMXCC - KERMIT EXECUTE CONTROL COMMAND PROCESSOR.
          COMMENT KERMXCC - KERMIT EXECUTE CONTROL COMMAND PROCESSOR. 
KERMXCC   SPACE    4,10 
**        KERMXCC - KERMIT EXECUTE CONTROL COMMAND PROCESSOR. 
* 
KERMXCC   SUBR                     ENTRY/EXIT 
          RJ       =XEXECMD        CALL THE REAL WORKHORSE
          EQ       KERMXCCX        RETURN 
  
          END 
*ENDIF
      SUBROUTINE EXECMD 
  
CCC   EXECMD - EXECUTE A CONTROL COMMAND
C 
C     EXECUTE A CONTROL COMMAND AND RETURN TO COMMAND MODE OR 
C     EXIT TO THE OPERATING SYSTEM.  NEXT EXECUTION OF KERMIT 
C     WILL RETURN WITH CURRENT ENVIRONMENT.  THIS SUBROUTINE
C     DOES NOT RETURN.
C 
*CALL KERMCOM 
      LOGICAL CONFIRM, EATLINE
C 
C     BEFORE WE DO ANYTHING RASH
C 
      IF (AUTORET .EQ. NO) THEN 
         IF (.NOT. CONFIRM(STDIN)) RETURN 
      ENDIF 
C 
C     WRITE OUT THE CURRENT ENVIRONMENT 
C 
      CFD = FOPEN('ZZZZKEN',WR) 
      IF (CFD .EQ. ERROR) THEN
         CALL REMARK(' CANNOT CREATE TEMP FILE')
         RETURN 
      ENDIF 
      CALL FWRITE(CFD,HEADER,LOCF(TRAILER)-LOCF(HEADER))
      CALL FCLOSE(CFD)
C 
C     IF ONLY EXIT TO THE OPERATING SYSTEM
C 
      IF (AUTORET .EQ. NO) THEN 
         NORMAL = .TRUE.
         CALL EXITPGM 
      ENDIF 
C 
C     WRITE THE CONTROL COMMAND FILE
C 
      DSKCSET = DSKDPC
      FD = FOPEN('ZZZZKCC',CREATE)
      IF (FD .EQ. ERROR) THEN 
         CALL REMARK(' CANNOT CREATE TEMPORARY FILE') 
         FD = CLOSED
         RETURN 
      ENDIF 
C 
C     COPY COMMAND TO COMMAND FILE
C 
      EATLINE = .FALSE. 
10    IF (GETC(STDIN,CH) .EQ. BLANK) THEN 
         GO TO 10 
      ELSE
         IF (CH .EQ. QMARK) THEN
            EATLINE = .TRUE.
            CALL FPRINTF(STDOUT,'^MONITOR COMMAND TO EXECUTE\N',0,0,0,0)
         ELSE 
            CALL PUTC(CH,FD)
         ENDIF
      ENDIF 
20    CH = GETC(STDIN,CH) 
      IF (.NOT. EATLINE) CALL PUTC(CH,FD) 
      IF (CH .NE. NEL) GO TO 20 
C 
C     COPY CLEANUP COMMANDS TO COMMAND FILE 
C 
      CALL FPRINTF(FD,'.SKIPCC\N.EXIT\N.RETURN ZZZZKCC\N.KERMIT\N', 
     +             0,0,0,0) 
      CALL FCLOSE(FD) 
C 
C     EXECUTE THE COMMAND FILE
C 
      CALL EXCST('.CNTRL,ZZZZKCC')
      END 
*IF DEF,OVCAP 
          IDENT  KERMHLP
          ENTRY  KERMHLP
          LCC    OVCAP. 
          LDSET  NOEPT=UNLFILE
 KERMHLP  TITLE  KERMHLP - KERMIT HELP COMMAND PROCESSOR. 
          COMMENT KERMIT HELP COMMAND PROCESSOR.
 KERMHLP  SPACE  4,10 
**        KERMHLP - KERMIT HELP COMMAND PROCESSOR.
  
  
 KERMHLP  SUBR               ENTRY/EXIT 
          RJ     =XHLPCMD    CALL THE REAL WORKHORSE
          EQ     KERMHLPX    RETURN 
  
          END 
*ENDIF
      SUBROUTINE HLPCMD 
  
CCC   HLPCMD - PROCESS THE HELP COMMAND.
C 
*CALL KERMCOM 
      PARAMETER (TSIZE=12)
      CHARACTER*10 HLPTYP(TSIZE)
      LOGICAL CONFIRM 
      DATA HLPTYP / 'EXIT', 'HELP', 'KERMIT', 'PUSH', 'QUIT', 'RECEIVE',
     +              'SEND', 'SERVER', 'SET', 'SHOW', 'STATUS', '!' /
  
      INDX = MATCH(HLPTYP,TSIZE,.TRUE.) 
      IF (INDX .EQ. EOF .OR. INDX .EQ. ERROR) RETURN
      IF (INDX .EQ. 0) GO TO 30 
      IF (.NOT. CONFIRM(STDIN)) RETURN
      GO TO (10, 20, 30, 40, 10, 50, 60, 70, 80, 90, 100, 110), INDX
C 
C     HELP EXIT 
C 
10    CALL FPRINTF(STDOUT,'^EXIT FROM ^KERMIT-170\N') 
      RETURN
C 
C     HELP HELP 
C 
20    CALL FPRINTF(STDOUT,'\N^H^E^L^P [TOPIC]\N\N^TYPING ^H^E^L^P ALONE 
     +PRINTS A BRIEF SUMMARY OF ^KERMIT-170 AND ITS COMMANDS.\N^YOU CAN 
     +ALSO TYPE\N\N   ^H^E^L^P COMMAND\N\NFOR ANY ^KERMIT-170 COMMAND, E
     +.G. "HELP SEND", TO GET MORE DETAILED INFORMATION\NABOUT A SPECIFI
     +C COMMAND.  ^TYPE\N\N   ^H^E^L^P ?\N\NTO SEE A LIST OF ALL THE AVA
     +ILABLE HELP COMMANDS, OR CONSULT THE ^KERMIT ^USERS\N^GUIDE.\N\N')
      RETURN
C 
C     HELP KERMIT 
C 
30    CALL FPRINTF(STDOUT,'\N^KERMIT IS A FILE TRANSFER PROTOCOL FOR USE
     + OVER AN ASYNCHRONOUS SERIAL\NTELECOMMUNICATION LINE.  ^FILES ARE 
     +BROKEN UP INTO "PACKETS" WITH CHECKSUMS AND\NOTHER CONTROL INFORMA
     +TION TO ENSURE (WITH HIGH PROBABILITY) ERROR-FREE AND\NCOMPLETE TR
     +ANSMISSION.\N\N^KERMIT-170 IS THE IMPLEMENTATION FOR THE ^CYBER 17
     +0/750 AND IS\NRUN "REMOTELY" FROM ANOTHER COMPUTER (E.G. A MICROCO
     +OPUTER).\N\N^YOU CAN RUN ^KERMIT INTERACTIVELY BY TYPING REPEATED 
     +COMMANDS IN RESPONSE TO\NITS "^KERMIT-170>" PROMPT, OR YOU CAN RUN
     + IT AS A REMOTE SERVER.\N\N^KERMIT-170 COMMAND SUMMARY -- OPTIONAL
     + PARTS ARE IN [BRACKETS]:\N\N') 
      CALL FPRINTF(STDOUT,'* ^FOR EXCHANGING FILES:         ^S^E^N^D FIL
     +E\N') 
      CALL FPRINTF(STDOUT,'                                ^R^E^C^E^I^V^
     +E\N\N') 
      CALL FPRINTF(STDOUT,'* ^FOR ACTING AS A SERVER:       ^S^E^R^V^E^R
     +\N\N')
      CALL FPRINTF(STDOUT,'* ^SETTING NONSTANDARD TRANSMISSION AND FILE 
     +PARAMETERS:\N        ^S^E^T ^D^E^B^U^G, ^D^E^L^A^Y, ^D^U^P^L^E^X, 
     +^P^A^R^I^T^Y, ^I^N^I^T-^R^E^T^R^Y, ^R^E^T^R^Y\N') 
      CALL FPRINTF(STDOUT,'        ^S^E^T ^S^E^N^D (OR ^R^E^C^E^I^V^E) ^
     +END-OF-^LINE, ^PACKET-LENGTH, ^PAD-^CHARACTER,\N                ^P
     +AD-^LENGTH, ^QUOTE-^CHARACTER, ^SYNC-^CHARACTER, ^TIME-^OUT\N') 
      CALL FPRINTF(STDOUT,'* ^GETTING INFORMATION:          ^H^E^L^P [TO
     +PIC], ^S^T^A^T^U^S, ^S^H^O^W\N\N')
      CALL FPRINTF(STDOUT,'* ^LEAVING THE PROGRAM:          ^E^X^I^T, ^Q
     +^U^I^T\N\N')
      CALL FPRINTF(STDOUT,'^FOR FURTHER INFORMATION, TYPE "HELP" FOR ANY
     + OF THE ABOVE, E.G. "HELP SET",\NOR SEE THE "^KERMIT ^USERS ^GUIDE
     +" AND THE "^KERMIT ^PROTOCOL ^MANUAL" FOR COMPLETE\NDETAILS.\N\N')
      RETURN
C 
C     HELP PUSH 
C 
40    CALL FPRINTF(STDOUT,'\N^P^U^S^H\N\N^EXIT FROM ^KERMIT-170 SAVING T
     +HE CURRENT ENVIRONMENT.  ^THE ENVIRONMENT WILL BE\NRESTORED UPON R
     +EENTERING ^KERMIT-170.\N')
      RETURN
C 
C     HELP RECEIVE
C 
50    CALL FPRINTF(STDOUT,'\N^R^E^C^E^I^V^E\N\N^RECEIVE A FILE OR GROUP 
     +OF FILES FROM THE OTHER HOST.  ^IF THE NAME IN THE\N')
      CALL FPRINTF(STDOUT,'HEADER PACKET IS NOT A LEGAL ^CYBER FILE NAME
     +, THE FIRST 7 LEGAL CHARACTERS\N')
      CALL FPRINTF(STDOUT,'WILL BE USED.\N\N^IF THE FILE ALREADY EXITS A
     +S A LOCAL FILE, ^KERMIT WILL ABORT THE TRANSFER.\N')
      CALL FPRINTF(STDOUT,'^IF AN ERROR OCCURS DURING TRANSFER, THE FILE
     + BEING RECEIVED WILL BE\NREMOVED FROM THE LOCAL FILE LIST TO ALLOW
     + THE TRANSFER TO BE RETRIED.\N')
      CALL FPRINTF(STDOUT,'^YOU SHOULD ESCAPE BACK TO YOUR LOCAL ^KERMIT
     + AFTER ENTERING ^R^E^C^E^I^V^E\NMODE AND GIVE THE ^S^E^N^D COMMAND
     +.\N\N') 
      RETURN
C 
C     HELP SEND 
C 
60    CALL FPRINTF(STDOUT,'\N^S^E^N^D FILENAME\N\N')
      CALL FPRINTF(STDOUT,'^SEND A FILE TO THE OTHER HOST.  ^THE NAME OF
     + THE FILE IS PASSED\NTO THE OTHER HOST IN A FILE HEADER PACKET, SO
     + THAT THE FILE CAN BE\NSTORED THERE WITH THE SAME NAME.\N\N') 
      CALL FPRINTF(STDOUT,'^YOU SHOULD ESCAPE BACK TO YOUR LOCAL ^KERMIT
     + AND GIVE THE ^R^E^C^E^I^V^E\NCOMMAND.  ^IF YOU DON''T DO THIS FAS
     +T ENOUGH THE "SEND-INIT" PACKET MAY\NARRIVE PREMATURELY.  ^TO PREV
     +ENT THIS, USE ^S^E^T ^D^E^L^A^Y OR HIT THE ^R^E^T^U^R^N KEY\NON YO
     +UR MICROCOMPUTER IF IT DOES NOT TIMEOUT.\N\N')
      RETURN
C 
C     HELP SERVER 
C 
70    CALL FPRINTF(STDOUT,'\N^S^E^R^V^E^R\N\N') 
C$    IF(UT2D .EQ. 1) 
      CALL FPRINTF(STDOUT,'^ACT AS A SERVER FOR ANOTHER ^KERMIT.  ^TAKE 
     +ALL FURTHER COMMANDS ONLY FROM\NTHE OTHER ^KERMIT.  ^AFTER ISSUING
     + THIS COMMAND, ESCAPE BACK TO YOUR LOCAL\NSYSTEM AND ISSUE ^S^E^N^
     +D, ^R^E^C^E^I^V^E OR ^G^E^T, ^B^Y^E, OR OTHER SERVER-ORIENTED\NCOM
     +MANDS FROM THERE.  ^IF YOUR LOCAL ^KERMIT DOES NOT HAVE A ^B^Y^E C
     +OMMAND,\NIT DOES NOT HAVE THE FULL ABILITY TO COMMUNICATE WITH A ^
     +KERMIT SERVER (IN\NWHICH CASE YOU CAN ONLY USE THE ^S^E^N^D COMMAN
     +D).  ^IF YOUR LOCAL ^KERMIT\NDOES HAVE A ^B^Y^E COMMAND, USE IT TO
     + SHUT DOWN AND LOG OUT THE ^KERMIT\NSERVER WHEN YOU ARE DONE WITH 
     +IT; OTHERWISE, CONNECT BACK TO THE ^CYBER, TYPE\NSEVERAL ^CONTROL-
     +^C''S TO STOP THE SERVER, AND LOGOUT.\N\N') 
C$    ELSE
C$    IF(NOSBE .EQ. 1  .OR.  SCOPE .EQ. 1)
      CALL FPRINTF(STDOUT,'^ACT AS A SERVER FOR ANOTHER ^KERMIT.  ^TAKE 
     +ALL FURTHER COMMANDS ONLY FROM\NTHE OTHER ^KERMIT.  ^AFTER ISSUING
     + THIS COMMAND, ESCAPE BACK TO YOUR LOCAL\NSYSTEM AND ISSUE ^S^E^N^
     +D, ^R^E^C^E^I^V^E OR ^G^E^T, ^B^Y^E, OR OTHER SERVER-ORIENTED\NCOM
     +MANDS FROM THERE.  ^IF YOUR LOCAL ^KERMIT DOES NOT HAVE A ^B^Y^E C
     +OMMAND,\NIT DOES NOT HAVE THE FULL ABILITY TO COMMUNICATE WITH A ^
     +KERMIT SERVER (IN\NWHICH CASE YOU CAN ONLY USE THE ^S^E^N^D COMMAN
     +D).  ^IF YOUR LOCAL ^KERMIT\NDOES HAVE A ^B^Y^E COMMAND, USE IT TO
     + SHUT DOWN AND LOG OUT THE ^KERMIT\NSERVER WHEN YOU ARE DONE WITH 
     +IT; OTHERWISE, CONNECT BACK TO THE ^CYBER, TYPE\NSEVERAL ^PERCENT-
     +^A''S TO STOP THE SERVER, AND LOGOUT.\N\N') 
C$    ELSE
      CALL FPRINTF(STDOUT,'^ACT AS A SERVER FOR ANOTHER ^KERMIT.  ^TAKE 
     +ALL FURTHER COMMANDS ONLY FROM\NTHE OTHER ^KERMIT.  ^AFTER ISSUING
     + THIS COMMAND, ESCAPE BACK TO YOUR LOCAL\NSYSTEM AND ISSUE ^S^E^N^
     +D, ^R^E^C^E^I^V^E OR ^G^E^T, ^B^Y^E, OR OTHER SERVER-ORIENTED\NCOM
     +MANDS FROM THERE.  ^IF YOUR LOCAL ^KERMIT DOES NOT HAVE A ^B^Y^E C
     +OMMAND,\NIT DOES NOT HAVE THE FULL ABILITY TO COMMUNICATE WITH A ^
     +KERMIT SERVER (IN\NWHICH CASE YOU CAN ONLY USE THE ^S^E^N^D COMMAN
     +D).  ^IF YOUR LOCAL ^KERMIT\NDOES HAVE A ^B^Y^E COMMAND, USE IT TO
     + SHUT DOWN AND LOG OUT THE ^KERMIT\NSERVER WHEN YOU ARE DONE WITH 
     +IT; OTHERWISE, CONNECT BACK TO THE ^CYBER, TYPE\NSEVERAL ^CONTROL-
     +^T''S TO STOP THE SERVER, AND LOGOUT.\N\N') 
C$    ENDIF 
C$    ENDIF 
      RETURN
C 
C     HELP SET
C 
80    CALL FPRINTF(STDOUT,'\N^S^E^T\N') 
      CALL FPRINTF(STDOUT,'  ^ESTABLISH SYSTEM-DEPENDENT PARAMETERS.  ^Y
     +OU CAN EXAMINE THEIR VALUES WITH THE\N  ^S^H^O^W COMMAND.  ^NUMERI
     +C VALUES MAY BE DECIMAL, OCTAL (POSTFIXED WITH A ^B),\N  OR HEXADE
     +CIMAL (POSTFIXED BY AN ^H).  ^THE FOLLOWING MAY BE ^S^E^T:\N\N')
      CALL FPRINTF(STDOUT,' ^D^A^T^A-^M^O^D^E KEYWORD\N') 
      CALL FPRINTF(STDOUT,'   ^DECLARES THE DATA MODE TO BE USED WHILE P
     +ROCESSING DISK FILES.  ^THE CHOICES\N   ARE ^A^S^C^I^I, ^D^I^S^P^L
     +^A^Y, AND ^IMAGE-^A^S^C^I^I.  ^A^S^C^I^I MEANS THE DISK FILE CONTA
     +INS\N   ^A^S^C^I^I DATA, ^D^I^S^P^L^A^Y MEANS THE FILE CONTAINS ^D
     +ISPLAY ^CODE DATA, AND ^IMAGE-\N   ^A^S^C^I^I MEANS THE FILE CONTA
     +INS 8-BIT ^A^S^C^I^I DATA.  ^THE DEFAULT IS ^D^I^S^P^L^A^Y.\N\N') 
      CALL FPRINTF(STDOUT,' ^D^E^B^U^G OPTIONS\N   ^SHOW PACKET TRAFFIC 
     +EXPLICITLY.  ^OPTIONS ARE:\N')
      CALL FPRINTF(STDOUT,'   ^A^L^L      ^SET ALL DEBUG OPTIONS.\N') 
      CALL FPRINTF(STDOUT,'   ^L^O^G-^F^I^L^E ^LOG STATES AND PACKETS TO
     + THE SPECIFIED FILE.  ^THE DEFAULT\N            LOG-FILE IS FILE ^
     +K^E^R^M^L^O^G.\N')
      CALL FPRINTF(STDOUT,'   ^O^F^F      ^DON''T DISPLAY DEBUGGING INFO
     +RMATION (THIS IS THE DEFAULT).  ^IF\N            DEBUGGING WAS IN 
     +EFFECT, TURN IT OFF AND CLOSE ANY LOG FILE.\N') 
      CALL FPRINTF(STDOUT,'   ^P^A^C^K^E^T^S  ^DISPLAY EACH INCOMING AND
     + OUTGOING PACKET (LENGTHY).\N') 
      CALL FPRINTF(STDOUT,'   ^S^T^A^T^E^S   ^SHOW KERMIT STATE TRANSITI
     +ONS AND PACKET NUMBERS (BRIEF).\N\N') 
      CALL FPRINTF(STDOUT,' ^D^E^L^A^Y DECIMAL-NUMBER\N') 
      CALL FPRINTF(STDOUT,'   ^HOW MANY SECONDS TO WAIT BEFORE SENDING T
     +HE FIRST PACKET.  ^THIS GIVES YOU\N   TIME TO "ESCAPE" BACK AND IS
     +SUE A ^R^E^C^E^I^V^E COMMAND.\N\N') 
      CALL FPRINTF(STDOUT,' ^D^U^P^L^E^X KEYWORD\N')
      CALL FPRINTF(STDOUT,'   ^CHANGES THE METHOD OF ECHOING CHARACTERS 
     +WHEN BEING PROMPTED FOR COMMANDS.\N   ^THE CHOICES ARE ^F^U^L^L AN
     +D ^H^A^L^F.  ^FULL MEANS THE ^CYBER WILL ECHO THE\N   CHARACTERS Y
     +OU TYPE.  ^HALF MEANS THE LOCAL SYSTEMS ECHOS THEM.  ^FULL IS\N 
     +THE DEFAULT, AND IS USED BY MOST HOSTS.\N\N') 
      CALL FPRINTF(STDOUT,' ^I^N^I^T-^R^E^T^R^Y DECIMAL-NUMBER\N')
      CALL FPRINTF(STDOUT,'   ^SET THE MAXIMUM NUMBER OF RETRIES ALLOWED
     + FOR THE INITIAL CONNECTION\N   BEFORE GIVING UP.\N\N') 
      CALL FPRINTF(STDOUT,' ^P^A^R^I^T^Y KEYWORD\N')
      CALL FPRINTF(STDOUT,'   ^IF THE OTHER COMPUTER IS USING PARITY ON 
     +THE COMMUNICATION LINE, YOU MUST\N   INFORM ^KERMIT-170, SO IT CAN
     + SEND THE DESIRED PARITY ON OUTGOING CHARACTERS,\N   AND STRIP IT 
     +FROM INCOMING ONES.\N') 
      CALL FPRINTF(STDOUT,'\N   ^THIS MUST BE SET IN ^KERMIT AND THE FRO
     +NT-END.  ^SEE A SYSTEM MANUAL FOR\N   SETTING PARITY IN THE FRONT-
     +END.\N')
      CALL FPRINTF(STDOUT,'\N   ^CHOICES ARE ^N^O^N^E (THE DEFAULT), ^E^
     +V^E^N, ^O^D^D, ^M^A^R^K, AND ^S^P^A^C^E.\N   ^N^O^N^E MEANS NO PAR
     +ITY PROCESSING IS DONE, AND THE 8TH BIT OF EACH CHARACTER\N   CAN 
     +BE USED FOR DATA WHEN TRANSMITTING BINARY FILES.\N\N')
      CALL FPRINTF(STDOUT,' ^R^D^E^L^A^Y DECIMAL-NUMBER\N') 
      CALL FPRINTF(STDOUT,'   ^SET THE NUMBER OF MILLISECONDS OF DELAY B
     +EFORE ISSUING A READ TO THE\N   TERMINAL.  ^THIS MAY BE USED TO TU
     +NE READS SO THAT DATA IS READY\N   WHEN THE READ FUNCTION IS ISSUE
     +D AND SWAPPING DOES NOT TAKE PLACE.\N\N') 
      CALL FPRINTF(STDOUT,' ^R^E^T^R^Y DECIMAL-NUMBER\N') 
      CALL FPRINTF(STDOUT,'   ^SET THE MAXIMUM NUMBER OF RETRIES ALLOWED
     + FOR SENDING A PARTICULAR PACKET.\N\N') 
      CALL FPRINTF(STDOUT,' ^S^E^N^D PARAMETER\N   ^PARAMETERS FOR OUTGO
     +ING PACKETS AS FOLLOWS:\N\N') 
      CALL FPRINTF(STDOUT,'   ^END-OF-^LINE OCTAL-NUMBER\N')
      CALL FPRINTF(STDOUT,'     ^THE OCTAL VALUE OF THE ^A^S^C^I^I CHARA
     +CTER TO BE USED AS A LINE TERMINATOR\N     FOR PACKETS, IF ONE IS 
     +REQUIRED BY THE OTHER SYSTEM.  ^CARRIAGE\N     RETURN (15^B) BY DE
     +FAULT.\N\N')
      CALL FPRINTF(STDOUT,'   ^PACKET-^LENGTH DECIMAL-NUMBER\N')
      CALL FPRINTF(STDOUT,'     ^MAXIMUM PACKET LENGTH TO SEND, DECIMAL 
     +NUMBER, BETWEEN 20 AND 94,\N     94 BY DEFAULT.\N\N') 
      CALL FPRINTF(STDOUT,'   ^PAD-^CHARACTER OCTAL-NUMBER\N')
      CALL FPRINTF(STDOUT,'     ^CHARACTER TO USE FOR PADDING.  ^DEFAULT
     + IS ^N^U^L.\N\N') 
      CALL FPRINTF(STDOUT,'   ^PAD-^LENGTH DECIMAL-NUMBER\N') 
      CALL FPRINTF(STDOUT,'     ^HOW MUCH PADDING TO SEND BEFORE A PACKE
     +T.  ^DEFAULT IS NO PADDING.\N\N') 
      CALL FPRINTF(STDOUT,'   ^QUOTE-^CHARACTER OCTAL-NUMBER\N')
      CALL FPRINTF(STDOUT,'     ^WHAT PRINTABLE CHARACTER TO USE FOR QUO
     +TING OF CONTROL CHARACTERS.\N     ^THE DEFAULT IS "#" (43^B).  ^TH
     +ERE SHOULD BE NO REASON TO CHANGE THIS.\N\N') 
      CALL FPRINTF(STDOUT,'   ^SYNC-^CHARACTER OCTAL-NUMBER\N') 
      CALL FPRINTF(STDOUT,'     ^THE CONTROL CHARACTER THAT MARKS THE BE
     +GINNING OF THE PACKET.  ^NORMALLY\N     ^S^O^H (^CONTROL-^A, ^A^S^
     +C^I^I 1).  ^THERE SHOULD BE NO REASON TO CHANGE THIS.\N\N') 
      CALL FPRINTF(STDOUT,'   ^TIME-^OUT DECIMAL-NUMBER\N') 
      CALL FPRINTF(STDOUT,'     ^HOW MANY SECONDS THE OTHER ^KERMIT WANT
     +S BEFORE BEING ASKED\N     FOR RETRANSMISSION.  ^UNFORTUNATELY, TH
     +E ^CYBER HAS NO WAY OF TIMING\N     OUT SO THIS PARAMETER IS IGNOR
     +ED.\N\N') 
      CALL FPRINTF(STDOUT,' ^R^E^C^E^I^V^E PARAMETER\N   ^PARAMETERS TO 
     +REQUEST OR EXPECT FOR INCOMING PACKETS, AS FOLLOWS:\N\N') 
      CALL FPRINTF(STDOUT,'   ^END-OF-^LINE OCTAL-NUMBER\N')
      CALL FPRINTF(STDOUT,'     ^THE OCTAL VALUE OF THE ^A^S^C^I^I CHARA
     +CTER TO BE USED AS A LINE TERMINATOR\N     FOR PACKETS, IF ONE IS 
     +REQUIRED BY THE OTHER SYSTEM.  ^CARRIAGE\N     RETURN (15^B) BY DE
     +FAULT.\N\N')
      CALL FPRINTF(STDOUT,'   ^PACKET-^LENGTH DECIMAL-NUMBER\N')
      CALL FPRINTF(STDOUT,'     ^MAXIMUM PACKET LENGTH TO SEND, DECIMAL 
     +NUMBER, BETWEEN 20 AND 94,\N     94 BY DEFAULT.\N\N') 
      CALL FPRINTF(STDOUT,'   ^PAD-^CHARACTER OCTAL-NUMBER\N')
      CALL FPRINTF(STDOUT,'     ^CHARACTER TO USE FOR PADDING.  ^DEFAULT
     + IS ^N^U^L.\N\N') 
      CALL FPRINTF(STDOUT,'   ^PAD-^LENGTH DECIMAL-NUMBER\N') 
      CALL FPRINTF(STDOUT,'     ^HOW MUCH PADDING TO SEND BEFORE A PACKE
     +T.  ^DEFAULT IS NO PADDING.\N\N') 
      CALL FPRINTF(STDOUT,'   ^QUOTE-^CHARACTER OCTAL-NUMBER\N')
      CALL FPRINTF(STDOUT,'     ^WHAT PRINTABLE CHARACTER TO USE FOR QUO
     +TING OF CONTROL CHARACTERS.\N     ^THE DEFAULT IS "#" (43^B).  THE
     +RE SHOULD BE NO REASON TO CHANGE THIS.\N\N')
      CALL FPRINTF(STDOUT,'   ^SYNC-^CHARACTER OCTAL-NUMBER\N') 
      CALL FPRINTF(STDOUT,'     ^THE CONTROL CHARACTER THAT MARKS THE BE
     +GINNING OF THE PACKET.  ^NORMALLY\N     ^S^O^H (^CONTROL-^A, ^A^S^
     +C^I^I 1).  ^THERE SHOULD BE NO REASON TO CHANGE THIS.\N\N') 
      CALL FPRINTF(STDOUT,'   ^TIME-^OUT DECIMAL-NUMBER\N') 
      CALL FPRINTF(STDOUT,'     ^HOW MANY SECONDS THE OTHER ^KERMIT SHOU
     +LD WAIT FOR A PACKET BEFORE\N     ASKING FOR RETRANSMISSION.\N\N')
      RETURN
C 
C     HELP SHOW 
C 
90    CALL FPRINTF(STDOUT,'^DISPLAY CURRENT ^S^E^T PARAMETERS, VERSION O
     +F ^KERMIT-170, AND OTHER INFO.\N')
      RETURN
C 
C     HELP STATUS 
C 
100   CALL FPRINTF(STDOUT,'^GIVE STATISTICS ABOUT THE MOST RECENT FILE T
     +RANSFER.\N')
      RETURN
C 
C     HELP !
C 
110   CALL FPRINTF(STDOUT,'\N! ^MONITOR-^COMMAND\N\N^EXECUTE A MONITOR C
     +OMMAND FROM WITHIN ^KERMIT-170.  ^THE CURRENT SETTINGS\NWILL BE PR
     +ESERVED.\N')
      RETURN
      END 
*IF DEF,OVCAP 
          IDENT  KERMRCV
          ENTRY  KERMRCV
          LCC    OVCAP. 
          LDSET  NOEPT=UNLFILE
 KERMRCV  TITLE  KERMRCV - KERMIT RECEIVE FILE PROCESSOR. 
          COMMENT KERMIT RECEIVE FILE PROCESSOR.
 KERMRCV  SPACE  4,10 
**        KERMRCV - KERMIT RECEIVE FILE PROCESSOR.
  
  
 KERMRCV  SUBR               ENTRY/EXIT 
          RJ     =XRCVFILE   CALL THE REAL WORKHORSE
          EQ     KERMRCVX    RETURN 
  
          END 
*ENDIF
      SUBROUTINE RCVFILE
  
CCC   RCVFILE - TOP LEVEL SUBROUTINE TO START RECEIVE STATE.
C 
*CALL KERMCOM 
      LOGICAL CONFIRM 
C 
C     CONFIRM THE COMMAND 
C 
      IF (.NOT. CONFIRM(STDIN)) RETURN
C 
C     INSURE THEIR IS NO JUNK IN THE FILE ARRAY.  THIS KEEPS REMOVE 
C     HAPPY, IN THE EVENT WE BLOW OFF BEFORE WE GET A FILE SPEC.
C 
      DO 10 I = 1, MAXPACK
          FILESTR(I) = 0
10    CONTINUE
  
      CALL STTY('BINARY',ON)
      IF(DSKCSET .EQ. DSKIMAG) CALL STTY('RAW',ON)
      SAVEDPX = GTTY('DUPLEX')
      CALL STTY('DUPLEX',HALFDUP) 
      IF (RECEIVE(R) .EQ. OK) THEN
         CALL FPRINTF(STDOUT,'^RECEIVE COMPLETE.\N',0,0,0,0)
      ELSE
         CALL FPRINTF(STDOUT,'^RECEIVE FAILED.\N',0,0,0,0)
      ENDIF 
      IF(DSKCSET .EQ. DSKIMAG) CALL STTY('RAW',OFF) 
      CALL STTY('BINARY',OFF) 
      IF (SAVEDPX .NE. HALFDUP) CALL STTY('DUPLEX',FULLDUP) 
      RETURN
      END 
*IF DEF,OVCAP 
          IDENT  KERMSND
          ENTRY  KERMSND
          LCC    OVCAP. 
          LDSET  NOEPT=UNLFILE
 KERMSND  TITLE  KERMSND - KERMIT SEND FILE PROCESSOR.
          COMMENT KERMIT SEND FILE PROCESSOR. 
 KERMSND  SPACE  4,10 
**        KERMSND - KERMIT SEND FILE PROCESSOR. 
  
  
 KERMSND  SUBR               ENTRY/EXIT 
          RJ     =XSNDFILE   CALL THE REAL WORKHORSE
          EQ     KERMSNDX    RETURN 
  
          END 
*ENDIF
      SUBROUTINE SNDFILE
  
CCC   SNDFILE - SEND A FILE TO OTHER KERMIT.
C 
*CALL KERMCOM 
      LOGICAL CFE 
      CHARACTER*10 LFN
C 
C     PICK UP THE FILE NAME AND SAVE IT FOR OPENING LATER 
C 
      CALL SETVAL(FILESTR,'S',IRET,7,0,0,HLPSNFN,.TRUE.)
      IF (IRET .EQ. ERROR) RETURN 
C 
C     MAKE SURE THE NAME IS LEGAL.
C 
      CALL AS2DPC(FILESTR,LFN)
      IF (XVFN(LFN) .NE. 0) THEN
         CALL FPRINTF(STDOUT,'?^ILLEGAL FILE NAME: @S.\N',FILESTR,0,0,0)
         RETURN 
      ENDIF 
C 
C     MAP IT TO UPPER-CASE
C 
      CALL DPC2AS(LFN,FILESTR,SLEN(FILESTR))
C 
C     CHECK TO MAKE SURE IT'S THERE TO SEND 
C 
      IF (.NOT. CFE(LFN)) THEN
         CALL FPRINTF(STDOUT,'?^FILE @S IS NOT LOCAL.\N',FILESTR,0,0,0) 
         RETURN 
      ENDIF 
C 
C     DELAY THE FIRST PACKET
C 
      IF (DELAYFP .GT. 0) CALL SLEEP(DELAYFP) 
      CALL STTY('BINARY',ON)
      IF(DSKCSET .EQ. DSKIMAG) CALL STTY('RAW',ON)
      SAVEDPX = GTTY('DUPLEX')
      CALL STTY('DUPLEX',HALFDUP) 
C 
C     START SENDING PACKETS 
C 
      PACKNUM = 0 
      IF (SEND() .EQ. OK) THEN
         CALL FPRINTF(STDOUT,'^SEND COMPLETE.\N',0,0,0,0) 
      ELSE
         CALL FPRINTF(STDOUT,'^SEND FAILED.\N',0,0,0,0) 
      ENDIF 
      IF(DSKCSET .EQ. DSKIMAG) CALL STTY('RAW',OFF) 
      CALL STTY('BINARY',OFF) 
      IF (SAVEDPX .NE. HALFDUP) CALL STTY('DUPLEX',FULLDUP) 
      RETURN
      END 
*IF DEF,OVCAP 
          IDENT  KERMSET
          ENTRY  KERMSET
          LCC    OVCAP. 
          LDSET  NOEPT=UNLFILE
 KERMSET  TITLE  KERMSET - KERMIT SET COMMAND PROCESSOR.
          COMMENT KERMIT SET COMMAND PROCESSOR. 
 KERMSET  SPACE  4,10 
**        KERMSET - KERMIT SET COMMAND PROCESSOR. 
  
  
 KERMSET  SUBR               ENTRY/EXIT 
          RJ     =XSET       CALL THE REAL WORKHORSE
          EQ     KERMSETX    RETURN 
  
          END 
*ENDIF
      SUBROUTINE SET
  
CCC   SET - SET SOME ATTRIBUTES.
C 
*CALL KERMCOM 
      PARAMETER (TSIZE=10)
      CHARACTER*10 SETTYP(TSIZE)
      DATA SETTYP / 'DATA-MODE', 'DEBUG', 'DELAY', 'DUPLEX',
     +    'INIT-RETRY', 'PARITY', 'RECEIVE', 'RDELAY',
     +    'RETRY', 'SEND' / 
  
      INDX = MATCH(SETTYP,TSIZE,.FALSE.)
      IF (INDX .LE. 0) RETURN 
      GO TO (10, 20, 30, 40, 50, 60, 70, 75, 80, 90), INDX
C 
C     SET CHARACTER SET 
C 
10    CALL DMODCMD
      RETURN
C 
C     SET DEBUGGING MODES 
C 
20    CALL DBUGCMD
      RETURN
C 
C     SET FIRST PACKET DELAY
C 
30    CALL SETVAL(DELAYFP,'I',0,30,0,30,HLPDLFP,.TRUE.) 
      RETURN
C 
C     SET THE DUPLEX
C 
40    CALL DPLXCMD
      RETURN
C 
C     SET INTIAL PACKET RETRY COUNT 
C 
50    CALL SETVAL(MAXRINI,'I',1,50,1,50,HLPIPRC,.TRUE.) 
      RETURN
C 
C     SET PARITY
C 
60    CALL PARCMD 
      RETURN
C 
C     SET RECEIVE PACKET ATTRIBUTES 
C 
70    CALL SETPACK(PACKSIZ) 
      RETURN
C 
C     SET READ DATA DELAY 
C 
75    CALL SETVAL(RDELAY,'I',0,2000,0,2000,HLPRDEL,.TRUE.)
      RETURN
C 
C     SET PACKET RETRY COUNT
C 
80    CALL SETVAL(MAXRTRY,'I',1,50,1,50,HLPPRTR,.TRUE.) 
      RETURN
C 
C     SET SEND PACKET ATTRIBUTES
C 
90    CALL SETPACK(SPKSIZ)
      RETURN
      END 
*IF DEF,OVCAP 
          IDENT  KERMSHO
          ENTRY  KERMSHO
          LCC    OVCAP. 
          LDSET  NOEPT=UNLFILE
 KERMSHO  TITLE  KERMSHO - KERMIT SHOW COMMAND PROCESSOR. 
          COMMENT KERMIT SHOW COMMAND PROCESSOR.
 KERMSHO  SPACE  4,10 
**        KERMSHO - KERMIT SHOW COMMAND PROCESSOR.
  
  
 KERMSHO  SUBR               ENTRY/EXIT 
          RJ     =XSHOW      CALL THE REAL WORKHORSE
          EQ     KERMSHOX    RETURN 
  
          END 
*ENDIF
      SUBROUTINE SHOW 
  
CCC   SHOW THE CURRENT PROGRAM SETTINGS 
C 
*CALL KERMCOM 
      LOGICAL CONFIRM 
C 
C     CONFIRM THE COMMAND 
C 
      IF (.NOT. CONFIRM(STDIN)) RETURN
      CALL FPRINTF(STDOUT,VERSION,0,0,0,0)
C 
C     DISPLAY THE CURRENT DATE AND TIME 
C 
      CALL GETNOW(MM,DD,YY,HR,MIN,SEC)
      CALL PUTDAY(STDOUT,MM,DD,YY)
      CALL FPRINTF(STDOUT,', ',0,0,0,0) 
      CALL PUTMNTH(STDOUT,MM) 
      CALL FPRINTF(STDOUT,' @D, @D ',DD,YY,0,0) 
      IF (HR .LT. 10) CALL PUTC(ASC('0'),STDOUT)
      CALL FPRINTF(STDOUT,'@D:',HR,0,0,0) 
      IF (MIN .LT. 10) CALL PUTC(ASC('0'),STDOUT) 
      CALL FPRINTF(STDOUT,'@D:',MIN,0,0,0)
      IF (SEC .LT. 10) CALL PUTC(ASC('0'),STDOUT) 
      CALL FPRINTF(STDOUT,'@D\N\N',SEC,0,0,0) 
C 
C     DISPLAY DISK CHARACTER SET
C 
      CALL FPRINTF(STDOUT,'  ^DATA-MODE: ',0,0,0,0) 
      IF(DSKCSET .EQ. DSKNOS8) THEN 
          CALL FPRINTF(STDOUT,'^N^O^S 812 ^A^S^C^I^I\N',0,0,0,0)
      ELSEIF(DSKCSET .EQ. DSKUT8) THEN
          CALL FPRINTF(STDOUT,'^U^T 812 ^A^S^C^I^I\N',0,0,0,0)
      ELSEIF(DSKCSET .EQ. DSKDPC) THEN
          CALL FPRINTF(STDOUT,'^DISPLAY-^CODE\N',0,0,0,0) 
      ELSEIF(DSKCSET .EQ. DSKIMAG) THEN 
          CALL FPRINTF(STDOUT,'^IMAGE-^A^S^C^I^I\N',0,0,0,0)
      ELSE
          CALL FPRINTF(STDOUT,'^UNKNOWN',0,0,0,0) 
      ENDIF 
C 
C     DISPLAY KNOWN PARITY
C 
      CALL FPRINTF(STDOUT,'  ^PARITY:    ',0,0,0,0) 
      PARITY = GTTY('PARITY') 
      IF (PARITY .EQ. NONE) THEN
         CALL FPRINTF(STDOUT,'^NONE\N',0,0,0,0) 
      ELSE IF (PARITY .EQ. EVEN) THEN 
         CALL FPRINTF(STDOUT,'^EVEN\N',0,0,0,0) 
      ELSE IF (PARITY .EQ. ODD) THEN
         CALL FPRINTF(STDOUT,'^ODD\N',0,0,0,0)
      ELSE IF (PARITY .EQ. MARK) THEN 
         CALL FPRINTF(STDOUT,'^MARK\N',0,0,0,0) 
      ELSE IF (PARITY .EQ. SPACE) THEN
         CALL FPRINTF(STDOUT,'^SPACE\N',0,0,0,0)
      ELSE
         CALL FPRINTF(STDOUT,'^UNKNOWN\N',0,0,0,0)
      ENDIF 
C 
C     DISPLAY THE CURRENT DUPLEX
C 
      CALL FPRINTF(STDOUT,'  ^DUPLEX:    ',0,0,0,0) 
      DUPLEX = GTTY('DUPLEX') 
      IF (DUPLEX .EQ. FULLDUP) THEN 
         CALL FPRINTF(STDOUT,'^FULL\N',0,0,0,0) 
      ELSE IF (DUPLEX .EQ. HALFDUP) THEN
         CALL FPRINTF(STDOUT,'^HALF\N',0,0,0,0) 
      ELSE
         CALL FPRINTF(STDOUT,'^UNKNOWN\N',0,0,0,0)
      ENDIF 
C 
C     DISPLAY CURRENT DEBUG MODES 
C 
      CALL FPRINTF(STDOUT,'  ^DEBUGGING: ',0,0,0,0) 
      IF ((DEBUG.AND.DBGSTAT).NE.0) CALL FPRINTF(STDOUT,'^STATES ', 
     +   0,0,0,0) 
      IF ((DEBUG.AND.DBGPACK).NE.0) CALL FPRINTF(STDOUT,'^PACKETS', 
     +   0,0,0,0) 
      IF (DEBUG.EQ.DBGOFF) CALL FPRINTF(STDOUT,'^OFF',0,0,0,0)
      CALL PUTC(NEL,STDOUT) 
      IF (DEBUG .NE. DBGOFF) THEN 
         CALL FPRINTF(STDOUT,'   ^LOG FILE: @S\N',DEBUGFN,0,0,0)
      ENDIF 
C 
C     DISPLAY PACKET SETTINGS 
C 
      CALL FPRINTF(STDOUT,'\N^PACKET ^PARAMETERS\N',0,0,0,0)
      CALL FPRINTF(STDOUT,
     +   '                    ^RECEIVE   ^SEND\N',0,0,0,0)
      CALL FPRINTF(STDOUT,'  ^SIZE:             @D        @D\N',
     +   PACKSIZ,SPKSIZ,0,0)
      CALL FPRINTF(STDOUT,'  ^TIMEOUT:          @D        @D\N',
     +   TIMEOUT,STIMOUT,0,0) 
      CALL FPRINTF(STDOUT,'  ^PADDING:          @D',NPAD,0,0,0) 
      IF (NPAD .LT. 10) CALL PUTC(BLANK,STDOUT) 
      CALL FPRINTF(STDOUT,'        @D\N',SPAD,0,0,0)
      CALL FPRINTF(STDOUT,'  ^PAD CHARACTER:    \^@C        \^@C\N',
     +   O"100".XOR.(PADCH),O"100".XOR.(SPADCH),0,0)
      CALL FPRINTF(STDOUT,'  ^END-OF-^LINE:      \^@C        \^@C\N', 
     +   O"100".XOR.(EOLCH),O"100".XOR.(SPEOL),0,0) 
      CALL FPRINTF(STDOUT,'  ^CONTROL QUOTE:    @C         @C\N', 
     +   QUOTECH,SPQUOTE,0,0) 
      CALL FPRINTF(STDOUT,'  ^START-OF-^PACKET:  \^@C        \^@C\N', 
     +   O"100".XOR.(SYNC),O"100".XOR.(SNDSYNC),0,0)
C 
C     DISPLAY PROTOCOL STUFF
C 
      CALL FPRINTF(STDOUT,'\N^DELAY BEFORE SENDING FIST PACKET: @D\N',
     +   DELAYFP,0,0,0) 
      CALL FPRINTF(STDOUT,
     +  '^DELAY @D MILLISECONDS BEFORE EACH ^T^T^Y READ\N',RDELAY,0,0,0)
      CALL FPRINTF(STDOUT,'^INIT PACKET RETRY COUNT: @D\N',MAXRINI,0,0, 
     +   0) 
      CALL FPRINTF(STDOUT,'^PACKET RETRY COUNT: @D\N\N',MAXRTRY,0,0,0)
      RETURN
      END 
*IF DEF,OVCAP 
          IDENT  KERMSTA
          ENTRY  KERMSTA
          LCC    OVCAP. 
          LDSET  NOEPT=UNLFILE
 KERMSTA  TITLE  KERMSTA - KERMIT STATUS COMMAND PROCESSOR. 
          COMMENT KERMIT STATUS COMMAND PROCESSOR.
 KERMSTA  SPACE  4,10 
**        KERMSTA - KERMIT STATUS COMMAND PROCESSOR.
  
  
 KERMSTA  SUBR               ENTRY/EXIT 
          RJ     =XSTATUS    CALL THE REAL WORKHORSE
          EQ     KERMSTAX    RETURN 
  
          END 
*ENDIF
      SUBROUTINE STATUS 
  
CCC   STATUS - TELL HOW LONG LAST TRANSFER TOOK.
C 
*CALL KERMCOM 
      LOGICAL CONFIRM 
C 
C     CONFIRM THE COMMAND 
C 
      IF (.NOT. CONFIRM(STDIN)) RETURN
      CALL FPRINTF(STDOUT,
     +   '^MAX CHARACTERS IN PACKET: @D RECEIVED; @D SENT\N',PACKSIZ, 
     +   SPKSIZ,0,0)
      IF (ENDTIM .LT. STARTIM) ENDTIM = ENDTIM + 86400
      NSEC = ENDTIM - STARTIM 
      HR = NSEC / 3600
      NSEC = NSEC - (HR * 3600) 
      MIN = NSEC / 60 
      NSEC = NSEC - (MIN * 60)
      CALL FPRINTF(STDOUT,'^NUMBER OF CHARACTERS TRANSMITTED IN ',
     +   0,0,0,0) 
      IF (HR .GT. 0) CALL FPRINTF(STDOUT,'@D HOURS ',HR,0,0,0)
      IF (MIN .GT. 0) CALL FPRINTF(STDOUT,'@D MINUTES ',MIN,0,0,0)
      CALL FPRINTF(STDOUT,'@D SECONDS\N\N',NSEC,0,0,0)
      CALL FPRINTF(STDOUT,'             ^SENT:  @20D',SCHCNT,0,0,0) 
      CALL FPRINTF(STDOUT,' ^OVERHEAD:  @D\N',SCHOVRH,0,0,0)
      CALL FPRINTF(STDOUT,'         ^RECEIVED:  @20D',RCHCNT,0,0,0) 
      CALL FPRINTF(STDOUT,' ^OVERHEAD:  @D\N',RCHOVRH,0,0,0)
      CALL FPRINTF(STDOUT,'^TOTAL TRANSMITTED:  @20D',SCHCNT+RCHCNT,0,0,
     +   0) 
      CALL FPRINTF(STDOUT,' ^OVERHEAD:  @D\N',SCHOVRH+RCHOVRH,0,0,0)
      CALL FPRINTF(STDOUT,
     +   '^TOTAL CHARACTERS TRANSMITTED PER SEC: @D\N', 
     +   (SCHCNT+RCHCNT) / (ENDTIM-STARTIM),0,0,0)
      CALL FPRINTF(STDOUT,
     +   '^EFFECTIVE DATA RATE: @D BAUD\N', ((SCHCNT+RCHCNT) -
     +   (SCHOVRH+RCHOVRH)) / (ENDTIM-STARTIM) * 10,0,0,0)
      IF (STATE .NE. C) THEN
         CALL GETEMSG(PACKET) 
         CALL FPRINTF(STDOUT,'?^KERMIT:  @S\N',PACKET,0,0,0)
      ENDIF 
      RETURN
      END 
*IF DEF,OVCAP 
          IDENT  KERMSRV
          ENTRY  KERMSRV
          LCC    OVCAP. 
          LDSET  NOEPT=UNLFILE
 KERMSRV  TITLE  KERMSRV - KERMIT SERVER-MODE PROCESSOR.
          COMMENT KERMIT SERVER-MODE PROCESSOR. 
 KERMSRV  SPACE  4,10 
**        KERMSRV - KERMIT SERVER-MODE PROCESSOR. 
  
  
 KERMSRV  SUBR               ENTRY/EXIT 
          RJ     =XSERVER    CALL THE REAL WORKHORSE
          EQ     KERMSRVX    RETURN 
  
          END 
*ENDIF
      SUBROUTINE SERVER 
  
CCC   SERVER - START KERMIT SERVER
C 
C     THE SERVER CURRENTLY KNOWS ABOUT THE SEND AND RECEIVE PACKETS 
C     AND ALSO THE GENERIC KERMIT PACKETS LOGOUT AND FINISH.  USING 
C     LOGOUT CAN CAUSE PROBLEM DUE TO FILES NOT BEING MADE PERMANENT
C     BEFORE LEAVING.  I SUPPOSE IMPLEMENTING SYSTEM COMMAND PACKETS
C     WOULD ALLOW FILES TO BE SAVED BUT WHAT OTHER KERMIT ALLOWS
C     SYSTEM COMMAND PACKETS AND IS THERE A STANDARD WHAT TO
C     CHECKPOINT PROGRAMS ON THE CYBER? 
C 
*CALL KERMCOM 
      CHARACTER*10 LFN
      LOGICAL CONFIRM, CFE
C 
C     CONFIRM THE COMMAND 
C 
      IF (.NOT. CONFIRM(STDIN)) RETURN
C 
C     INITIALIZE MSG #, SAY NO TRIES YET
C 
      PACKNUM = 0 
      NUMTRY = 0
      CALL FPRINTF(STDOUT,'[^KERMIT SERVER RUNNING ON ^CYBER HOST.  ^PLE
     +ASE TYPE YOUR ESCAPE SEQUENCE TO\N RETURN TO YOUR LOCAL MACHINE. ^
     +SHUT DOWN THE SERVER BY TYPING THE ^KERMIT ^B^Y^E \N COMMAND ON YO
     +UR LOCAL MACHINE.]\N',0,0,0,0)
      CALL STTY('BINARY',ON)
      SAVEDPX = GTTY('DUPLEX')
      CALL STTY('DUPLEX',HALFDUP) 
    1 PTYP = RDPACK(LEN,NUM,RECPACK)
      IF (PTYP .EQ. S) THEN 
         PACKNUM = NUM
         CALL RDPARAM(RECPACK)
         I = SNDPAR(PACKET) 
         CALL SNDPACK(Y,PACKNUM,I,PACKET) 
         NUMTRY = 0 
         PACKNUM = MOD(PACKNUM+1,64)
         RECSTAT = RECEIVE(F) 
         IF (DEBUG .NE. 0) THEN 
            IF (RECSTAT .EQ. ERROR) THEN
               CALL FPRINTF(DEBUGFD,'^RECEIVE FAILED.\N',0,0,0,0) 
            ELSE
               CALL FPRINTF(DEBUGFD,'^RECEIVE COMPLETED.\N',0,0,0,0)
            ENDIF 
         ENDIF
      ELSE IF (PTYP .EQ. R) THEN
            I = 0 
            CALL STRCPY(RECPACK,FILESTR)
            CALL AS2DPC(FILESTR,LFN)
            IF (XVFN(LFN) .NE. 0) THEN
               ABORTYP = INVFN
               CALL GETEMSG(ERRMSG(15)) 
               CALL SNDPACK(E,PACKNUM,SLEN(ERRMSG),ERRMSG)
            ELSE IF (.NOT. CFE(LFN)) THEN 
               ABORTYP = NOTLCL 
               CALL GETEMSG(ERRMSG(15)) 
               CALL SNDPACK(E,PACKNUM,SLEN(ERRMSG),ERRMSG)
            ELSE
               SNDSTAT = SEND() 
               PACKNUM = 0
               IF (DEBUG .NE. 0) THEN 
                  IF (SNDSTAT .EQ. ERROR) THEN
                     CALL FPRINTF(DEBUGFD,'^SEND FAILED.\N',0,0,0,0)
                  ELSE
                     CALL FPRINTF(DEBUGFD,'^SEND COMPLETED.\N',0,0,0,0) 
                  ENDIF 
               ENDIF
            ENDIF 
      ELSE IF (PTYP .EQ. G) THEN
            IF (RECPACK(1) .EQ. L) THEN 
               CALL SNDPACK(Y,NUM,0,0)
               CALL LOGOUT
            ELSE IF (RECPACK(1) .EQ. F) THEN
                  CALL SNDPACK(Y,NUM,0,0) 
                  NORMAL = .TRUE. 
                  CALL EXITPGM
            ELSE
               ABORTYP = SRVCMD 
               CALL GETEMSG(ERRMSG(15)) 
               CALL SNDPACK(E,PACKNUM,SLEN(ERRMSG),ERRMSG)
            ENDIF 
      ELSE
         IF (DEBUG .NE. 0) CALL FPRINTF 
     +     (DEBUGFD,'SERVER: INVALID PACKET TYPE: @D\N',PTYP,0,0,0) 
         ABORTYP = INVALID.OR.READING.OR.SRVERR 
         CALL GETEMSG(ERRMSG(15)) 
         CALL SNDPACK(E,PACKNUM,SLEN(ERRMSG),ERRMSG)
      ENDIF 
      GO TO 1 
      END 
*IF DEF,OVCAP 
*CWEOR
*ENDIF
*DECK KERMLIB 
      SUBROUTINE DMODCMD
  
CCC   DMODCMD - PERFORM A SET DATA-MODE XXXX COMMAND. 
C 
*CALL KERMCOM 
      LOGICAL CONFIRM 
C$    IF (UT2D .EQ. 1)
      PARAMETER (TSIZE=4) 
C$    ENDIF 
C$    IF (UT2D .NE. 1)
      PARAMETER (TSIZE=3) 
C$    ENDIF 
      CHARACTER*15 DATATYP(TSIZE) 
C$    IF (UT2D .EQ. 1)
      DATA DATATYP /'ASCII', 'DISPLAY-CODE', 'IMAGE-ASCII', 'NOS-ASCII'/
C$    ENDIF 
C$    IF (UT2D .NE. 1)
      DATA DATATYP / 'ASCII', 'DISPLAY-CODE', 'IMAGE-ASCII' / 
C$    ENDIF 
C 
C     MATCH THE PARAMETER.
C 
      INDX = MATCH(DATATYP,TSIZE,.FALSE.) 
      IF (INDX .LE. 0) RETURN 
      IF (.NOT. CONFIRM(STDIN)) RETURN
C 
C     TAKE THE APPROPRIATE ACTION.
C 
C$    IF (UT2D .EQ. 1)
      GO TO (10, 20, 30, 40), INDX
C$    ENDIF 
C$    IF (UT2D .NE. 1)
      GO TO (10, 20, 30), INDX
C$    ENDIF 
C 
C     SET ASCII CHARACTER SET.
C 
C$    IF (UT2D .EQ. 1)
10    DSKCSET = DSKUT8
C$    ENDIF 
C$    IF (UT2D .NE. 1)
10    DSKCSET = DSKNOS8 
C$    ENDIF 
      RETURN
C 
C     SET DISPLAY CHARACTER SET.
C 
20    DSKCSET = DSKDPC
      RETURN
C 
C     SET IMAGE DATA MODE.
C 
30    DSKCSET = DSKIMAG 
      RETURN
  
C$    IF (UT2D .EQ. 1)
C 
C     SET NOS 812 ASCII 
C 
40    DSKCSET = DSKNOS8 
      RETURN
C$    ENDIF 
      END 
      SUBROUTINE DBUGCMD
  
CCC   DBUGCMD - SET THE DEBUGGING MODES.
C 
*CALL KERMCOM 
      CHARACTER*10 FN 
      LOGICAL CONFIRM 
      PARAMETER (TSIZE=5) 
      CHARACTER*10 DBGTYP(TSIZE)
      DATA DBGTYP / 'ALL', 'LOG-FILE', 'OFF', 'PACKETS', 'STATES' / 
  
      INDX = MATCH(DBGTYP,TSIZE,.FALSE.)
      IF (INDX .LE. 0) RETURN 
      GO TO (10, 20, 30, 40, 50), INDX
C 
C     SET ALL DEBUG MODES 
C 
10    IF (.NOT. CONFIRM(STDIN)) RETURN
      DEBUG = DBGALL
      GO TO 100 
C 
C     SET DEBUG LOGFILE 
C 
20    CALL SETVAL(DEBUGFN,'S',IRET,7,0,0,HLPDBFN,.TRUE.)
      IF (IRET .EQ. OK) THEN
         IF (DEBUGFD .NE. 0) THEN 
            CALL FCLOSE(DEBUGFD)
            DEBUGFD = 0 
         ENDIF
         GO TO 100
      ENDIF 
      RETURN
C 
C     TURN OFF ALL DEBUGGING
C 
30    IF (.NOT. CONFIRM(STDIN)) RETURN
      DEBUG = DBGOFF
      IF (DEBUGFD .NE. 0) THEN
         CALL FCLOSE(DEBUGFD) 
         DEBUGFD = 0
      ENDIF 
      RETURN
C 
C     TOGGLE DEBUG PACKETS
C 
40    IF (.NOT. CONFIRM(STDIN)) RETURN
      DEBUG = DEBUG .XOR. DBGPACK 
      GO TO 100 
C 
C     TOGGLE DEBUG STATES 
C 
50    IF (.NOT. CONFIRM(STDIN)) RETURN
      DEBUG = DEBUG .XOR. DBGSTAT 
      GO TO 100 
C 
C     OPEN THE DEBUG FILE IF NOT DONE ALREADY 
C 
100   IF (DEBUGFD .EQ. 0) THEN
         CALL AS2DPC(DEBUGFN,FN)
         DEBUGFD = FOPEN(FN,WR) 
      ENDIF 
      RETURN
      END 
      SUBROUTINE SETPACK(ATTR)
  
CCC   SET PACKET SEND OR RECEIVE ATTRIBUTES.
C 
C     SETPACK WILL WET THE ATTRIBUTES OF THE PASSED ATTRIBUTE 
C     LIST.  THIS SUBROUTINE WILL SET THE APPROPRIATE PACKET
C     PARAMETER.  THE PARAMETER TO SET IS PASSED IN AN ARRAY
C     AND IS VERY ORDER DEPENDENT.  SEE COMMON BLOCK /PACKET/ 
C     FOR THE ORDERING.  NOTE THAT SEND AND RECEIVE PARAMETER 
C     ORDERING AND STORAGE SIZE IN THE COMMON BLOCK ARE 
C     IDENTICAL.  KEEP IT THAT WAY! 
C 
*CALL KERMCOM 
      INTEGER ATTR(12)
      PARAMETER (TSIZE=7) 
      CHARACTER*15 ATTRTYP(TSIZE) 
      DATA ATTRTYP / 'END-OF-LINE', 'PACKET-LENGTH', 'PAD-CHARACTER', 
     +               'PAD-LENGTH', 'QUOTE-CHARACTER', 'SYNC-CHARACTER', 
     +               'TIME-OUT' / 
  
      INDX = MATCH(ATTRTYP,TSIZE,.FALSE.) 
      IF (INDX .LE. 0) RETURN 
      GO TO (10, 20, 30, 40, 50, 60, 70), INDX
C 
C     SET EOL CHARACTER 
C 
10    CALL SETVAL(ATTR(5),'I',1,31,127,127,HLPASCH,.TRUE.)
      RETURN
C 
C     SET MAXIMUM PACKET LENGTH 
C 
20    CALL SETVAL(ATTR(1),'I',20,94,20,94,HLPPLEN,.TRUE.) 
      RETURN
C 
C     SET PAD CHARACTER 
C 
30    CALL SETVAL(ATTR(4),'I',0,31,127,127,HLPASCH,.TRUE.)
      RETURN
C 
C     SET PAD LENGTH
C 
40    CALL SETVAL(ATTR(3),'I',0,94,0,94,HLPPADL,.TRUE.) 
      RETURN
C 
C     SET QUOTE CHARACTER 
C 
50    CALL SETVAL(ATTR(6),'I',33,62,96,126,HLPASCH,.TRUE.)
      RETURN
C 
C     SET SYNC CHARACTER
C 
60    CALL SETVAL(ATTR(12),'I',0,127,0,127,HLPASCH,.TRUE.)
      RETURN
C 
C     SET TIMEOUT VALUE 
C 
70    CALL SETVAL(ATTR(2),'I',0,94,0,94,HLPTIMO,.TRUE.) 
      RETURN
      END 
      SUBROUTINE DPLXCMD
  
CCC   DPLXCMD - PERFORM A SET DUPLEX XXXX COMMAND 
C 
*CALL KERMCOM 
      LOGICAL CONFIRM 
      PARAMETER (TSIZE=2) 
      CHARACTER*10 DUPTYP(TSIZE)
      DATA DUPTYP / 'FULL', 'HALF' /
C 
C     MATCH THE PARAMETER 
C 
      INDX = MATCH(DUPTYP,TSIZE,.FALSE.)
      IF (INDX .LE. 0) RETURN 
      IF (.NOT. CONFIRM(STDIN)) RETURN
C 
C     TAKE THE APPROPRIATE ACTION 
C 
      GO TO (10, 20), INDX
C 
C     SET FULL DUPLEX 
C 
10    CALL STTY('DUPLEX',FULLDUP) 
      RETURN
C 
C     SET HALF DUPLEX 
C 
20    CALL STTY('DUPLEX',HALFDUP) 
      RETURN
      END 
      SUBROUTINE PARCMD 
  
CCC   PARCMD - SET THE PARITY FOR TERMINAL I/O. 
C 
*CALL KERMCOM 
      LOGICAL CONFIRM 
      PARAMETER (TSIZE=5) 
      CHARACTER*10 PARTYP(TSIZE)
      DATA PARTYP / 'EVEN', 'MARK', 'NONE', 'ODD', 'SPACE' /
C 
C     MATCH THE PARAMETER 
C 
      INDX = MATCH(PARTYP,TSIZE,.FALSE.)
      IF (INDX .LE. 0) RETURN 
      IF (.NOT. CONFIRM(STDIN)) RETURN
C 
C     SET THE PROPER PARITY 
C 
      GO TO (10, 20, 30, 40, 50), INDX
10    CALL STTY('PARITY',EVEN)
      RETURN
20    CALL STTY('PARITY',MARK)
      RETURN
30    CALL STTY('PARITY',NONE)
      RETURN
40    CALL STTY('PARITY',ODD) 
      RETURN
50    CALL STTY('PARITY',SPACE) 
      RETURN
      END 
      INTEGER FUNCTION MATCH(TABLE,TABLEN,NELOK)
  
CCC   MATCH - MATCH INPUT WITH A TABLE OF POSSIBILITIES.
C 
C     TABLE SHOULD BE AN ARRAY OF CHARACTER STRINGS DEFINING WHAT 
C     IS REASONABLE INPUT.  MATCH WILL READ INPUT AND RETURN THE
C     INDEX OF THE TABLE ENTRY THAT MATCHES OR "ERROR" IF A PROPER
C     MATCH COULDN'T BE MADE.  MATCHS WILL FAIL IF THE INPUT MATCH
C     IS AMBIGUOUS OR DOESN'T MATCH AT ALL.  A QUESTION MARK IN THE 
C     INPUT WILL OUTPUT THE POSSIBLE MATCHES ACCORDING TO THE INPUT 
C     PREVIOUSLY READ AND THEN RETURN AS IF NO MATCH WAS MADE.
C 
*CALL KERMCOM 
      CHARACTER*(*) TABLE(TABLEN) 
      LOGICAL NELOK 
      CHARACTER*40 WORD 
      INTEGER ASTR(41)
C 
C     GET THE WORD TO MATCH 
C 
      LEN = GETWORD(STDIN,ASTR,40)
      IF (LEN .EQ. 0 .OR. LEN .EQ. EOF) THEN
         MATCH = LEN
         IF (LEN .EQ. 0 .AND. .NOT. NELOK) THEN 
            MATCH = ERROR 
            CALL FPRINTF(STDOUT,'?^NULL SWITCH OR KEYWORD GIVEN\N',0,0, 
     +         0,0) 
         ENDIF
         CALL FFLUSH(STDIN) 
         RETURN 
      ENDIF 
      CALL AS2DPC(ASTR,WORD)
C 
C     BEGIN THE MATCHING HERE; TABLES MUST BE IN ALPHABETICAL ORDER 
C 
      T1 = 1
      T2 = TABLEN 
      CHP = 1 
10    IF (CHP .LE. LEN) THEN
C 
C        IF WE FIND A "?", THEN GIVE THE POSSIBILITIES
C 
         IF (WORD(CHP:CHP) .EQ. '?') THEN 
            CALL FPRINTF(STDOUT,FOLLOW,0,0,0,0) 
            CALL OUTTBL(TABLE,T1,T2)
            CALL FFLUSH(STDIN)
            MATCH = ERROR 
            RETURN
         ENDIF
C 
C        WHILE WORD IS LESS THAN LOWER TABLE ENTRY
C 
20       IF (WORD(CHP:CHP) .GT. TABLE(T1)(CHP:CHP) .AND.
     +       T1 .LE. T2) THEN 
            T1 = T1 + 1 
            GO TO 20
         ENDIF
C 
C        WHILE WORD IS GREATER THAN UPPER TABLE ENTRY 
C 
30       IF (WORD(CHP:CHP) .LT. TABLE(T2)(CHP:CHP) .AND.
     +       T2 .GE. T1) THEN 
            T2 = T2 - 1 
            GO TO 30
         ENDIF
C 
C        IF WE KNOW WE HAVE A MISMATCH
C 
         IF (T2 .LT. T1) THEN 
            CALL FPRINTF(STDOUT,NOMATCH,0,0,0,0)
            CALL PUTSTR(STDOUT,ASTR)
            CALL FPRINTF(STDOUT,'"\N',0,0,0,0)
            CALL FFLUSH(STDIN)
            MATCH = ERROR 
            RETURN
         ENDIF
         CHP = CHP + 1
         GO TO 10 
      ENDIF 
C 
C     AFTER LOOKING AT THE WHOLE WORD, IS IT STILL AMBIGUOUS? 
C 
      IF (T1 .NE. T2) THEN
         CALL FPRINTF(STDOUT,AMBIG,0,0,0,0) 
         CALL PUTSTR(STDOUT,ASTR) 
         CALL FPRINTF(STDOUT,'"\N',0,0,0,0) 
         CALL FFLUSH(STDIN) 
         MATCH = ERROR
      ELSE
         MATCH = T1 
      ENDIF 
      RETURN
      END 
      SUBROUTINE OUTTBL(TABLE,START,FIN)
  
CCC   OUTTBL - OUTPUT A STRING ARRAY IN TABULAR FORMAT. 
C 
*CALL KERMCOM 
      CHARACTER*(*) TABLE(FIN)
      INTEGER START, FIN
  
      CHARACTER*80 LINE 
      INTEGER ASTR(81)
      INTEGER COLWID, NCOLS 
  
      COLWID = LEN(TABLE(1)) + 2
      NCOLS = 80 / COLWID 
      LINE = ' '
      ICOL = 1
      DO 100 I = START,FIN
         IPOS = (ICOL-1)*COLWID + 1 
         LINE(IPOS:) = TABLE(I) 
         ICOL = ICOL + 1
         IF (ICOL .GT. NCOLS .OR. I .EQ. FIN) THEN
            CALL DPC2AS(LINE,ASTR,LEN(LINE))
C 
C           DELETE TRAILING BLANKS
C 
            J = LEN(LINE) 
10          IF (LINE(J:J) .EQ. ' ') THEN
               ASTR(J) = 0
               J = J - 1
               GO TO 10 
            ENDIF 
            CALL PUTSTR(STDOUT,ASTR)
            CALL PUTC(NEL,STDOUT) 
            LINE = ' '
            ICOL = 1
         ENDIF
100   CONTINUE
      RETURN
      END 
      SUBROUTINE SETVAL(VAR,VTYP,MN1,MX1,MN2,MX2,HLPMSG,CONFRM) 
  
CCC   SETVAL - SET A VARIABLE VALUE.
C 
C     SETVAL WILL READ A TOKEN FROM INPUT AND SET A VARIABLE TO 
C     THAT VALUE.  IF THE TOKEN IS A QUESTION MARK THEN THE 
C     HELP MESSAGE WILL BE DISPLAYED AND SETVAL WILL RETURN 
C     WITHOUT SETTING A VALUE.
C 
C     ENTRY:   (VTYP) = CHARACTER 'S' FOR STRING VARIABLE.
C                     = CHARACTER 'I' FOR INTEGER VARIABLE. 
C              (MN1-MX1) = RANGE #1 FOR VAR TO FIT IN IF INTEGER. 
C                        = MN1 IS RETURN CODE FOR ERROR AND MX1 IS
C                          MAX SIZE OF STRING IF STRING VAR.
C              (MN2-MX2) = SECONDARY RANGE FOR VAR TO FIT IN IF 
C                          INTEGER VAR. 
C                        = UNUSED FOR STRING VAR. 
C              (HLPMSG) = FPRINTF MESSAGE FORMAT TO DISPLAY IF
C                       A QUESTION MARK IS READ.
C 
C     EXIT:    (VAR) = INT VALUE READ IF INTEGER VAR. OR STRING 
C                      VALUE READ IF STRING VAR.
C 
*CALL KERMCOM 
      CHARACTER*(*) VTYP, HLPMSG
      INTEGER VAR(41), STR(41)
      LOGICAL CONFRM, CONFIRM 
C 
C     CHECK VAR TYPE
C 
      IF (VTYP .NE. 'S' .AND. VTYP .NE. 'I') THEN 
         CALL FPRINTF(STDOUT,'SETVAL - INVALID VAR TYPE @C\N',ASC(VTYP),
     +      0,0,0)
         RETURN 
      ENDIF 
      IF (VTYP .EQ. 'S' .AND. MX1 .GT. 40) THEN 
         CALL FPRINTF(STDOUT,'SETVAL - STRING MAX OF @D IS TOO LARGE\N',
     +      MX1,0,0,0)
         RETURN 
      ENDIF 
      LEN = GETWORD(STDIN,STR,MX1)
      IF (LEN .EQ. 0 .OR. LEN .EQ. EOF) THEN
         IF (VTYP .EQ. 'I') THEN
            CALL FPRINTF(STDOUT,NODIGIT,0,0,0,0)
         ELSE 
            CALL FPRINTF(STDOUT,MISSING,0,0,0,0)
            MN1 = ERROR 
         ENDIF
         RETURN 
      ENDIF 
      IF (STR(1) .EQ. QMARK) THEN 
         CALL FPRINTF(STDOUT,HLPMSG,0,0,0,0)
         CALL FFLUSH(STDIN) 
         IF (VTYP .EQ. 'S') MN1 = ERROR 
         RETURN 
      ENDIF 
C 
C     CONFIRM THE REQUEST IF NECESSARY
C 
      IF (CONFRM) THEN
         IF (.NOT. CONFIRM(STDIN)) THEN 
            IF (VTYP .EQ. 'S') MN1 = ERROR
            RETURN
         ENDIF
      ENDIF 
C 
C     GO AHEAD AND SET THE VARIABLE 
C 
      IF (VTYP .EQ. 'I') THEN 
         I = CTOI(STR)
         IF (I .GE. MN1 .AND. I .LE. MX1) THEN
            VAR(1) = I
         ELSE IF (I .GE. MN2 .AND. I .LE. MX2) THEN 
            VAR(2) = I
         ELSE 
            CALL FPRINTF(STDOUT,
     +         '?^VALUE IS NOT WITHIN RANGE OF @D - @D',
     +         MN1,MX1,0,0) 
            IF (MN1 .NE. MN2 .OR. MX1 .NE. MX2) CALL FPRINTF(STDOUT,
     +         ' OR @D - @D',MN2,MX2,0,0) 
            CALL PUTC(NEL,STDOUT) 
         ENDIF
      ELSE
         DO 100 I = 1,LEN 
            VAR(I) = STR(I) 
100      CONTINUE 
         VAR(LEN+1) = 0 
         MN1 = OK 
      ENDIF 
      RETURN
      END 
      LOGICAL FUNCTION CONFIRM(FD)
  
CCC   CONFIRM - LOOK FOR A NEWLINE. 
C 
C     CONFIRM WILL EXPECT THAT THE NEXT TOKEN OF INPUT BE A 
C     NEWLINE FOR CONFIRMATION TO BE TRUE.  IF THE NEXT TOKEN 
C     IS A QUESTION MARK, THEN CONFIRMATION IS FALSE AND
C     A "CONFIRM WITH A CARRIAGE RETURN" MESSAGE WILL BE DISPLAYED. 
C     ANY OTHER TEXT WILL CAUSE A 'NOT CONFIRMED "TEXT"' MESSAGE
C     TO BE DISPLAYED AND CONFIRM WILL RETURN FALSE.
C 
*CALL KERMCOM 
C 
C     GET LEADING BLANKS TIL A TOKEN IS FOUND 
C 
      CONFIRM = .FALSE. 
10    IF (GETC(FD,CH) .EQ. NEL) THEN
         CONFIRM = .TRUE. 
      ELSE IF (CH .EQ. EOF) THEN
         RETURN 
      ELSE IF (CH .EQ. BLANK .OR. CH .EQ. TAB) THEN 
         GO TO 10 
      ELSE IF (CH .EQ. QMARK) THEN
         CALL FPRINTF(STDOUT,CONFMSG,0,0,0,0) 
      ELSE
         CALL FPRINTF(STDOUT,NOTCONF,0,0,0,0) 
20       CALL PUTC(CH,STDOUT) 
         CH = GETC(FD,CH) 
         IF (CH .NE. NEL .AND. CH .NE. EOF) GO TO 20
         CALL FPRINTF(STDOUT,'"\N',0,0,0,0) 
      ENDIF 
      RETURN
      END 
      SUBROUTINE LOGOUT 
  
CCC   LOGOUT - LOG OUT THE JOB
C 
C     THIS IS SITE DEPENDENT. 
*CALL KERMCOM 
      IRET = ERROR
C$    IF (UT2D .EQ. 1)
      CALL BELLC(L"LOGOUT",0,IRET)
C$    ENDIF 
C$    IF(NOSBE .EQ. 1)
      IF(SAVEDPX .NE. HALFDUP) CALL STTY('DUPLEX',FULLDUP)
      CALL EXCST('LOGOUT.') 
C$    ENDIF 
      IF (IRET .NE. 0) CALL DISPLA('LOGOUT ERROR',IRET) 
      RETURN
      END 
      INTEGER FUNCTION RECEIVE(ISTATE)
  
CCC   RECEIVE - RECEIVE FILE STATE SWITCHING ROUTINE. 
C 
*CALL KERMCOM 
C 
C     INITIALIZE STATISTICS VARIABLES 
C 
      CALL GETNOW(MM,DD,YY,HR,MIN,SEC)
      STARTIM = HR * 3600 + MIN * 60 + SEC
      SCHCNT = 0
      RCHCNT = 0
      SCHOVRH = 0 
      RCHOVRH = 0 
C 
C     SET PACKET RETRY COUNT & CURRENT STATE
C 
      NUMTRY = 0
      STATE = ISTATE
C 
C     TAKE APPROPRIATE ACTION FOR THE CURRENT STATE 
C 
10    IF (STATE .EQ. D) THEN
         STATE = RDATA()
      ELSE IF (STATE .EQ. F) THEN 
         STATE = RFILE()
      ELSE IF (STATE .EQ. R) THEN 
         STATE = RINIT()
      ELSE IF (STATE .EQ. C) THEN 
         CALL GETNOW(MM,DD,YY,HR,MIN,SEC) 
         ENDTIM = HR * 3600 + MIN * 60 + SEC
         RECEIVE = OK 
         RETURN 
      ELSE IF (STATE .EQ. E) THEN 
         RECEIVE = ERROR
         IF (FFD .NE. CLOSED) THEN
            CALL FCLOSE(FFD)
            CALL REMOVE(FILESTR)
         ENDIF
         RETURN 
      ELSE IF (STATE .EQ. A) THEN 
         CALL GETNOW(MM,DD,YY,HR,MIN,SEC) 
         ENDTIM = HR * 3600 + MIN * 60 + SEC
         RECEIVE = ERROR
         IF (FFD .NE. CLOSED) THEN
            CALL FCLOSE(FFD)
            CALL REMOVE(FILESTR)
         ENDIF
         CALL GETEMSG(ERRMSG(15)) 
         CALL SNDPACK(E,PACKNUM,SLEN(ERRMSG),ERRMSG)
         RETURN 
      ELSE
         CALL DISPLA(' RECEIVE - STATE ERROR = ',STATE) 
         IF (FFD .NE. CLOSED) CALL FCLOSE(FFD)
         RECEIVE = ERROR
         RETURN 
      ENDIF 
      IF ((DEBUG.AND.DBGSTAT).NE.0) THEN
         CALL FPRINTF(DEBUGFD,'@C@2D ',STATE,PACKNUM,0,0) 
         IF (MOD(PACKNUM+1,16) .EQ. 0) CALL PUTC(NEL,DEBUGFD) 
      ENDIF 
      GO TO 10
      END 
      INTEGER FUNCTION RINIT()
  
CCC   RINIT - RECEIVE A SEND-INIT PACKET. 
C 
*CALL KERMCOM 
C 
C     CLEAN OUT FILESTR ARRAY SO REMOVE DOES NOT DO DIRE THINGS 
C     TO THE PREVIOUSLY RECEIVED FILE IF WE DIE BEFORE WE GET 
C     THE NEW FILE SPECIFICATION. 
C 
      DO 10 I = 1, MAXPACK
          FILESTR(I) = 0
10    CONTINUE
C 
C     CHECK RETRY COUNT 
C 
      IF (NUMTRY .GT. MAXRINI) THEN 
         RINIT = A
         ABORTYP = TOOMANY.OR.READING.OR.INITERR
         RETURN 
      ENDIF 
      NUMTRY = NUMTRY + 1 
C 
C     READ A PACKET AND HOPE FOR THE BEST 
C 
      PTYP = RDPACK(LEN,NUM,PACKET) 
C 
C     IS IT A VALID PACKET TYPE?
C 
      IF (PTYP .EQ. S) THEN 
         PACKNUM = NUM
         CALL RDPARAM(PACKET) 
         LEN = SNDPAR(PACKET) 
         CALL SNDPACK(Y,NUM,LEN,PACKET) 
         NUMTRY = 0 
         PACKNUM = MOD(PACKNUM+1,64)
         RINIT = F
C 
C     DID WE GET A CHECKSUM ERROR 
C 
      ELSE IF (PTYP .EQ. ERROR) THEN
         RINIT = STATE
         CALL SNDPACK(N,NUM,0,0)
      ELSE
         RINIT = A
         ABORTYP = INVALID.OR.READING.OR.INITERR
      ENDIF 
      RETURN
      END 
      INTEGER FUNCTION RFILE()
  
CCC   RFILE  READ A FILENAME PACKET.
C 
C     RFILE EXPECTS TO SEE A FILENAME (TYPE F) PACKET.  HOWEVER, IT MAY 
C     FIND A SEND-INIT RETRY, END-OF-FILE RETRY OR BREAK PACKET.
C 
*CALL KERMCOM 
      IF (NUMTRY .GT. MAXRTRY) THEN 
         RFILE = A
         ABORTYP = TOOMANY.OR.READING.OR.FILERR 
         RETURN 
      ENDIF 
      NUMTRY = NUMTRY + 1 
C 
C     READ A PACKET 
C 
      PTYP = RDPACK(LEN,NUM,PACKET) 
C 
C     IS IT A FILENAME PACKET?
C 
      IF (PTYP .EQ. F) THEN 
         IF (NUM .NE. PACKNUM) THEN 
            RFILE = A 
            ABORTYP = SEQERR.OR.READING.OR.FILERR 
            RETURN
         ENDIF
         FFD = CREAT(PACKET)
         IF (FFD .EQ. ERROR) THEN 
            FFD = CLOSED
            RFILE = A 
            ABORTYP = LCLFILE.OR.READING.OR.FILERR
         ELSE 
            IF (DEBUG .NE. 0) CALL FPRINTF(DEBUGFD, 
     +         '^RECEIVING FILE @S\N',PACKET,0,0,0) 
            CALL STRCPY(PACKET,FILESTR) 
            CALL SNDPACK(Y,NUM,0,0) 
            NUMTRY = 0
            PACKNUM = MOD(PACKNUM+1,64) 
            RFILE = D 
         ENDIF
C 
C     IS IT AN OLD SEND-INIT PACKET 
C 
      ELSE IF (PTYP .EQ. S) THEN
         IF (MOD(NUM+1,64) .EQ. PACKNUM) THEN 
            LEN = SNDPAR(PACKET)
            CALL SNDPACK(Y,NUM,LEN,PACKET)
            NUMTRY = 0
            RFILE = STATE 
         ELSE 
            RFILE = A 
            ABORTYP = SEQERR.OR.READING.OR.INITERR
         ENDIF
C 
C     IS IT AN OLD EOF PACKET?
C 
      ELSE IF (PTYP .EQ. Z) THEN
         IF (MOD(NUM+1,64) .EQ. PACKNUM) THEN 
            CALL SNDPACK(Y,NUM,0,0) 
            NUMTRY = 0
            RFILE = STATE 
         ELSE 
            RFILE = A 
            ABORTYP = SEQERR.OR.READING.OR.EOFERR 
         ENDIF
C 
C     IS IT A BREAK PACKET? 
C 
      ELSE IF (PTYP .EQ. B) THEN
         IF (NUM .NE. PACKNUM) THEN 
            RFILE = A 
            ABORTYP = SEQERR.OR.READING.OR.BRKERR 
         ELSE 
            CALL SNDPACK(Y,PACKNUM,0,0) 
            RFILE = C 
         ENDIF
C 
C     DID WE GET AN ERROR PACKET? 
C 
      ELSE IF (PTYP .EQ. E) THEN
         RFILE = E
         RETURN 
C 
C     DID WE GET A CHECKSUM ERROR?
C 
      ELSE IF (PTYP .EQ. ERROR) THEN
         RFILE = STATE
         CALL SNDPACK(N,NUM,0,0)
C 
C     INVALID PACKET TYPE, SO ABORT 
C 
      ELSE
         RFILE = A
         ABORTYP = INVALID.OR.READING.OR.FILERR 
      ENDIF 
      RETURN
      END 
      INTEGER FUNCTION RDATA()
  
CCC   RDATA - READ A DATA PACKET. 
C 
*CALL KERMCOM 
C 
C     CHECK RETRY COUNT 
C 
      IF (NUMTRY .GT. MAXRTRY) THEN 
         RDATA = A
         ABORTYP = TOOMANY.OR.READING.OR.DATAERR
         RETURN 
      ENDIF 
      NUMTRY = NUMTRY + 1 
C 
C     READ A PACKET 
C 
      PTYP = RDPACK(LEN,NUM,PACKET) 
C 
C     DID WE GET A DATA PACKET? 
C 
      IF (PTYP .EQ. D) THEN 
         IF (NUM .NE. PACKNUM) THEN 
            IF (MOD(NUM+1,64) .EQ. PACKNUM) THEN
               CALL SNDPACK(Y,NUM,0,0)
               RDATA = STATE
            ELSE
               RDATA = A
               ABORTYP = SEQERR.OR.READING.OR.DATAERR 
            ENDIF 
         ELSE 
            CALL BUFEMP(PACKET,FFD,LEN) 
            CALL SNDPACK(Y,PACKNUM,0,0) 
            NUMTRY = 0
            PACKNUM = MOD(PACKNUM+1,64) 
            RDATA = STATE 
         ENDIF
C 
C     IS IT AN OLD FILENAME PACKET? 
C 
      ELSE IF (PTYP .EQ. F) THEN
         IF (MOD(NUM+1,64) .EQ. PACKNUM) THEN 
            CALL SNDPACK(Y,NUM,0,0) 
            NUMTRY = 0
            RDATA = STATE 
         ELSE 
            RDATA = A 
            ABORTYP = SEQERR.OR.READING.OR.FILERR 
         ENDIF
C 
C     IS IT AN EOF PACKET?
C 
      ELSE IF (PTYP .EQ. Z) THEN
         IF (NUM .NE. PACKNUM) THEN 
            RDATA = A 
            ABORTYP = SEQERR.OR.READING.OR.EOFERR 
         ELSE 
            CALL SNDPACK(Y,PACKNUM,0,0) 
            CALL FCLOSE(FFD)
            FFD = 0 
            PACKNUM = MOD(PACKNUM+1,64) 
            RDATA = F 
         ENDIF
C 
C     DID WE GET AN ERROR PACKET? 
C 
      ELSE IF (PTYP .EQ. E) THEN
         RDATA = E
         RETURN 
      ELSE IF (PTYP .EQ. ERROR) THEN
         RDATA = STATE
         CALL SNDPACK(N,NUM,0,0)
      ELSE
         RDATA = A
         ABORTYP = INVALID.OR.READING.OR.DATAERR
      ENDIF 
      RETURN
      END 
      INTEGER FUNCTION SEND() 
  
CCC   SEND - SEND FILE STATE SWITCHING ROUTINE
C 
C     THE FILENAME TO SEND IS ASSUMED TO HAVE ALREADY BEEN
C     OBTAINED AND SET IN ASCII STRING BUFFER FILESTR.
C 
*CALL KERMCOM 
C 
C     INITIALIZE STATICS VARIABLES
C 
      CALL GETNOW(MM,DD,YY,HR,MIN,SEC)
      STARTIM = HR * 3600 + MIN * 60 + SEC
      SCHCNT = 0
      RCHCNT = 0
      SCHOVRH = 0 
      RCHOVRH = 0 
      STATE = S 
      NUMTRY = 0
C 
C     TAKE APPROPRIATE ACTION FOR THE CURRENT STATE 
C 
10    IF (STATE .EQ. D) THEN
         STATE = SDATA()
      ELSE IF (STATE .EQ. F) THEN 
         STATE = SFILE()
      ELSE IF (STATE .EQ. Z) THEN 
         STATE = SEOF() 
      ELSE IF (STATE .EQ. S) THEN 
         STATE = SINIT()
      ELSE IF (STATE .EQ. B) THEN 
         STATE = SBREAK() 
      ELSE IF (STATE .EQ. C) THEN 
         CALL GETNOW(MM,DD,YY,HR,MIN,SEC) 
         ENDTIM = HR * 3600 + MIN * 60 + SEC
         SEND = OK
         RETURN 
      ELSE IF (STATE .EQ. E) THEN 
         CALL GETNOW(MM,DD,YY,HR,MIN,SEC) 
         ENDTIM = HR * 3600 + MIN * 60 + SEC
         SEND = ERROR 
         IF (FFD .NE. CLOSED) CALL FCLOSE(FFD)
         RETURN 
      ELSE IF (STATE .EQ. A) THEN 
         CALL GETNOW(MM,DD,YY,HR,MIN,SEC) 
         ENDTIM = HR * 3600 + MIN * 60 + SEC
         SEND = ERROR 
         IF (FFD .NE. CLOSED) CALL FCLOSE(FFD)
         CALL GETEMSG(ERRMSG(15)) 
         CALL SNDPACK(E,PACKNUM,SLEN(ERRMSG),ERRMSG)
         RETURN 
      ELSE
         CALL DISPLA(' SEND - STATE ERROR = ',STATE)
         SEND = ERROR 
         IF (FFD .NE. CLOSED) CALL FCLOSE(FFD)
         RETURN 
      ENDIF 
      IF ((DEBUG.AND.DBGSTAT).NE.0) THEN
         CALL FPRINTF(DEBUGFD,'@C@2D ',STATE,PACKNUM,0,0) 
         IF (MOD(PACKNUM+1,16) .EQ. 0) CALL PUTC(NEL,DEBUGFD) 
      ENDIF 
      GO TO 10
      END 
      INTEGER FUNCTION SINIT()
  
CCC   SINIT - SEND THE SEND-INIT PACKET AND WAIT FOR REPLY. 
C 
C     ASSUMES FILESTR HAS ALREADY BEEN CHECKED FOR LEGAL FILENAME 
C     AND BEING LOCAL.
C 
*CALL KERMCOM 
      CHARACTER*10 FILENAM
C 
C     CHECK NUMBER OF RETRIES 
C 
      IF (NUMTRY .GT. MAXRINI) THEN 
         SINIT = A
         ABORTYP = TOOMANY.OR.SENDING.OR.INITERR
         RETURN 
      ENDIF 
      NUMTRY = NUMTRY + 1 
C 
C     SEND THE SEND-INIT PACKET WITH THE RIGHT INFO 
C 
      LEN = SNDPAR(PACKET)
      CALL SNDPACK(S,PACKNUM,LEN,PACKET)
C 
C     PICK UP AND PROCESS THE REPLY 
C 
      PTYP = RDPACK(LEN,NUM,RECPACK)
      IF (PTYP .EQ. N) THEN 
         SINIT = STATE
         RETURN 
      ELSE IF (PTYP .EQ. Y) THEN
         IF (PACKNUM .NE. NUM) THEN 
            SINIT = STATE 
            RETURN
         ENDIF
         CALL RDPARAM(RECPACK)
         NUMTRY = 0 
         PACKNUM = MOD(PACKNUM+1,64)
         CALL AS2DPC(FILESTR,FILENAM) 
         FFD = FOPEN(FILENAM,RD)
         IF (FFD .EQ. ERROR) THEN 
            SINIT = A 
            FFD = CLOSED
         ELSE 
            SINIT = F 
         ENDIF
C 
C     DID WE GET AN ERROR PACKET? 
C 
      ELSE IF (PTYP .EQ. E) THEN
         SINIT = E
         RETURN 
      ELSE IF (PTYP .EQ. ERROR) THEN
         SINIT = STATE
      ELSE
         SINIT = A
         ABORTYP = INVALID.OR.SENDING.OR.INITERR
      ENDIF 
      RETURN
      END 
      INTEGER FUNCTION SFILE()
  
CCC   SFILE - SEND A FILENAME PACKET AND WAIT FOR REPLY.
C 
C     THE FILENAME IS ASSUMED TO HAVE BEEN PREVIOUSLY OBTAINED
C     AND STORED IN THE ASCII STRING BUFFER FILESTR IN UPPER CASE.
C 
*CALL KERMCOM 
C 
C     HAVE WE TRIED THIS TOO MANY TIMES?
C 
      IF (NUMTRY .GT. MAXRTRY) THEN 
         SFILE = A
         ABORTYP = TOOMANY.OR.SENDING.OR.FILERR 
         RETURN 
      ENDIF 
      NUMTRY = NUMTRY + 1 
C 
C     SEND THE FILENAME PACKET
C 
      CALL SNDPACK(F,PACKNUM,SLEN(FILESTR),FILESTR) 
C 
C     CHECK ON THE REPLY
C 
      PTYP = RDPACK(LEN,NUM,RECPACK)
      IF (PTYP .EQ. N) THEN 
         IF (MOD(PACKNUM+1,64) .NE. NUM) THEN 
            SFILE = STATE 
            RETURN
         ELSE 
            PTYP = Y
            NUM = NUM - 1 
         ENDIF
      ENDIF 
      IF (PTYP .EQ. Y) THEN 
         IF (PACKNUM .NE. NUM) THEN 
            SFILE = STATE 
            RETURN
         ENDIF
         NUMTRY = 0 
         PACKNUM = MOD(PACKNUM+1,64)
C 
C        GET FIRST PACKET OF DATA FROM THE FILE 
C 
         PSIZE = BUFFILL(FFD,PACKET)
         SFILE = D
C 
C     DID WE GET AN ERROR PACKET? 
C 
      ELSE IF (PTYP .EQ. E) THEN
         SFILE = E
         RETURN 
      ELSE IF (PTYP .EQ. ERROR) THEN
         SFILE = STATE
      ELSE
         SFILE = A
         ABORTYP = INVALID.OR.SENDING.OR.FILERR 
      ENDIF 
      RETURN
      END 
      INTEGER FUNCTION SDATA()
  
CCC   SDATA - SEND A DATA PACKET AND WAIT FOR REPLY.
C 
*CALL KERMCOM 
C 
C     HAVE WE TRIED THIS TOO MANY TIMES?
C 
      IF (NUMTRY .GT. MAXRTRY) THEN 
         SDATA = A
         ABORTYP = TOOMANY.OR.SENDING.OR.DATAERR
         RETURN 
      ENDIF 
      NUMTRY = NUMTRY + 1 
C 
C     SEND THE CURRENT DATA BUFFER
C 
      IF (PSIZE .EQ. EOF) THEN
         SDATA = Z
         RETURN 
      ENDIF 
      CALL SNDPACK(D,PACKNUM,PSIZE,PACKET)
C 
C     CHECK ON THE REPLY
C 
      PTYP = RDPACK(LEN,NUM,RECPACK)
      IF (PTYP .EQ. N) THEN 
         IF (MOD(PACKNUM+1,64) .NE. NUM) THEN 
            SDATA = STATE 
            RETURN
         ELSE 
            PTYP = Y
            NUM = NUM - 1 
         ENDIF
      ENDIF 
      IF (PTYP .EQ. Y) THEN 
         IF (PACKNUM .NE. NUM) THEN 
            SDATA = STATE 
            RETURN
         ENDIF
         NUMTRY = 0 
         PACKNUM = MOD(PACKNUM+1,64)
         PSIZE = BUFFILL(FFD,PACKET)
         IF (PSIZE .EQ. EOF) THEN 
            SDATA = Z 
         ELSE 
            SDATA = STATE 
         ENDIF
C 
C     DID WE GET AN ERROR PACKET? 
C 
      ELSE IF (PTYP .EQ. E) THEN
         SDATA = E
         RETURN 
      ELSE IF (PTYP .EQ. ERROR) THEN
         SDATA = STATE
      ELSE
         SDATA = A
         ABORTYP = INVALID.OR.SENDING.OR.DATAERR
      ENDIF 
      RETURN
      END 
      INTEGER FUNCTION SEOF() 
  
CCC   SEOF - SEND AN EOF PACKET AND WAIT FOR THE REPLY. 
C 
*CALL KERMCOM 
C 
C     HAVE WE TRIED THIS TOO MANY TIMES?
C 
      IF (NUMTRY .GT. MAXRTRY) THEN 
         SEOF = A 
         ABORTYP = TOOMANY.OR.SENDING.OR.EOFERR 
         RETURN 
      ENDIF 
      NUMTRY = NUMTRY + 1 
C 
C     SEND THE EOF PACKET 
C 
      CALL SNDPACK(Z,PACKNUM,0,0) 
C 
C     CHECK THE REPLY 
C 
      PTYP = RDPACK(LEN,NUM,RECPACK)
      IF (PTYP .EQ. N) THEN 
         IF (MOD(PACKNUM+1,64) .NE. NUM) THEN 
            SEOF = STATE
            RETURN
         ELSE 
            PTYP = Y
            NUM = NUM - 1 
         ENDIF
      ENDIF 
      IF (PTYP .EQ. Y) THEN 
         IF (PACKNUM .NE. NUM) THEN 
            SEOF = STATE
            RETURN
         ENDIF
         NUMTRY = 0 
         PACKNUM = MOD(PACKNUM+1,64)
         CALL FCLOSE(FFD) 
         SEOF = B 
C 
C     DID WE GET AN ERROR PACKET? 
C 
      ELSE IF (PTYP .EQ. E) THEN
         SEOF = E 
         RETURN 
      ELSE IF (PTYP .EQ. ERROR) THEN
         SEOF = STATE 
      ELSE
         SEOF = A 
         ABORTYP = INVALID.OR.SENDING.OR.EOFERR 
      ENDIF 
      RETURN
      END 
      INTEGER FUNCTION SBREAK() 
  
CCC   SBREAK - SEND THE BREAK PACKET AND WAIT FOR REPLY.
C 
*CALL KERMCOM 
C 
C     HAVE WE TRIED THIS TOO MANY TIMES?
C 
      IF (NUMTRY .GT. MAXRTRY) THEN 
         SBREAK = A 
         ABORTYP = TOOMANY.OR.SENDING.OR.BRKERR 
         RETURN 
      ENDIF 
      NUMTRY = NUMTRY + 1 
C 
C     SEND THE BREAK PACKET 
C 
      CALL SNDPACK(B,PACKNUM,0,0) 
C 
C     CHECK ON THE REPLY
C 
      PTYP = RDPACK(LEN,NUM,RECPACK)
      IF (PTYP .EQ. N) THEN 
         IF (MOD(PACKNUM+1,64) .NE. NUM) THEN 
            SBREAK = STATE
            RETURN
         ELSE 
            PTYP = Y
            NUM = NUM - 1 
         ENDIF
      ENDIF 
      IF (PTYP .EQ. Y) THEN 
         IF (PACKNUM .NE. NUM) THEN 
            SBREAK = STATE
            RETURN
         ENDIF
         NUMTRY = 0 
         PACKNUM = MOD(PACKNUM+1,64)
         SBREAK = C 
C 
C     DID WE GET AN ERROR PACKET? 
C 
      ELSE IF (PTYP .EQ. E) THEN
         SBREAK = E 
         RETURN 
      ELSE IF (PTYP .EQ. ERROR) THEN
         SBREAK = STATE 
      ELSE
         SBREAK = A 
         ABORTYP = INVALID.OR.SENDING.OR.BRKERR 
      ENDIF 
      RETURN
      END 
      SUBROUTINE SNDPACK(TYPE,NUM,LEN,DATA) 
  
CCC   SNDPACK - SEND A PACKET DOWN AN OUTPUT STREAM 
C 
C     SNDPACK WILL SEND A PACKET OF INFORMATION AND LOG IT
C     IF DEBUG IS TURNED ON.  THIS SUBROUTINE COULD BE MADE 
C     MORE EFFICIENT BY NOT CALLING A SUBROUTINE FOR EACH 
C     CHARACTER, BUT THAT MIGHT CAUSE PORTABILITY PROBLEMS. 
C 
*CALL KERMCOM 
      INTEGER DATA(200) 
C 
C     DEFINE THE TOCHAR STATEMENT FUNCTION
C 
      TOCHAR(ASCCH) = ASCCH + BLANK 
  
      IF ((DEBUG.AND.DBGPACK).NE.0) CALL FPRINTF(DEBUGFD,'^SENDING...', 
     +   0,0,0,0) 
C 
C     PUT OUT PAD CHARS 
C 
      DO 100 I = 1,SPAD 
         CALL PUTC(SPADCH,OFD)
         IF ((DEBUG.AND.DBGPACK).NE.0) THEN 
            CALL PUTC(SPADCH,DEBUGFD) 
         ENDIF
100   CONTINUE
      CALL PUTC(SNDSYNC,OFD)
C 
C     PACKET LEN ASSUMES ONE CHARACTER CHECKSUMS
C 
      CHKSUM = TOCHAR(LEN+3)
      CALL PUTC(CHKSUM,OFD) 
      TMP = TOCHAR(NUM) 
      CHKSUM = CHKSUM + TMP 
      CALL PUTC(TMP,OFD)
      CHKSUM = CHKSUM + TYPE
      CALL PUTC(TYPE,OFD) 
      DO 110 I = 1,LEN
         CHKSUM = CHKSUM + (DATA(I) .AND. O"377") 
         CALL PUTC(DATA(I),OFD) 
110   CONTINUE
      CHKSUM = (CHKSUM + (CHKSUM.AND.O"300") / O"100") .AND. O"77"
      CALL PUTC(TOCHAR(CHKSUM),OFD) 
      CALL PUTC(SPEOL,OFD)
      IF ((DEBUG.AND.DBGPACK).NE.0) THEN
         CALL PUTC(SNDSYNC,DEBUGFD) 
         CALL PUTC(TOCHAR(LEN+3),DEBUGFD) 
         CALL PUTC(TOCHAR(NUM),DEBUGFD) 
         CALL PUTC(TYPE,DEBUGFD)
         IF (LEN .GT. 0) CALL PUTSTR(DEBUGFD,DATA)
         CALL PUTC(TOCHAR(CHKSUM),DEBUGFD)
         CALL PUTC(SPEOL,DEBUGFD) 
         CALL PUTC(NEL,DEBUGFD) 
      ENDIF 
  
C     FORCE BUFFER FLUSH SINCE DESIRED EOL CHAR WON'T.  UNDER NOS/BE, 
C     SCOPE, AND (I SUSPECT) NOS, WE NEED 12 BITS OF ZERO IN THE
C     LOW ORDER 12 BITS OF A WORD TO BE THE EOL, OR THE DATA GETS LEFT
C     IN AN INTERCOM SMALL BUFFER TILL THE EOL (OR A WRITER) COMES
C     ALONG.  THE CONDITIONAL CODE ADDS A 60 BIT EOL IN THE CASE
C     WHERE THE DATA IS A MULTIPLE OF 5 CHARACTERS.  IN ALL OTHER 
C     CASES THE EOL IS PRESENT, AS THE WORD WAS ZEROED BEFORE ANY 
C     DATA WAS PUT IN IT. 
  
      IF(FWSHFT(OFD) .EQ. 0) THEN 
          FWSHFT(OFD) = 48
          FNWDS(OFD) = FNWDS(OFD) + 1 
          FCHBUF(FNWDS(OFD),OFD) = 0
      ENDIF 
      CALL FFLUSH(OFD)
C 
C     UPDATE THE STATISTICS 
C 
      NCH = SPAD + 5 + LEN + 1
      SCHCNT = SCHCNT + NCH 
      SCHOVRH = SCHOVRH + NCH - LEN 
      RETURN
      END 
      INTEGER FUNCTION RDPACK(LEN,NUM,DATA) 
  
CCC   RDPACK - READ A PACKET OF INFORMATION.
C 
C     RDPACK WILL READ A PACKET OF DATA AND RETURN THE PACKET TYPE
C     AS A RESULT.  IF THE PACKET CONTAINS AN ERROR (CHECKSUM) THEN 
C     ERROR WILL BE RETURNED.  LEN, NUM, AND DATA WILL BE SET ACCORDING 
C     TO THE FIELDS OF THE PACKET.
C 
*CALL KERMCOM 
      INTEGER DATA(*) 
C 
C     DEFINE THE UNCHAR STATEMENT FUNCTION
C 
      UNCHAR(ASCCH) = ASCCH - BLANK 
C 
C     IS DEBUG PACKETS TURNED ON? 
C 
      IF ((DEBUG.AND.DBGPACK).NE.0) THEN
         CALL FPRINTF(DEBUGFD,'^READING...',0,0,0,0)
      ENDIF 
      NCH = 0 
C 
C     HUNT FOR THE START OF PACKET
C 
10    IF(GETC(IFD,CH) .EQ. EOF) THEN
          CALL REMARK(' RDPACK - FOUND UNEXPECTED EOF.')
          CALL ABTP("ND") 
      ENDIF 
      NCH = NCH + 1 
      IF ((DEBUG.AND.DBGPACK).NE.0) CALL PUTC(CH,DEBUGFD) 
      IF (CH .NE. SYNC) GO TO 10
      CHKSUM = 0
      LEN = 0 
C 
C     PARSE EACH FIELD OF THE PACKET
C 
C     FOR (FIELD=1; FIELD <= 5; FIELD++)
      FIELD = 1 
20    IF (FIELD .LE. 5) THEN
C 
C        A CHARACTER READ IN FIELD 4 HERE IS THE FIRST CHAR OF THE
C        DATA FIELD OR THE CHECKSUM CHARACTER IF THE DATA FIELD IS EMPTY
C 
         IF (FIELD .NE. 5 .OR. LEN .GT. 0) THEN 
            IF(GETC(IFD,CH) .EQ. EOF) THEN
               CALL REMARK(' RDPACK - FOUND UNEXPECTED EOF.') 
               CALL ABTP("ND")
            ENDIF 
            IF (CH .EQ. SYNC) FIELD = 0 
            NCH = NCH + 1 
            IF ((DEBUG.AND.DBGPACK).NE.0) CALL PUTC(CH,DEBUGFD) 
         ENDIF
         IF (FIELD .LE. 3) CHKSUM = CHKSUM + CH 
C 
C        IF RESYNC
         IF (FIELD .EQ. 0) THEN 
            CHKSUM = 0
            IF ((DEBUG.AND.DBGPACK).NE.0) THEN
               CALL FPRINTF(DEBUGFD,'\N^READING...@C',SYNC,0,0,0) 
            ENDIF 
C 
C        IF DATA LENGTH 
         ELSE IF (FIELD .EQ. 1) THEN
            LEN = UNCHAR(CH-3)
C 
C        IF PACKET NUMBER 
         ELSE IF (FIELD .EQ. 2) THEN
            NUM = UNCHAR(CH)
C 
C        IF PACKET TYPE 
         ELSE IF (FIELD .EQ. 3) THEN
            TYPE = CH 
C 
C        IF DATA FIELD IS NOT EMPTY 
         ELSE IF (FIELD .EQ. 4 .AND. LEN .GT. 0) THEN 
C 
C           READ 2ND-LEN CHARS OF DATA & CHECKSUM CHAR
C 
            DO 100 I = 1,LEN
               IF (I .GT. 1) THEN 
                  CH = GETC(IFD,CH) 
                  IF(CH .EQ. EOF) THEN
                     CALL REMARK(' RDPACK - FOUND UNEXPECTED EOF.') 
                     CALL ABTP("ND")
                  ENDIF 
                  NCH = NCH + 1 
                  IF (CH .EQ. SYNC) THEN
                     FIELD = 0
                     GO TO 20 
                  ENDIF 
                  IF ((DEBUG.AND.DBGPACK).NE.0) CALL PUTC(CH,DEBUGFD) 
               ENDIF
               CHKSUM = CHKSUM + CH 
               DATA(I) = CH 
100         CONTINUE
C 
C        IF CHKSUM CHAR 
         ELSE IF (FIELD .EQ. 5) THEN
            DATA(LEN+1) = 0 
            CHKSUM = (CHKSUM + ((CHKSUM .AND. O"300") / O"100"))
     +               .AND. O"77"
         ENDIF
C 
C     PROCESS NEXT PACKET FIELD 
C 
         FIELD = FIELD + 1
         GO TO 20 
      ENDIF 
      IF ((DEBUG.AND.DBGPACK).NE.0) CALL PUTC(NEL,DEBUGFD)
C 
C     DOES THE CHECKSUM MATCH?
C 
      IF (CHKSUM .NE. UNCHAR(CH)) THEN
         RDPACK = ERROR 
         RCHOVRH = RCHOVRH + NCH
         IF (DEBUG .NE. 0) THEN 
            CALL FPRINTF(DEBUGFD,'CHKSUM ERROR, FOUND @D NEEDED @D\N',
     +                   UNCHAR(CH),CHKSUM,0,0) 
         ENDIF
      ELSE
         RDPACK = TYPE
         RCHOVRH = RCHOVRH + NCH - LEN
      ENDIF 
      RCHCNT = RCHCNT + NCH 
C 
C     FLUSH ANY END-OF-LINE CHARACTERS AND OTHER GARBAGE
C 
      CALL FFLUSH(IFD)
      RETURN
      END 
      INTEGER FUNCTION BUFFILL(FD,BUFFER) 
  
CCC   BUFFILL - GET SOME DATA TO SEND.
C 
C     BUFFILL READS FROM THE FILE TO SEND AND PERFORMS ALL
C     THE PROPER ESCAPING OF CONTROL CHARACTERS AND MAPPING 
C     NEWLINES INTO CRLF SEQUENCES.  IF IT EVER GETS SMART
C     ENOUGH, IT WILL ALSO DO THE 8 BIT QUOTING AND REPEAT
C     COUNTS. 
C 
C *** NOTE: THIS ALGORITHM ASSUMES 5 OVERHEAD CHARACTERS FOR THE
C     PACKET AND LEAVES 3 CHARACTERS IN CASE THE LAST CHARACTER 
C     TO BUFFER IS A NEL (EXPANDS TO 4 CHARACTERS). 
C 
*CALL KERMCOM 
      BOOLEAN BUFFER(*) 
C 
C     DEFINE CTL STATEMENT FUNCTION 
C 
      CTL(ASCCH) = ASCCH .XOR. O"100" 
C 
C     GET A PACKET WORTH OF DATA
C 
      I = 0 
10    IF (GETC(FD,CH) .NE. EOF) THEN
         IF(CH .EQ. NULL) CH = 0
         TCH = CH .AND. O"177"
         IF (TCH.LT.BLANK .OR. TCH.EQ.DEL .OR. TCH.EQ.SPQUOTE) THEN 
            IF (CH .EQ. NEL .AND. DSKCSET .NE. DSKIMAG) THEN
               BUFFER(I+1) = SPQUOTE
               BUFFER(I+2) = CTL(CR)
               I = I + 2
               CH = LF
            ENDIF 
            I = I + 1 
            BUFFER(I) = SPQUOTE 
            IF (TCH.LT.BLANK .OR. TCH.EQ.DEL) CH = CTL(CH)
         ENDIF
         I = I + 1
         BUFFER(I) = CH 
         IF (I .GE. SPKSIZ-8) THEN
            BUFFILL = I 
            GO TO 99
         ENDIF
         GO TO 10 
      ENDIF 
      IF (I .EQ. 0) THEN
         BUFFILL = EOF
      ELSE
         BUFFILL = I
      ENDIF 
99    BUFFER(I+1) = 0 
      RETURN
      END 
      SUBROUTINE BUFEMP(BUFFER,FD,LEN)
  
CCC   BUFEMP - DUMP A BUFFER TO A FILE. 
C 
*CALL KERMCOM 
      BOOLEAN BUFFER(*), CH, PREVCH 
      SAVE PREVCH 
      DATA PREVCH / -1 /
C 
C     DEFINE CTL STATEMENT FUNCTION 
C 
      CTL(ASCCH) = ASCCH .XOR. O"100" 
C 
C     WRITE THE PACKET DATA TO THE FILE 
C 
      I = 1 
10    IF (I .LE. LEN) THEN
         CH = BUFFER(I) 
         IF (CH .EQ. QUOTECH) THEN
            I = I + 1 
            CH = BUFFER(I)
            TCH = CH .AND. O"177" 
            IF ((CTL(TCH).LT.BLANK).OR.(CTL(TCH).EQ.DEL)) CH = CTL(CH)
            IF(CH .EQ. 0) CH = NULL 
         ENDIF
C 
C     IF IMAGE TRANSFER, DO NOT CONVERT THINGS. 
C 
         IF(DSKCSET .EQ. DSKIMAG) THEN
            CALL PUTC(CH,FD)
         ELSE 
C 
C     CONVERT CR/LF PAIR TO NEL (205B)
C 
            IF (CH .EQ. LF .AND. PREVCH .EQ. CR) THEN 
               CH = NEL 
C 
C     JUST A LONE CR
C 
            ELSE IF (PREVCH .EQ. CR) THEN 
               CALL PUTC(PREVCH,FD) 
            ENDIF 
            IF (CH .NE. CR) CALL PUTC(CH,FD)
            PREVCH = CH 
         ENDIF
         I = I + 1
         GO TO 10 
      ENDIF 
      RETURN
      END 
      INTEGER FUNCTION FOPEN(FN,MODE) 
  
CCC   FOPEN - PRETEND TO OPEN A FILE FOR I/O. 
C 
C     FOPEN JUST ASSIGNS A FILE DESCIPTOR (INTEGER INDEX) TO
C     A FILE NAME.  NO OPENING OF THE FILE IS REALLY PERFORMED
C     SINCE THIS IS DONE AUTOMATICALLY BY IOP.
C 
*CALL KERMCOM 
      CHARACTER*10 FN 
      LOGICAL CFE 
C 
C     CHECK FOR VALID PARAMETERS
C 
      IF (MODE .LT. RD .OR. MODE .GT. CREATE) THEN
         CALL DISPLA(' FOPEN - INVALID MODE ',MODE) 
         CALL ABTP("ND")
      ENDIF 
C 
C     FIND THE NEXT UNUSED ENTRY
C 
      DO 100 I = 1, MAXFILE 
C 
C        IF UNUSED TABLE ENTRY IS FOUND 
C 
         IF (FMODE(I) .EQ. CLOSED) THEN 
            FNAME(I) = FN 
            FWPTR(I) = 1
            FNWDS(I) = 0
            IF (MODE .EQ. RD) THEN
               FWSHFT(I) = 12 
            ELSE
               FWSHFT(I) = 0
            ENDIF 
            IF (MODE .EQ. CREATE) THEN
               IF (CFE(FNAME(I))) THEN
                  FMODE(I) = CLOSED 
                  FOPEN = ERROR 
                  RETURN
               ENDIF
               FMODE(I) = WR
            ELSE
               FMODE(I) = MODE
            ENDIF 
            FEOF(I) = .FALSE. 
            CTDEV(I) = .FALSE.
            FOPEN = I 
            CALL MAKEFET(FNAME(I),FETS(0,I),FETL,CIOBUFF(1,I),CIOBUFL)
C 
C           IF STANDARD I/O FILES, CONNECT THEM TO THE TERMINAL.
C 
            IF (FN .EQ. 'STDIN' .OR. FN .EQ. 'STDOUT') THEN 
               CALL XCON(FETS(0,I),1) 
               CTDEV(I) = .TRUE.
            ENDIF 
C 
C        SET THE ASCII FLAG AND REWIND THE FILE.
C 
            IF(FMODE(I) .EQ. RD) THEN 
                CALL OPEN(FETS(0,I),"READ") 
            ELSE
                CALL OPEN(FETS(0,I),"WRITE")
            ENDIF 
            CALL RECALL(FETS(0,I))
            FETS(0,I) = AND(FETS(0,I),SHIFT(MASK(44),2))
            IF(FMODE(I) .EQ. RD) FETS(0,I) = OR(FETS(0,I),CIORD)
            RETURN
C 
C        IF TABLE ENTRY FILE NAME MATCHES FN
C 
         ELSE IF (FNAME(I) .EQ. FN) THEN
            CALL REMARK(' FOPEN - FILE ' // FN // ' ALREADY OPEN.') 
            CALL ABTP("ND") 
         ENDIF
100   CONTINUE
      CALL REMARK(' FOPEN - TOO MANY FILES OPEN.')
      CALL ABTP("ND") 
      RETURN
      END 
      SUBROUTINE FCLOSE(FD) 
  
CCC   FCLOSE - REMOVE AN FD FROM THE ACTIVE LIST. 
C 
C     FCLOSE WILL REMOVE THE FD FROM THE ACTIVE LIST FOR
C     ALLOCATION AT A LATER DATE. 
C 
*CALL KERMCOM 
  
      IF (FD .LT. 1 .OR. FD .GT. MAXFILE) THEN
         CALL DISPLA(' FCLOSE - INVALID FD ',FD)
         CALL ABTP("ND")
      ENDIF 
      IF (FMODE(FD) .EQ. 0) THEN
         CALL DISPLA(' FCLOSE - FD NOT OPEN.',FD) 
         RETURN 
      ENDIF 
C 
C     FORCE EMPTYING OF THE BUFFER
C 
      CALL FFLUSH(FD) 
C 
C     WRITE A FILE MARK 
C 
      IF(FMODE(FD) .EQ. WR) THEN
          CALL WRITER(FETS(0,FD)) 
          CALL RECALL(FETS(0,FD)) 
      ENDIF 
      FMODE(FD) = CLOSED
      IF(CTDEV(FD)) THEN
          CALL CLOSE(FETS(0,FD),"UNLOAD") 
          CALL RECALL(FETS(0,FD)) 
      ELSE
          CALL CLOSE(FETS(0,FD),"REWIND") 
          CALL RECALL(FETS(0,FD)) 
      ENDIF 
      RETURN
      END 
      SUBROUTINE FFLUSH(FD) 
  
CCC   FFLUSH - FLUSH AN I/O BUFFER. 
C 
C     FFLUSH WILL FLUSH THE ASCII STRING BUFFER FOR A PARTICULAR
C     FILE DESCRIPTOR.
C 
*CALL KERMCOM 
  
      PARAMETER (INTRCOM = 42, ASC128 = 22, ASC256 = 23)
      PARAMETER (FIRST = 1, IN = 2, OUT = 3, LIMIT = 4, INTWD = 5)
C 
C     IS THE FD VALID?
C 
      IF (FD .LT. 1 .OR. FD .GT. MAXFILE) THEN
         CALL DISPLA(' FFLUSH - INVALID FILE DESCRIPTOR',FD)
         CALL ABTP("ND")
      ENDIF 
      IF (FMODE(FD) .EQ. 0) THEN
         CALL DISPLA(' FFLUSH - FILE DESCRIPTOR NOT OPEN',FD) 
         CALL ABTP("ND")
      ENDIF 
C 
C     IF FD WAS OPENED AS WRITE, THEN FLUSH TO THE FILE 
C 
      IF (FMODE(FD) .EQ. WR) THEN 
         IF(CTDEV(FD)) THEN 
C$    IF (UT2D .EQ. 1) THEN 
            FETS(FIRST,FD) = OR(FETS(FIRST,FD),SHIFT(1,ASCIIIO))
C$    ELSE
            FETS(FIRST,FD) = OR(FETS(FIRST,FD),SHIFT(1,INTRCOM))
            FETS(INTWD,FD) = SHIFT(1,ASC256)
C$    ENDIF 
         ELSEIF(FD .NE. DEBUGFD  .AND.  DSKCSET .EQ. DSKDPC) THEN 
            TEMP = DPCTBL(0)
            DPCTBL(0) = 0 
            CALL XTXS(FCHBUF(1,FD),FNWDS(FD),FCHBUF(1,FD),DPCTBL) 
            IF(MOD(FNWDS(FD),2) .EQ. 0) 
     +        FCHBUF(FNWDS(FD) / 2 + 1,FD) = 0
            DPCTBL(0) = TEMP
            FNWDS(FD) = FINDEOL(FCHBUF(1,FD),FNWDS(FD),.FALSE.) 
         ENDIF
         CALL WRITEW(FETS(0,FD),FCHBUF(1,FD),FNWDS(FD)) 
      ELSE IF (FMODE(FD) .EQ. RD) THEN
         CALL RECALL(FETS(0,FD))
         FETS(IN,FD) = AND(FETS(FIRST,FD),O"777777")
         FETS(OUT,FD) = FETS(IN,FD) 
      ENDIF 
C 
C     RESET BUFFER CHARACTER COUNT
C 
      FWPTR(FD) = 1 
      FNWDS(FD) = 0 
      IF (FMODE(FD) .EQ. RD) THEN 
         FWSHFT(FD) = 12
      ELSE
         FWSHFT(FD) = 0 
      ENDIF 
      RETURN
      END 
      INTEGER FUNCTION GETC(FD,CH)
  
CCC   GETC - RETURN NEXT CHARACTER FROM THE INPUT STREAM. 
C 
C     GETC WILL RETURN THE NEXT ASCII CHARACTER THAT WAS
C     READ FROM THE FILE DESCRIPTOR FD.  READS ARE BUFFERED 
C     WITH 5 CHARACTERS PACKED TO A WORD.  O"0000" BYTES
C     ARE IGNORED.  NULS ARE O"4000" BYTES.  EOF (-1) IS
C     RETURNED WHEN EOF IS READ.
C 
*CALL KERMCOM 
C 
C     IS THE FD VALID?
C 
      IF (FD .LT. 1 .OR. FD .GT. MAXFILE) THEN
         CALL DISPLA(' GETC - INVALID FILE DESCRIPTOR',FD)
         CALL ABTP("ND")
      ENDIF 
      IF (FMODE(FD) .EQ. CLOSED) THEN 
         CALL DISPLA(' GETC - FILE DESCRIPTOR NOT OPEN',FD) 
         CALL ABTP("ND")
      ENDIF 
C 
C     CHECK IF OK TO READ 
C 
      IF ((FMODE(FD).AND.RD) .NE. RD) THEN
         CALL DISPLA(' GETC - READ ON WRITE-ONLY FILE ',FD) 
         CALL ABTP("ND")
      ENDIF 
C 
C     CHECK IF MORE DATA NEEDED 
C 
10    IF (FWPTR(FD) .GT. FNWDS(FD)) THEN
         IF (FEOF(FD)) THEN 
            GETC = EOF
            RETURN
         ENDIF
C 
C        GET A BUFFER WORTH OF DATA 
C 
         NREAD = GETREC(FD,FCHBUF(1,FD),MAXWD,FEOF(FD)) 
         FWPTR(FD) = 1
         FNWDS(FD) = NREAD
         FWSHFT(FD) = 12
         GO TO 10 
      ENDIF 
C 
C     PICKUP CHAR TO RETURN AND CHECK FOR IGNORED O"0000" BYTE
C 
      CH = SHIFT(FCHBUF(FWPTR(FD),FD),FWSHFT(FD)) .AND. O"7777" 
      FWSHFT(FD) = FWSHFT(FD) + 12
      IF (FWSHFT(FD) .GT. 60) THEN
         FWSHFT(FD) = 12
         FWPTR(FD) = FWPTR(FD) + 1
      ENDIF 
C 
C     IF THE FRONT-END ISN'T STRIPPING PARITY AND WE AREN'T USING 
C     THE EIGTH BIT FOR DATA, THEN STRIP THE PARITY BIT.  ALSO, CONVERT 
C     CARRIAGE RETURNS AND LINEFEEDS WHICH COME FROM THE KEYBOARD INTO
C     REGULAR END-OF-LINES (THIS ONLY HAPPENS IN BINMODE).
C 
      IF (BINMODE .AND. .NOT. RAWMODE) THEN 
         IF (PARITY .NE. NOPAR .AND. CTDEV(FD)) CH = CH .AND. O"177"
         IF(CTDEV(FD)  .AND.  (CH .EQ. CR .OR. CH .EQ. LF)) CH = NEL
      ENDIF 
      IF (CH .EQ. 0) GO TO 10 
      GETC = CH 
      RETURN
      END 
      SUBROUTINE UNGETC(FD,CH)
  
CCC   UNGETC - TRY TO PUT A CHARACTER BACK INTO THE INPUT STREAM. 
C 
C     UNGETC CAN ONLY PUT BACK CHARACTERS AS FAR AS THE BEGINNING 
C     OF THE BUFFER.  HOPEFULLY, THIS IS OK, SINCE ONLY GETWORD 
C     DOES THIS WITH AN NEL WHICH SHOULD BE WELL INTO THE BUFFER. 
*CALL KERMCOM 
C 
C     IS IT OK TO BACK UP THE POINTER?
C 
      IF (FWSHFT(FD) .EQ. 12 .AND. FWPTR(FD) .EQ. 1) THEN 
         CALL DISPLA('UNGETC - CANNOT PUSH CHARACTER ',CH)
         RETURN 
      ENDIF 
C 
C     BACK UP THE POINTER 
C 
      IF (FWSHFT(FD) .EQ. 12) THEN
         FWSHFT(FD) = 60
         FWPTR(FD) = FWPTR(FD) - 1
      ELSE
         FWSHFT(FD) = FWSHFT(FD) - 12 
      ENDIF 
      FCHBUF(FWPTR(FD),FD) = (FCHBUF(FWPTR(FD),FD) .AND. SHIFT( 
     +   O"7777",60-FWSHFT(FD))) .OR. SHIFT(CH,60-FWSHFT(FD)) 
      FEOF(FD) = .FALSE.
      RETURN
      END 
      INTEGER FUNCTION GETWORD(FD,STR,MAXLEN) 
  
CCC   GETWORD - GET A WORD FROM AN INPUT STREAM.
C 
C     GETWORD CONSIDERS A WORD TO BE DELIMITED BY BLANKS. 
C     IT WILL RETURN THE LENGTH OF THE WORD AS ITS VALUE. 
C 
*CALL KERMCOM 
      INTEGER STR(MAXLEN) 
  
      LEN = 0 
C 
C     SKIP LEADING WHITE SPACES 
C 
10    IF (GETC(FD,CH) .EQ. EOF) THEN
         GETWORD = EOF
         RETURN 
      ELSE IF (CH .EQ. NEL) THEN
         GETWORD = 0
         RETURN 
      ENDIF 
      IF (CH .EQ. BLANK .OR. CH .EQ. TAB) GO TO 10
C 
C     FOUND THE FIRST CHARACTER, SO KEEP GOING
C 
20    IF (LEN .LT. MAXLEN) THEN 
         LEN = LEN + 1
         STR(LEN) = CH
      ENDIF 
      CH = GETC(FD,CH)
      IF (CH .NE. EOF .AND. CH .NE. BLANK .AND. CH .NE. TAB .AND. 
     +    CH .NE. NEL) GO TO 20 
C 
C     SAVE EOLS FOR NEXT GETWORD
C 
      IF (CH .EQ. NEL) CALL UNGETC(FD,CH) 
      STR(LEN+1) = 0
      GETWORD = LEN 
      RETURN
      END 
      SUBROUTINE PUTC(TCH,FD) 
  
CCC   PUTC - PUT A CHARACTER INTO AN OUTPUT STREAM
C 
C     PUTC OUTPUTS A CHARACTER WITH THE PARITY BIT SET TO THE 
C     PROPER PARITY IF THE OUTPUT FILE IS CONVERSATIONAL. 
C     THE FIVE TYPES OF PARITY ARE DEFINED FOR EACH CHARACTER 
C     IN A TABLE. 
C 
*CALL KERMCOM 
      INTEGER CHPARTY(128)
      DATA (CHPARTY(I),I=1,38) /
     +               O"40000200020040004000", O"02010001020100010001",
C                            NUL                      SOH 
     +               O"02020002020200020002", O"00030203020300030003",
C                            STX                      ETX 
     +               O"02040004020400040004", O"00050205020500050005",
C                            EOT                      ENQ 
     +               O"00060206020600060006", O"02070007020700070007",
C                            ACK                      BEL 
     +               O"02100010021000100010", O"00110211021100110011",
C                            BS                       HT
     +               O"00120212021200120012", O"02130013021300130013",
C                            LF                       VT
     +               O"00140214021400140014", O"02150015021500150015",
C                            FF                       CR
     +               O"02160016021600160016", O"00170217021700170017",
C                            SO                       SI
     +               O"02200020022000200020", O"00210221022100210021",
C                            DLE                      DC1 
     +               O"00220222022200220022", O"02230023022300230023",
C                            DC2                      DC3 
     +               O"00240224022400240024", O"02250025022500250025",
C                            DC4                      NAK 
     +               O"02260026022600260026", O"00270227022700270027",
C                            SYN                      ETB 
     +               O"00300230023000300030", O"02310031023100310031",
C                            CAN                      EM
     +               O"02320032023200320032", O"00330233023300330033",
C                            SUB                      ESC 
     +               O"02340034023400340034", O"00350235023500350035",
C                            FS                       GS
     +               O"00360236023600360036", O"02370037023700370037",
C                            RS                       US
     +               O"02400040024000400040", O"00410241024100410041",
C                                                     ! 
     +               O"00420242024200420042", O"02430043024300430043",
C                            "                        POUND 
     +               O"00440244024400440044", O"02450045024500450045" / 
C                            $                        PERCENT 
      DATA (CHPARTY(I),I=39,76) / 
     +               O"02460046024600460046", O"00470247024700470047",
C                            &                        ' 
     +               O"00500250025000500050", O"02510051025100510051",
C                            (                        ) 
     +               O"02520052025200520052", O"00530253025300530053",
C                            *                        + 
     +               O"02540054025400540054", O"00550255025500550055",
C                            ,                        - 
     +               O"00560256025600560056", O"02570057025700570057",
C                            .                        / 
     +               O"00600260026000600060", O"02610061026100610061",
C                            0                        1 
     +               O"02620062026200620062", O"00630263026300630063",
C                            2                        3 
     +               O"02640064026400640064", O"00650265026500650065",
C                            4                        5 
     +               O"00660266026600660066", O"02670067026700670067",
C                            6                        7 
     +               O"02700070027000700070", O"00710271027100710071",
C                            8                        9 
     +               O"00720272027200720072", O"02730073027300730073",
C                            :                        ; 
     +               O"00740274027400740074", O"02750075027500750075",
C                            <                        = 
     +               O"02760076027600760076", O"00770277027700770077",
C                            >                        ? 
     +               O"03000100030001000100", O"01010301030101010101",
C                            @                        A 
     +               O"01020302030201020102", O"03030103030301030103",
C                            B                        C 
     +               O"01040304030401040104", O"03050105030501050105",
C                            D                        E 
     +               O"03060106030601060106", O"01070307030701070107",
C                            F                        G 
     +               O"01100310031001100110", O"03110111031101110111",
C                            H                        I 
     +               O"03120112031201120112", O"01130313031301130113" / 
C                            J                        K 
      DATA (CHPARTY(I),I=77,114) /
     +               O"03140114031401140114", O"01150315031501150115",
C                            L                        M 
     +               O"01160316031601160116", O"03170117031701170117",
C                            N                        O 
     +               O"01200320032001200120", O"03210121032101210121",
C                            P                        Q 
     +               O"03220122032201220122", O"01230323032301230123",
C                            R                        S 
     +               O"03240124032401240124", O"01250325032501250125",
C                            T                        U 
     +               O"01260326032601260126", O"03270127032701270127",
C                            V                        W 
     +               O"03300130033001300130", O"01310331033101310131",
C                            X                        Y 
     +               O"01320332033201320132", O"03330133033301330133",
C                            Z                        [ 
     +               O"01340334033401340134", O"03350135033501350135",
C                            \                        ] 
     +               O"03360136033601360136", O"01370337033701370137",
C                            ^                        UNDERSCORE
     +               O"01400340034001400140", O"03410141034101410141",
C                            GRAVE ACCENT             A 
     +               O"03420142034201420142", O"01430343034301430143",
C                            B                        C 
     +               O"03440144034401440144", O"01450345034501450145",
C                            D                        E 
     +               O"01460346034601460146", O"03470147034701470147",
C                            F                        G 
     +               O"03500150035001500150", O"01510351035101510151",
C                            H                        I 
     +               O"01520352035201520152", O"03530153035301530153",
C                            J                        K 
     +               O"01540354035401540154", O"03550155035501550155",
C                            L                        M 
     +               O"03560156035601560156", O"01570357035701570157",
C                            N                        O 
     +               O"03600160036001600160", O"01610361036101610161" / 
      DATA (CHPARTY(I),I=115,128) / 
C                            P                        Q 
     +               O"01620362036201620162", O"03630163036301630163",
C                            R                        S 
     +               O"01640364036401640164", O"03650165036501650165",
C                            T                        U 
     +               O"03660166036601660166", O"01670367036701670167",
C                            V                        W 
     +               O"01700370037001700170", O"03710171037101710171",
C                            X                        Y 
     +               O"03720172037201720172", O"01730373037301730173",
C                            Z                        LEFT BRACE
     +               O"03740174037401740174", O"01750375037501750175",
C                            BAR                      RIGHT BRACE 
     +               O"01760376037601760176", O"03770177037701770177" / 
C                            TILDE                    DEL 
C 
C     IS THE FD VALID?
C 
      IF (FD .LT. 1 .OR. FD .GT. MAXFILE) THEN
         CALL DISPLA(' PUTC - INVALID FILE DESCRIPTOR',FD)
         CALL ABTP("ND")
      ENDIF 
      IF (FMODE(FD) .EQ. CLOSED) THEN 
         CALL DISPLA(' PUTC - FILE DESCRIPTOR NOT OPEN',FD) 
         CALL ABTP("ND")
      ENDIF 
C 
C     IS IT OK TO WRITE ON THIS STREAM? 
C 
      IF ((FMODE(FD).AND.WR) .NE. WR) THEN
         CALL DISPLA(' PUTC - WRITE ON READ-ONLY FILE ',FD) 
         CALL ABTP("ND")
      ENDIF 
C 
C     ADD ANOTHER CHARACTER TO THE OUTPUT BUFFER
C 
      CH = TCH
10    IF (CTDEV(FD)) THEN 
         IF (CH .EQ. NEL .AND. .NOT. RAWMODE) CH = CR 
         IF (CH .GE. 0 .AND. CH .LT. 128) 
     +      CH = SHIFT(CHPARTY(CH+1),PARITY*12) .AND. O"7777" 
      ENDIF 
      IF (FWSHFT(FD) .EQ. 0) THEN 
         IF (FNWDS(FD) .EQ. MAXWD) THEN 
            CALL FFLUSH(FD) 
         ENDIF
         FWSHFT(FD) = 48
         FNWDS(FD) = FNWDS(FD) + 1
         FCHBUF(FNWDS(FD),FD) = 0 
      ELSE
         FWSHFT(FD) = FWSHFT(FD) - 12 
      ENDIF 
C 
C     IF THIS IS AN MASS STORAGE DEVICE (DISK), AND WE HAVE A NEL 
C     CHARACTER, FLUSH THE LINE INTO THE CIO BUFFER.  THE STANDARD CDC
C     LINE TERMINATOR IS ALREADY PRESENT THANKS TO THE ABOVE CODE 
C     PRE-ZEROING THE TARGET WORD BEFORE ANYTHING IS PUT IN IT. 
C     HOWEVER, DON'T FLUSH IF WE NEED THE NEL CHARACTER IN THE
C     LINE (E.G. UT 812 ASCII AND DISK IMAGE FORMAT). 
C 
      IF(.NOT.CTDEV(FD) .AND. TCH.EQ.NEL .AND. DSKCSET.NE.DSKUT8 .AND.
     +   DSKCSET.NE.DSKIMAG) THEN 
          CALL FFLUSH(FD) 
          RETURN
      ENDIF 
  
      FCHBUF(FNWDS(FD),FD) = FCHBUF(FNWDS(FD),FD) .OR.
     +   SHIFT(AND(CH,O"7777"),FWSHFT(FD))
      IF (TCH .EQ. NEL .AND. (CH.AND.O"0177") .EQ. CR) THEN 
         CH = LF
         GO TO 10 
      ENDIF 
      IF (TCH .EQ. NEL .AND. CTDEV(FD)) CALL FFLUSH(FD) 
      RETURN
      END 
      SUBROUTINE FREAD(FD,BUF,NWD)
  
CCC   FREAD - READ SOME WORDS FROM A FILE.
C 
*CALL KERMCOM 
      INTEGER BUF(NWD)
C 
C     IS THE FD VALID?
C 
      IF (FD .LT. 1 .OR. FD .GT. MAXFILE) THEN
         CALL DISPLA(' FREAD - INVALID FILE DESCRIPTOR',FD) 
         CALL ABTP("ND")
      ENDIF 
      IF (FMODE(FD) .EQ. CLOSED) THEN 
         CALL DISPLA(' FREAD - FILE DESCRIPTOR NOT OPEN',FD)
         CALL ABTP("ND")
      ENDIF 
C 
C     CHECK IF OK TO READ 
C 
      IF ((FMODE(FD).AND.RD) .NE. RD) THEN
         CALL DISPLA(' FREAD - READ ON WRITE-ONLY FILE ',FD)
         CALL ABTP("ND")
      ENDIF 
C 
C     TRANSFER A CIO BUFFER FULL AT A TIME UNTIL DONE 
C 
      ISTART = 1
      NLEFT = NWD 
10    NRD = NLEFT 
      IF (NRD .GT. CIOBUFL-1) THEN
         NRD = CIOBUFL-1
      ENDIF 
      CALL READW(FETS(0,FD),BUF(ISTART),NRD)
      ISTART = ISTART + NRD 
      NLEFT = NLEFT - NRD 
      IF (NLEFT .GT. 0) GOTO 10 
      RETURN
      END 
      SUBROUTINE FWRITE(FD,BUF,NWD) 
  
CCC   FWRITE - WRITE SOME WORDS TO A FILE.
C 
*CALL KERMCOM 
C 
C     IS THE FD VALID?
C 
      IF (FD .LT. 1 .OR. FD .GT. MAXFILE) THEN
         CALL DISPLA(' FWRITE - INVALID FD ',FD)
         CALL ABTP("ND")
      ENDIF 
      IF (FMODE(FD) .EQ. CLOSED) THEN 
         CALL DISPLA(' FWRITE - FD NOT OPEN.',FD) 
         RETURN 
      ENDIF 
C 
C     IS IT OK TO WRITE ON THIS STREAM? 
C 
      IF ((FMODE(FD).AND.WR) .NE. WR) THEN
         CALL DISPLA(' FWRITE - WRITE ON READ-ONLY FILE ',FD) 
         CALL ABTP("ND")
      ENDIF 
C 
C     WRITE THE WORDS TO THE FILE 
C 
      CALL WRITEW(FETS(0,FD),BUF,NWD) 
      RETURN
      END 
      SUBROUTINE PUTSTR(FD,STR) 
  
CCC   PUTSTR - OUTPUT A STRING TO AN OUTPUT STREAM. 
C 
C     PUTSTR WILL ADD CHARACTERS FROM THE NULL TERMINATED CHARACTER 
C     BUFFER STR TO THE SPECIFIED OUTPUT STREAM.
C 
*CALL KERMCOM 
      INTEGER STR(*)
C 
C     IS THE FD VALID?
C 
      IF (FD .LT. 1 .OR. FD .GT. MAXFILE) THEN
         CALL DISPLA(' PUTC - INVALID FD ',FD)
         CALL ABTP("ND")
      ENDIF 
      IF (FMODE(FD) .EQ. 0) THEN
         CALL DISPLA(' PUTC - FD NOT OPEN.',FD) 
         RETURN 
      ENDIF 
C 
C     IS IT OK TO WRITE ON THIS STREAM? 
C 
      IF ((FMODE(FD).AND.WR) .NE. WR) THEN
         CALL DISPLA(' PUTC - WRITE ON READ-ONLY FILE ',FD) 
         CALL ABTP("ND")
      ENDIF 
C 
C     PUT CHARS IN THE OUTPUT BUFFER
C 
      I = 1 
10    IF (STR(I) .NE. 0) THEN 
C 
C        IS IT A VALID CHARACTER? 
C 
C        IF ((STR(I).AND.MASK(48)) .NE. 0) THEN 
C           CALL DISPLA(' PUTSTR - INVALID ASCII BYTE ',STR(I)) 
C           CALL ABORT
C        ENDIF
         CALL PUTC(STR(I),FD) 
         I = I + 1
         GO TO 10 
      ENDIF 
      RETURN
      END 
      SUBROUTINE PUTINT(FD,INT,MINWID)
  
CCC   PUTINT - OUTPUT AN INTEGER. 
C 
*CALL KERMCOM 
      INTEGER STRING(21)
  
      WIDTH = 0 
      IF (INT .LT. 0) THEN
         CALL PUTC(ASC('-'),FD) 
         WIDTH = 1
      ENDIF 
      VAL = IABS(INT) 
      ASCII0 = ASC('0') 
      NCH = 0 
10    NCH = NCH + 1 
      STRING(NCH) = MOD(VAL,10) + ASCII0
      VAL = VAL / 10
      IF (VAL .NE. 0 .AND. NCH .LT. 20) GO TO 10
      WIDTH = WIDTH + NCH 
C 
C     NOW OUTPUT THE DIGITS 
C 
20    CALL PUTC(STRING(NCH),FD) 
      NCH = NCH - 1 
      IF (NCH .GT. 0) GO TO 20
30    IF (WIDTH .LT. MINWID) THEN 
         CALL PUTC(BLANK,FD)
         WIDTH = WIDTH + 1
         GO TO 30 
      ENDIF 
      RETURN
      END 
      SUBROUTINE PUTDAY(FD,MM,DD,YY)
  
CCC   OUTPUT DAY OF WEEK. 
C 
*CALL KERMCOM 
      IZLR(IYR,M,IDY)=MOD((13*(M+10-(M+10)/13*12)-1)/5+IDY+77 
     1 +5*(IYR+(M-14)/12-(IYR+(M-14)/12)/100*100)/4 
     2 +(IYR+(M-14)/12)/400-(IYR+(M-14)/12)/100*2,7)+1
      WKDAY = IZLR(YY,MM,DD)
      IF (WKDAY .EQ. 1) THEN
         CALL FPRINTF(FD,'^SUNDAY') 
      ELSE IF (WKDAY .EQ. 2) THEN 
         CALL FPRINTF(FD,'^MONDAY') 
      ELSE IF (WKDAY .EQ. 3) THEN 
         CALL FPRINTF(FD,'^TUESDAY')
      ELSE IF (WKDAY .EQ. 4) THEN 
         CALL FPRINTF(FD,'^WEDNESDAY')
      ELSE IF (WKDAY .EQ. 5) THEN 
         CALL FPRINTF(FD,'^THURSDAY') 
      ELSE IF (WKDAY .EQ. 6) THEN 
         CALL FPRINTF(FD,'^FRIDAY') 
      ELSE
         CALL FPRINTF(FD,'^SATURDAY') 
      ENDIF 
      RETURN
      END 
      SUBROUTINE PUTMNTH(FD,MM) 
  
CCC   PUTMNTH - OUTPUT THE MONTH NAME.
C 
*CALL KERMCOM 
      IF (MM .EQ. 1) THEN 
         CALL FPRINTF(FD,'^JANUARY',0)
      ELSE IF (MM .EQ. 2) THEN
         CALL FPRINTF(FD,'^FEBRUARY',0) 
      ELSE IF (MM .EQ. 3) THEN
         CALL FPRINTF(FD,'^MARCH',0)
      ELSE IF (MM .EQ. 4) THEN
         CALL FPRINTF(FD,'^APRIL',0)
      ELSE IF (MM .EQ. 5) THEN
         CALL FPRINTF(FD,'^MAY',0)
      ELSE IF (MM .EQ. 6) THEN
         CALL FPRINTF(FD,'^JUNE',0) 
      ELSE IF (MM .EQ. 7) THEN
         CALL FPRINTF(FD,'^JULY',0) 
      ELSE IF (MM .EQ. 8) THEN
         CALL FPRINTF(FD,'^AUGUST',0) 
      ELSE IF (MM .EQ. 9) THEN
         CALL FPRINTF(FD,'^SEPTEMBER',0)
      ELSE IF (MM .EQ. 10) THEN 
         CALL FPRINTF(FD,'^OCTOBER',0)
      ELSE IF (MM .EQ. 11) THEN 
         CALL FPRINTF(FD,'^NOVEMBER',0) 
      ELSE IF (MM .EQ. 12) THEN 
         CALL FPRINTF(FD,'^DECEMBER',0) 
      ELSE
         CALL FPRINTF(FD,'PUTMNTH - NO SUCH MONTH AS @D\N',MM)
      ENDIF 
      RETURN
      END 
      SUBROUTINE FPRINTF(FD,FMT,I1,I2,I3,I4)
  
CCC   FPRINTF - POOR ATTEMPT AT FORMATTED ASCII OUTPUT. 
C 
C     CONVERSION IS SIMILAR TO FPRINTF USED IN C.  SUPPORTED
C     CONVERSIONS ARE @D (INTEGER), @C (ASCII CHARACTER), @S (ASCII 
C     STRING BUFFER).  A \N WILL MAP TO A NEWLINE, A \T WILL
C     WILL MAP TO A TAB, A \0 WILL TERMINATE THE FORMAT SCANNING. 
C     A \ FOLLOWED BY ANY OTHER CHARACTER WILL CAUSE THAT CHARACTER 
C     TO BE OUTPUT.  THE DEFAULT OUTPUT CASE WILL BE LOWERCASE. 
C     A ^ FOLLOWED BY A LETTER WILL CAUSE THAT CHARACTER TO BE OUTPUT 
C     AS UPPERCASE.  A @D CONVERSION MAY NOW SPECIFY A MINIMUM FIELD
C     WIDTH AS @<N>D (I.E. @10D) IN WHICH THE NUMBER WILL BE BLANK
C     PADDED TO THE RIGHT TO USE UP <N> CHARACTERS. 
C 
*CALL KERMCOM 
      CHARACTER*(*) FMT 
C 
C     IS THE FD VALID?
C 
      IF (FD .LT. 1 .OR. FD .GT. MAXFILE) THEN
         CALL DISPLA(' FPRINTF - INVALID FD ',FD) 
         CALL ABTP("ND")
      ENDIF 
      IF (FMODE(FD) .EQ. CLOSED) THEN 
         CALL DISPLA(' FPRINTF - FD NOT OPEN.',FD)
         RETURN 
      ENDIF 
C 
C     IS IT OK TO WRITE ON THIS STREAM? 
C 
      IF ((FMODE(FD).AND.WR) .NE. WR) THEN
         CALL DISPLA(' FPRINTF - WRITE ON READ-ONLY FILE ',FD)
         CALL ABTP("ND")
      ENDIF 
C 
C     NOW CALL THE REAL FPRINTF WORKHORSE 
C 
      CALL DOPRNT(FD,0,1,FMT,I1,I2,I3,I4) 
      RETURN
      END 
      SUBROUTINE SPRINTF(STR,FMT,I1,I2,I3,I4) 
  
CCC   SPRINTF - POOR ATTEMPT AT DOING INTERNAL FORMATTED I/O. 
C 
C     SPRINTF IS THE SAME AS FPRINTF EXCEPT THAT IT WRITES TO 
C     AND ASCII STRING BUFFER INSTEAD.
C 
*CALL KERMCOM 
      CHARACTER*(*) FMT 
      BOOLEAN STR(*)
C 
C     CALL THE REAL SPRINTF WORKHORSE 
C 
      CALL DOPRNT(0,STR,2,FMT,I1,I2,I3,I4)
      RETURN
      END 
      SUBROUTINE DOPRNT(FD,STRNG,PTYP,FMT,I1,I2,I3,I4)
  
CCC   DOPRNT - WORKHORSE FOR FORMATTED ASCII I/O. 
C 
C     CONVERSION IS SIMILAR TO FPRINTF USED IN C.  SUPPORTED
C     CONVERSIONS ARE @D (INTEGER), @C (ASCII CHARACTER), @S (ASCII 
C     STRING BUFFER).  A \N WILL MAP TO A NEWLINE, A \T WILL
C     WILL MAP TO A TAB, A \0 WILL TERMINATE THE FORMAT SCANNING. 
C     A \ FOLLOWED BY ANY OTHER CHARACTER WILL CAUSE THAT CHARACTER 
C     TO BE OUTPUT.  THE DEFAULT OUTPUT CASE WILL BE LOWERCASE. 
C     A ^ FOLLOWED BY A LETTER WILL CAUSE THAT CHARACTER TO BE OUTPUT 
C     AS UPPERCASE.  A @D CONVERSION MAY NOW SPECIFY A MINIMUM FIELD
C     WIDTH AS @<N>D (I.E. @10D) IN WHICH THE NUMBER WILL BE BLANK
C     PADDED TO THE RIGHT TO USE UP <N> CHARACTERS. 
C 
*CALL KERMCOM 
      CHARACTER*(*) FMT 
      BOOLEAN STR(21), STRNG(*) 
      CHARACTER*1 CH
C 
C     CHECK FOR FILE OR STRING WRITE
C 
      IF (PTYP .NE. 1 .AND. PTYP .NE. 2) THEN 
         CALL DISPLA(' DOPRNT - INVALID WRITE FUNCTION',PTYP) 
         CALL ABTP("ND")
      ENDIF 
C 
C     OUTPUT THE FORMATTED STRING 
C 
      IPTR = 1
      OPTR = 1
      FPTR = 1
      FMTLEN = LEN(FMT) 
10    IF (FPTR .LE. FMTLEN) THEN
         CH = FMT(FPTR:FPTR)
         IF (CH .NE. '\' .AND. CH .NE. '@' .AND. CH .NE. '^') THEN
            IF (PTYP .EQ. 1) THEN 
               CALL PUTC(ASC(CH),FD)
            ELSE
               STRNG(OPTR) = ASC(CH)
               OPTR = OPTR + 1
            ENDIF 
C 
C        IS IT A QUOTE OR SPECIAL SEQUENCE CHARACTER? 
C 
         ELSE IF (CH .EQ. '\') THEN 
            FPTR = FPTR+1 
            CH = FMT(FPTR:FPTR) 
            IF (CH .EQ. 'N' .AND. PTYP .EQ. 1) THEN 
               CALL PUTC(NEL,FD)
            ELSE IF (CH .EQ. 'T' .AND. PTYP .EQ. 1) THEN
               CALL PUTC(TAB,FD)
            ELSE IF (CH .EQ. '0') THEN
               IF (PTYP .EQ. 2) STRNG(OPTR) = 0 
               RETURN 
            ELSE IF (CH .EQ. 'N') THEN
               STRNG(OPTR) = NEL
               OPTR = OPTR + 1
            ELSE IF (CH .EQ. 'T') THEN
               STRNG(OPTR) = TAB
               OPTR = OPTR + 1
            ELSE
               IF (PTYP .EQ. 1) THEN
                  CALL PUTC(ASC(CH),FD) 
               ELSE 
                  STRNG(OPTR) = ASC(CH) 
                  OPTR = OPTR + 1 
               ENDIF
            ENDIF 
C 
C     IS IT AN UPPERCASE MAPPING? 
C 
         ELSE IF (CH .EQ. '^') THEN 
            FPTR = FPTR + 1 
            CH = FMT(FPTR:FPTR) 
            IF (CH .GE. 'A' .AND. CH .LE. 'Z') THEN 
               ACH = ASC(CH)-32 
            ELSE
               ACH = ASC(CH)
            ENDIF 
            IF (PTYP .EQ. 1) THEN 
               CALL PUTC(ACH,FD)
            ELSE
               STRNG(OPTR) = ACH
               OPTR = OPTR + 1
            ENDIF 
C 
C        MUST BE A CONVERSION (@) 
C 
         ELSE 
            INTWDTH = 1 
            FPTR = FPTR + 1 
            CH = FMT(FPTR:FPTR) 
C 
C           IS IT AN INTEGER VALUE FORMAT SPEC? 
C 
20          IF (CH .EQ. 'D') THEN 
               IF (IPTR .EQ. 1) THEN
                  ACH = I1
               ELSE IF (IPTR .EQ. 2) THEN 
                  ACH = I2
               ELSE IF (IPTR .EQ. 3) THEN 
                  ACH = I3
               ELSE 
                  ACH = I4
               ENDIF
               IF (PTYP .EQ. 1) THEN
                  CALL PUTINT(FD,ACH,INTWDTH) 
               ELSE 
                  TLEN = ITOS(ACH,STRNG(OPTR),INTWDTH)
                  OPTR = OPTR + TLEN
               ENDIF
               IPTR = IPTR + 1
C 
C           IS IT A CHARACTER VALUE OUTPUT SPEC?
C 
            ELSE IF (CH .EQ. 'C') THEN
               IF (IPTR .EQ. 1) THEN
                  ACH = I1
               ELSE IF (IPTR .EQ. 2) THEN 
                  ACH = I2
               ELSE IF (IPTR .EQ. 3) THEN 
                  ACH = I3
               ELSE 
                  ACH = I4
               ENDIF
               IF (PTYP .EQ. 1) THEN
                  CALL PUTC(ACH,FD) 
               ELSE 
                  STRNG(OPTR) = ACH 
                  OPTR = OPTR + 1 
               ENDIF
               IPTR = IPTR + 1
C 
C           IS IT A STRING VALUE OUTPUT SPEC? 
C 
            ELSE IF (CH .EQ. 'S') THEN
               IF (IPTR .EQ. 1) THEN
                  IF (PTYP .EQ. 1) THEN 
                     CALL PUTSTR(FD,I1) 
                  ELSE
                     CALL STRCPY(I1,STRNG(OPTR))
                     OPTR = OPTR + SLEN(I1) 
                  ENDIF 
               ELSE IF (IPTR .EQ. 2) THEN 
                  IF (PTYP .EQ. 1) THEN 
                     CALL PUTSTR(FD,I2) 
                  ELSE
                     CALL STRCPY(I2,STRNG(OPTR))
                     OPTR = OPTR + SLEN(I2) 
                  ENDIF 
               ELSE IF (IPTR .EQ. 3) THEN 
                  IF (PTYP .EQ. 1) THEN 
                     CALL PUTSTR(FD,I3) 
                  ELSE
                     CALL STRCPY(I3,STRNG(OPTR))
                     OPTR = OPTR + SLEN(I3) 
                  ENDIF 
               ELSE 
                  IF (PTYP .EQ. 1) THEN 
                     CALL PUTSTR(FD,I4) 
                  ELSE
                     CALL STRCPY(I4,STRNG(OPTR))
                     OPTR = OPTR + SLEN(I4) 
                  ENDIF 
               ENDIF
               IPTR = IPTR + 1
C 
C           IS IT A FIELD WIDTH SPECIFIER?
C 
            ELSE IF (CH .GE. '0' .AND. CH .LE. '9') THEN
               SPTR = 0 
30             SPTR = SPTR + 1
               STR(SPTR) = ASC(CH)
               FPTR = FPTR + 1
               CH = FMT(FPTR:FPTR)
               IF (CH .GE. '0' .AND. CH .LE. '9') GO TO 30
               STR(SPTR+1) = 0
               INTWDTH = CTOI(STR)
               GO TO 20 
C 
C           UNKNOWN CONVERSION SO OUTPUT THE @ AND CONVERSION CHAR
C 
            ELSE
               IF (PTYP .EQ. 1) THEN
                  CALL PUTC(ASC('@'),FD)
                  CALL PUTC(ASC(CH),FD) 
               ELSE 
                  STRNG(OPTR) = ASC('@')
                  STRNG(OPTR+1) = ASC(CH) 
                  OPTR = OPTR + 2 
               ENDIF
         ENDIF
         ENDIF
         FPTR = FPTR + 1
         GO TO 10 
      ENDIF 
      IF (PTYP .EQ. 2) STRNG(OPTR) = 0
      RETURN
      END 
      SUBROUTINE STTY(MODE,VALUE) 
  
CCC   STTY - SET A TERMINAL MODE. 
C 
*CALL KERMCOM 
      CHARACTER*(*) MODE
      INTEGER VALUE 
C 
C     IS IT SETTING DUPLEX? 
C 
      IF (MODE .EQ. 'DUPLEX') THEN
         IF (VALUE .EQ. FULLDUP) THEN 
C$          IF (UT2D .EQ. 1)
            CALL BELLC(L"FULL",0,0) 
C$          ENDIF 
C$          IF(UARIZ .EQ. 1)
            CALL ECHOPLX('ON')
C$          ENDIF 
            DUPLEX = FULLDUP
         ELSE IF (VALUE .EQ. HALFDUP) THEN
C$          IF (UT2D .EQ. 1)
            CALL BELLC(L"HALF",0,0) 
C$          ENDIF 
C$          IF(UARIZ .EQ. 1)
            CALL ECHOPLX('OFF') 
C$          ENDIF 
            DUPLEX = HALFDUP
         ELSE 
            CALL DISPLA(' STTY - INVALID DUPLEX ',VALUE)
            CALL ABTP("ND") 
         ENDIF
C 
C     IS IT SETTING PARITY? 
C 
      ELSE IF (MODE .EQ. 'PARITY') THEN 
         IF (VALUE .EQ. NOPAR .OR. VALUE .EQ. EVEPAR .OR. 
     +       VALUE .EQ. ODDPAR .OR. VALUE .EQ. MRKPAR .OR.
     +       VALUE .EQ. SPCPAR) THEN
            PARITY = VALUE
         ELSE 
            CALL DISPLA(' STTY - INVALID PARITY ',VALUE)
            CALL ABTP("ND") 
         ENDIF
C 
C     IS IT SETTING BINARY (NO TRANSLATION) I/O?
C 
      ELSE IF (MODE .EQ. 'BINARY') THEN 
         BINMODE = (VALUE .EQ. ON)
         DO 100 I = 1,MAXFILE 
            IF (FMODE(I) .NE. CLOSED) THEN
               IF (CTDEV(I)) THEN 
                  IF (BINMODE) THEN 
                     FETS(0,I) = OR(FETS(0,I),CIOODD) 
                  ELSE
                     FETS(0,I) = AND(FETS(0,I),.NOT.CIOODD) 
                  ENDIF 
               ENDIF
            ENDIF 
100      CONTINUE 
C 
C     IS IT SETTING TRANSPARENT (RAW) I/O?
C 
      ELSE IF (MODE .EQ. 'RAW') THEN
         IF (VALUE .EQ. 0) THEN 
            RAWMODE = .FALSE. 
         ELSE 
            IRET = 0
            RAWMODE = .TRUE.
         ENDIF
      ELSE
         CALL DISPLA(' STTY - INVALID MODE ',BOOL(MODE))
         CALL ABTP("ND")
      ENDIF 
      RETURN
      END 
      INTEGER FUNCTION GTTY(MODE) 
  
CCC   GTTY - GET A TTY MODE.
C 
*CALL KERMCOM 
      CHARACTER*(*) MODE
C 
C     IS IT DUPLEX THEY'RE LOOKING FOR? 
C 
      IF (MODE .EQ. 'DUPLEX') THEN
         GTTY = DUPLEX
C 
C     IS IT PARITY THEY'RE LOOKING FOR? 
C 
      ELSE IF (MODE .EQ. 'PARITY') THEN 
         GTTY = PARITY
      ELSE
         CALL DISPLA(' GTTY - INVALID MODE ',BOOL(MODE))
         CALL ABTP("ND")
      ENDIF 
      RETURN
      END 
      SUBROUTINE AS2DPC(ASTR,DSTR)
  
CCC   AS2DPC - TRANSLATE AN ASCII STRING BUFFER TO DPC CHAR STRING. 
C 
C     ASCII STRING IS TERMINATED BY A ZERO BYTE.
C 
C 
*CALL KERMCOM 
      BOOLEAN ASTR(*) 
      CHARACTER DSTR*(*)
      INTEGER CLEN
C 
C 
      I = 1 
      CLEN = LEN(DSTR)
      DSTR = ' '
10    IF (ASTR(I) .NE. 0 .AND. I .LE. CLEN) THEN
         IF (ASTR(I) .GT. 127) THEN 
            CALL MOVECH(DPCTBL(BLANK),9,DSTR,I - 1,1) 
         ELSE 
            CALL MOVECH(DPCTBL(ASTR(I)),9,DSTR,I - 1,1) 
         ENDIF
         I = I + 1
         GO TO 10 
      ENDIF 
C 
      RETURN
      END 
      INTEGER FUNCTION ASC(DPCH)
  
CCC   ASC - CONVERT A DPC CHARACTER TO LOWER CASE ASCII.
C 
C 
*CALL KERMCOM 
      CHARACTER*1 DPCH
C 
C 
      ASC = LASCII(ICHAR(DPCH)) 
C 
      RETURN
      END 
      SUBROUTINE DPC2AS(DSTR,ASTR,NWORDS) 
C 
C  TRANSLATE STRING OF DISPLAY CODE CHARACTERS TO UPPERCASE ASCII.
C  STRING IS NWORDS CHARACTERS (WORDS) LONG.
C 
C 
*CALL KERMCOM 
  
      CHARACTER*(*) DSTR
      BOOLEAN ASTR(NWORDS)
C 
C 
      DO 1 I=1,NWORDS 
         ASTR(I) = UASCII((ICHAR(DSTR(I:I)))) 
    1    CONTINUE 
C 
C     SET ASCII END-OF-STRING-BUFFER
C 
      ASTR(NWORDS+1) = 0
C 
      RETURN
      END 
      INTEGER FUNCTION CTOI(ASTR) 
  
CCC   CTOI - CONVERT CHARACTER BUFFER TO INTEGER. 
C 
C     CTOI CONVERTS THE NUMBER USING BASE 10 AS A DEFAULT.
C     A SUFFIX OF H WILL CONVERT USING BASE 16 AND A SUFFIX 
C     OF O WILL CONVERT USING BASE 8.  DEFAULT SUFFIX IS
C     D.
C 
*CALL KERMCOM 
      PARAMETER (DIG0=48, DIG7=55, DIG9=57, BIGA=65, BIGB=66, BIGD=68)
      PARAMETER (BIGF=70, BIGH=72, BIGO=79, LETA=97, LETB=98, LETD=100) 
      PARAMETER (LETF=102, LETH=104, LETO=111)
      INTEGER ASTR(*) 
  
      BASE = 0
      PTR = 0 
C 
C     FIND LAST VALID DIGIT 
C 
10    PTR = PTR + 1 
      IF (ASTR(PTR) .NE. 0) GO TO 10
      PTR = PTR - 1 
      IF (ASTR(PTR) .EQ. LETO .OR. ASTR(PTR) .EQ. BIGO .OR. 
     +    ASTR(PTR) .EQ. LETB .OR. ASTR(PTR) .EQ. BIGB .OR. 
     +    ASTR(PTR) .EQ. LETH .OR. ASTR(PTR) .EQ. BIGH) THEN
         EOD = PTR - 1
      ELSE
         EOD = PTR
         PTR = PTR + 1
      ENDIF 
C 
C     TRY TO FIGURE OUT THE BASE
C 
      IF (ASTR(PTR) .EQ. 0) THEN
         BASE = 10
      ELSE IF (ASTR(PTR) .EQ. LETO .OR. ASTR(PTR) .EQ. BIGO .OR.
     +         ASTR(PTR) .EQ. LETB .OR. ASTR(PTR) .EQ. BIGB) THEN 
         BASE = 8 
      ELSE IF (ASTR(PTR) .EQ. LETH .OR. ASTR(PTR) .EQ. BIGH) THEN 
         BASE = 16
      ENDIF 
C 
C     IF DIDN'T FIND A BASE 
C 
      IF (BASE .EQ. 0) THEN 
         CALL FPRINTF(STDOUT,'CTOI - INVALID BASE @C\N',ASTR(PTR),0,0,0)
         CTOI = 0 
         RETURN 
      ENDIF 
C 
C     ADD UP THE DIGITS 
C 
      TOTAL = 0 
      ISNEG = 1 
      DO 100 I = 1,EOD
         CH = ASTR(I) 
         IF (CH .EQ. MINUS) THEN
            ISNEG = -1
            GO TO 100 
         ENDIF
         IF (BASE .EQ. 10) THEN 
            IF (CH .LT. DIG0 .OR. CH .GT. DIG9) THEN
               CALL FPRINTF(STDOUT,'CTOI - INVALID DECIMAL DIGIT @C\N', 
     +                      CH,0,0,0) 
               CTOI = 0 
               RETURN 
            ELSE
               CH = CH - DIG0 
            ENDIF 
         ELSE IF (BASE .EQ. 8) THEN 
            IF (CH .LT. DIG0 .OR. CH .GT. DIG7) THEN
               CALL FPRINTF(STDOUT,'CTOI - INVALID OCTAL DIGIT @C\N', 
     +                      CH,0,0,0) 
               CTOI = 0 
               RETURN 
            ELSE
               CH = CH - DIG0 
            ENDIF 
         ELSE IF (BASE .EQ. 16) THEN
            IF (CH .GE. DIG0 .AND. CH .LE. DIG9) THEN 
               CH = CH - DIG0 
            ELSE IF (CH .GE. LETA .AND. CH .LE. LETF) THEN
               CH = 10 + CH - LETA
            ELSE IF (CH .GE. BIGA .AND. CH .LE. BIGF) THEN
               CH = 10 + CH - BIGA
            ELSE
               CALL FPRINTF(STDOUT,'CTOI - INVALID HEX DIGIT @C\N', 
     +                      CH,0,0,0) 
               CTOI = 0 
               RETURN 
            ENDIF 
         ENDIF
         TOTAL = TOTAL*BASE + CH
100   CONTINUE
      CTOI = TOTAL * ISNEG
      RETURN
      END 
      INTEGER FUNCTION ITOS(INT,STR,MINWID) 
  
CCC   ITOS - CONVERT AN INTEGER TO STRING FORMAT. 
C 
*CALL KERMCOM 
      INTEGER STR(*)
  
      WIDTH = 0 
      IF (INT .LT. 0) THEN
         WIDTH = 1
         STR(WIDTH) = ASC('-')
      ENDIF 
      VAL = IABS(INT) 
      ASCII0 = ASC('0') 
10    WIDTH = WIDTH + 1 
      STR(WIDTH) = MOD(VAL,10) + ASCII0 
      VAL = VAL / 10
      IF (VAL .NE. 0) GO TO 10
      STR(WIDTH+1) = 0
C 
C     NOW REVERSE THE DIGITS
C 
      IPTR = 1
      ENDPTR = WIDTH
      IF (STR(IPTR) .EQ. ASC('-')) IPTR = IPTR + 1
20    IF (IPTR .LT. ENDPTR) THEN
         TCH = STR(IPTR)
         STR(IPTR) = STR(ENDPTR)
         STR(ENDPTR) = TCH
         IPTR = IPTR + 1
         ENDPTR = ENDPTR - 1
         GO TO 20 
      ENDIF 
      ITOS = WIDTH
      RETURN
      END 
      SUBROUTINE GETEMSG(STRNG) 
  
CCC   GETEMSG - GET AN ERROR MESSAGE STRING FOR THE CURRENT ERROR.
C 
*CALL KERMCOM 
      INTEGER DIREC(8,2)
      INTEGER PACKNAM(9,0:6)
      DATA DIREC / 115, 101, 110, 100, 4*0, 
C                    S    E    N    D 
     +             114, 101,  99, 101, 105, 118, 101, 0 / 
C                    R    E    C    E    I    V    E
      DATA PACKNAM / 85,  78,  75,  78,  79,  87,  78, 2*0, 
C                     U    N    K    N    O    W    N 
     +               73, 110, 105, 116, 5*0,
C                     I    N    I    T
     +               70, 105, 108, 101, 110,  97, 109, 101, 0,
C                     F    I    L    E    N    A    M    E
     +               68,  97, 116,  97, 5*0,
C                     D    A    T    A
     +               69,  79,  70, 6*0, 
C                     E    O    F 
     +               66, 114, 101,  97, 107, 4*0, 
C                     B    R    E    A    K 
     +               83, 101, 114, 118, 101, 114, 3*0 / 
C                     S    E    R    V    E    R
      IF ((ABORTYP.AND.INITERR) .NE. 0) THEN
         PTYP = 1 
      ELSE IF ((ABORTYP.AND.FILERR) .NE. 0) THEN
         PTYP = 2 
      ELSE IF ((ABORTYP.AND.DATAERR) .NE. 0) THEN 
         PTYP = 3 
      ELSE IF ((ABORTYP.AND.EOFERR) .NE. 0) THEN
         PTYP = 4 
      ELSE IF ((ABORTYP.AND.BRKERR) .NE. 0) THEN
         PTYP = 5 
      ELSE IF ((ABORTYP.AND.SRVERR) .NE. 0) THEN
         PTYP = 6 
      ELSE
         PTYP = 0 
      ENDIF 
      DTYP = SHIFT(ABORTYP.AND.O"300",-6) 
      IF ((ABORTYP.AND.TOOMANY) .NE. 0) THEN
         CALL SPRINTF(STRNG,'^CANNOT @S @S PACKET',DIREC(1, 
     +      DTYP),PACKNAM(1,PTYP),0,0)
      ELSE IF ((ABORTYP.AND.INVALID) .NE. 0) THEN 
         CALL SPRINTF(STRNG,
     +  '^RECEIVED AN INVALID PACKET WHILE TRYING TO @S @S PACKET', 
     +  DIREC(1,DTYP),PACKNAM(1,PTYP),0,0)
      ELSE IF ((ABORTYP.AND.SEQERR) .NE. 0) THEN
         CALL SPRINTF(STRNG,
     +   '^PACKET SEQUENCE ERROR WHILE TRYING TO @S @S PACKET', 
     +   DIREC(1,DTYP),PACKNAM(1,PTYP),0,0) 
      ELSE IF ((ABORTYP.AND.LCLFILE) .NE. 0) THEN 
         CALL SPRINTF(STRNG,'^FILE IS ALREADY LOCAL',0,0,0,0) 
      ELSE IF ((ABORTYP.AND.NOTLCL) .NE. 0) THEN
         CALL SPRINTF(STRNG,'^FILE IS NOT LOCAL',0,0,0,0) 
      ELSE IF ((ABORTYP.AND.INVFN) .NE. 0) THEN 
         CALL SPRINTF(STRNG,'^INVALID FILENAME',0,0,0,0)
      ELSE IF ((ABORTYP.AND.SRVCMD) .NE. 0) THEN
         CALL SPRINTF(STRNG,'^UNIMPLEMENTED SERVER COMMAND',0,0,0,0)
      ENDIF 
      RETURN
      END 
      INTEGER FUNCTION CREAT(FN)
  
CCC   CREAT - OPEN A FILE FOR WRITING PACKET DATA TO. 
C 
C     CREAT WILL TRY TO CREATE A FILE TO WRITE TO.  IF IT 
C     ALREADY EXISTS, THEN IT WILL FAIL.
C 
*CALL KERMCOM 
      CHARACTER*10 FILENAM
C 
C     GET THE DPC VERSION OF THE FILENAME 
C 
      CALL AS2DPC(FN,FILENAM) 
      CALL FILCHK(FILENAM)
      CREAT = FOPEN(FILENAM,CREATE) 
      RETURN
      END 
      SUBROUTINE GETNOW(MM,DD,YY,HR,MIN,SEC)
  
CCC   GET THE CURRENT DATE AND TIME.
C 
*CALL KERMCOM 
      CHARACTER*10 DATE, TIME, STRING 
  
      STRING = DATE() 
      OFFSET = ICHAR('0') 
C$    IF (UT2D .EQ. 1)
      DD = (ICHAR(STRING(2:2))-OFFSET)*10 + ICHAR(STRING(3:3))-OFFSET 
      MM = -1 
      IF (STRING(5:7) .EQ. 'JAN') THEN
         MM = 1 
      ELSE IF (STRING(5:7) .EQ. 'FEB') THEN 
         MM = 2 
      ELSE IF (STRING(5:7) .EQ. 'MAR') THEN 
         MM = 3 
      ELSE IF (STRING(5:7) .EQ. 'APR') THEN 
         MM = 4 
      ELSE IF (STRING(5:7) .EQ. 'MAY') THEN 
         MM = 5 
      ELSE IF (STRING(5:7) .EQ. 'JUN') THEN 
         MM = 6 
      ELSE IF (STRING(5:7) .EQ. 'JUL') THEN 
         MM = 7 
      ELSE IF (STRING(5:7) .EQ. 'AUG') THEN 
         MM = 8 
      ELSE IF (STRING(5:7) .EQ. 'SEP') THEN 
         MM = 9 
      ELSE IF (STRING(5:7) .EQ. 'OCT') THEN 
         MM = 10
      ELSE IF (STRING(5:7) .EQ. 'NOV') THEN 
         MM = 11
      ELSE IF (STRING(5:7) .EQ. 'DEC') THEN 
         MM = 12
      ENDIF 
      YY = (ICHAR(STRING(9:9))-OFFSET)*10 + ICHAR(STRING(10:10))-OFFSET 
C$    ENDIF 
C$    IF (NOS .EQ. 1) 
      YY = (ICHAR(STRING(2:2))-OFFSET)*10 + ICHAR(STRING(3:3))-OFFSET 
      DD = (ICHAR(STRING(5:5))-OFFSET)*10 + ICHAR(STRING(6:6))-OFFSET 
      MM = (ICHAR(STRING(8:8))-OFFSET)*10 + ICHAR(STRING(9:9))-OFFSET 
C$    ENDIF 
C$    IF (NOSBE .EQ. 1) 
       DD = (ICHAR(STRING(5:5))-OFFSET)*10 + ICHAR(STRING(6:6))-OFFSET
       MM = (ICHAR(STRING(2:2))-OFFSET)*10 + ICHAR(STRING(3:3))-OFFSET
       YY = (ICHAR(STRING(8:8))-OFFSET)*10 + ICHAR(STRING(9:9))-OFFSET
C$    ENDIF 
      YY = YY + 1900
      STRING = TIME() 
      HR  = (ICHAR(STRING(2:2))-OFFSET)*10 + ICHAR(STRING(3:3))-OFFSET
      MIN = (ICHAR(STRING(5:5))-OFFSET)*10 + ICHAR(STRING(6:6))-OFFSET
      SEC = (ICHAR(STRING(8:8))-OFFSET)*10 + ICHAR(STRING(9:9))-OFFSET
      RETURN
      END 
      SUBROUTINE FILCHK(FN) 
  
CCC   FILCHK - CHECK AND FIX FILENAME VALIDITY. 
C 
C     CHECK VALIDITY OF FILENAME.  INVALID CHARACTERS ARE DROPPED 
C     AND THE FILENAME IS TRUNCATED AT 7 CHARACTERS.  IF THERE
C     IS STILL NOT A VALID FILENAME (ALL CHARACTERS WERE BAD) THEN
C     USE FILE KERMDAT. 
C 
*CALL KERMCOM 
      BOOLEAN CH
      CHARACTER *(*) FN 
      INTEGER PTR,LENGTH
C 
      PTR = 0 
      LENGTH = LEN(FN)
      DO 2 I=1,7
    1    PTR = PTR + 1
         IF (PTR .GT. LENGTH) GO TO 3 
         CH = ICHAR(FN(PTR:PTR))
         IF (CH .LT. 1 .OR. CH .GT. 36) GO TO 1 
         FN(I:I)=FN(PTR:PTR)
    2 CONTINUE
      I = 8 
C 
    3 IF (LENGTH .GT. 7) THEN 
         DO 4 J=I,LENGTH
            FN(J:J) = ' ' 
    4    CONTINUE 
      ENDIF 
C 
C     USE OUR MAGIC FILE IF NO VALID CHARACTERS IN THE FILE NAME. 
C     THIS CAN HAPPEN AS SOME MICROS ALLOW THINGS LIKE '&' FOR
C     A FILE NAME.  NOTE THAT NOS ALLOWS A DIGIT IN THE FIRST 
C     CHARACTER OF AN LFN WHILE SCOPE AND NOS/BE DO NOT.
C 
C$    IF(UT2D .EQ. 1 .OR. NOSBE .EQ. 1  .OR.  SCOPE .EQ. 1) 
      IF(ICHAR(FN(1:1)) .LT. 1  .OR.  ICHAR(FN(1:1)) .GT. 26) 
     +  FN = 'KERMDAT'
C$    ELSE
      IF(ICHAR(FN(1:1)) .LT. 1  .OR.  ICHAR(FN(1:1)) .GT. 36) 
     +  FN = 'KERMDAT'
C$    ENDIF 
      RETURN
      END 
      SUBROUTINE RDPARAM(PDATA) 
  
CCC   RDPARAM - GET THE PACKET PARAMETERS FROM THE OTHER KERMIT.
C 
*CALL KERMCOM 
      BOOLEAN PDATA(*)
      INTEGER PARAMS(11)
      EQUIVALENCE (PARAMS,SPKSIZ) 
C 
C     DEFINE CTL AND UNCHAR STATEMENT FUNCTIONS 
C 
      CTL(ASCCH) = ASCCH .XOR. O"100" 
      UNCHAR(ASCCH) = ASCCH - BLANK 
C 
C     CYCLE THROUGH THE LIST OF PARAMETERS UNTIL THE END-OF-LIST
C     IS FOUND (A 0 BYTE).
C 
      I = 1 
10    IF (PDATA(I) .NE. 0) THEN 
C 
C        IS IT THE PAD CHARACTER? 
C 
         IF (I .EQ. 4) THEN 
            PARAMS(I) = CTL(PDATA(I)) 
            IF (PARAMS(I) .EQ. 0) PARAMS(I) = NULL
C 
C        IS IT THE QUOTE CHARACTER? 
C 
         ELSE IF (I .EQ. 6) THEN
            PARAMS(I) = PDATA(I)
         ELSE 
            IF (UNCHAR(PDATA(I)) .NE. 0) THEN 
               PARAMS(I) = UNCHAR(PDATA(I)) 
            ENDIF 
         ENDIF
         I = I + 1
         GO TO 10 
      ENDIF 
      RETURN
      END 
      SUBROUTINE REMOVE(FN) 
  
CCC   REMOVE - REMOVE A FILE FROM THE LOCAL FILE LIST.
C 
*CALL KERMCOM 
      BOOLEAN FN(*) 
      CHARACTER*10 LFN
C 
C     QUIT IF NOTHING USEFUL IN THE FILE NAME ARRAY.
C 
      IF(FN(1) .EQ. 0) RETURN 
C 
C     CONVERT THE FILE NAME TO DISPLAY CODE.
C 
      CALL AS2DPC(FN,LFN) 
C 
C     GET RID OF THE FILE.
C 
      CALL RETFILE(LFN) 
      RETURN
      END 
      SUBROUTINE STRCPY(S1,S2)
  
CCC   STRCPY - COPY ONE ASCII STRING TO ANOTHER 
C 
*CALL KERMCOM 
      BOOLEAN S1(*),S2(*) 
  
      I1 = 1
10    S2(I1) = S1(I1) 
      IF (S1(I1) .NE. 0) THEN 
         I1 = I1 + 1
         GO TO 10 
      ENDIF 
      RETURN
      END 
      INTEGER FUNCTION SLEN(STR)
  
CCC   SLEN - RETURN THE LENGTH OF A ZERO TERMINATED ASCII STRING BUFFER.
C 
*CALL KERMCOM 
      BOOLEAN STR(*)
  
      I = 0 
10    IF (STR(I+1) .NE. 0) THEN 
         I = I + 1
         GO TO 10 
      ENDIF 
      SLEN = I
      RETURN
      END 
      INTEGER FUNCTION SNDPAR(PDATA)
  
CCC   SNDPAR - SET UP PARAMETERS TO SEND TO OTHER KERMIT. 
C 
*CALL KERMCOM 
      BOOLEAN PDATA(*)
C 
C     DEFINE CTL AND TOCHAR STATEMENT FUNCTIONS 
C 
      CTL(ASCCH) = ASCCH .XOR. O"100" 
      TOCHAR(ASCCH) = ASCCH + BLANK 
C 
C     SEND WHAT WE WANT 
C 
      PDATA(1) = TOCHAR(PACKSIZ)
      PDATA(2) = TOCHAR(TIMEOUT)
      PDATA(3) = TOCHAR(NPAD) 
      PDATA(4) = CTL(PADCH) 
      PDATA(5) = TOCHAR(EOLCH)
      PDATA(6) = QUOTECH
      PDATA(7) = 0
C 
C     RETURN LENGTH OF HOW MANY THINGS WE WANT TO SET 
C 
      SNDPAR = 6
C 
C     OTHER VALUES ARE SET BY DEFAULT TO NOT OPERATE
C 
      RETURN
      END 
      SUBROUTINE SLEEP(SECONDS) 
  
CC    SLEEP - USE PERIODIC RECALL TO DELAY THINGS.
C 
C     ENTRY   SECONDS = INTEGER NUMBER OF SECONDS TO SLEEP. 
C 
C     EXIT    INDICATED NUMBER OF SECONDS HAS ELAPSED.
C 
*CALL KERMCOM 
  
      DO 100 I=1,SECONDS
         CALL DELAY(1000) 
100   CONTINUE
      RETURN
      END 
      SUBROUTINE DELAY(MSEC)
  
CC    DELAY - DELAY FOR A FEW MILLISECONDS. 
C 
C     ENTRY   MSEC = DELAY TIME IN MILLISECONDS.
C 
C     EXIT    TIME HAS ELAPSED. 
C 
C     NOTES   WORKS FOR SCOPE, UT2D, AND NOS/BE SYSTEMS.  NOS USERS MUST
C             CHANGE THE COMPUTATION TO ACCOUNT FOR THE DIFFERENCE
C             IN DATA RETURNED BY RTIME MACRO.
C 
*CALL KERMCOM 
C 
C    USE REAL TIME CLOCK TO CONTROL DELAY PERIOD. 
C 
      CALL RTIME(RTCL)
      RTCL = AND(RTCL,COMPL(MASK(24)))
10    CALL RTIME(RTCL1) 
      RTCL1 = AND(RTCL1,COMPL(MASK(24)))
C 
C     CONVERT FROM SECONDS/4096 TO MILLISECONDS.
C 
      IF((RTCL1-RTCL)/4.096 .GT. MSEC) RETURN 
C 
C     SLEEP FOR 100 MILLISECONDS. 
C 
      CALL RECALL(0)
      GO TO 10
  
      END 
      SUBROUTINE ECHOPLX(ECMODE)
  
  
***   ECHOPLX - SET ECHOPLEX MODE FOR 2550 FRONT END. 
* 
*     DEPENDS ON U OF ARIZONA MODIFICATIONS TO CCI, PLUS A U OF 
*     ARIZONA PP ROUTINE 'UUI'.  THIS SUBROUTINE IS ONLY CALLED 
*     FROM STTY IF UARIZ IS DEFINED.
* 
*     ENTRY   ECMODE = 'ON' OR 'OFF' TO ENABLE OR DISABLE ECHOPLEX. 
* 
*     EXIT    UUI CALLED TO CHANGE ECHOPLEX MODE. 
  
  
*CALL KERMCOM 
  
C 
C     DON'T COMPILE IF NOT UNIVERSITY OF ARIZONA
C 
C$    IF (UARIZ .EQ. 1) 
      BOOLEAN ECHOFNC, ECHOOFF, ECHOON, UUIWD 
      CHARACTER*(3) ECMODE
      PARAMETER (ECHOFNC=O"10",ECHOOFF=0,ECHOON=1)
  
      IF(ECMODE .EQ. 'ON') THEN 
          UUIWD = OR(SHIFT(ECHOON,12),ECHOFNC)
      ELSEIF(ECMODE .EQ. 'OFF') THEN
          UUIWD = OR(SHIFT(ECHOOFF,12),ECHOFNC) 
      ELSE
          CALL REMARK(' KERMIT - INVALID ECHOPLEX OPTION.') 
          CALL ABTP("ND") 
      ENDIF 
      CALL MTR(L"UUI","RCL",LOCF(UUIWD))
  
*     NUDGE 2550 INTO PROCESSING THE RECONFIGURATION MESSAGE
*     SENT BY THE UUI CALL, SO ECHO GETS FULLY RESET, EVEN IF 
*     NEXT KERMIT OPERATION IS A READ, NOT A WRITE. 
  
      CALL PUTC(NULL,STDOUT)
      CALL FFLUSH(STDOUT) 
C$    ENDIF 
      RETURN
  
      END 
      INTEGER FUNCTION GETREC(FD,WSA,WSAL,EOFFLAG)
  
CC    GETREC - GET A RECORD FROM A FILE.
C 
C     NREAD = GETREC(FD,WSA,WSAL,EOFFLAG) 
C 
C     ENTRY   FD = FILE DESCRIPTOR. 
C             WSAL = LENGTH OF WSA. 
C 
C     EXIT    WSA CONTAINS DATA RECORD. 
C             NREAD = NUMBER OF WORDS ACTUALLY PLACED IN WSA
C             EOFFLAG = .TRUE. IF EOF HIT (IFF NREAD .EQ. 0). 
C 
C     NOTES   PERFORMS DISPLAY TO ASCII CONVERSION IF NEEDED. 
  
*CALL KERMCOM 
  
      PARAMETER (INTRCOM = 42, ASC128 = 22, ASC256 = 23)
      PARAMETER (FIRST = 1, IN = 2, OUT = 3, LIMIT = 4, INTWD = 5)
      BOOLEAN STATUS, WSA(WSAL) 
      LOGICAL EOFFLAG 
  
      EOFFLAG = .FALSE. 
C 
C     START READ IF POSSIBLE, AND DETERMINE DISK CHARACTER SET
C     IF NOT IN RAW DATA MODE.
C 
1     IF(.NOT. CTDEV(FD)  .AND.  AND(FETS(0,FD),O"1") .EQ. O"1") THEN 
          IF(FETS(IN,FD) .EQ. FETS(OUT,FD)  .AND. 
     +      AND(FETS(0,FD),O"20") .EQ. 0) THEN
              CALL READ(FETS(0,FD)) 
              IF(.NOT. RAWMODE) THEN
                  CSET = XSCS(FETS(0,FD)) 
                  IF(CSET .EQ. 0) GO TO 1 
                  IF (CSET .EQ. -1) THEN
                     DSKCSET = DSKNOS8
C$    IF (UT2D .EQ. 1)
C     MUST SET NOS BIT FOR SCREWY CODED READ ROUTINES 
                     FETS(FIRST,FD) = FETS(FIRST,FD)
     +                  .OR.SHIFT(1,NOSBIT) 
C$    ENDIF 
                  ELSEIF(CSET .EQ. -2) THEN 
                     DSKCSET = DSKUT8 
C$    IF (UT2D .EQ. 1)
C     MUST CLEAR NOS BIT FOR SCREWY CODED READ ROUTINES 
                     FETS(FIRST,FD) = AND(FETS(FIRST,FD), 
     +                  .NOT.SHIFT(1,NOSBIT)) 
C$    ENDIF 
                  ENDIF 
                  IF(CSET .LT. 0) THEN
C$    IF (UT2D .EQ. 1)
C     THESE ARE NEEDED FOR STRANGE CODED READ ROUTINES. 
                     FETS(FIRST,FD) = FETS(FIRST,FD).OR.SHIFT(1,ASCIIIO)
C$    ENDIF 
                  ELSE
                     DSKCSET = DSKDPC 
C$    IF (UT2D .EQ. 1)
                     FETS(FIRST,FD) = AND(FETS(FIRST,FD), 
     +                  .NOT.SHIFT(1,ASCIIIO))
C$    ENDIF 
                  ENDIF 
              ENDIF 
          ENDIF 
      ENDIF 
C 
C     PROCESS TERMINAL DEVICES. 
C 
      IF(CTDEV(FD)) THEN
C$    IF (UT2D .EQ. 1) THEN 
         FETS(FIRST,FD) = OR(FETS(FIRST,FD),SHIFT(1,ASCIIIO)) 
C$    ELSE
          FETS(FIRST,FD) = OR(FETS(FIRST,FD),SHIFT(1,INTRCOM))
          FETS(INTWD,FD) = SHIFT(1,ASC128)
          IF(BINMODE .OR. RAWMODE) FETS(INTWD,FD) = SHIFT(1,ASC256) 
C$    ENDIF 
          IF (RDELAY .GT. 0) CALL DELAY(RDELAY) 
          CALL READC(FETS(0,FD),WSA,WSAL,STATUS)
          IF(STATUS .EQ. 0) THEN
              NREAD = WSAL
          ELSEIF(STATUS .LT. 0) THEN
              NREAD = 0 
              EOFFLAG = .TRUE.
          ELSE
              NREAD = STATUS - LOCF(WSA)
              FETS(0,FD) = OR(AND(FETS(0,FD),SHIFT(MASK(44),2)),CIORD)
              IF(NREAD .LE. 0) GO TO 1
          ENDIF 
          GETREC = NREAD
          IF(NREAD .GT. 0) GETREC = FINDEOL(WSA,NREAD,.NOT. BINMODE)
      ELSE
C 
C     PROCESS MASS STORAGE (DISK) FILES.
C 
          IF(RAWMODE) THEN
              CALL READW(FETS(0,FD),WSA,WSAL,STATUS)
          ELSEIF((DSKCSET.AND.DSKASCI) .NE. 0) THEN 
              CALL READC(FETS(0,FD),WSA,WSAL,STATUS)
          ELSE
              CALL READC(FETS(0,FD),WSA(WSAL / 2 + 1),WSAL / 2, STATUS) 
              IF(STATUS .GE. 0) THEN
                  CALL EDL(WSA,WSA(WSAL / 2 + 1),WSAL / 2,STATUS) 
              ENDIF 
          ENDIF 
C 
C     PROCESS MASS STORAGE (DISK) FILE STATUS RETURN. 
C 
          IF(STATUS .EQ. 0) THEN
              GETREC = FINDEOL(WSA,WSAL,.NOT. RAWMODE)
          ELSEIF(STATUS .GT. 0) THEN
              GETREC = FINDEOL(WSA,STATUS - LOCF(WSA),.NOT. RAWMODE)
              FETS(0,FD) = OR(AND(FETS(0,FD),SHIFT(MASK(44),2)),CIORD)
              IF(GETREC .LE. 0) GO TO 1 
          ELSEIF(STATUS .EQ. -1) THEN 
              GETREC = 0
              FETS(0,FD) = OR(AND(FETS(0,FD),SHIFT(MASK(44),2)),CIORD)
C$    IF (UT2D .EQ. 1) THEN 
              EOFFLAG = .TRUE.
C$    ELSE
              GO TO 1 
C$    ENDIF 
          ELSE
              GETREC = 0
              EOFFLAG = .TRUE.
          ENDIF 
      ENDIF 
      RETURN
      END 
      INTEGER FUNCTION FINDEOL(WSA,WSAL,ADDNEL) 
  
CC    FINDEOL - FIND EOL BYTE IN WORKING BUFFER.
C 
C     LEN = FINDEOL(WSA,WSAL,ADDNEL)
C 
C     ENTRY   WSA = LINE IMAGE. 
C             WSAL = LENGTH OF WSA. 
C             ADDNEL = .TRUE. IF A NEL SHOULD BE STUFFED IN BUFFER. 
C 
C     EXIT    LEN = LENGTH OF DATA LINE IN WORDS. 
  
*CALL KERMCOM 
  
      BOOLEAN WSA(WSAL) 
      LOGICAL ADDNEL
C 
C     IF THE LINE LENGTH IS ZERO, RETURN ZERO LENGTH. 
C 
      IF(WSAL .LE. 0) THEN
          FINDEOL = 0 
          RETURN
      ENDIF 
C 
C     FIND EOL, AND STICK NEL IN IF NEEDED. 
C 
      DO 10 I = 1, WSAL 
          IF((AND(WSA(I),O"7777") .EQ. 0) .OR.
     +       (AND(WSA(I),O"7777") .EQ. NEL)) THEN 
            IF(ADDNEL .AND. (DSKCSET.NE.DSKUT8)) WSA(I) = OR(WSA(I),NEL)
            FINDEOL = I 
            RETURN
          ENDIF 
10    CONTINUE
      IF(ADDNEL) WSA(WSAL) = OR(AND(WSA(WSAL),MASK(48)),NEL)
      FINDEOL = WSAL
      RETURN
      END 
      SUBROUTINE EDL(ASCBUF,DPCBUF,DPCBUFL,STATUS)
  
CC    EDL - EXPAND DISPLAY CODE LINE. 
C 
C     CALL EDL(ASCBUF,DPCBUF,DPCBUFL,STATUS)
C 
C     ENTRY   DPCBUF = DISPLAY CODE LINE IMAGE. 
C             DPCBUFL = DIMENSIONED SIZE OF DPCBUF. 
C             STATUS = READC STATUS.
C 
C     EXIT    ASCBUF = ASCII LINE.
C             STATUS = LWA + 1 OF DATA CONVERTED, IFF STATUS WAS
C             NON-ZERO ON ENTRY TO EDL. 
C 
C     NOTES   EDL MUST NOT BE CALLED WITH NEGATIVE STATUS VALUES. 
  
*CALL KERMCOM 
  
      BOOLEAN ASCBUF(*), DPCBUF(DPCBUFL), DPCCH, STATUS, TEMPDPC
C 
C     DETERMINE NUMBER OF WORDS IN BUFFER (WORST CASE). 
C 
      WC = DPCBUFL
      IF(STATUS .GT. 0) WC = STATUS - LOCF(DPCBUF)
      IF(WC .LE. 0) THEN
          STATUS = LOCF(ASCBUF) 
          RETURN
      ENDIF 
C 
C     NOW SCAN FOR ZERO BYTE. 
C 
      DO 10 I = 1, WC 
          IF(AND(DPCBUF(I),O"7777") .EQ. 0) GO TO 1 
10    CONTINUE
C 
C     NO EOL WAS FOUND, SO WE FORCE ONE IN THE LAST WORD. 
C 
      I = WC
      DPCBUF(I) = AND(DPCBUF(I),MASK(48)) 
C 
C     AT THIS POINT, 'I' CONTAINS THE POSITION OF THE EOL WORD. 
C 
1     EOLWD = I 
      ASCBUF(1) = 0 
      IF(EOLWD .EQ. 1  .AND.  DPCBUF(EOLWD) .EQ. 0) RETURN
      IF(EOLWD .GT. 1  .AND.  DPCBUF(EOLWD) .EQ. 0  .AND. 
     +  AND(DPCBUF(EOLWD - 1),O"77") .EQ. 0) EOLWD = EOLWD - 1
C 
C     NOW WE CONVERT EVERYTHING UP TO THE EOL WORD, BUT NOT THE EOL WORD
C     ITSELF, AS WE DO NOT WANT TO 'CONVERT' THE LINE TERMINATOR. 
C 
      WC = 0
      IF(EOLWD .GT. 1) THEN 
          CALL XSXT(DPCBUF,EOLWD - 1,ASCBUF,UASCII) 
          WC = 2 * (EOLWD - 1)
      ENDIF 
C 
C     NOW CONVERT THE EOL WORD.  CODE CAN HANDLE OVERLAPPING BUFFERS. 
C 
      WC = WC + 1 
      TEMPDPC = DPCBUF(EOLWD) 
      ASCBUF(WC) = 0
      ASCBUF(WC + 1) = 0
      DO 20 I = 0, 9
          TEMPDPC = SHIFT(TEMPDPC,6)
          DPCCH = AND(TEMPDPC,O"77")
          TEMPDPC = AND(TEMPDPC,MASK(54)) 
          IF(TEMPDPC .EQ. 0  .AND. DPCCH .EQ. 0) THEN 
              IF(STATUS .GT. 0) STATUS = LOCF(ASCBUF(WC + I / 5)) + 1 
              RETURN
          ENDIF 
          ASCBUF(WC + I / 5) = OR(ASCBUF(WC + I / 5), 
     +      SHIFT(UASCII(DPCCH),60 - 12 * (MOD(I,5) + 1)))
20    CONTINUE
      IF(STATUS .GT. 0) STATUS = LOCF(ASCBUF(WC + 1)) + 1 
      RETURN
      END 
          IDENT  MAKEFET
          ENTRY  MAKEFET
          SST 
          SYSCOM B1 
 MAKEFET  TITLE  MAKEFET - MAKE A FILE ENVIRONMENT TABLE. 
          COMMENT MAKE A FILE ENVIRONMENT TABLE.
 MAKEFET  SPACE  4,10 
**        MAKEFET - MAKE A FILE ENVIRONMENT TABLE.
* 
*         CALL MAKEFET(LFN,FET,FETL,CIOBUF,CIOBUFL) 
* 
*         ENTRY  (LFN) = IS THE CHARACTER*7 FILE NAME.
*                (FET) = AN ARRAY TO RECEIVE THE FET. 
*                (FETL) = LENGTH OF FET IN WORDS (MINIMUM OF 5).
*                (CIOBUF) = AN ARRAY TO BE USED AS THE CIO BUFFER.
*                (CIOBUFL) = THE LENGTH OF CIOBUF.
* 
*         EXIT   FET BUILT. 
  
  
 MAKEFET  SUBR               ENTRY/EXIT 
          SB1    1           ALWAYS 
          SA2    A1+B1
          SB6    X2          (B6) = FET ADDRESS 
          SA2    A2+B1
          SA3    X2          (X3) = FET LENGTH
          SA2    A2+B1
          SX6    X2          (X6) = FWA OF CIO BUFFER 
          SA2    A2+B1
          SA2    X2          (X2) = BUFFER LENGTH 
          IX7    X6+X2       (X7) = LIMIT POINTER 
          SA6    B6+2        SET IN AND OUT 
          SA6    A6+B1
          SA7    A6+B1       SET LIMIT
          SX7    X3-5        (X7) = FET LENGTH - 5
          SB7    X7 
          LX7    18 
          BX6    X6+X7       ADD (FET LENGTH - 5) TO FIRST
          SA6    B6+B1       SET FIRST
          MX7    0
 MAKEFET1 GT     B7,B0,MAKEFET2  IF NO MORE WORDS TO SET
          SA7    A7+B1
          SB7    B7-B1
          EQ     MAKEFET1    LOOP TILL DONE 
  
 MAKEFET2 SB7    B1          LENGTH OF TRANSFER 
          RJ     =XMFS>      MOVE LFN INTO FET
          SA1    B6-B1
          RJ     =XBTZ>      CONVERT BLANKS TO 00B
          SX1    B1          ADD COMPLETE BIT TO LFN
          BX6    X6+X1
          SA6    A1 
          EQ     MAKEFETX    RETURN 
  
          END 
          IDENT  CFE
          ENTRY  CFE
          SST 
          SYSCOM B1 
 CFE      TITLE  CFE - CHECK FILES EXISTANCE. 
          COMMENT CHECK FILES EXISTANCE.
 CFE      SPACE  4,10 
**        CFE - CHECK FILES EXISTANCE.
* 
*         LOGICAL CFE, RESULT 
* 
*         RESULT =  CFE(LFN)
* 
*         ENTRY  (LFN) = IS THE CHARACTER*7 FILE NAME.
* 
*         EXIT   (RESULT) = .TRUE. IF FILE EXISTS.
*                (RESULT) = .FALSE. OTHERWISE.
  
  
 CFE      SUBR               ENTRY/EXIT 
          SB1    1           ALWAYS 
          SB6    CFEA 
          SB7    B1 
          RJ     =XMFS>      MOVE LFN INTO FILINFO BLOCK
          SA1    CFEA 
          RJ     =XBTZ>      CONVERT BLANKS TO 00B
          SX1    B1          SET COMPLETE 
          BX6    X6+X1
          SA6    A1 
          MX7    0           CLEAR REST OF BLOCK
          SA7    A6+B1
          SA7    A7+B1
          SA7    A7+B1
          SA7    A7+B1
          STATUS CFEA        CHECK ON FILE
          MX6    0           ASSUME NO FILE (.FALSE.) 
          MX7    11 
          LX7    12 
          SA1    CFEA 
          BX7    X7*X1       (X7) = 0 IF FILE DOESN'T EXIST 
          ZR     X7,CFEX     IF NO FILE 
          MX6    -1          SET FILE FOUND (.TRUE.)
          EQ     CFEX        RETURN 
  
CFEA      BSSZ   1           FAKE FET 
  
          END 
