#%TITLE% BLMENU.MAC
#%NAME%
# Macros to easily prepare a menu to access
# SPEC subsystems functionalities on a beamline.
#
#%CATEGORY% tools
#%SEARCH% blmenuadd
#
#%DESCRIPTION%
# This macro set allows you:
# %UL%
# %LI% To change the state on a subsystem chosen from a list (main menu)
# %LI% To call a macro to see definitions, state or other interesting
# functionality on a subsystem chosen from a list (extra menu)
# %XUL%
#
# To get this functionality the macro has to be adapted to your beamline.
# You or your spec administrator must:
#%BR%%BR%
#
# %DL%
# %DD%- Write a macro function like for instance %B%mcabody(mode)%B%
# that accept a mode (0,1,2). Mode 0 should return a string with
# the status of the system that will be shown in blmenu. Mode 1
# would do the necessary to change the state of the system. Mode 2
# may call any macro to access other functionality in the system
# %DD%- A call to %B%blmenuadd%B% will add a line to blmenu. blmenuadd
# defines the necessary labels and macro name
# %XDL%
#
#%BR% %BR%
# The user will have to call a single macro \"blmenu\" and choose the
# subsystem from the list to change the state. Or select the option \"e\"
# to get a second menu with extra functionality
#
#%EXAMPLE%
#
# %DL%
# %DT% blmenu %DD% Starts the program
# %DT% blmenuadd("MCA","MCA setup","mcabody","mca")
# %DD% Will add a line to blmenu with the string \"MCA\" for main menu
# and \"MCA setup\" for extra menu. The macro that will be called in
# all cases is \"mcabody\" (with mode = 1 from main menu and mode=2
# from extra menu) and the key for handling definitions is \"mca\".
#
# %DT% blmenuadd("Keithley 2001","NONE","k2001body","k2001",0x02)
# %DD% Same as before but includes as well the flag \"0x02\". As result the
# line will be added if and only if %B%k2001%B% is defined as a counter in config.
# %XDL%
# See \"help funcs\" and look in the %B%cdef%B% paragraph for the meaning
# of other possible flags.
#
#%UU% ( label, extra-label, macro, key [,flag] )
#%MDESC%
# Add lines to blmenu. This macro should be called from a setup
# file. Lines will be deleted automatically when taken out from
# setup
global BL_PHASE
global BL_MAIN BL_SHOWEX BL_EXTRA
BL_MAIN=0
BL_SHOWEX=1
BL_EXTRA=2
def blmenuadd(label,elabel,macro,key,flag) '{
local nok_flag
nok_flag=0
#
# Checking
# - that there is a key present
# - that the macro exists
#
if (whatis("key")&0x8000000) {
p "No key present in blmenuadd"
nok_flag=1
}
if ((whatis(macro)) == 0) {
printf("Macro \"%s\" is not a macro name (blmenuadd)\n",macro)
nok_flag=1
}
if (!nok_flag) {
cdef("blmenubody",sprintf("blmenuoption \"%s\" \"%s\" %s\n",label,elabel,macro),key,flag)
setup_tail("blmenu",key)
}
}'
#%IU%
#%MDESC%
def blmenuunsetup '{
cdef("blmenubody","","$1","delete")
}'
#%UU%
#%MDESC%
# Will start the \"blmenu\" program
def blmenu '
blmenuhead
blmenubody
blmenutail
'
#%IU%
#%MDESC%
# This is the title for blmenu. Do not need any change
#
def blmenuhead '
#
# the bracket is closed in blmenutail
for (;;) {
local option ite yes_e state
ite=0
clscreen()
if (BL_PHASE==BL_SHOWEX || BL_PHASE==BL_EXTRA)
prtitle(SPECBL,"Instrument Menu (EXTRA)")
else
prtitle(SPECBL,"Instrument Menu")
'
#%IU%
#%MDESC%
#
def blmenuoption '
if (BL_PHASE==BL_EXTRA || BL_PHASE == BL_SHOWEX) {
if ("$2" != "") {
ite++
}
} else {
ite++
}
if (option == ite) {
if (BL_PHASE==BL_EXTRA) {
clscreen()
$3(2)
input("\n\nPress return to continue.")
state = $3(0)
option = -1
continue
}
if (BL_PHASE==BL_MAIN) {
state = $3(1)
}
}
else state = $3(0)
if (BL_PHASE==BL_SHOWEX || BL_PHASE==BL_EXTRA) {
if ("$2" != "") {
state=""
proption "$2" ite state
}
} else {
proption "$1" ite state
}
'
#%IU%
#%MDESC%
#
def blmenutail '
if ( BL_PHASE != BL_MAIN) {
BL_PHASE = BL_EXTRA
option = getval("\n\tEnter option number or 0 to return to main",0)
if (option < 1 || option > ite ) { BL_PHASE = BL_MAIN }
} else {
option = getval("\n\tEnter number to change, e for extra, or 0 to exit",0)
yes_e = index(option,"e")
if (yes_e) {
BL_PHASE = BL_SHOWEX
} else {
if (option < 1 || option > ite ) break
}
}
#
# This close the bracket opened in blmenuhead
}
'
#%IU%
#%MDESC%
# Prints the title on the menu.
def prtitle(bl,title) '{
printf("\t\t")
tty_cntl("mr"); tty_cntl("md"); printf(" %s - %s ",bl,title); tty_cntl("me")
printf("\n\n")
}'
#%IU%
#%MDESC%
# Prints one option line
def proption '{
tty_cntl("md"); printf("%02d",$2); tty_cntl("me")
printf(" %26s ","$1")
tty_cntl("md"); printf("%s",$3); tty_cntl("me")
printf(" \n")
}'
#%MACROS%
#%IMACROS%
#%AUTHOR%
# BLMENU.MAC - ICNTL - V.Rey 15/10/96.
#%TOC%
|