A.3 Finding libraries

Environment Variable: MBFL_LIBRARY_PATH

A Unix–style colon separated list of directories to be searched, left–to–right, for MBFL libraries. This variable’s value is parsed at linker library loading–time, it cannot be reset by the script itself.

Preprocessor Macro: mbfl_linker_source_library_by_stem (STEM)

Expand into code that searches a library in the current search path and sources the corresponding file. If the library is not found: the script exits with exit_because_error_loading_library().

If the library has already been searched and found: the search path is not visited again; the already found pathname is used.

If the library has already been sourced: the source file is not sourced again; nothing happens.

Function: mbfl_linker_search_by_stem_var PATHNAME_RV STEM

Search a library in the current search path and store the resulting absolute file pathname in the result variable PATHNAME_RV. When successful return true, otherwise return false and leave PATHNAME_RV untouched.

Searching is performed by mbfl_linker_search_by_stem_in_search_path_var().

First the library is searched in the custom search path defined by the environment variable MBFL_LIBRARY_PATH. Then the library is searched in MBFL’s default search path:

/usr/local/share/mbfl
/usr/share/mbfl
/share/mbfl
Function: mbfl_linker_search_by_stem_in_search_path_var PATHNAME_RV STEM SEARCH_PATH_ARRY

Search a library in the search path defined by SEARCH_PATH_ARRY and store the resulting absolute file pathname in the result variable PATHNAME_RV. When successful return true, otherwise return false and leave PATHNAME_RV untouched.

The parameter STEM must be an identifier which is used to build the library filename as follows:

printf -v FILENAME 'libmbfl-%s.bash' STEM

The parameter SEARCH_PATH_ARRY must be the name of an index array whose values are directories in which to search for the library file. The array is visited in increasing index order, starting from index ‘0’.

mbfl_declare_varref(PATHNAME)
mbfl_declare_index_array_varref(SEARCH_PATH)

mbfl_slot_set(SEARCH_PATH, 0, '/home/marco/share/mbfl')
mbfl_slot_set(SEARCH_PATH, 1, '/opt/mbfl/4.0.0')

mbfl_linker_search_by_stem_in_search_path_var mbfl_datavar(PATHNAME) 'core' mbfl_datavar(SEARCH_PATH)

This document describes version 3.0.0-devel.9 of Marcos Bash Functions Library.