groff-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[groff] 26/32: [tbl]: Fix Savannah #61040.


From: G. Branden Robinson
Subject: [groff] 26/32: [tbl]: Fix Savannah #61040.
Date: Wed, 30 Nov 2022 07:26:12 -0500 (EST)

gbranden pushed a commit to branch master
in repository groff.

commit 950f92e25f3f446d9e4d4560e1563c5944839d8a
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Mon Nov 28 02:53:16 2022 -0600

    [tbl]: Fix Savannah #61040.
    
    [tbl]: Suppress line numbering when formatting tables, and restore it
    afterward.
    
    * src/preproc/tbl/table.cpp: Revert much of commit b69062693's
      (2011-07-20) changes to this file.  They were too complex for me to
      understand, and permitted Savannah #61040 to persist (or caused it).
    
      (ROW_START_LINE_REG, ROW_SAVE_LINE_REG, ROW_MAX_LINE_REG)
      (REPEATED_NM_SET_MACRO, REPEATED_NM_SUS_MACRO): Drop preprocessor
      macros.
    
      (SAVED_NUMBERING_LINENO, SAVED_NUMBERING_SUPPRESSION_COUNT): Add new
      preprocessor macros.
    
      (table::init_output, table::print_single_hline)
      (table::print_double_hline, table::define_bottom_macro)
      (table::do_row, table::do_top, table::do_bottom): Drop old logic.
    
      (table::init_output): When the table begins, save the current line
      number register `ln` and the count of remaining lines to be suppressed
      (the new `.nn` register).  Then suppress numbering for the next 2
      billion+ lines of output, with a groveling apology to the elegance
      police.
    
      (table::do_bottom): Restore saved value of `.nn`.  If numbering was
      active (even if suppressed), restore it with `nm` request.  If it
      wasn't, disable it, in case it was turned on inside the table region.
    
    Fixes <https://savannah.gnu.org/bugs/?61040>.  Thanks to Hans Bezemer
    for noting the practical significance of this bug.
---
 ChangeLog                 | 32 ++++++++++++++++++
 src/preproc/tbl/table.cpp | 82 +++++++++++------------------------------------
 2 files changed, 51 insertions(+), 63 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 8173b0cb8..24cbb64a2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,35 @@
+2022-11-29  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       [tbl]: Suppress line numbering when formatting tables, and
+       restore it afterward.
+
+       * src/preproc/tbl/table.cpp: Revert much of commit b69062693's
+       {2011-07-20} changes to this file.  They were too complex for me
+       to understand, and permitted Savannah #61040 to persist (or
+       caused it).
+       (ROW_START_LINE_REG, ROW_SAVE_LINE_REG, ROW_MAX_LINE_REG)
+       (REPEATED_NM_SET_MACRO, REPEATED_NM_SUS_MACRO): Drop
+       preprocessor macros.
+       (SAVED_NUMBERING_LINENO, SAVED_NUMBERING_SUPPRESSION_COUNT): Add
+       new preprocessor macros.
+       (table::init_output, table::print_single_hline)
+       (table::print_double_hline, table::define_bottom_macro)
+       (table::do_row, table::do_top, table::do_bottom): Drop old
+       logic.
+
+       (table::init_output): When the table begins, save the current
+       line number register `ln` and the count of remaining lines to be
+       suppressed (the new `.nn` register).  Then suppress numbering
+       for the next 2 billion+ lines of output, with a groveling
+       apology to the elegance police.
+       (table::do_bottom): Restore saved value of `.nn`.  If numbering
+       was active (even if suppressed), restore it with `nm` request.
+       If it wasn't, disable it, in case it was turned on inside the
+       table region.
+
+       Fixes <https://savannah.gnu.org/bugs/?61040>.  Thanks to Hans
+       Bezemer for noting the practical significance of this bug.
+
 2022-11-29  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        [tbl]: Regression-test Savannah #61040.
diff --git a/src/preproc/tbl/table.cpp b/src/preproc/tbl/table.cpp
index 39ea5621e..fbc7e994f 100644
--- a/src/preproc/tbl/table.cpp
+++ b/src/preproc/tbl/table.cpp
@@ -1,4 +1,4 @@
-/* Copyright (C) 1989-2021 Free Software Foundation, Inc.
+/* Copyright (C) 1989-2022 Free Software Foundation, Inc.
      Written by James Clark (jjc@jclark.com)
 
 This file is part of groff.
@@ -58,16 +58,13 @@ const int DEFAULT_COLUMN_SEPARATION = 3;
 #define REPEATED_VPT_MACRO PREFIX "rvpt"
 #define SUPPRESS_BOTTOM_REG PREFIX "supbot"
 #define SAVED_DN_REG PREFIX "dn"
-#define ROW_START_LINE_REG PREFIX "lnst"
-#define ROW_SAVE_LINE_REG PREFIX "lnsv"
-#define ROW_MAX_LINE_REG PREFIX "lnmx"
-#define REPEATED_NM_SET_MACRO PREFIX "rlns"
-#define REPEATED_NM_SUS_MACRO PREFIX "rlnx"
 #define SAVED_HYPHENATION_MODE_REG PREFIX "hyphmode"
 #define SAVED_HYPHENATION_LANG_NAME PREFIX "hyphlang"
 #define SAVED_HYPHENATION_MAX_LINES_REG PREFIX "hyphmaxlines"
 #define SAVED_HYPHENATION_MARGIN_REG PREFIX "hyphmargin"
 #define SAVED_HYPHENATION_SPACE_REG PREFIX "hyphspace"
+#define SAVED_NUMBERING_LINENO PREFIX "linenumber"
+#define SAVED_NUMBERING_SUPPRESSION_COUNT PREFIX "linenumbersuppresscnt"
 
 // this must be one character
 #define COMPATIBLE_REG PREFIX "c"
@@ -1821,31 +1818,6 @@ void table::init_output()
         ".de " REPEATED_VPT_MACRO "\n"
         ".vpt \\$1\n"
         ".if !'\\n(.z'' \\!." REPEATED_VPT_MACRO " \"\\$1\"\n"
-        "..\n"
-        ".de " REPEATED_NM_SET_MACRO "\n"
-        ".ie !'\\n(.z'' \\{.nm\n"
-        "\\!." REPEATED_NM_SET_MACRO " \"\\$1\"\n"
-        ".\\}\n"
-        ".el .if \\n[.nm] .if \\n[ln] \\{\\\n"
-        ".if '\\$1'd' .nr " ROW_START_LINE_REG " \\n[ln]\n"
-        ".if '\\$1's' .nm \\n[" ROW_START_LINE_REG "]\n"
-        ".if '\\$1'm' .nr " ROW_MAX_LINE_REG " \\n[ln]>?\\n[" ROW_MAX_LINE_REG 
"]\n"
-        ".\\}\n"
-        "..\n"
-        ".de " REPEATED_NM_SUS_MACRO "\n"
-        ".ie !'\\n(.z'' \\{.nm\n"
-        "\\!." REPEATED_NM_SUS_MACRO " \"\\$1\"\n"
-        ".\\}\n"
-        ".el .if \\n[.nm] .if \\n[ln] \\{\\\n"
-        ".ie '\\$1's' \\{\\\n"
-        ".nr " ROW_SAVE_LINE_REG " \\n(ln<?\\n[" ROW_MAX_LINE_REG "]\n"
-        ".nm +0 \\n[ln]+42\n"
-        ".\\}\n"
-        ".el \\{\\\n"
-        ".nr ln \\n[" ROW_SAVE_LINE_REG "]\n"
-        ".nm \\n[ln] 1\n"
-        ".\\}\n"
-        ".\\}\n"
         "..\n");
   if (!(flags & NOKEEP)) {
     prints(".de " KEEP_MACRO_NAME "\n"
@@ -1890,12 +1862,9 @@ void table::init_output()
       prints(".\\}\n");
     }
     prints(".nf\n"
-          ".if \\n[.nm] .if \\n[ln] .nm \\n[ln]\n"
-          ".nr " ROW_MAX_LINE_REG " \\n[ln]\n"
           ".ls 1\n"
           "." SECTION_DIVERSION_NAME "\n"
           ".ls\n"
-          ".if \\n[.nm] .if \\n[ln] .nm\n"
           ".rm " SECTION_DIVERSION_NAME "\n"
           ".\\}\n"
           "..\n"
@@ -1939,19 +1908,19 @@ void table::init_output()
           ".in 0\n"
           ".ls 1\n"
           ".nf\n"
-          ".if \\n[.nm] .if \\n[ln] .nm \\n[ln]\n"
           "." TABLE_DIVERSION_NAME "\n"
           ".\\}\n"
           ".rm " TABLE_DIVERSION_NAME "\n"
           ".\\}\n"
-          ".if \\n[.nm] .if \\n[ln] \\{.nm\n"
-          ".nr ln \\n[" ROW_MAX_LINE_REG "]\n"
-          ".\\}\n"
           "..\n");
   }
   prints(".ec\n"
-        ".ce 0\n"
-        ".nf\n");
+        ".ce 0\n");
+  prints(".nr " SAVED_NUMBERING_LINENO " \\n[ln]\n"
+        ".nr ln 0\n"
+        ".nr " SAVED_NUMBERING_SUPPRESSION_COUNT " \\n[.nn]\n"
+        ".nn 2147483647\n"); // 2^31-1; inelegant but effective
+  prints(".nf\n");
 }
 
 string block_width_reg(int r, int c)
@@ -2416,7 +2385,6 @@ void table::print_single_hline(int r)
 {
   prints(".vs " LINE_SEP ">?\\n[.V]u\n"
         ".ls 1\n"
-        "." REPEATED_NM_SUS_MACRO " s\n"
         "\\v'" BODY_DEPTH "'"
         "\\s[\\n[" LINESIZE_REG "]]");
   if (r > nrows - 1)
@@ -2453,8 +2421,7 @@ void table::print_single_hline(int r)
     }
   }
   prints("\\s0\n");
-  prints("." REPEATED_NM_SUS_MACRO " r\n"
-        ".ls\n"
+  prints(".ls\n"
         ".vs\n");
 }
 
@@ -2463,7 +2430,6 @@ void table::print_double_hline(int r)
   prints(".vs " LINE_SEP "+" DOUBLE_LINE_SEP
         ">?\\n[.V]u\n"
         ".ls 1\n"
-        "." REPEATED_NM_SUS_MACRO " s\n"
         "\\v'" BODY_DEPTH "'"
         "\\s[\\n[" LINESIZE_REG "]]");
   if (r > nrows - 1)
@@ -2522,7 +2488,6 @@ void table::print_double_hline(int r)
     }
   }
   prints("\\s0\n"
-        "." REPEATED_NM_SUS_MACRO " r\n"
         ".ls\n"
         ".vs\n");
 }
@@ -2729,8 +2694,7 @@ void table::define_bottom_macro()
     print_single_hline(0);
     prints(".\\}\n");
   }
-  prints("." REPEATED_NM_SUS_MACRO " s\n"
-        ".ls 1\n");
+  prints(".ls 1\n");
   for (vertical_rule *p = vrule_list; p; p = p->next)
     p->contribute_to_bottom_macro(this);
   if (flags & DOUBLEBOX)
@@ -2747,8 +2711,7 @@ void table::define_bottom_macro()
           ".sp -1\n"
           "\\v'" BODY_DEPTH "'\\h'|\\n[TW]u'\\s[\\n[" LINESIZE_REG "]]"
           "\\D'l 0 |\\n[" TOP_REG "]u-1v'\\s0\n");
-  prints("." REPEATED_NM_SUS_MACRO " r\n"
-        ".ls\n");
+  prints(".ls\n");
   prints(".nr " LAST_PASSED_ROW_REG " \\n[" CURRENT_ROW_REG "]\n"
         ".sp |\\n[" SAVED_VERTICAL_POS_REG "]u\n"
         "." REPEATED_VPT_MACRO " 1\n"
@@ -2824,8 +2787,6 @@ void table::do_row(int r)
   // we might have had a .TH, for example,  since we last tried
   if (!(flags & NOKEEP) && row_begins_section(r))
     prints(".if \\n[" USE_KEEPS_REG "] ." KEEP_MACRO_NAME "\n");
-  prints("." REPEATED_NM_SET_MACRO " d\n"
-        ".nr " ROW_MAX_LINE_REG " \\n[ln]\n");
   printfs(".mk %1\n", row_start_reg(r));
   prints(".mk " BOTTOM_REG "\n"
         "." REPEATED_VPT_MACRO " 0\n");
@@ -2922,7 +2883,6 @@ void table::do_row(int r)
     table_entry *e = entry[r][c];
     if (e) {
       if (e->end_row == r && e->to_simple_entry() == 0) {
-       prints("." REPEATED_NM_SET_MACRO " s\n");
        e->position_vertically();
        e->print();
        prints(".nr " BOTTOM_REG " \\n[" BOTTOM_REG "]>?\\n[.d]\n");
@@ -2931,8 +2891,7 @@ void table::do_row(int r)
       c = e->end_col;
     }
   }
-  prints("." REPEATED_NM_SET_MACRO " m\n"
-        "." REPEATED_VPT_MACRO " 1\n"
+  prints("." REPEATED_VPT_MACRO " 1\n"
         ".sp |\\n[" BOTTOM_REG "]u\n"
         "\\*[" TRANSPARENT_STRING_NAME "].nr " NEED_BOTTOM_RULE_REG " 1\n");
   if (r != nrows - 1 && (flags & ALLBOX)) {
@@ -2960,7 +2919,6 @@ void table::do_row(int r)
     if (!(flags & NOKEEP) && row_ends_section(r))
       prints(".if \\n[" USE_KEEPS_REG "] ." RELEASE_MACRO_NAME "\n");
   }
-  prints(".if \\n[.nm] .if \\n[ln] .nr ln \\n[" ROW_MAX_LINE_REG "]\n");
 }
 
 void table::do_top()
@@ -2969,8 +2927,7 @@ void table::do_top()
   if (!(flags & NOKEEP) && (flags & (BOX | DOUBLEBOX | ALLBOX)))
     prints("." TABLE_KEEP_MACRO_NAME "\n");
   if (flags & DOUBLEBOX) {
-    prints("." REPEATED_NM_SUS_MACRO " s\n"
-          ".ls 1\n"
+    prints(".ls 1\n"
           ".vs " LINE_SEP ">?\\n[.V]u\n"
           "\\v'" BODY_DEPTH "'\\s[\\n[" LINESIZE_REG "]]\\D'l \\n[TW]u 
0'\\s0\n"
           ".vs\n"
@@ -2984,8 +2941,7 @@ void table::do_top()
            "\n",
            column_divide_reg(0),
            column_divide_reg(ncolumns));
-    prints("." REPEATED_NM_SUS_MACRO " r\n"
-          ".ls\n"
+    prints(".ls\n"
           ".vs\n");
   }
   else if (flags & (ALLBOX | BOX)) {
@@ -3019,10 +2975,6 @@ void table::do_bottom()
         "..\n");
   if (!(flags & NOKEEP) && (flags & (BOX | DOUBLEBOX | ALLBOX)))
     prints("." TABLE_RELEASE_MACRO_NAME "\n");
-  else
-    prints(".if \\n[.nm] .if \\n[ln] \\{.nm\n"
-          ".nr ln \\n[" ROW_MAX_LINE_REG "]\n"
-          ".\\}\n");
   if (flags & DOUBLEBOX)
     prints(".sp " DOUBLE_LINE_SEP "\n");
   // Horizontal box lines take up an entire row on nroff devices (maybe
@@ -3035,6 +2987,10 @@ void table::do_bottom()
   if (flags & DOUBLEBOX)
     prints(".if n .sp\n");
   prints("." RESET_MACRO_NAME "\n"
+        ".nn \\n[" SAVED_NUMBERING_SUPPRESSION_COUNT "]\n"
+        ".ie \\n[" SAVED_NUMBERING_LINENO "] \\\n"
+        ".    nm \\n[" SAVED_NUMBERING_LINENO "]\n"
+        ".el .nm\n"
         ".fc\n"
         ".cp \\n(" COMPATIBLE_REG "\n");
 }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]