29.2 Driving script execution ¶
- Function: mbfl_main ¶
The invocation to this function must be the last line of code in the script. It does the following:
- Register the value of the variable
script_PROGNAME
in the message module using the functionmbfl_message_set_progname()
. - Validate the semantic version specification hard–coded in the MBFL with the requirements of the
script. If an error occurs in this step: terminate the script by calling
exit_because_invalid_mbfl_version()
, exit_because_invalid_mbfl_version.- Check if a function named
script_check_mbfl_semantic_version()
exists. If it does not exist: move on to the next step. If it does exist: call it with MBFL’s semantic version specification string as single argument; if the function returns successfully: the version requirements are considered satisfied; otherwise exit the script by callingexit_because_invalid_mbfl_version()
. - Check if the service variable
script_REQUIRED_MBFL_VERSION
is defined to a non–empty value, the value is expected to be a valid semantic version specification representing the minimum version required by the script; variables service.If an error occurs while parsing the semantic version specification in
script_REQUIRED_MBFL_VERSION
: terminate the script by callingexit_because_invalid_mbfl_version()
.If MBFL’s version is lesser than the one required by the script: terminate the script itself by calling
exit_because_invalid_mbfl_version()
; otherwise the version requirements are considered satisfied.
- Check if a function named
- Parse the command line arguments according to the command actions configuration; this step may
change the selection of: main function, “before parsing options” function, “after parsing
options” function; if no command actions are configured: nothing is done.
This function searches for a declared action set with name
MAIN
: if such set exists, it expects the first command line argument to be an action identifier in the set. - If it exists: invoke the function
script_before_parsing_options()
or the one selected bymbfl_main_set_before_parsing_options()
. - Parse command line options with
mbfl_getopts_parse()
. - If it exists: invoke the function
script_after_parsing_options()
or the one selected bymbfl_main_set_after_parsing_options()
. - Invoke the function whose name is stored in the global variable
mbfl_main_SCRIPT_FUNCTION
, if it exists, with no arguments; if its return value is non–zero: exit the script with the same code. The default value ismain
. - Exit the script with the return code of the action function or zero.
- Register the value of the variable
- Function: mbfl_main_set_main FUNCNAME ¶
Select the main function storing FUNCNAME into
mbfl_main_SCRIPT_FUNCTION
.
- Variable: mbfl_main_SCRIPT_FUNCTION ¶
Global variable that holds the name of the custom main script function. The default name is
main
.
- Function: mbfl_main_set_before_parsing_options FUNCNAME ¶
The name of the function to be called right before parsing command line options. This value can be customised by both the MBFL and the user script.
The default function name is:
script_before_parsing_options
.
- Function: mbfl_main_set_after_parsing_options FUNCNAME ¶
The name of the function to be called right after parsing command line options. This value can be customised by both the MBFL and the user script.
The default function name is:
script_after_parsing_options
.