C******************** START FILE URGET1.FOR ; GROUP UREAD5 *************
C
C--------------------------------------------------------------
C
C& URGET1   UREAD: READ ONE INPUT LINE FROM TTY OR FILE
C
C  IF(NLINDI) -- LINE COMES FROM INDIRECT INPUT FILE BUFFER
C     MAIN PROGRAM (CALLER OF UREAD3) IS BEING CONTROLLED AUTOMATICALLY
C     BY INPUT FROM A DISK FILE
C  IF NOT, LINE COMES FROM TERMINAL; PROGRAM IS BEING CONTROLLED
C     INTERACTIVELY
C
C  OUTPUT FLAGS
C   IER=1 IF ERROR ON READ FROM INPUT FILE
C   IEOF=1 IF EOF ON INPUT FILE
C  OTHERWISE, OR IF INPUT IS FROM TTY, BOTH FLAGS =0
C
C  LREADY FLAG IS SET (FLAG THAT UREAD SYSTEM IS READY TO ACCEPT
C  A COMMAND AND RETURN IT TO MAIN PROGRAM) IF TTY IS SOURCE OF INPUT
C
C  MOD DMC FEB 1989 -- ACCEPT COMMAND LEVEL INPUT FROM THE LINE
C  PRE-BUFFER (PREBUF) WHICH MAY BE FILLED FROM THE APPLICATION VIA
C  URDTTY CALLS
C
      SUBROUTINE URGET1(IER,IEOF)
C
      INCLUDE 'USERIO'
C
C-------------------------------------------------------------------
C  URFILE-- IND. INPUT FILE NAME (IF ANY)
C
      IER=0
      IEOF=0
C
C  MAINTAIN RECORD OF RECENT INPUT LINES TO DUMP IN CASE OF ERROR
      CALL UCBCLR
      IF(NLINDI) GO TO 210
c
c  read from terminal
c
      CALL UREADY(1)
      IERTRM=0
 9998 IF(IERTRM.GT.0) WRITE(LUNTRM,9999)
 9999 FORMAT(' TTY READ ERROR')
      IERTRM=IERTRM+1
C  STOP IF ERROR COUNT TOO LARGE
      IF(IERTRM.LT.10) GO TO 9996
      WRITE(LUNTRM,9997)
 9997 FORMAT(//' ? TTY ERROR COUNT .GT. 10  ==>  ABORT'//)
      CALL URDABO
 9996 CONTINUE
C
C  USE APPLICATION PRESET LINE BUFFER IF AVAILABLE, OR, READ
C  FROM TERMINAL
C
      IF(NPRBUF.GT.0) THEN
        CBUFF=PREBUF(LPRBUF)
        LPRBUF=LPRBUF+1
        NPRBUF=NPRBUF-1
      ELSE
        CALL URDSTR(CBUFF,IEOF,IERR)
        IF(IEOF.EQ.1) GO TO 9994
        IF(IERR.NE.0) GO TO 9998
CXX	    READ(LUNTIN(1),'(A)',ERR=9998,END=9994) CBUFF
      ENDIF
C
      IL=MAX0(NLUNIN,NLUNIO)
      NCMND(IL)=NCMND(IL)+1
      GO TO 219
C-------------
 9994 CONTINUE
      WRITE(LUNTRM,9995)
 9995 FORMAT(/' *** END OF FILE EXIT ***'/)
      CALL UEXITA(0)
      CALL URDABO
C
C-------------
 210  CONTINUE
c  read buffered from indirect input file
      call ufiget(URFILE,2,ier,ieof)
C-------------
 219  CONTINUE
C
C  RECORD INPUT LINE/TYPEAHEAD BUFFER IN 2NDRY STORAGE FOR
C  DEBUG IF ERROR OCCURS
      CALL UCBUFP
      RETURN
      END
C******************** END FILE URGET1.FOR ; GROUP UREAD5 ***************
