diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-06-26 11:41:02 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-06-26 11:41:02 +0300 |
commit | 00f3dc3e1f8f48d9c3ebed51dedf652ff2401eca (patch) | |
tree | 80af165fa31081493c0a5b38467ce80e86c67e7f | |
parent | 63a96475801be6ba432ac1153ae7c16089ab2639 (diff) | |
download | smap-00f3dc3e1f8f48d9c3ebed51dedf652ff2401eca.tar.gz smap-00f3dc3e1f8f48d9c3ebed51dedf652ff2401eca.tar.bz2 |
Improve help output.
* src/getopt.m4 (_getopt_mangle_option)
(_getopt_set_option, _getopt_get_option)
(_getopt_if_option_set, _getopt_option_switch)
(_getopt_if_option_val, _getopt_switch_option_val)
(_getopt_set_options): New macros.
(print_help): Improve output.
(version_etc_copyright): Change to a generic version
(print_version_only): Improve output. Use copyright_year
and copyright_holder variables.
[authors] (program_author): New global.
(print_version): Print the "written by" clause if authors are
defined.
(OPTIONS_BEGIN): Change argument ordering, introduce flags.
* src/smapccmd.opt (OPTIONS_BEGIN): Update declaration.
* src/cmdline.opt : Likewise.
* src/smapc.c (cmd_warranty): Use program_version.
-rw-r--r-- | src/cmdline.opt | 7 | ||||
-rw-r--r-- | src/getopt.m4 | 161 | ||||
-rw-r--r-- | src/smapc.c | 2 | ||||
-rw-r--r-- | src/smapccmd.opt | 9 |
4 files changed, 162 insertions, 17 deletions
diff --git a/src/cmdline.opt b/src/cmdline.opt index 565c97d..3dbf9d7 100644 --- a/src/cmdline.opt +++ b/src/cmdline.opt @@ -14,8 +14,11 @@ You should have received a copy of the GNU General Public License along with Smap. If not, see <http://www.gnu.org/licenses/>. */ -OPTIONS_BEGIN(gnu,"smapd", - [<A socket map daemon.>]) +OPTIONS_BEGIN("smapd", + [<A socket map daemon.>],[<>], + [<gnu>], + [<copyright_year=2009, 2010>], + [<copyright_holder=Sergey Poznyakoff>]) GROUP([<Operation mode>]) OPTION(lint, t,, diff --git a/src/getopt.m4 b/src/getopt.m4 index 26278e4..29bab9c 100644 --- a/src/getopt.m4 +++ b/src/getopt.m4 @@ -17,6 +17,77 @@ divert(-1) changequote([<,>]) changecom(/*,*/) +dnl _getopt_mangle_option(NAME) +dnl --------------------------- +dnl Convert NAME to a valid m4 identifier, by replacing invalid characters +dnl with underscores, and prepend the _GETOPT_OPTION_ suffix to it. +define([<_getopt_mangle_option>], + [<[<_GETOPT_OPTION_>]patsubst($1, [<[^a-zA-Z0-9_]>], [<_>])>]) + +dnl _getopt_set_option(NAME[=VAL]) +dnl ------------------------------ +dnl Set option NAME. +define([<_getopt_set_option>], + [<ifelse(index([<$1>],=),-1,[<define(_getopt_mangle_option($1))>], + [<define(regexp([<$1>],\([^=]+\)=\(.*\), + [<_getopt_mangle_option(\1),[<\2>]>]))>])>]) + +dnl _getopt_get_option(NAME[,DEFAULT]) +dnl ------------------------------ +define([<_getopt_get_option>], + [<_getopt_if_option_set($1,[<indir(_getopt_mangle_option($1))>],[<$2>])>]) + +dnl _getopt_if_option_set(NAME,IF-SET,IF-NOT-SET) +dnl --------------------------------------------- +dnl Check if option NAME is set. +define([<_getopt_if_option_set>], + [<ifdef(_getopt_mangle_option([<$1>]),[<$2>],[<$3>])>]) + +dnl _getopt_option_switch(NAME1,IF-SET1,[NAME2,IF-SET2,[...]],[IF-NOT-SET]) +dnl ------------------------------------------------------------------------ +dnl If NAME1 is set, run IF-SET1. Otherwise, if NAME2 is set, run IF-SET2. +dnl Continue the process for all name-if-set pairs within [...]. If none +dnl of the options is set, run IF-NOT-SET. +define([<_getopt_option_switch>], + [<ifelse([<$4>],,[<_getopt_if_option_set($@)>], + [<$3>],,[<_getopt_if_option_set($@)>], + [<_getopt_if_option_set([<$1>],[<$2>], + [<_getopt_option_switch(shift(shift($@)))>])>])>]) + +dnl _getopt_if_option_val(NAME,val,IF-TRUE,IF-FALSE) +dnl --------------------------------------------- +dnl Check if option NAME is set. +define([<_getopt_if_option_val>], + [<ifelse(_getopt_get_option([<$1>]),[<$2>],[<$3>],[<$4>])>]) + +define([<__getopt_switch_option_val>], +[<ifelse([<$#>],2,[<$2>],dnl + [<$#>],3,[<ifelse([<$1>],[<$2>],[<$3>])>],dnl +[<ifelse([<$1>],[<$2>],[<$3>],dnl +[<__getopt_switch_option_val([<$1>],shift(shift(shift($@))))>])>])>]) + +dnl _getopt_switch_option_val(NAME,val1,IF-VAL1,val2,IF-VAL2...,ELSE) +dnl ----------------------------------------------------------------- +dnl Check if option NAME is set. +define([<_getopt_switch_option_val>], +[<pushdef([<val>],[<_getopt_get_option($1)>])dnl +__getopt_switch_option_val(val, shift($@))[<>]dnl +popdef([<val>])>]) + +dnl _getopt_set_options(OPTION[,OPTION...]) +dnl --------------------------------------- +dnl Set options given as arguments. +define([<_getopt_set_options>], + [<ifelse([<$1>],,, + [<_getopt_set_option([<$1>]) + _getopt_set_options(shift($@))>])>]) + +dnl format_authors(name[,name...]) +dnl ------------------------------ +define([<format_authors>],dnl + [<ifelse([<$1>],,NULL,[<"$1", +format_authors(shift($@))>])>]) + dnl upcase(ARGS...) dnl Concatenate and convert ARGS to upper case. dnl @@ -381,7 +452,22 @@ dnl ************************************************************************** print_option_descr (_("Mandatory or optional arguments to long options are also mandatory or optional for any corresponding short options."), 0, RMARGIN); putchar ('\n'); } + + /* TRANSLATORS: The placeholder indicates the bug-reporting address + for this package. Please add _another line_ saying + "Report translation bugs to <...>\n" with the address for translation + bugs (typically your translation team's web or email address). */ printf (_("Report bugs to %s.\n"), program_bug_address); + +#ifdef PACKAGE_URL + printf (_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL); +_getopt_if_option_set([<gnupackage>],[<#else + printf (_("%s home page: <http://www.gnu.org/software/%s/>\n"), + PACKAGE_NAME, PACKAGE); +#endif + fputs (_("General help using GNU software: <http://www.gnu.org/gethelp/>\n"), + stdout);>], +[<#endif>]) } static int @@ -566,10 +652,10 @@ print_usage (void) } const char version_etc_copyright[] = - /* Do *not* mark this string for translation. %s is a copyright - symbol suitable for this locale, and %d is the copyright - year. */ - "Copyright %s 2005, 2006, 2007, 2008 Sergey Poznyakoff"; + /* Do *not* mark this string for translation. First %s is a copyright + symbol suitable for this locale, and second %s are the copyright + years. */ + "Copyright %s %s %s"; void print_version_only(const char *program_version, FILE *stream) @@ -578,13 +664,37 @@ print_version_only(const char *program_version, FILE *stream) /* TRANSLATORS: Translate "(C)" to the copyright symbol (C-in-a-circle), if this symbol is available in the user's locale. Otherwise, do not translate "(C)"; leave it as-is. */ - fprintf (stream, version_etc_copyright, _("(C)")); + fprintf (stream, version_etc_copyright, _("(C)"), + "_getopt_get_option(copyright_year, 2010)", + "_getopt_get_option(copyright_holder)"); fputc ('\n', stream); } +_getopt_if_option_set([<authors>],[< +char *program_author[] = { +format_authors(_getopt_get_option(authors)) +};>]) + void print_version(const char *program_version, FILE *stream) { + _getopt_if_option_set([<authors>],[<int i; + unsigned width; + const char *written_by = _("Written by "); + /* TRANSLATORS: This string is used as a delimiter between authors' names + as in: + + Written by Winnie the Pooh, Piglet ... + */ + const char *middle_delim = _(", "); + /* TRANSLATORS: This string acts as a delimiter before the last author's + names, e.g.: + + Written by Winnie the Pooh, Piglet and Christopher Robin. + */ + const char *final_delim = _(" and "); + +>]) print_version_only(program_version, stream); dnl ************************************************************************** @@ -594,9 +704,37 @@ dnl directives between the lines. dnl ************************************************************************** fputs (_("License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law.\n\n"), stream); +_getopt_if_option_set([<authors>],[< + width = strlen (written_by); + fputs (written_by, stream); + for (i = 0; ; ) + { + char *author = program_author[i++]; + size_t len = strlen (author); + const char *delim = NULL; -dnl /* TRANSLATORS: %s denotes an author name. */ -dnl fprintf (stream, _("Written by %s.\n"), "Sergey Poznyakoff"); + if (program_author[i]) + { + delim = program_author[i+1] ? middle_delim : final_delim; + len += strlen (delim); + } + else + len++; + if (width + len > RMARGIN) + { + fputc ('\n', stream); + width = 0; + } + fputs (author, stream); + width += len; + if (delim) + fputs (delim, stream); + else + break; + } + fputc ('.', stream); + fputc ('\n', stream); +>]) } divert(-1) @@ -606,13 +744,14 @@ popdef([<FLUSH>]) define([<OPTIONS_BEGIN>], [<divert(-1) - define([<GETOPT_STYLE>],[<$1>]) - ifelse([<$1>],[<gnu>], - [<STDFUNC([<$2 " (" PACKAGE_NAME ") " PACKAGE_VERSION>], [<$2>], [<$3>], [<$4>])>]) + _getopt_set_options(shift(shift(shift($@)))) + _getopt_if_option_set([<gnu>], + [<STDFUNC([<$1 " (" PACKAGE_NAME ") " PACKAGE_VERSION>], + [<$1>], [<$2>], [<$3>])>]) >]) define([<OPTIONS_END>],[< -ifelse(GETOPT_STYLE,[<gnu>],[< +_getopt_if_option_set([<gnu>],[< GROUP([<Other options>]) OPTION([<help>],h,,[<Give this help list>]) BEGIN diff --git a/src/smapc.c b/src/smapc.c index 7cec3ca..6da79b8 100644 --- a/src/smapc.c +++ b/src/smapc.c @@ -402,7 +402,7 @@ static char gplv3_text[] = "\ static int cmd_warranty(int argc, char **argv) { - print_version_only(PACKAGE_STRING, stdout); + print_version_only(program_version, stdout); putchar('\n'); printf("%s", gplv3_text); return 0; diff --git a/src/smapccmd.opt b/src/smapccmd.opt index 7849c2c..70b494c 100644 --- a/src/smapccmd.opt +++ b/src/smapccmd.opt @@ -14,12 +14,15 @@ You should have received a copy of the GNU General Public License along with Smap. If not, see <http://www.gnu.org/licenses/>. */ -OPTIONS_BEGIN(gnu, "smapc", +OPTIONS_BEGIN("smapc", [<A socket map client.>], - [<[URL] [map [key]]]>]) + [<[URL] [map [key]]]>], + [<gnu>], + [<copyright_year=2009, 2010>], + [<copyright_holder=Sergey Poznyakoff>]) OPTION(debug, x, LEVEL-SPEC, - [<set debug verbosity level.>]) + [<set debug verbosity level>]) BEGIN if (smap_debug_set(optarg)) smap_error("invalid debug specification: %s", optarg); |