From 2cc980567a3bf9b714295e88392798dd347fa156 Mon Sep 17 00:00:00 2001
From: Neil Booth <neil@daikokuya.co.uk>
Date: Sat, 19 Jul 2003 08:13:58 +0000
Subject: [PATCH] common.opt: Document --param.

	* common.opt:  Document --param.
	* opts.c (columns, undocumented_msg): New.
	(print_help): Get number of columns from environment.  Print
	--param help.  Tweak newline handling.
	(print_param_help): New.
	(print_filtered_help): Better handling of duplicates.  Complain
	about undocumented switches.
	(print_switch): New.
	(wrap_help): Improve wrapping, use COLUMNS.
	* opts.sh: Ignore comments in records.
	* params.def: Fix typos and remove trailing periods.
	* toplev.c (display_help): Don't dump --param help.
	* doc/sourcebuild.texi: Update.
java:
	* lang.opt: Don't show -MD_ and -MDD_.

From-SVN: r69581
---
 gcc/ChangeLog            |  16 +++++
 gcc/common.opt           |   1 +
 gcc/doc/sourcebuild.texi |   9 +--
 gcc/java/ChangeLog       |   4 ++
 gcc/java/lang.opt        |   4 +-
 gcc/opts.c               | 144 ++++++++++++++++++++++++++++++++++-----
 gcc/opts.sh              |   2 +-
 gcc/params.def           |  18 ++---
 gcc/toplev.c             |  12 ----
 9 files changed, 163 insertions(+), 47 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index fea014e81b83..98200dd51c03 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,19 @@
+2003-07-19  Neil Booth  <neil@daikokuya.co.uk>
+
+	* common.opt:  Document --param.
+	* opts.c (columns, undocumented_msg): New.
+	(print_help): Get number of columns from environment.  Print
+	--param help.  Tweak newline handling.
+	(print_param_help): New.
+	(print_filtered_help): Better handling of duplicates.  Complain
+	about undocumented switches.
+	(print_switch): New.
+	(wrap_help): Improve wrapping, use COLUMNS.
+	* opts.sh: Ignore comments in records.
+	* params.def: Fix typos and remove trailing periods.
+	* toplev.c (display_help): Don't dump --param help.
+	* doc/sourcebuild.texi: Update.
+
 2003-07-18  Richard Henderson  <rth@redhat.com>
 
 	PR target/11556
diff --git a/gcc/common.opt b/gcc/common.opt
index 7f1e995c30b9..65341d1b33cf 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -28,6 +28,7 @@ Display this information
 
 -param
 Common Separate
+--param <param>=<value>	Set paramter <param> to value.  See below for a complete list of parameters
 
 -target-help
 Common
diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi
index 593ae1fcc3ce..59ab3eb85971 100644
--- a/gcc/doc/sourcebuild.texi
+++ b/gcc/doc/sourcebuild.texi
@@ -601,12 +601,9 @@ Move to the stage directory files not included in @code{stagestuff} in
 
 @item lang.opt
 This file registers the set of switches that the front end accepts on
-the command line.  The file format is documented in the file
-@file{c.opt}.  These files are processed by the script @file{opts.sh}.
-@item lang-options.h
-This file provides entries for @code{documented_lang_options} in
-@file{toplev.c} describing command-line options the front end accepts
-for @option{--help} output.
+the command line, and their --help text.  The file format is
+documented in the file @file{c.opt}.  These files are processed by the
+script @file{opts.sh}.
 @item lang-specs.h
 This file provides entries for @code{default_compilers} in
 @file{gcc.c} which override the default of giving an error that a
diff --git a/gcc/java/ChangeLog b/gcc/java/ChangeLog
index bc27074f89dc..df76ce6ba9de 100644
--- a/gcc/java/ChangeLog
+++ b/gcc/java/ChangeLog
@@ -1,3 +1,7 @@
+2003-07-19  Neil Booth  <neil@daikokuya.co.uk>
+
+	* lang.opt: Don't show -MD_ and -MDD_.
+
 2003-07-18  Neil Booth  <neil@daikokuya.co.uk>
 
 	* lang-options.h: Remove.
diff --git a/gcc/java/lang.opt b/gcc/java/lang.opt
index 6fd0a605c3bb..987eb82e4441 100644
--- a/gcc/java/lang.opt
+++ b/gcc/java/lang.opt
@@ -34,7 +34,7 @@ Java
 ; Documented for C
 
 MD_
-Java
+Java Undocumented
 ; Documented for C
 
 MF
@@ -46,7 +46,7 @@ Java
 ; Documented for C
 
 MMD_
-Java
+Java Undocumented
 ; Documented for C
 
 MP
diff --git a/gcc/opts.c b/gcc/opts.c
index 6e966633f20d..5659d2add6cb 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -128,6 +128,12 @@ bool warn_unused_value;
 /* Hack for cooperation between set_Wunused and set_Wextra.  */
 static bool maybe_warn_unused_parameter;
 
+/* Columns of --help display.  */
+static unsigned int columns = 80;
+
+/* What to print when a switch has no documentation.  */
+static const char undocumented_msg[] = N_("This switch lacks documentation");
+
 static size_t find_opt (const char *, int);
 static int common_handle_option (size_t scode, const char *arg, int value);
 static void handle_param (const char *);
@@ -137,9 +143,11 @@ static char *write_langs (unsigned int lang_mask);
 static void complain_wrong_lang (const char *, const struct cl_option *,
 				 unsigned int lang_mask);
 static void handle_options (unsigned int, const char **, unsigned int);
-static void wrap_help (const char *help, const char *item, int item_width);
+static void wrap_help (const char *help, const char *item, unsigned int);
 static void print_help (void);
+static void print_param_help (void);
 static void print_filtered_help (unsigned int flag);
+static unsigned int print_switch (const char *text, unsigned int indent);
 
 /* Perform a binary search to find which option the command-line INPUT
    matches.  Returns its index in the option array, and N_OPTS
@@ -1487,39 +1495,104 @@ static void
 print_help (void)
 {
   size_t i;
+  const char *p;
+
+  GET_ENVIRONMENT (p, "COLUMNS");
+  if (p)
+    {
+      int value = atoi (p);
+      if (value > 0)
+	columns = value;
+    }
 
   puts (_("The following options are language-independent:\n"));
 
   print_filtered_help (CL_COMMON);
+  print_param_help ();
 
   for (i = 0; lang_names[i]; i++)
     {
-      printf (_("\nThe %s front end recognizes the following options:\n"),
+      printf (_("The %s front end recognizes the following options:\n\n"),
 	      lang_names[i]);
       print_filtered_help (1U << i);
     }
 
-  puts ( "\n" );
   display_help ();
 }
 
+/* Print the help for --param.  */
+static void
+print_param_help (void)
+{
+  size_t i;
+
+  puts (_("The --param option recognizes the following as parameters:\n"));
+
+  for (i = 0; i < LAST_PARAM; i++)
+    {
+      const char *help = compiler_params[i].help;
+      const char *param = compiler_params[i].option;
+
+      if (help == NULL || *help == '\0')
+	help = undocumented_msg;
+
+      /* Get the translation.  */
+      help = _(help);
+
+      wrap_help (help, param, strlen (param));
+    }
+
+  putchar ('\n');
+}
+
 /* Print help for a specific front-end, etc.  */
 static void
 print_filtered_help (unsigned int flag)
 {
-  size_t i, len;
-  unsigned int filter;
+  unsigned int i, len, filter, indent = 0;
+  bool duplicates = false;
+  const char *help, *opt, *tab;
+  static char *printed;
+
+  if (flag == CL_COMMON)
+    {
+      filter = flag;
+      if (!printed)
+	printed = xmalloc (cl_options_count);
+      memset (printed, 0, cl_options_count);
+    }
+  else
+    {
+      /* Don't print COMMON options twice.  */
+      filter = flag | CL_COMMON;
 
-  /* Don't print COMMON options twice.  */
-  filter = flag;
-  if (flag != CL_COMMON)
-    filter |= CL_COMMON;
+      for (i = 0; i < cl_options_count; i++)
+	{
+	  if ((cl_options[i].flags & filter) != flag)
+	    continue;
+
+	  /* Skip help for internal switches.  */
+	  if (cl_options[i].flags & CL_UNDOCUMENTED)
+	    continue;
+
+	  /* Skip switches that have already been printed, mark them to be
+	     listed later.  */
+	  if (printed[i])
+	    {
+	      duplicates = true;
+	      indent = print_switch (cl_options[i].opt_text, indent);
+	    }
+	}
+
+      if (duplicates)
+	{
+	  putchar ('\n');
+	  putchar ('\n');
+	}
+    }
 
   for (i = 0; i < cl_options_count; i++)
     {
-      const char *help;
-      const char *opt, *tab;
-
       if ((cl_options[i].flags & filter) != flag)
 	continue;
 
@@ -1527,10 +1600,15 @@ print_filtered_help (unsigned int flag)
       if (cl_options[i].flags & CL_UNDOCUMENTED)
 	continue;
 
-      /* During transition, ignore switches with no help.  */
+      /* Skip switches that have already been printed.  */
+      if (printed[i])
+	continue;
+
+      printed[i] = true;
+
       help = cl_options[i].help;
       if (!help)
-	continue;
+	help = undocumented_msg;
 
       /* Get the translation.  */
       help = _(help);
@@ -1550,14 +1628,42 @@ print_filtered_help (unsigned int flag)
 
       wrap_help (help, opt, len);
     }
+
+  putchar ('\n');
+}
+
+/* Output ITEM, of length ITEM_WIDTH, in the left column, followed by
+   word-wrapped HELP in a second column.  */
+static unsigned int
+print_switch (const char *text, unsigned int indent)
+{
+  unsigned int len = strlen (text) + 1; /* trailing comma */
+
+  if (indent)
+    {
+      putchar (',');
+      if (indent + len > columns)
+	{
+	  putchar ('\n');
+	  putchar (' ');
+	  indent = 1;
+	}
+    }
+  else
+    putchar (' ');
+
+  putchar (' ');
+  fputs (text, stdout);
+
+  return indent + len + 1;
 }
 
 /* Output ITEM, of length ITEM_WIDTH, in the left column, followed by
    word-wrapped HELP in a second column.  */
 static void
-wrap_help (const char *help, const char *item, int item_width)
+wrap_help (const char *help, const char *item, unsigned int item_width)
 {
-  const int columns = 80, col_width = 27;
+  unsigned int col_width = 27;
   unsigned int remaining, room, len;
 
   remaining = strlen (help);
@@ -1565,6 +1671,8 @@ wrap_help (const char *help, const char *item, int item_width)
   do
     {
       room = columns - 3 - MAX (col_width, item_width);
+      if (room > columns)
+	room = 0;
       len = remaining;
 
       if (room < len)
@@ -1577,7 +1685,9 @@ wrap_help (const char *help, const char *item, int item_width)
 		break;
 	      if (help[i] == ' ')
 		len = i;
-	      else if (help[i] == '-')
+	      else if ((help[i] == '-' || help[i] == '/')
+		       && help[i + 1] != ' '
+		       && ISALPHA (help[i - 1]))
 		len = i + 1;
 	    }
 	}
diff --git a/gcc/opts.sh b/gcc/opts.sh
index 13cd4c4fccc1..871c85542115 100644
--- a/gcc/opts.sh
+++ b/gcc/opts.sh
@@ -42,7 +42,7 @@ ${AWK} '
 	# Note that RS="" falls foul of gawk 3.1.2 bugs
 	/^[^ \t]/       { record = $0
 			  do { getline tmp;
-			       if (tmp != "" )
+			       if (!(tmp ~ "^[ \t]*(;|$)"))
 			          record = record "\034" tmp
 			  } while (tmp != "")
 			  print record
diff --git a/gcc/params.def b/gcc/params.def
index cb527f0feae2..1d50e2b1a04d 100644
--- a/gcc/params.def
+++ b/gcc/params.def
@@ -158,11 +158,11 @@ DEFPARAM(PARAM_LARGE_FUNCTION_INSNS,
 	 10000)
 DEFPARAM(PARAM_LARGE_FUNCTION_GROWTH,
 	 "large-function-growth",
-	 "Maximal growth due to inlining of large function (in percents)",
+	 "Maximal growth due to inlining of large function (in percent)",
 	 100)
 DEFPARAM(PARAM_INLINE_UNIT_GROWTH,
 	 "inline-unit-growth",
-	 "how much can given compilation unit grow because of the inlining (in percents)",
+	 "how much can given compilation unit grow because of the inlining (in percent)",
 	 50)
 
 /* The GCSE optimization will be disabled if it would require
@@ -253,22 +253,22 @@ must be covered by trace formation. Used when profile feedback is not available"
 	 75)
 DEFPARAM(TRACER_MAX_CODE_GROWTH,
 	 "tracer-max-code-growth",
-	 "Maximal code growth caused by tail duplication (in percents)",
+	 "Maximal code growth caused by tail duplication (in percent)",
 	 100)
 DEFPARAM(TRACER_MIN_BRANCH_RATIO,
 	 "tracer-min-branch-ratio",
 	 "Stop reverse growth if the reverse probability of best edge is less \
-than this threshold (in percents)",
+than this threshold (in percent)",
 	 10)
 DEFPARAM(TRACER_MIN_BRANCH_PROBABILITY_FEEDBACK,
 	 "tracer-min-branch-probability-feedback",
 	 "Stop forward growth if the probability of best edge is less than \
-this threshold (in percents). Used when profile feedback is available",
+this threshold (in percent). Used when profile feedback is available",
 	 80)
 DEFPARAM(TRACER_MIN_BRANCH_PROBABILITY,
 	 "tracer-min-branch-probability",
 	 "Stop forward growth if the probability of best edge is less than \
-this threshold (in percents). Used when profile feedback is not available",
+this threshold (in percent). Used when profile feedback is not available",
 	 50)
 
 /* The maximum number of incoming edges to consider for crossjumping.  */
@@ -280,7 +280,7 @@ DEFPARAM(PARAM_MAX_CROSSJUMP_EDGES,
 /* The maximum length of path considered in cse.  */
 DEFPARAM(PARAM_MAX_CSE_PATH_LENGTH,
 	 "max-cse-path-length",
-	 "The maximum length of path considered in cse.",
+	 "The maximum length of path considered in cse",
 	 10)
 
 #ifdef ENABLE_GC_ALWAYS_COLLECT
@@ -294,12 +294,12 @@ DEFPARAM(PARAM_MAX_CSE_PATH_LENGTH,
 DEFPARAM(GGC_MIN_EXPAND,
 	 "ggc-min-expand",
 	 "Minimum heap expansion to trigger garbage collection, as \
-a percentage of the total size of the heap.",
+a percentage of the total size of the heap",
 	 GGC_MIN_EXPAND_DEFAULT)
 
 DEFPARAM(GGC_MIN_HEAPSIZE,
 	 "ggc-min-heapsize",
-	 "Minimum heap size before we start collecting garbage, in kilobytes.",
+	 "Minimum heap size before we start collecting garbage, in kilobytes",
 	 GGC_MIN_HEAPSIZE_DEFAULT)
 
 #undef GGC_MIN_EXPAND_DEFAULT
diff --git a/gcc/toplev.c b/gcc/toplev.c
index cf61228dc83d..3bf601113a9c 100644
--- a/gcc/toplev.c
+++ b/gcc/toplev.c
@@ -3591,18 +3591,6 @@ display_help (void)
 {
   unsigned long i;
 
-  for (i = LAST_PARAM; i--;)
-    {
-      const char *description = compiler_params[i].help;
-      const int length = 21 - strlen (compiler_params[i].option);
-
-      if (description != NULL && *description != 0)
-	printf ("  --param %s=<value>%.*s%s\n",
-		compiler_params[i].option,
-		length > 0 ? length : 1, "                     ",
-		_(description));
-    }
-
   for (i = ARRAY_SIZE (debug_args); i--;)
     {
       if (debug_args[i].description != NULL)
-- 
GitLab