2004-09-12  Ulrich Drepper  <drepper@redhat.com>

	* nss/getent.c: Don't preconstruct help message.  Do it only when
	needed.

	* locale/programs/locale.c: Simplify help message printing.
This commit is contained in:
Ulrich Drepper 2004-09-13 05:30:21 +00:00
parent 9d9ab48728
commit f69425fa29
2 changed files with 59 additions and 36 deletions

View File

@ -1,3 +1,10 @@
2004-09-12 Ulrich Drepper <drepper@redhat.com>
* nss/getent.c: Don't preconstruct help message. Do it only when
needed.
* locale/programs/locale.c: Simplify help message printing.
2004-09-12 Roland McGrath <roland@frob.com> 2004-09-12 Roland McGrath <roland@frob.com>
* sysdeps/mach/hurd/i386/init-first.c (init1) [! SHARED]: Add decls * sysdeps/mach/hurd/i386/init-first.c (init1) [! SHARED]: Add decls

View File

@ -57,13 +57,21 @@ static const struct argp_option args_options[] =
{ NULL, 0, NULL, 0, NULL }, { NULL, 0, NULL, 0, NULL },
}; };
/* Short description of program. */
static const char doc[] = N_("Get entries from administrative database.\v\
For bug reporting instructions, please see:\n\
<http://www.gnu.org/software/libc/bugs.html>.\n");
/* Prototype for option handler. */ /* Prototype for option handler. */
static error_t parse_option (int key, char *arg, struct argp_state *state); static error_t parse_option (int key, char *arg, struct argp_state *state);
/* Function to print some extra text in the help message. */
static char *more_help (int key, const char *text, void *input);
/* Data structure to communicate with argp functions. */ /* Data structure to communicate with argp functions. */
static struct argp argp = static struct argp argp =
{ {
args_options, parse_option, args_doc, NULL, args_options, parse_option, args_doc, doc, NULL, more_help
}; };
/* Print the version information. */ /* Print the version information. */
@ -771,52 +779,63 @@ parse_option (int key, char *arg, struct argp_state *state)
return 0; return 0;
} }
/* build doc */
static void static char *
build_doc (void) more_help (int key, const char *text, void *input)
{ {
int i, j, len; int len;
char *short_doc, *long_doc, *doc, *p; char *long_doc, *doc, *p;
short_doc = _("getent - get entries from administrative database."); switch (key)
long_doc = _("Supported databases:");
len = strlen (short_doc) + strlen (long_doc) + 3;
for (i = 0; databases[i].name; ++i)
len += strlen (databases[i].name) + 1;
doc = (char *) malloc (len);
if (doc == NULL)
doc = short_doc;
else
{ {
p = stpcpy (doc, short_doc); case ARGP_KEY_HELP_EXTRA:
*p++ = '\v'; /* We print some extra information. */
p = stpcpy (p, long_doc); #if 0
*p++ = '\n'; return xstrdup (gettext ("\
For bug reporting instructions, please see:\n\
<http://www.gnu.org/software/libc/bugs.html>.\n"));
#endif
long_doc = _("Supported databases:");
len = strlen (long_doc) + 2;
for (i = 0, j = 0; databases[i].name; ++i) for (int i = 0; databases[i].name; ++i)
len += strlen (databases[i].name) + 1;
doc = (char *) malloc (len);
if (doc != NULL)
{ {
len = strlen (databases[i].name); p = stpcpy (doc, long_doc);
if (i != 0) *p++ = '\n';
for (int i = 0, col = 0; databases[i].name; ++i)
{ {
if (j + len > 72) len = strlen (databases[i].name);
if (i != 0)
{ {
j = 0; if (col + len > 72)
*p++ = '\n'; {
col = 0;
*p++ = '\n';
}
else
*p++ = ' ';
} }
else
*p++ = ' '; p = mempcpy (p, databases[i].name, len);
col += len + 1;
} }
p = mempcpy (p, databases[i].name, len); return doc;
j += len + 1;
} }
} break;
argp.doc = doc; default:
break;
}
return (char *) text;
} }
/* the main function */ /* the main function */
int int
main (int argc, char *argv[]) main (int argc, char *argv[])
@ -828,9 +847,6 @@ main (int argc, char *argv[])
/* Set the text message domain. */ /* Set the text message domain. */
textdomain (PACKAGE); textdomain (PACKAGE);
/* Build argp.doc. */
build_doc ();
/* Parse and process arguments. */ /* Parse and process arguments. */
argp_parse (&argp, argc, argv, 0, &remaining, NULL); argp_parse (&argp, argc, argv, 0, &remaining, NULL);