summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--nss/getent.c90
2 files changed, 60 insertions, 37 deletions
diff --git a/ChangeLog b/ChangeLog
index efd0a2ceac..0d1bfb3515 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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>
 
 	* sysdeps/mach/hurd/i386/init-first.c (init1) [! SHARED]: Add decls
diff --git a/nss/getent.c b/nss/getent.c
index 45a6a1ffe5..f9f0a6e22a 100644
--- a/nss/getent.c
+++ b/nss/getent.c
@@ -57,13 +57,21 @@ static const struct argp_option args_options[] =
     { 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.  */
 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.  */
 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.  */
@@ -771,52 +779,63 @@ parse_option (int key, char *arg, struct argp_state *state)
   return 0;
 }
 
-/* build doc */
-static void
-build_doc (void)
-{
-  int i, j, len;
-  char *short_doc, *long_doc, *doc, *p;
-
-  short_doc = _("getent - get entries from administrative database.");
-  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;
+static char *
+more_help (int key, const char *text, void *input)
+{
+  int len;
+  char *long_doc, *doc, *p;
 
-  doc = (char *) malloc (len);
-  if (doc == NULL)
-    doc = short_doc;
-  else
+  switch (key)
     {
-      p = stpcpy (doc, short_doc);
-      *p++ = '\v';
-      p = stpcpy (p, long_doc);
-      *p++ = '\n';
-
-      for (i = 0, j = 0; databases[i].name; ++i)
+    case ARGP_KEY_HELP_EXTRA:
+      /* We print some extra information.  */
+#if 0
+      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 (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);
-	  if (i != 0)
+	  p = stpcpy (doc, long_doc);
+	  *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;
-		  *p++ = '\n';
+		  if (col + len > 72)
+		    {
+		      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);
-	  j += len + 1;
+	  return doc;
 	}
-    }
+      break;
 
-  argp.doc = doc;
+    default:
+      break;
+    }
+  return (char *) text;
 }
 
+
 /* the main function */
 int
 main (int argc, char *argv[])
@@ -828,9 +847,6 @@ main (int argc, char *argv[])
   /* Set the text message domain.  */
   textdomain (PACKAGE);
 
-  /* Build argp.doc.  */
-  build_doc ();
-
   /* Parse and process arguments.  */
   argp_parse (&argp, argc, argv, 0, &remaining, NULL);