"Fossies" - the Fresh Open Source Software Archive

Member "argbash-2.10.0/src/progs.m4" (22 Sep 2020, 2770 Bytes) of package /linux/privat/argbash-2.10.0.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "progs.m4": 2.9.0_vs_2.10.0.

    1 dnl A function for handling a generic program
    2 dnl Macro:
    3 dnl no args
    4 m4_define([_CHECK_PROG_FACTORY_INDIR], [MAKE_FUNCTION(
    5 	[[Checks for the program @S|@2, that can be optionally pin-pointed by @S|@1],
    6 		[and fail with the @S|@3 error message if not successful.],
    7 		[@S|@1: Name of the env var],
    8 		[@S|@2: The program name],
    9 		[@S|@3: The error message]],
   10 	[check_prog],
   11 	[_JOIN_INDENTED(1,
   12 		[test -n "$_msg" || _msg="Unable to find a reachable executable '@S|@2'"],
   13 		[eval "test -n \"\@S|@@S|@1\" || @S|@1=\"@S|@2\""],
   14 		[eval "command -v \"\@S|@@S|@1\" > /dev/null 2> /dev/null" || die "$_msg" 1],
   15 	)],
   16 	[_msg="@S|@3"],
   17 )])
   18 
   19 
   20 dnl
   21 dnl Works well when there is only one program wanted
   22 dnl Macro:
   23 dnl $1: The env var name
   24 dnl $2: The prog name
   25 dnl $3: The msg
   26 dnl Function:
   27 dnl no args
   28 m4_define([_CHECK_PROG_FACTORY_SINGLE], [MAKE_FUNCTION(
   29 	[],
   30 	[check_prog_for_$1],
   31 	[_JOIN_INDENTED(1,
   32 		[test -n "@S|@$1" || $1="$2"],
   33 		[$1="$(command -v "@S|@$1")" || die "m4_default([$3], [Unable to find a reachable executable '$2'])" 1],
   34 	)])])
   35 
   36 
   37 dnl
   38 dnl $1 - prog name
   39 dnl $2 - env var (default: argbash translit of prog name)
   40 dnl $3 - msg if not OK (optional)
   41 dnl $4 - help message (if you want to mention existence of this in the help)
   42 dnl
   43 dnl  In case of path issues (i.e. script is in a crontab), update the PATH variable yourself above the argbash code.
   44 dnl
   45 dnl  internally:
   46 dnl  PROG_NAMES, PROG_VARS, PROG_MSGS, PROG_HELPS
   47 argbash_api([ARG_USE_PROGRAM], [m4_ifndef([WRAPPED_FILE_STEM], [m4_do(
   48 	[[$0($@)]],
   49 	[m4_list_append([PROG_VARS], m4_default_quoted([$2], _translit_prog([$1])))],
   50 	[m4_list_append([PROG_NAMES], [$1])],
   51 	[m4_list_append([PROG_MSGS], [$3])],
   52 	[m4_list_append([PROG_HELPS], [$4])],
   53 )])])
   54 
   55 
   56 dnl
   57 dnl $1: A prologue message
   58 m4_define([_HELP_PROGS], [m4_list_ifempty([PROG_VARS], , [m4_do(
   59 	[m4_ifnblank([$1], [m4_n([$1])])],
   60 	[m4_lists_foreach([PROG_VARS,PROG_NAMES,PROG_HELPS], [_envvarname,_progname,_proghelp], [m4_do(
   61 		[_INDENT_()printf '%s: %s (define manually using %s)\n' "_progname" "_proghelp" "_envvarname"
   62 ],
   63 	)])],
   64 )])])
   65 
   66 
   67 m4_define([_SETTLE_PROGS], [m4_list_ifempty([PROG_NAMES], , [m4_if(m4_list_len([PROG_NAMES]),
   68 		1, [_SETTLE_ONE_PROG()],
   69 		[_SETTLE_MORE_PROGS()])])])
   70 
   71 
   72 m4_define([_SETTLE_MORE_PROGS], [m4_do(
   73 	[_CHECK_PROG_FACTORY_INDIR()
   74 
   75 ],
   76 	[# Make sure that m4_list_format_sequence([PROG_NAMES], [ and ]) are assigned to respective env vars.
   77 ],
   78 	[m4_lists_foreach([PROG_VARS,PROG_NAMES,PROG_MSGS], [_envvarname,_progname,_progmsg], [m4_do(
   79 		[check_prog "_envvarname" '_progname' _sh_quote(_progmsg)
   80 ],
   81 )])],
   82 )])
   83 
   84 
   85 m4_define([_SETTLE_ONE_PROG], [m4_do(
   86 	[_CHECK_PROG_FACTORY_SINGLE(m4_list_nth([PROG_VARS], 1), m4_list_nth([PROG_NAMES], 1), m4_list_nth([PROG_MSGS], 1))
   87 
   88 ],
   89 	[check_prog_for_[]m4_list_nth([PROG_VARS], 1)
   90 ],
   91 )])