gbranden pushed a commit to branch master
in repository groff.

commit d84dd6ddc7b14fe2d79d1e4542b294e2fbcfa065
Author: G. Branden Robinson <g.branden.robin...@gmail.com>
AuthorDate: Tue Feb 4 05:36:08 2025 -0600

    [troff]: Add experimental charinfo dump feature.
    
    * src/roff/troff/charinfo.h (class charinfo): Declare `dump()` member
      function, taking and returning no arguments.
    
    * src/roff/troff/input.cpp (charinfo::dump): Implement it.
    
      (report_character_request): Add request handler that iterates each
      ordinary or special character in the argument and calls `dump()` on
      it.
    
      (init_input_requests): Wire up `pchar` request to handler.
---
 ChangeLog                 | 13 ++++++++++++
 src/roff/troff/charinfo.h |  1 +
 src/roff/troff/input.cpp  | 53 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 67 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index f1fcffd2f..ddb08d0de 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2025-02-04  G. Branden Robinson <g.branden.robin...@gmail.com>
+
+       [troff]: Add experimental charinfo dump feature.
+
+       * src/roff/troff/charinfo.h (class charinfo): Declare `dump()`
+       member function, taking and returning no arguments.
+
+       * src/roff/troff/input.cpp (charinfo::dump): Implement it.
+       (report_character_request): Add request handler that iterates
+       each ordinary or special character in the argument and calls
+       `dump()` on it.
+       (init_input_requests): Wire up `pchar` request to handler.
+
 2025-02-04  G. Branden Robinson <g.branden.robin...@gmail.com>
 
        * src/roff/troff/input.cpp (define_character): Refactor and
diff --git a/src/roff/troff/charinfo.h b/src/roff/troff/charinfo.h
index b44a53f40..fecd10347 100644
--- a/src/roff/troff/charinfo.h
+++ b/src/roff/troff/charinfo.h
@@ -111,6 +111,7 @@ public:
   bool contains(int, bool = false);
   bool contains(symbol, bool = false);
   bool contains(charinfo *, bool = false);
+  void dump();
 };
 
 charinfo *get_charinfo(symbol);
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index f9406fd50..5c350101f 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -4680,6 +4680,29 @@ static void define_special_character_request()
   define_character(CHAR_SPECIAL_FALLBACK);
 }
 
+static void report_character_request()
+{
+  if (!has_arg()) {
+    warning(WARN_MISSING, "character report request expects arguments");
+    skip_line();
+    return;
+  }
+  charinfo *ci;
+  do {
+    ci = tok.get_char();
+    if (0 /* nullptr */ == ci)
+      warning(WARN_CHAR, "%1 is not a character", tok.description());
+    else {
+      // A charinfo doesn't know the name by which it is accessed.
+      errprint("%1\n", tok.description());
+      fflush(stderr);
+      ci->dump();
+    }
+    tok.next();
+  } while (!tok.is_newline() && !tok.is_eof());
+  skip_line();
+}
+
 static void remove_character()
 {
   if (!has_arg()) {
@@ -9415,6 +9438,7 @@ void init_input_requests()
   init_request("opena", opena_request);
   init_request("output", output_request);
   init_request("pc", set_page_character);
+  init_request("pchar", report_character_request);
   init_request("pcolor", report_color);
   init_request("pcomposite", report_composite_characters);
   init_request("phcode", report_hyphenation_codes);
@@ -10186,6 +10210,35 @@ bool charinfo::contains(charinfo *, bool)
   return false;
 }
 
+void charinfo::dump()
+{
+  if (translation != 0 /* nullptr */)
+    errprint("  is translated\n");
+  else
+    errprint("  is not translated\n");
+  if (mac != 0 /* nullptr */)
+    errprint("  has a macro\n");
+  else
+    errprint("  does not have a macro\n");
+  errprint("  special translation: %1\n",
+          static_cast<int>(special_translation));
+  errprint("  hyphenation code: %1\n",
+          static_cast<int>(hyphenation_code));
+  errprint("  flags: %1\n", flags);
+  errprint("  ASCII code: %1\n", static_cast<int>(ascii_code));
+  errprint("  asciify code: %1\n", static_cast<int>(asciify_code));
+  errprint("  is%1 found\n", is_not_found ? " not" : "");
+  errprint("  is%1 transparently translatable\n",
+          is_transparently_translatable ? "" : " not");
+  errprint("  is%1 translatable as input\n",
+          translatable_as_input ? "" : " not");
+  const char *modestr = character_mode_description(mode);
+  if (strcmp(modestr, "") == 0)
+    modestr =" normal";
+  errprint("  mode:%1\n", modestr);
+  fflush(stderr);
+}
+
 symbol UNNAMED_SYMBOL("---");
 
 // For numbered characters not between 0 and 255, we make a symbol out

_______________________________________________
groff-commit mailing list
groff-commit@gnu.org
https://lists.gnu.org/mailman/listinfo/groff-commit

Reply via email to