
** Version# 26.0001[3] - 04/21/2014 - 08:03pm - TSMITH - eclipse
*** V26.0001 Change - Custom Coding . - 04/21/2014 - TSMITH - eclipse

*** Subroutine - MENU.DRIVER
*-------------------------------------------------------------------------*
*** This is the program that handles the menus for Eclipse.
*-------------------------------------------------------------------------*
*** Note: Definitions for values in each line for MENUS
***       1 - eclipse screen desccription
***       2 - eclipse function
***       3 - eclipse screen hotkey position
***       4 - passer value to function
***       5 - auth key for product if entry is to be displayed only if
***           product at site
***       6 - solar menu description override
***       7 - solar menu hotkey override
*-------------------------------------------------------------------------*
          GET(ARG.,1) MOPTION     ;* Menu ID to display
          GET(ARG.,2) REFRESH     ;* Refresh menu

          SET.BEEP

          MENUS    = MENU.STACK<TCL.LEVEL+1>
          MEN.DATA = RAISE(RAISE(MEN<1,4>))

          BEGIN CASE
          CASE MOPTION = 'MAIN'
             MENU.STACK<TCL.LEVEL+1>=''
             MAIN.MENU
             MOPTION = ''
             MENUS   = MENU.STACK<TCL.LEVEL+1>
             MENU.ID = '*MAIN*'
             IF DCOUNT(MAIN.MEN,AM)=1 THEN MOPTION=1; GOTO GOTMOPT
          CASE MOPTION#'' AND MOPTION MATCHES "0N"
             GOSUB MOPT
          CASE MOPTION#''
             MENU.ID  = MOPTION
             GET.ACTIVE.DATA 'MENUS',MENU.ID,DATA.REC
             MEN      = DATA.REC<4>:AM:RAISE(DATA.REC<3>)
             MEN.DATA = RAISE(RAISE(MEN<1,4>))
             MOPTION  = ''
          END CASE
*------------------------------------------------------------------------*
OPT:      ***
          IF RELOG.NOW AND TCL.LEVEL=0 THEN
             CHAIN 'RELOG'
          END
          RELOG.NOW = NO

          IF TTY.DATA<3> AND TCL.LEVEL=0 THEN
             STARTTIME=DATE()*86400+INT(TIME())
          END

          INSIDE.ROE$ = ''
          IF TTY.DATA<6>='R' THEN
             PRINT @(0,0):
          END

          MOPTION = MENU.ID
          MENU.SELECT 0,0,1,MOPTION
          IF TTY.DATA<3> AND TCL.LEVEL=0 THEN
             SELTIME  =DATE()*86400+INT(TIME())
             READV RELOG.SECS FROM CTRLFILE,'RELOG.SECS',1 ELSE
                RELOG.SECS = 10
             END
             IF SELTIME-STARTTIME > RELOG.SECS THEN
                CHAIN 'RELOG'
             END
          END

          IF USER.ID AND LASTKEY=1 AND OPTION>140 AND OPTION<152 THEN
             * Code to fix bug in term < 3.17 (CTRL+F1 was not accessable)
             TEST.ETERM.VERSION ETERM.OK,'3.17'
             IF ETERM.OK THEN
                FKEY = OPTION-139
             END ELSE
                FKEY = OPTION-140
             END
             FKEYS.CTRL FKEY
             GOTO OPT
          END

          IF USER.ID AND LASTKEY>140 AND LASTKEY<153 THEN
             FKEY = LASTKEY - 140
             FKEYS.SHIFT FKEY
             GOTO OPT
          END

GOTMOPT:  ***
          IF MOPTION OR (DCOUNT(MENUS,VM)<2 AND OPTION) THEN
             IF MOPTION < 1 THEN MOPTION = OPTION
             IF MOPTION > 8 THEN PRINT BELL:; GOTO OPT
             GOSUB MOPT
             IF DCOUNT(MEN.DATA,AM)=1 THEN OPTION=1 ELSE GOTO OPT
          END

GOTOPT:   ***
          IF OPTION = 0 THEN
             IF TCL.LEVEL > 0 THEN GOTO ENDLEVEL
             STACK.COUNT = DCOUNT(MENUS,VM)
             IF STACK.COUNT > 1 THEN GOSUB BACKMEN
             GOTO OPT
          END

          IF OPTION > 0 THEN
             COMMAND = TRIM(MEN.DATA<OPTION,2>)
             PASSER  = MEN.DATA<OPTION,4>

             * Update dynamic PASSER variables
             GOSUB PASSVARS

             IF COMMAND = 'RELOG' THEN
                RELOG.NOW=1
                GOTO OPT
             END

             IF COMMAND = 'GOTO.TCL' THEN
                IF TCL.LEVEL > 0 THEN
                   WINDOW ,,60,7,4
                   PRINT @(3,2):"You are at TCL Level ":TCL.LEVEL
                   PRINT @(3,3):"Please finish lower levels before exiting."
                   PRINT @(3,5):"Press enter to continue:"
IN$$1:             INP ANS,27,5,1
                   WINDOW.CLOSE
                   GOTO OPT
                END ELSE
                   IF ECLIPSE.TRACKER$ = 'NO-PGMG' THEN
                      WINDOW ,,60,6,4
                      PRINT @(3,2):"Going to TCL in a no-programming session is prohibited."
                      PRINT @(3,4):"Press enter to continue:"
IN$$2:                INP ANS,27,4,1
                      WINDOW.CLOSE
                      GOTO OPT
                   END ELSE
                      NEW.SCREEN ''
                      PRINT CHAR(27):'^T';*Put workstation in terminal mode
                      STOP
                   END
                END
             END

             IF COMMAND[1,4]='MENU' THEN
                MENU.ID = COMMAND[6,99]
                IF MENU.ID[1,2]='&&' THEN
                   MENU.ID = '&':USER.ID:MENU.ID[3,99]:'&'
                END
                GOSUB NEWMEN
                IF DCOUNT(MEN.DATA,AM)=1 THEN OPTION=1; GOTO GOTOPT
                GOTO OPT
             END

             IF COMMAND[1,5]='EXEC ' THEN
                WINDOW
                PRINT HOLDOFF$
                PRINT COMMAND
                EXECUTE COMMAND[6,999]
                WINDOW.CLOSE
                GOTO OPT
             END

             IF COMMAND[1,4]='REP-' OR COMMAND[1,5]='FORM-' OR COMMAND[1,7]='EGRAPH-' OR COMMAND[1,5]='LREP-' OR COMMAND[1,5]='LOAD-' OR COMMAND[1,3]='GL-' THEN
                PREV.WINDOW.LEVEL = WINDOW.LEVEL
                LFILESUB = ''
                LRETSUB  = ''
                NEXTMENU.= ''

                BEGIN CASE
                CASE COMMAND[1,4]='REP-'
                   REP.DVR.WRITER COMMAND[5,999]
                CASE COMMAND[1,5]='LREP-'
                   REP.DVR.WRITER2 COMMAND[6,999]
                CASE COMMAND[1,5]='LOAD-'
                   UPD.DVR.LOADIN COMMAND[6,999]
                CASE COMMAND[1,5]='FORM-'
                   FORM.RUN COMMAND[6,999], PASSER
                CASE COMMAND[1,7]='EGRAPH-'
                   EGRAPH.RUN COMMAND[8,999]
                CASE COMMAND[1,3]='GL-'
                   GL.DVR.REPORT COMMAND[4,999]
                END CASE

                FOR X=WINDOW.LEVEL TO PREV.WINDOW.LEVEL+1 STEP -1
                   WINDOW.CLOSE
                NEXT X

                IF TCL.LEVEL > 0 THEN GOTO ENDLEVEL
                CHAIN 'MENU.DRIVER ':MENU.ID:' 0'
             END

             IF COMMAND#'' THEN
                READV TEST FROM MDFILE,COMMAND,1 THEN
                   PREV.WINDOW.LEVEL = WINDOW.LEVEL
                   LFILESUB = ''
                   LRETSUB  = ''
                   NEXTMENU.=''
                   CALL @COMMAND (PASSER)

                   FOR X=WINDOW.LEVEL TO PREV.WINDOW.LEVEL+1 STEP -1
                      WINDOW.CLOSE
                   NEXT X

                   IF TCL.LEVEL > 0 THEN GOTO ENDLEVEL
                   CHAIN 'MENU.DRIVER ':MENU.ID:' 0'
                END
             END

             IF DCOUNT(MEN.DATA,AM)=1 THEN OPTION=0; GOTO GOTOPT
          END
          GOTO OPT
*------------------------------------------------------------------------*
MOPT:     ***

          MAINN = DCOUNT(MAIN.MEN,AM)
          MMO = MAINMEN.OFF<TCL.LEVEL+1>
          IF MAINN > 8 AND MOPTION = 8 THEN
             MMO += 1
             IF MMO*7 >= MAINN THEN MMO = 0
             MAINMEN.OFF<TCL.LEVEL+1> = MMO
             GOSUB CLOSE.ALL
             MAIN.MENU.BAR MENUS

             * Set back to the main menu so we know where we are
             MEN.DATA = MAIN.MEN
          END ELSE
             IF REFRESH THEN
                MAIN.MENU.BAR MENUS
                REFRESH = NO
             END
             IF MAIN.MEN<MOPTION+MMO*7,2>[1,4]='MENU' THEN
                MENU.ID = MAIN.MEN<MOPTION+MMO*7,2>[6,99]
                IF MENU.ID[1,2]='&&' THEN MENU.ID = '&':USER.ID:MENU.ID[3,99]:'&'
                GOSUB CLOSE.ALL
                OPTION = MOPTION
                GOSUB NEWMEN
             END
          END

          RETURN
*------------------------------------------------------------------------*
BACKMEN:  ***

          STACK.COUNT = DCOUNT(MENUS,VM)
          IF STACK.COUNT > 1 THEN
             WINDOW.CLOSE
             MENUS       = DELETE(MENUS,1,STACK.COUNT)
             MENU.STACK<TCL.LEVEL+1> = MENUS
             STACK.COUNT = STACK.COUNT-1
             MENU.ID     = MENUS<1,STACK.COUNT,1>
             GET.ACTIVE.DATA 'MENUS',MENU.ID,DATA.REC
             MEN         = DATA.REC<4>:AM:RAISE(DATA.REC<3>)
             MEN.DATA    = RAISE(RAISE(MEN<1,4>))
          END

          RETURN
*------------------------------------------------------------------------*
NEWMEN:   ***

          GET.ACTIVE.DATA 'MENUS',MENU.ID,DATA.REC,FOUND
          IF FOUND THEN
             MEN      = DATA.REC<4>:AM:RAISE(DATA.REC<3>)
             MENU.SUB MENU.ID
             MENUS    = MENU.STACK<TCL.LEVEL+1>
             MEN.DATA = RAISE(RAISE(MEN<1,4>))
          END

          RETURN
*-------------------------------------------------------------------------*
PASSVARS: *** This will change dynamic PASSER (MEN.DATA<OPTION,4>)
          *** variables such as $USER.ID$ and $DATE$ to thier actual
          *** value.  The contents of the variable PASSER will be changed.

          BEGIN CASE
          CASE TRIM(PASSER) = '$USER.ID$'
             PASSER = USER.ID
          CASE TRIM(PASSER) = '$DATE$'
             PASSER = DATE()
          CASE TRIM(PASSER) = '$PIPE.LINE$'
             PASSER = USER.ID:'~':OCONV(DATE(),'D2-')
          END CASE

          RETURN
*------------------------------------------------------------------------*
ENDLEVEL: *** end all open menus
          GOSUB CLOSE.ALL
          STOP
*-------------------------------------------------------------------------*
CLOSE.ALL: *** close all menus

          STACK.COUNT = DCOUNT(MENUS,VM)
          FOR LEVEL = STACK.COUNT TO 2 STEP - 1
             WINDOW.CLOSE
             MENUS = DELETE(MENUS,1,LEVEL)
             MENU.STACK<TCL.LEVEL+1> = MENUS
          NEXT LEVEL
          STACK.COUNT = 1

          RETURN
!TSMITH~04/21/14~20:03
