public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: binutils@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 1/4] Fix formatting of long function description in chew output
Date: Fri, 17 Feb 2023 12:29:02 -0700	[thread overview]
Message-ID: <20230217192905.3160819-2-tom@tromey.com> (raw)
In-Reply-To: <20230217192905.3160819-1-tom@tromey.com>

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

bfd/ChangeLog
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   |  6 ++++++
 bfd/doc/chew.c  | 33 +++++++++++++++++++++++++++++++++
 bfd/doc/doc.str |  2 ++
 3 files changed, 41 insertions(+)

diff --git a/bfd/doc/chew.c b/bfd/doc/chew.c
index 19e3781bdda..eca9305fee0 100644
--- a/bfd/doc/chew.c
+++ b/bfd/doc/chew.c
@@ -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)
 {
@@ -1479,6 +1511,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;
diff --git a/bfd/doc/doc.str b/bfd/doc/doc.str
index 2a0953a3ece..5077ada9812 100644
--- a/bfd/doc/doc.str
+++ b/bfd/doc/doc.str
@@ -55,8 +55,10 @@ variable synopsis_seen
 	"@deftypefn {Function} " catstr
 	get_stuff_in_command  
 	kill_bogus_lines
+	collapse_whitespace
 	indent
 	catstr
+	"\n" catstr
 	;
 
 : func
-- 
2.39.1


  reply	other threads:[~2023-02-17 19:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-17 19:29 [PATCH 0/4] More fixes to chew documentation Tom Tromey
2023-02-17 19:29 ` Tom Tromey [this message]
2023-02-17 19:29 ` [PATCH 2/4] Don't use chew comments for static functions Tom Tromey
2023-02-17 19:29 ` [PATCH 3/4] Hoist the SECTION comment in opncls.c Tom Tromey
2023-02-17 19:29 ` [PATCH 4/4] Redefine FUNCTION in doc.str Tom Tromey
2023-02-20 14:59 ` [PATCH 0/4] More fixes to chew documentation Nick Clifton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230217192905.3160819-2-tom@tromey.com \
    --to=tom@tromey.com \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).