Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow checking whether optionals provided explicitly #187

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/stuff.m4
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ dnl $5: Where to get the last value (optional)
m4_define([_VAL_OPT_ADD_SPACE_WITHOUT_GETOPT_OR_SHORT_OPT], [_JOIN_INDENTED(_INDENT_LEVEL_IN_ARGV_CASE_BODY,
[test $[]# -lt 2 && die "Missing value for the optional argument '$_key'." 1],
[$3([$1], ["@S|@2"], [$4])],
[_optionals+=($4)]
[_APPEND_WRAPPED_ARGUMENT_TO_ARRAY_SPACE([$4], [m4_default_quoted([$5], [@S|@2])])],
[shift],
)])
Expand All @@ -458,6 +459,7 @@ dnl $5: Where to get the last value (optional)
m4_define([_VAL_OPT_ADD_GETOPTS], [_JOIN_INDENTED(_INDENT_LEVEL_IN_ARGV_CASE_BODY,
[test "$OPTARG" = "" && die "Missing value for the optional argument '-$_key'." 1],
[$3([$1], ["$OPTARG"], [$4])],
[_optionals+=($3)dnl]
[_APPEND_WRAPPED_ARGUMENT_TO_ARRAY_SPACE([$4], [m4_default_quoted([$5], [$OPTARG])])],
)])

Expand All @@ -470,6 +472,7 @@ dnl $4: The name of the argument-holding variable
dnl $5: Where to get the last value (optional)
m4_define([_VAL_OPT_ADD_EQUALS_WITH_LONG_OPT], [_JOIN_INDENTED(_INDENT_LEVEL_IN_ARGV_CASE_BODY,
[$3([$1], ["${_key##--$1=}"], [$4])],
[_optionals+=($4)dnl]
[_APPEND_WRAPPED_ARGUMENT_TO_ARRAY_EQUALS([$4])],
)])

Expand All @@ -482,6 +485,7 @@ dnl $4: The name of the argument-holding variable
dnl $5: Where to get the last value (optional)
m4_define([_VAL_OPT_ADD_ONLY_WITH_SHORT_OPT_GETOPT], [_JOIN_INDENTED(_INDENT_LEVEL_IN_ARGV_CASE_BODY,
[$3([$1], ["${_key##-$2}"], [$4])],
[_optionals+=($4)dnl]
[_APPEND_WRAPPED_ARGUMENT_TO_ARRAY_GETOPT([$4])],
)])

Expand Down Expand Up @@ -731,12 +735,14 @@ m4_define([_MAKE_OPTARG_SIMPLE_CASE_SECTION], [m4_do(
[bool],
[_JOIN_INDENTED(_INDENT_LEVEL_IN_ARGV_CASE_BODY,
[[$5="on"]],
[[_optionals+=($5)]],
[_APPEND_WRAPPED_ARGUMENT_TO_ARRAY_SPACE([$5])],
[[test "${1:0:5}" = "--no-" && $5="off"]],
)],
[incr],
[_JOIN_INDENTED(_INDENT_LEVEL_IN_ARGV_CASE_BODY,
[[$5=$(($5 + 1))]],
[[_optionals+=($5)]],
[_APPEND_WRAPPED_ARGUMENT_TO_ARRAY_SPACE([$5])],
)],
[action],
Expand All @@ -763,11 +769,13 @@ m4_define([_MAKE_OPTARG_GETOPTS_CASE_SECTION], [m4_do(
[bool],
[_JOIN_INDENTED(_INDENT_LEVEL_IN_ARGV_CASE_BODY,
[[$5="on"]],
[[_optionals+=($5)]],
[_APPEND_WRAPPED_ARGUMENT_TO_ARRAY_SPACE([$5])],
)],
[incr],
[_JOIN_INDENTED(_INDENT_LEVEL_IN_ARGV_CASE_BODY,
[[$5=$(($5 + 1))]],
[[_optionals+=($5)]],
[_APPEND_WRAPPED_ARGUMENT_TO_ARRAY_SPACE([$5])],
)],
[action],
Expand Down Expand Up @@ -823,12 +831,14 @@ m4_define([_MAKE_OPTARG_GETOPT_CASE_SECTION], [m4_do(
[bool],
[_JOIN_INDENTED(_INDENT_LEVEL_IN_ARGV_CASE_BODY,
[[$5="on"]],
[[_optionals+=($5)]],
_PASS_WHEN_GETOPT([$2]),
[_APPEND_WRAPPED_ARGUMENT_TO_ARRAY_SPACE([$5])],
)],
[incr],
[_JOIN_INDENTED(_INDENT_LEVEL_IN_ARGV_CASE_BODY,
[[$5=$(($5 + 1))]],
[[_optionals+=($5)]],
_PASS_WHEN_GETOPT([$2]),
[_APPEND_WRAPPED_ARGUMENT_TO_ARRAY_SPACE([$5])],
)],
Expand Down Expand Up @@ -1226,6 +1236,7 @@ m4_define([_MAKE_DEFAULTS_POSITIONAL_POSIX], [m4_do(

m4_define([_MAKE_DEFAULTS_OPTIONAL], [m4_do(
[[# THE DEFAULTS INITIALIZATION - OPTIONALS]_ENDL_],
[[_optionals=()]_ENDL_],
[m4_lists_foreach_optional([_ARGS_LONG,_ARGS_CATH,_ARGS_DEFAULT,_ARGS_VARNAME], [_argname,_arg_type,_default,_arg_varname], [m4_do(
[dnl We have to handle 'incr' as a special case, there is a m4_default(..., 0)
],
Expand Down