gbranden pushed a commit to branch master
in repository groff.

commit 8b88431be795a081ddac782614f0a3976c8d90e2
Author: G. Branden Robinson <[email protected]>
AuthorDate: Wed Aug 7 08:57:26 2024 -0500

    [troff]: Implement new `phcode` request.
    
    * src/roff/troff/input.cpp (report_hyphenation_codes): Add.
      (init_input_requests): Wire up `phcode` request name to
      `report_hyphenation_codes()`.
    
    * doc/groff.texi (Manipulating Hyphenation, Debugging):
    * man/groff.7.man (Request short reference, Debugging):
    * man/groff_diff.7.man (New requests, Debugging):
    * NEWS: Document it.
---
 ChangeLog                | 13 +++++++++++++
 NEWS                     |  3 +++
 doc/groff.texi.in        |  9 +++++++++
 man/groff.7.man          |  9 +++++++++
 man/groff_diff.7.man     | 14 ++++++++++++++
 src/roff/troff/input.cpp | 39 +++++++++++++++++++++++++++++++++++++++
 6 files changed, 87 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index aa28b4ac7..b30151cb6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2024-08-08  G. Branden Robinson <[email protected]>
+
+       [troff]: Implement new `phcode` request.
+
+       * src/roff/troff/input.cpp (report_hyphenation_codes): Add.
+       (init_input_requests): Wire up `phcode` request name to
+       `report_hyphenation_codes()`.
+
+       * doc/groff.texi (Manipulating Hyphenation, Debugging):
+       * man/groff.7.man (Request short reference, Debugging):
+       * man/groff_diff.7.man (New requests, Debugging):
+       * NEWS: Document it.
+
 2024-08-08  G. Branden Robinson <[email protected]>
 
        * src/roff/troff/input.cpp (set_hyphenation_codes): Handle the
diff --git a/NEWS b/NEWS
index e34aa1352..208370027 100644
--- a/NEWS
+++ b/NEWS
@@ -87,6 +87,9 @@ o A new request, `pcolor`, reports to the standard error 
stream the
 o A new request, `pcomposite`, reports to the standard error stream the
   current list of defined composite characters.
 
+o A new request, `phcode`, reports to the standard error stream the
+  hyphenation code of each ordinary or special character argument.
+
 o A new request, `phw`, reports to the standard error stream the current
   list of hyphenation exceptions.
 
diff --git a/doc/groff.texi.in b/doc/groff.texi.in
index 02749c5ab..f0d5fad50 100644
--- a/doc/groff.texi.in
+++ b/doc/groff.texi.in
@@ -8985,6 +8985,9 @@ If for some reason you desire to remove a character's 
hyphenation code,
 use @code{hcode} to copy the code of a punctuation character to it; for
 example, @samp{.hcode � $} assigns a hyphenation code of zero to
 @samp{�} (unless @samp{$} has already been assigned a different one).
+
+The @code{phcode} request may be helpful to troubleshoot hyphenation
+code assignments.  @xref{Debugging}.
 @endDefreq
 
 @DefreqList {hla, [@Var{lang}]}
@@ -17129,6 +17132,12 @@ Report the state of the current environment followed 
by that of all
 other environments to the standard error stream.
 @endDefreq
 
+@Defreq {phcode, c @r{@dots{}}}
+Report, to the standard error stream, the hyphenation code of each
+ordinary or special character@tie{}@var{c}.  Special characters are
+listed in bracketed syntax using the default escape character.
+@endDefreq
+
 @Defreq {phw, }
 @cindex dumping hyphenation exceptions (@code{phw})
 @cindex hyphenation exceptions, dumping (@code{phw})
diff --git a/man/groff.7.man b/man/groff.7.man
index aa960b549..b5596d228 100644
--- a/man/groff.7.man
+++ b/man/groff.7.man
@@ -3931,6 +3931,13 @@ Report the state of the current environment followed by 
that of all
 other environments to the standard error stream.
 .
 .TPx
+.REQ .phcode "c \fR\&.\|.\|.\&\fP"
+Report,
+to the standard error stream,
+the hyphenation code of each ordinary or special
+.RI character\~ c .
+.
+.TPx
 .REQ .phw
 Report,
 to the standard error stream,
@@ -8422,6 +8429,8 @@ composite characters
 .RB ( .pcomposite );
 environments
 .RB ( .pev );
+hyphenation codes
+.RB ( .phcode );
 hyphenation exceptions
 .RB ( .phw );
 registers
diff --git a/man/groff_diff.7.man b/man/groff_diff.7.man
index e5941cf1d..3e3dbf81b 100644
--- a/man/groff_diff.7.man
+++ b/man/groff_diff.7.man
@@ -3216,6 +3216,18 @@ other environments to the standard error stream.
 .
 .
 .TP
+.BI .phcode\~ c\~\c
+\&.\|.\|.
+Report,
+to the standard error stream,
+the hyphenation code of each ordinary or special
+.RI character\~ c .
+.
+Special characters are listed in bracketed syntax using the default
+escape character.
+.
+.
+.TP
 .B .phw
 Report,
 to the standard error stream,
@@ -5388,6 +5400,8 @@ composite characters
 .RB ( pcomposite ),
 environments
 .RB ( pev ),
+hyphenation codes
+.RB ( .phcode ),
 hyphenation exceptions
 .RB ( phw ),
 registers
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 946b93570..7a75e4b28 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -7339,6 +7339,44 @@ static void set_hyphenation_codes()
   skip_line();
 }
 
+static void report_hyphenation_codes()
+{
+  tok.skip();
+  if (tok.is_newline() || tok.is_eof()) {
+    warning(WARN_MISSING, "hyphenation code report request expects"
+           " arguments");
+    skip_line();
+    return;
+  }
+  while (!tok.is_newline() && !tok.is_eof()) {
+    unsigned char ch = tok.ch();
+    if (csdigit(ch)) {
+      error("a numeral cannot have a hyphenation code");
+      break;
+    }
+    charinfo *ci = tok.get_char();
+    if (0 == ch) {
+      // Is the argument a non-special-character escape sequence?
+      if (0 /* nullptr */ == ci) {
+       error("%1 cannot have a hyphenation code", tok.description());
+       break;
+      }
+    }
+    unsigned char code = ci->get_hyphenation_code();
+    if (ci->get_translation()
+       && ci->get_translation()->get_translation_input())
+      code = ci->get_translation()->get_hyphenation_code();
+    if (0 == ch)
+      errprint("\\[%1]\t%2\n", ci->nm.contents(), int(code));
+    else
+      errprint("%1\t%2\n", ch, int(code));
+    tok.next();
+    tok.skip();
+  }
+  fflush(stderr);
+  skip_line();
+}
+
 void hyphenation_patterns_file_code()
 {
   tok.skip();
@@ -8630,6 +8668,7 @@ void init_input_requests()
   init_request("pc", set_page_character);
   init_request("pcolor", report_color);
   init_request("pcomposite", report_composite_characters);
+  init_request("phcode", report_hyphenation_codes);
   init_request("pi", pipe_output);
   init_request("pm", print_macros);
   init_request("psbb", ps_bbox_request);

_______________________________________________
Groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit

Reply via email to