]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Fix formatting of long function description in chew output
authorTom Tromey <tom@tromey.com>
Fri, 17 Feb 2023 19:12:11 +0000 (12:12 -0700)
committerTom Tromey <tom@tromey.com>
Mon, 20 Feb 2023 21:35:15 +0000 (14:35 -0700)
Currently, if a function description spans a line, the resulting info
can look like this:

 -- Function: long bfd_canonicalize_reloc
     (bfd *abfd, asection *sec, arelent **loc, asymbol **syms); Call the
     back end associated with the open BFD ABFD and translate the
     external form of the relocation information attached to SEC into
     the internal canonical form.  Place the table into memory at LOC,

That is, the function prototype runs together with the text in an ugly
way.  This patch fixes this by introducing a new primitive, so that
the generated Texinfo can be a bit nicer.  Now this output looks like:

 -- Function: long bfd_canonicalize_reloc (bfd *abfd, asection *sec,
          arelent **loc, asymbol **syms);
     Call the back end associated with the open BFD ABFD and translate
     the external form of the relocation information attached to SEC

2023-02-17  Tom Tromey  <tom@tromey.com>

* doc/doc.str (SYNOPSIS): Use collapse_whitespace.
* doc/chew.c (collapse_whitespace): New function.
(main): Register collapse_whitespace.

bfd/ChangeLog
bfd/doc/chew.c
bfd/doc/doc.str

index e160e4472dfc595b029b64b8fa9a8ff8f36def3f..2b48781872177ed8f3af3a59e168f3a8d4379004 100644 (file)
@@ -1,3 +1,9 @@
+2023-02-17  Tom Tromey  <tom@tromey.com>
+
+       * doc/doc.str (SYNOPSIS): Use collapse_whitespace.
+       * doc/chew.c (collapse_whitespace): New function.
+       (main): Register collapse_whitespace.
+
 2023-02-07  Tom Tromey  <tom@tromey.com>
 
        * bfd.c, cache.c, compress.c, opncls.c: Remove RETURNS from
index cd399697abdca39d456ed43a18e698338a782dd5..e8478969d64b46d5e21291eaf3b9744bb683d66e 100644 (file)
@@ -884,6 +884,38 @@ kill_bogus_lines (void)
 
 }
 
+static void
+collapse_whitespace (void)
+{
+  int last_was_ws = 0;
+  int idx;
+
+  string_type out;
+  init_string (&out);
+
+  for (idx = 0; at (tos, idx) != 0; ++idx)
+    {
+      char c = at (tos, idx);
+      if (isspace (c))
+       {
+         if (!last_was_ws)
+           {
+             catchar (&out, ' ');
+             last_was_ws = 1;
+           }
+       }
+      else
+       {
+         catchar (&out, c);
+         last_was_ws = 0;
+       }
+    }
+
+  pc++;
+  delete_string (tos);
+  *tos = out;
+}
+
 static void
 indent (void)
 {
@@ -1485,6 +1517,7 @@ main (int ac, char *av[])
   add_intrinsic ("indent", indent);
   add_intrinsic ("print_stack_level", print_stack_level);
   add_intrinsic ("strip_trailing_newlines", strip_trailing_newlines);
+  add_intrinsic ("collapse_whitespace", collapse_whitespace);
 
   internal_mode = xmalloc (sizeof (intptr_t));
   *internal_mode = 0;
index 2a0953a3ece4b5f64997be4e71bd0ca5632cb263..5077ada98123b092e172b4f4905b52d016d0de85 100644 (file)
@@ -55,8 +55,10 @@ variable synopsis_seen
        "@deftypefn {Function} " catstr
        get_stuff_in_command  
        kill_bogus_lines
+       collapse_whitespace
        indent
        catstr
+       "\n" catstr
        ;
 
 : func