



      SUBROUTINE FLUSHAHEAD


















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'IRIGRA.INC'
      INTEGER       DEV, QTEST, QREAD, GVFLEN
      INTEGER*2     VALUE







      IF (GVFLEN(OPTINP).GT.0) THEN
         IF (GVFLEN(OPTINP).GT.2) THEN
            IF (WIFPAR(173).EQ.0) THEN
               CALL GVST6C ('?M0722',OPTINP,.TRUE.)
            END IF
         END IF
         CALL GVSCTB (OPTINP,LEN(OPTINP))
      END IF






      RETURN
      END
      SUBROUTINE GETWORD (WORD,IERR)




















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IERR, GVFLEN
      CHARACTER*(*) WORD







      IERR=0
      CALL GVSCTB (WORD,LEN(WORD))



      IF (GVFLEN(OPTINP).LE.0) CALL GETLINE5 (OPTINP,IERR)
      IF (GVFLEN(OPTINP).LE.0) THEN
         IERR=2
      ELSE



         CALL SPLITLINE (OPTINP,WORD,OPTINP)
         IF (GVFLEN(WORD).LE.0) IERR=2
      END IF
      IF (GVFLEN(WORD).EQ.1.AND.WORD(1:1).EQ.'0') IERR=1





      RETURN
      END   
      SUBROUTINE NEEDWORD (WORD,DEFAULT,IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IERR, GVFLEN
      CHARACTER*(*) WORD
      CHARACTER*(*) DEFAULT
      CHARACTER*80  LOCPROMPT







      CALL GVSSTX (LOCPROMPT,VPROMPT)



   10 CONTINUE
      CALL GVSSTX (VPROMPT,LOCPROMPT)
      CALL GETWORD (WORD,IERR)




      IF (IERR.EQ.2) THEN
         IF (GVFLEN(DEFAULT).GT.0) THEN
            CALL GVSSTX (WORD,DEFAULT)
            IERR=0
         ELSE
            CALL WIFBO0
            GOTO 10
         END IF
      END IF
      CALL WIFBO1 (0,' ')





      RETURN
      END   
      SUBROUTINE GETFULLLINE (FULINE,IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IERR, GVFLEN
      CHARACTER*(*) FULINE







      IERR=0
      CALL GVSCTB (FULINE,LEN(FULINE))



      IF (GVFLEN(OPTINP).EQ.0) THEN
         CALL GETLINE5 (OPTINP,IERR)
         IF (IERR.NE.0) THEN
            CALL GVSSTX (FULINE,OPTINP)
            CALL GVSCTB (OPTINP,LEN(OPTINP))
            GOTO 998
         END IF
      END IF
      IF (OPTINP(1:1).EQ.'"') THEN
         CALL GETWORD (FULINE,IERR)
      ELSE
         CALL GVSSTX (FULINE,OPTINP)
         CALL GVSCTB (OPTINP,LEN(OPTINP))
      END IF
      IF (FULINE(1:2).EQ.'0 ') IERR=1
      IF (GVFLEN(FULINE).EQ.0) IERR=2



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE NEEDFULLLINE (WORD,DEFAULT,IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IERR, GVFLEN
      CHARACTER*(*) WORD
      CHARACTER*(*) DEFAULT
      CHARACTER*80  LOCPROMPT







      CALL GVSSTX (LOCPROMPT,VPROMPT)



   10 CONTINUE
      CALL GVSSTX (VPROMPT,LOCPROMPT)
      CALL GETFULLLINE (WORD,IERR)




      IF (IERR.EQ.2) THEN
         IF (GVFLEN(DEFAULT).GT.0) THEN
            CALL GVSSTX (WORD,DEFAULT)
            IERR=0
         ELSE
            CALL WIFBO0
            GOTO 10
         END IF
      END IF
      CALL WIFBO1 (0,' ')





      RETURN
      END   
      SUBROUTINE NEEDF (N,DEFAULT,IERR)



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       I, IERR, GVFLFR, GVFLEN
      REAL          DEFAULT, N
      CHARACTER*80  WORD, BACKUP







   10 CONTINUE
      CALL GVSSTX (BACKUP,VPROMPT)



      CALL GETWORD (WORD,IERR)



      IF (IERR.EQ.1) THEN
         N=0
         GOTO 998
      END IF
      IF (IERR.EQ.2) THEN
         IF (DEFAULT.EQ.0) THEN
            CALL WIFBO0
            CALL GVSSTX (VPROMPT,BACKUP)
            GOTO 10
         ELSE
            N=DEFAULT
            IERR=0
            GOTO 998
         END IF
      END IF



      IERR=0



      I=GVFLFR(1,N,WORD(1:GVFLEN(WORD)))
      IF (I.NE.1) THEN
         CALL FLUSHAHEAD
         CALL GVSTTE ('?M0995')
         CALL GVSSTX (VPROMPT,BACKUP)
         GOTO 10
      END IF



  998 CONTINUE


      RETURN
      END
      SUBROUTINE NEEDI (N,DEFAULT,IERR)



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       DEFAULT, N, I, IERR, GVFLFI, GVFLEN
      CHARACTER*80  WORD, BACKUP















   10 CONTINUE
      CALL GVSSTX (BACKUP,VPROMPT)



      CALL GETWORD (WORD,IERR)











      IF (IERR.EQ.1) THEN
         N=0
         GOTO 998
      END IF
      IF (IERR.EQ.2) THEN
         IF (DEFAULT.EQ.0) THEN
            CALL WIFBO0
            CALL GVSSTX (VPROMPT,BACKUP)
            GOTO 10
         ELSE
            N=DEFAULT
            IERR=0
            GOTO 998
         END IF
      END IF



      IERR=0



      I=GVFLFI(1,N,WORD(1:GVFLEN(WORD)))





      IF (I.NE.1) THEN



         CALL FLUSHAHEAD



         CALL GVSTTE ('?M0995')




         CALL GVSSTX (VPROMPT,BACKUP)
         GOTO 10
      END IF



  998 CONTINUE


      RETURN
      END
      SUBROUTINE PEEKWORD (WORD,IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IERR, GVFLEN
      CHARACTER*(*) WORD
      CHARACTER*250 LOCLIN







      IERR=0
      CALL GVSCTB (WORD,LEN(WORD))



      IF (GVFLEN(OPTINP).LE.0) THEN
         IERR=1
         GOTO 998
      END IF
      CALL GVSSHL (OPTINP)



      CALL SPLITLINE (OPTINP,WORD,LOCLIN)



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE GETLINE5 (LINEIN,IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IERR, GVFLEN, LENLIN, IERRCNT, I, IARG, IARGC,
     +              IPOS, GVFPOS, JPOS, OLDIU54, LENPR1
      LOGICAL       GVFFOP, GVFIBN, ARGDON, INTERRUPTED
      CHARACTER*(*) LINEIN
      CHARACTER*6   CHUMAN
      CHARACTER*180 LOC1, LOC2
      SAVE          IERRCNT, ARGDON
      DATA IERRCNT  /0/
      DATA ARGDON   /.FALSE./







      CALL GVSCTB (LINEIN,LEN(LINEIN))
      IERR=0



    9 CONTINUE
      IF (GVFFOP(IU54)) THEN
         IF (.NOT.GVFIBN(IU54,61,65)) THEN
            CALL GVSTTI ('?M0172',IU54)
            IERR=1
            GOTO 997
         END IF



         IF (INTERRUPTED()) THEN
            CALL GVSCLF (IU54)
            IU54=MAX(IU54-1,61)
            WIFPAR(915)=0
            CALL GVSCLF (70)
            GOTO 9
         END IF



         CALL GVSFMT ('?FMT027A')
         READ (IU54,FMT,ERR=10,END=10) LINEIN
         CALL GVSSHL (LINEIN)



         IF (LINEIN(1:1).EQ.'#') GOTO 9
         IPOS=GVFPOS(LINEIN,' # ') 
         JPOS=GVFPOS(LINEIN,'"') 
         IF (IPOS.NE.0.AND.IPOS.GT.JPOS) CALL GVSCTB 
     +    (LINEIN(IPOS:LEN(LINEIN)),LEN(LINEIN)-IPOS+1)



         CALL GVSSTX (CHUMAN,LINEIN(1:6))
         CALL GVSCUC (CHUMAN)
         IF (CHUMAN.EQ.'@HUMAN') THEN
            IF (GVFLEN(LINEIN).GT.7) THEN
               VPROMPT=LINEIN(7:)
               CALL GVSCTB (LINEIN,80)
            END IF
            GOTO 15
         END IF












         IF (VPROMPT.NE.'WHAT IF>') THEN
            IF (WIFPAR(1064).EQ.0) CALL GVST6C ('?SCR_IN',VPROMPT,
     +       .TRUE.)
         END IF
         IF (WIFPAR(1064).EQ.0) CALL GVST6C ('?SCR_OUT',LINEIN,.TRUE.)
         GOTO 800



   10    CONTINUE
         CALL GVSCTB (LINEIN,80)



         IF (WIFPAR(915).NE.0) THEN






         ELSE



            CALL GVSTT6 ('?ENDSCR')
            CALL GVSCLF (IU54)
            OLDIU54=IU54
            IU54=MAX(IU54-1,61)




            IF (WIFPAR(946).EQ.OLDIU54) THEN
               WIFPAR(946)=-1
               IERR=1
               GOTO 997
            END IF
         END IF
         GOTO 9
      END IF



 15   CONTINUE



      CALL RESETINTERRUPT
      IERR=0

         IF (.NOT.ARGDON) THEN
            ARGDON=.TRUE.
            CALL GVSCTB (LOC1,180)
            CALL GVSCTB (LOC2,180)
            DO 6 IARG=1,IARGC()
               CALL GETARG (IARG,LOC2)
               IF (GVFPOS(LOC2,'STARTUP.SCR').NE.0) THEN
                  WIFPAR(75)=1
               END IF
               IF (GVFLEN(LOC2).GT.0) THEN
                  IF (GVFLEN(LOC1)+GVFLEN(LOC2)+1.GT.180)
     +             STOP 'Too many command line arguments'
                  CALL GVSSTX (LOC1(GVFLEN(LOC1)+2:180),LOC2)
                  CALL GVSRDB (LOC1)
                  CALL GVSSHL (LOC1)
               END IF
    6       CONTINUE
            IF (GVFLEN(LOC1).GT.0) THEN
               IF (GVFPOS(LOC1,'STARTUP.SCR').NE.0) WIFPAR(75)=1
               CALL GVSSTX (LINEIN,LOC1)
               CALL GVST6C ('?M4471',LINEIN(1:GVFLEN(LINEIN)),.TRUE.)
               GOTO 800
            END IF
         END IF



















      LENPR1=GVFLEN(VPROMPT)+1



         WRITE (6,'($,71A1)',ERR=998) (VPROMPT(I:I),I=1,LENPR1)

      CALL GVSCTB (VPROMPT,80)
      CALL GVSFMT ('?FMT027A')
      READ (5,FMT,END=100,ERR=999) LINEIN
      GOTO 800
  100 CONTINUE
      IERR=2
      IERRCNT=IERRCNT+1
      IF (IERRCNT.GE.25) STOP 'Infinite loop on terminal input'
      GOTO 997



  800 CONTINUE
      CALL GVSSHL (LINEIN)
      LENLIN=GVFLEN(LINEIN)
      IF (GVFFOP(7)) THEN 
         IF (LENLIN.GT.0) THEN
            CALL GVSFMT ('?FMT027A')
            WRITE (7,FMT,ERR=998) LINEIN(1:LENLIN)
         ELSE
            CALL GVSNLU (7,1)
         END IF
      END IF
      IF (LINEIN(1:2).EQ.'0'.AND.LENLIN.EQ.1) THEN
         IERR=1
      ELSE
         IERR=0
      END IF
      IERRCNT=0
      CALL GVSCTB (VPROMPT,80)
      GOTO 997



  999 CONTINUE
      CALL GVSTTE ('?ERTFIN')
      IERR=1
      GOTO 997



  998 CONTINUE
      CALL GVSEIW ('GETLINE5')



  997 CONTINUE


      RETURN
      END
      LOGICAL FUNCTION AHEAD()



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       GVFLEN







      AHEAD=(GVFLEN(OPTINP).GT.0)





      RETURN
      END
      SUBROUTINE POKEAHEAD (S)



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      CHARACTER*(*) S
      INTEGER       GVFLEN, LO, LS, I







      LO=GVFLEN(OPTINP)
      LS=GVFLEN(S)+1



      IF (LO+LS.GT.LEN(OPTINP)) THEN
         CALL FLUSHAHEAD
         LO=0
      END IF



      DO 10 I=LO,1,-1
         OPTINP(LS+I:LS+I)=OPTINP(I:I)
   10 CONTINUE
      DO 20 I=1,LS-1
         OPTINP(I:I)=S(I:I)
   20 CONTINUE
      OPTINP(LS:LS)=' '




 
      RETURN
      END
      SUBROUTINE SPLITLINE (LINEIN,LINE1,LINE2)

















      IMPLICIT      NONE
      INTEGER       I, GVFLEN, J, LEN1, LEN2, L
      CHARACTER*(*) LINEIN, LINE1, LINE2







      IF (LEN(LINEIN).LE.0) THEN
         CALL GVSTTB ('?M0700')
         CALL FLUSHAHEAD
         CALL GVSKIL
         CALL GVSCTB (LINE1,LEN(LINE1))
         GOTO 998
      END IF




      CALL GVSSHL (LINEIN)
      CALL GVSRDB (LINEIN)
      CALL GVSCTB (LINE1,LEN(LINE1))
      LEN1=LEN(LINE1)
      LEN2=LEN(LINE2)
      L=GVFLEN(LINEIN)
      I=0
      IF (LINEIN(1:1).EQ.'"') THEN



         I=1
         IF (LINEIN(2:2).EQ.'"') GOTO 11
   10    CONTINUE
         IF (I.GT.MIN(L-1,LEN1).OR.LINEIN(I+1:I+1).EQ.'"') GOTO 11
            LINE1(I:I)=LINEIN(I+1:I+1)
            I=I+1
            GOTO 10
   11    CONTINUE
         I=I+1



   20    CONTINUE
         I=I+1
         IF (I.LE.L.AND.LINEIN(I:I).EQ.' ') GOTO 20



         DO 30 J=1,MIN(L-I+1,LEN2)
            LINE2(J:J)=LINEIN(J+I-1:J+I-1)
   30    CONTINUE
      ELSE



         I=1
   40    CONTINUE
            LINE1(I:I)=LINEIN(I:I)
            I=I+1
         IF (I.LE.MIN(L,LEN1).AND.LINEIN(I:I).NE.' ') GOTO 40



   50    CONTINUE
         I=I+1
         IF (I.LE.L.AND.LINEIN(I:I).EQ.' ') GOTO 50



         DO 60 J=1,MIN(L-I+1,LEN2)
            LINE2(J:J)=LINEIN(J+I-1:J+I-1)
   60    CONTINUE
      END IF



      DO 70 J=MAX(1,MIN(L-I+1,LEN2)+1),LEN2
         LINE2(J:J)=' '
   70 CONTINUE



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE WIFBO0


















      IMPLICIT      NONE

         CALL SHOWTEXT ('?WIFBO0')

      CALL GVSNL6 (1)



  998 CONTINUE


      RETURN
      END
      SUBROUTINE WIFBO1 (TYPE,MESS)



















      IMPLICIT      NONE
      INTEGER       BO0TYPE, TYPE
      CHARACTER*80  BO0MESS
      CHARACTER*(*) MESS
      COMMON /BO0I/ BO0TYPE
      COMMON /BO0C/ BO0MESS







      BO0TYPE=TYPE
      BO0MESS=MESS





      RETURN
      END
