esrf

Beamline Instrument Software Support
SPEC Macro documentation: [ Macro Index | BCU Home ]

#%TITLE% HELP.MAC
#%NAME%
# Macros to handle help in SPEC
#%SETUP%
# Just charge the macros
#%END%

#%UU%
#%MDESC%
# Shortcut to help. It uses the same parameters.   
def h 'help'

#%UU% [macro_name] or [local [macro_set_file]]
#%MDESC%
#%PRE%
# It has three different ways of operation
#%B%help%B% %B%macro_name%B%
# Finds out in which file macro_name was defined
# and displays the associated help
#%B%help%B%
# Displays the options of the internal help of SPEC
#%B%help%B% %B%local%B% %B%[macro_set_file]%B%
# Displays files containing macros, giving the option
# to select help on one them or looks directly into
# the macro_set_file for help
#%PRE%
def help '
    global H_MACFILE
    if ($# == 0) {
		local t
		printf("This command accepts three different formats\n")
		printf("1 - help\n")
		printf("    Displays these messages and offers internal SPEC help\n")	
        printf("2 - help local [macro_set_file]\n")
        printf("    Displays the help associated to the specied file or\n")
        printf("    offers a menu of possible macro_sets\n")
        printf("3 - help macro_name\n")
        printf("    Finds out in which file macro_name was defined and\n")
        printf("    displays the associated help (if  any!).  You  can\n")
        printf("    obtain the list of available macros typing lsdef\n")
        t=input("Press enter to continue")         
		t="help"
		gethelp(t)
		while(1) {
			if((t=input("\nSubject?  "))== "") break
			gethelp(t)
		}
#		help_help "help"
		exit
    }
    if ("$1" == "local") {
        if ($# > 1) {
    	    unix(sprintf("machelp %s\n","$2")) 	
        }else{
            unix("machelp")
        }
    }else{
    	help_help "$1"
    }
'

#%IU%()
def h_getfile() ' {
    local inputline idx
    inputline [0] = inputline [0]
    if(getline("/tmp/piped","open") != 0) {
        printf("Error opening the file %s\n",chbuffer)
        return(-1)
    }
    #reads the 1st two lines of the file
    inputline [0] = getline("/tmp/piped")
    inputline [0] = getline("/tmp/piped")
    getline("/tmp/piped","close")
    #printf("Input line = %s\n",inputline [0]) 
    H_MACFILE = sprintf("%s",inputline [0])
    if(split(H_MACFILE, inputline, " ") < 2) {
	    H_MACFILE = " "
	    return(-1)
    }else{
	    H_MACFILE = inputline [1]
	    if ((idx=index(H_MACFILE,"\n")) > 0) {
    		H_MACFILE = substr(H_MACFILE,1,idx-1)
    	}
	    return(0)
    }
}'

#%IU%
def help_help '{
	unix("/bin/rm -f /tmp/piped")
    on("/tmp/piped");offt;
    prdef $1
    close("/tmp/piped");ont;
    if(h_getfile() != -1) {
    	local pieces flag
        pieces [0] = pieces [0]
   	    if(split(H_MACFILE,pieces,"SPECD/") == 2) {
   	        H_MACFILE=sprintf("%s/%s",SPECD,pieces[1])
   	        flag =0 
   	        if (pieces [1] == "standard.mac") {
    	    	flag = 1
            }
        }
        printf("The macro %s was defined in %s\n","$1",H_MACFILE)
        if (H_MACFILE == "tty") {
            printf("That means on the terminal (at the prompt)\n")
        	printf("No help available\n")
        }else{
   	        if (flag == 1) {
                gethelp("$1")
    	    }else {
	            unix(sprintf("if (test -r %s) then machelp %s;fi\n",\
	            H_MACFILE,H_MACFILE))
    	    }
        }
	}else{
    	gethelp("$1")
    }
    unix("/bin/rm -f /tmp/piped")
}'

#%MACROS%
#%AUTHOR% V.A.Sole - BLISS - ESRF - Copyright 2000
#%TOC%