From b1790f4cc71f14422255bbfba78e91f037e035dd Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Sun, 31 Oct 2021 17:44:08 +0100 Subject: argparse: Add support to read values from the Windows Registry. * src/argparse.c (struct variable_s): New. (struct _gpgrt_argparse_internal_s): New fields expand, if_cond, if_active and vartbl. (deinitialize): Free vartbl. (initialize): Clear new vars. (get_var): New. (substitute_vars): New. (set_variable): New. (handle_meta_if): New. (handle_meta_let): New. (handle_meta_getenv): New. (handle_meta_echo): Re-implement in terms of variabale substitution. (handle_meta_expand): New. (handle_metacmd): Add new meta commands. (_gpgrt_argparse): Expand values if enabled. (_gpgrt_argparse): Take care of conditions. (_gpgrt_argparser): Reset some state at the end of a file. * tests/etc/t-argparse.conf: Adjust for changed system variables. * tests/t-argparse.c (my_strusage): Add a value for a version test. (main): Add new option "street". * tests/t-argparse.conf: A couple if additions for the new conditions. -- The whole thing is actually only for here for doing this [let tkey HKLM\Foo\Bar\GnuPG:trusted-key-1] [if $tkey] trusted-key $tkey [fi] But we are hackers and tend to make things more complicated^Wflexible. Documentation will be done eventually. Signed-off-by: Werner Koch --- tests/etc/t-argparse.conf | 8 ++++---- tests/t-argparse.c | 7 ++++++- tests/t-argparse.conf | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/etc/t-argparse.conf b/tests/etc/t-argparse.conf index 6559266..92c373d 100644 --- a/tests/etc/t-argparse.conf +++ b/tests/etc/t-argparse.conf @@ -8,10 +8,10 @@ # prefix it does not prepend the file name and line number. [-echo Begin global config] -[-echo use $${user} to echo the current user (${user})] -[-echo use $${file} to echo the current file (${file})] -[-echo use $${line} to echo the current line (${line})] -[-echo use $${epoch} to echo a timestamp (${epoch})] +[-echo use $${_user} to echo the current user (${_user})] +[-echo use $${_file} to echo the current file (${_file})] +[-echo use $${_line} to echo the current line (${_line})] +[-echo use $${_epoch} to echo a timestamp (${_epoch})] [verbose] diff --git a/tests/t-argparse.c b/tests/t-argparse.c index 8ba5841..4d24e5f 100644 --- a/tests/t-argparse.c +++ b/tests/t-argparse.c @@ -39,6 +39,7 @@ static struct { int myopt; int echo; int a_long_one; + char *street; } opt; @@ -53,6 +54,7 @@ my_strusage (int level) case 9: p = "LGPL-2.1-or-later"; break; case 11: p = "t-argparse"; break; + case 13: p = "6.42.17-beta99"; break; default: p = NULL; } @@ -74,7 +76,7 @@ main (int argc, char **argv) ARGPARSE_o_s('c', "cross-ref", "cross-reference erzeugen\n" ), /* Note that on a non-utf8 terminal the ß might garble the output. */ ARGPARSE_header("extra-options", "List of extra options"), - ARGPARSE_s_n('s', "street","|Straße|set the name of the street to Straße"), + ARGPARSE_s_s('s', "street","|Straße|set the name of the street to Straße"), ARGPARSE_o_i('m', "my-option", 0), ARGPARSE_o_i('M', "not-my-option", 0), ARGPARSE_s_n(500, "a-long-option", 0 ), @@ -135,6 +137,7 @@ main (int argc, char **argv) case 'c': opt.crf = pargs.r_type? pargs.r.ret_str:"a.crf"; break; case 'm': opt.myopt = pargs.r_type? pargs.r.ret_int : 1; break; case 'M': opt.myopt = 0; break; + case 's': opt.street = pargs.r.ret_str; break; case 500: opt.a_long_one++; break; default : pargs.err = ARGPARSE_PRINT_WARNING; any_warn = 1; break; } @@ -151,6 +154,8 @@ main (int argc, char **argv) printf (" outfile='%s'\n", opt.outfile ); if (opt.crf) printf (" crffile='%s'\n", opt.crf ); + if (opt.street) + printf (" street='%s'\n", opt.street ); if (opt.myopt) printf (" myopt=%d\n", opt.myopt ); if (opt.a_long_one) diff --git a/tests/t-argparse.conf b/tests/t-argparse.conf index 431ee7d..4e0dc8a 100644 --- a/tests/t-argparse.conf +++ b/tests/t-argparse.conf @@ -13,4 +13,56 @@ my-option 4711 not-my-option verbose + +[let user ${_}Montgomery Scott$_$_ ] +[-echo The name of the user is: "$user". ] +[getenv foo FOO] +[if $_verbose] +[-echo foo=$foo] +[fi] +[getenv home HOME] +[getenv path PATH ] +[if $_verbose] +[-echo home=$home path=$path] +[fi] + +[-info checking user] +[if $user = Scottie's engines ] +[fi] +[-info checking substring check] +[getenv home $HOME] +[if $home =~ home ] + [-echo in home condition] +[expand] +[if $foo -n ] + cross-ref "$home/project/$user.crf" + [-echo FOO is set] + [if $home -n] + [-echo home is set] + [else] + [-echo home is not set] + [fi] +[else] + [-echo FOO is not set] +[fi] +street Mühlenstraße + +[getreg x hkcu\fhghfkhkfh] +[if $_windows -n] +[if $x -n] + trusted-key $x +[fi] +[fi] + +[-echo pgm="$_pgm" ver="$_version"] +[if $_version -v3gt 6.42.16] + [-echo is > 6.42.16] +[fi] +[if $_version -v3ge 6.42.17] + [-echo is >= 6.42.17] +[fi] +[if $_version -v3lt 6.42.17] +[else] + [-echo is not < 6.42.17] +[fi] [-echo end of user config] -- cgit v1.2.3