diff options
-rw-r--r-- | src/argparse.c | 21 | ||||
-rw-r--r-- | src/gpg-error.h.in | 21 | ||||
-rw-r--r-- | tests/t-argparse.c | 3 |
3 files changed, 38 insertions, 7 deletions
diff --git a/src/argparse.c b/src/argparse.c index 223d267..0c42fa6 100644 --- a/src/argparse.c +++ b/src/argparse.c @@ -2171,9 +2171,10 @@ cmp_ordtbl (const void *a_v, const void *b_v) * meanings: * - A description string which is "@" suppresses help output for * this option - * - a description,ine which starts with a '@' and is followed by + * - a description which starts with a '@' and is followed by * any other characters is printed as is; this may be used for examples - * ans such. + * and such. This is a legacy methiod, moder codes uses the flags + * ARGPARSE_OPT_VERBATIM or ARGPARSE_OPT_HEADER. * - A description which starts with a '|' outputs the string between this * bar and the next one as arguments of the long option. */ @@ -2228,14 +2229,26 @@ show_help (opttable_t *opts, unsigned int nopts, unsigned int flags) /* Example: " -v, --verbose Viele Sachen ausgeben" */ indent += 10; - if ( *opts[ordtbl[0]].description != '@' ) + if ( *opts[ordtbl[0]].description != '@' + && !(opts[ordtbl[0]].flags + & (ARGPARSE_OPT_VERBATIM|ARGPARSE_OPT_HEADER))) writestrings (0, "Options:", "\n", NULL); for (i=0; i < nopts; i++ ) { s = map_fixed_string (_( opts[ordtbl[i]].description )); if ( s && *s== '@' && !s[1] ) /* Hide this line. */ continue; - if ( s && *s == '@' ) /* Unindented comment only line. */ + if ( s && (opts[ordtbl[i]].flags + & (ARGPARSE_OPT_VERBATIM|ARGPARSE_OPT_HEADER))) + { + if ((opts[ordtbl[i]].flags & ARGPARSE_OPT_HEADER)) + writestrings (0, "\n", NULL); + writestrings (0, s, NULL); + if ((opts[ordtbl[i]].flags & ARGPARSE_OPT_HEADER)) + writestrings (0, ":\n", NULL); + continue; + } + if ( s && *s == '@' ) /* Unindented legacy comment only line. */ { for (s++; *s; s++ ) { diff --git a/src/gpg-error.h.in b/src/gpg-error.h.in index b0b1972..9042a0f 100644 --- a/src/gpg-error.h.in +++ b/src/gpg-error.h.in @@ -1230,6 +1230,8 @@ typedef struct #define ARGPARSE_OPT_IGNORE (1<<6) /* Ignore command or option. */ #define ARGPARSE_OPT_COMMAND (1<<7) /* The argument is a command. */ #define ARGPARSE_OPT_CONFFILE (1<<8) /* The value is a conffile. */ +#define ARGPARSE_OPT_HEADER (1<<9) /* The value is printed as a header. */ +#define ARGPARSE_OPT_VERBATIM (1<<10)/* The value is printed verbatim. */ #define ARGPARSE_ATTR_FORCE (1<<14)/* Attribute force is set. */ #define ARGPARSE_ATTR_IGNORE (1<<15)/* Attribute ignore is set. */ @@ -1304,15 +1306,28 @@ typedef struct #define ARGPARSE_noconffile(s,l,d) \ { (s), (l), (ARGPARSE_TYPE_NONE|ARGPARSE_OPT_CONFFILE), (d) } +/* This macro is for stub or obsolete options. */ #define ARGPARSE_ignore(s,l) \ - { (s), (l), (ARGPARSE_OPT_IGNORE), "@" } + { (s), (l), (ARGPARSE_OPT_IGNORE), "@" } +/* This is a legacy version of ARGPARSE_verbatim which really does + * verbatim printing. */ #define ARGPARSE_group(s,d) \ - { (s), NULL, 0, (d) } + { (s), NULL, 0, (d) } + +/* Verbatim print the string D in the help output. It does not make + * use of the "@" hack as ARGPARSE_group does. */ +#define ARGPARSE_verbatim(d) \ + { 1, NULL, (ARGPARSE_OPT_VERBATIM), (d) } + +/* Same as ARGPARSE_verbatim but also print a colon and a LF. N can + * be used give a symbolic name to the header. */ +#define ARGPARSE_header(n,d) \ + { 1, (n), (ARGPARSE_OPT_HEADER), (d) } /* Mark the end of the list (mandatory). */ #define ARGPARSE_end() \ - { 0, NULL, 0, NULL } + { 0, NULL, 0, NULL } #endif /* GPGRT_ENABLE_ARGPARSE_MACROS */ diff --git a/tests/t-argparse.c b/tests/t-argparse.c index 80da5ac..8ba5841 100644 --- a/tests/t-argparse.c +++ b/tests/t-argparse.c @@ -65,6 +65,7 @@ int main (int argc, char **argv) { gpgrt_opt_t opts[] = { + ARGPARSE_verbatim("Now for the options:\n"), ARGPARSE_x ('v', "verbose", NONE, 0, "Laut sein"), ARGPARSE_s_n('e', "echo" , ("Zeile ausgeben, damit wir sehen, " "was wir eingegeben haben")), @@ -72,12 +73,14 @@ main (int argc, char **argv) ARGPARSE_s_s('o', "output", 0 ), 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_o_i('m', "my-option", 0), ARGPARSE_o_i('M', "not-my-option", 0), ARGPARSE_s_n(500, "a-long-option", 0 ), ARGPARSE_conffile(501, "options", "|FILE|read options from FILE"), ARGPARSE_noconffile(502, "no-options", "Ignore conf files"), + ARGPARSE_verbatim("This epilog consists\nof only 2 lines\n"), ARGPARSE_end() }; gpgrt_argparse_t pargs = { &argc, &argv, (ARGPARSE_FLAG_ALL |