
      SUBROUTINE MENU1( ROW, STRING, POSSIBLEVALUES, ITEMSELECTED,
     1 SELECTION, ABORT )

C--
C Similar to LOTUS menu
C--

C     COMMON DATA STORES
C     ------------------

      CHARACTER*80 BUFFER


C     PARAMETERS
C     ----------

      CHARACTER STRING*(*), POSSIBLEVALUES*(*)
      INTEGER*2 ROW, ITEMSELECTED, SELECTION
      LOGICAL*1 ABORT


C     LOCAL DATA ELEMENTS
C     -------------------

      INTEGER*2 STATE, CHR, LEN,
     1 R, C, LASTITEM, ESC, F1, ATTR,
     1 LEFT, RIGHT, RETURN,
     1 I, NITEMS, STARTCOL(20), ENDCOL(20), NumOfPossibleValues
      CHARACTER*1 SINGLECHAR


C     FUNCTIONS
C     ---------

      INTEGER*2 LENGTH
      LOGICAL*1 ECHO


      DATA LEFT /130/ , RIGHT /131/ , RETURN /13/,
     1 ESC /27/, F1 /141/
C<PAGE>

      CALL GETATTRIBUTE( ATTR )

      ABORT = .FALSE.

      IF( ECHO(0) ) CALL TTYSET

      NUMOFPOSSIBLEVALUES = LENGTH( POSSIBLEVALUES )

      LEN = LENGTH( STRING )

      CALL DSPATTRIBUTE(0)
      CALL ERASEREGION( ROW, 1, ROW, 80 )


      CHR = 0
      NITEMS = 0
      STATE = 1
      DO 100 I = 1 , LEN
         CHR = ICHAR( STRING(I:I) )
         IF( STATE .EQ. 1 ) THEN
           IF( CHR .NE. 32 ) THEN
             IF( CHR .EQ. 95 ) CHR = 32
             BUFFER(I:I) = CHAR( CHR )
             NITEMS = NITEMS + 1
             STARTCOL(NITEMS) = I
             STATE = 2
           ELSE
             BUFFER(I:I) = ' '
           END IF
         ELSE IF( STATE .EQ. 2 ) THEN
           IF( CHR .EQ. 32 ) THEN
             ENDCOL(NITEMS) = I - 1
             STATE = 1
             BUFFER(I:I) = ' '
           ELSE
             IF( CHR .EQ. 95 ) CHR = 32
             BUFFER(I:I) = CHAR( CHR )
           END IF
         END IF
100   CONTINUE

      ENDCOL(NITEMS) = LEN

      IF( ITEMSELECTED .LT. 1 .OR. ITEMSELECTED .GT. NITEMS ) THEN
        ITEMSELECTED = 1
      END IF
      LASTITEM = ITEMSELECTED

C--
C Output the menu line
C--
      IF( LEN .GT. 0 ) THEN
	CALL DSPATTRIBUTE( ATTR )
        CALL OUTSTRING( BUFFER(1:LEN) )
      END IF

C--
C Do until SELECTION is a possible value, a left or right arrow, or a <CR>
C--
200   CONTINUE

      CALL DSPMENUITEM( BUFFER, LEN, ROW, ITEMSELECTED,
     1 LASTITEM, NITEMS, STARTCOL, ENDCOL, ATTR )

      LASTITEM = ITEMSELECTED

      R = ROW
      C = STARTCOL( ITEMSELECTED )
      CALL CSRPOS( R, C )
      CALL FPGetChar( SELECTION )

      IF( SELECTION .EQ. ESC .OR. SELECTION .EQ. F1 ) THEN
        ABORT = .TRUE.
        GOTO 400

      ELSE IF( SELECTION .EQ. RIGHT ) THEN
        ITEMSELECTED = ITEMSELECTED+1
        IF( ITEMSELECTED .GT. NITEMS ) ITEMSELECTED = 1
        GOTO 200

      ELSE IF( SELECTION .EQ. LEFT ) THEN
        ITEMSELECTED = ITEMSELECTED-1
        IF( ITEMSELECTED .LT. 1 ) ITEMSELECTED = NITEMS
        GOTO 200

      ELSE IF( SELECTION .EQ. RETURN ) THEN
        SELECTION = ICHAR( POSSIBLEVALUES(ITEMSELECTED:ITEMSELECTED) )
        GOTO 400

      END IF

      SINGLECHAR = CHAR( SELECTION )
      CALL CVTTOUPCASE( SINGLECHAR )
      SELECTION = ICHAR( SINGLECHAR )

      DO 300 I = 1 , NUMOFPOSSIBLEVALUES
         IF( SELECTION .EQ. ICHAR( POSSIBLEVALUES(I:I) ) ) THEN
	   ITEMSELECTED = I
           GOTO 400
         END IF
300   CONTINUE
      CALL BEEP
      GOTO 200

400   CONTINUE

      CALL DSPATTRIBUTE(0)
      CALL ERASEREGION( ROW, 1, ROW, 80 )

      IF( ECHO(0) ) CALL TTYRST

      CALL DSPATTRIBUTE( ATTR )

      RETURN
      END


      SUBROUTINE DSPMENUITEM( BUFFER, LEN, ROW, ITEM, LASTITEM,
     1 NITEMS, STARTCOL, ENDCOL, ATTR )

      CHARACTER*(*) BUFFER
      INTEGER*2 LEN, ROW, NITEMS, ITEM, STARTCOL(NITEMS), ENDCOL(NITEMS)
      INTEGER*2 LASTITEM, ATTR

      IF( LASTITEM .NE. ITEM ) THEN
        CALL CSRPOS( ROW, STARTCOL(LASTITEM) )
        CALL DSPATTRIBUTE( ATTR )
        CALL OUTSTRING( BUFFER(STARTCOL(LASTITEM):ENDCOL(LASTITEM)) )
      END IF

      CALL CSRPOS( ROW, STARTCOL(ITEM) )
      CALL DSPATTRIBUTE( ATTR+1 )
      CALL OUTSTRING( BUFFER(STARTCOL(ITEM):ENDCOL(ITEM)) )

      RETURN
      END

