From 9078b75a73600fc6b7b5502ceee8de032bb9c446 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Tue, 17 Mar 2015 11:22:28 +0100 Subject: common: Add feature to ease using argparse's usage(). * common/argparse.c (show_help): Take care of flag value (usage): Ditto. -- It is common that the long usage note starts with the short usage note. The new flag feature allows to combine both. Signed-off-by: Werner Koch --- common/argparse.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'common/argparse.c') diff --git a/common/argparse.c b/common/argparse.c index a4d1552e6..e31b67ea5 100644 --- a/common/argparse.c +++ b/common/argparse.c @@ -1239,6 +1239,14 @@ show_help (ARGPARSE_OPTS *opts, unsigned int flags) show_version (); writestrings (0, "\n", NULL); + s = strusage (42); + if (s && *s == '1') + { + s = strusage (40); + writestrings (1, s, NULL); + if (*s && s[strlen(s)] != '\n') + writestrings (1, "\n", NULL); + } s = strusage(41); writestrings (0, s, "\n", NULL); if ( opts[0].description ) @@ -1432,6 +1440,14 @@ usage (int level) } else if (level == 2) { + p = strusage (42); + if (p && *p == '1') + { + p = strusage (40); + writestrings (1, p, NULL); + if (*p && p[strlen(p)] != '\n') + writestrings (1, "\n", NULL); + } writestrings (0, strusage(41), "\n", NULL); exit (0); } @@ -1455,6 +1471,10 @@ usage (int level) *30..39: Additional program info (with LFs) * 40: short usage note (with LF) * 41: long usage note (with LF) + * 42: Flag string: + * First char is '1': + * The short usage notes needs to be printed + * before the long usage note. */ const char * strusage( int level ) -- cgit v1.2.3