groff-commit
[Top][All Lists]
Advanced

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

[groff] 01/03: src/preproc/tbl/table.cpp: Update assertions.


From: G. Branden Robinson
Subject: [groff] 01/03: src/preproc/tbl/table.cpp: Update assertions.
Date: Fri, 9 Oct 2020 05:18:59 -0400 (EDT)

gbranden pushed a commit to branch master
in repository groff.

commit 3cab2cf735b0d6b4271d80f8a5d0e36a0db3a66f
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Fri Oct 9 06:27:48 2020 +1100

    src/preproc/tbl/table.cpp: Update assertions.
    
    src/preproc/tbl/table.cpp (simple_entry::position_vertically):
    (block_entry::position_vertically):
    (table::determine_row_type):
    (printfs): Update assertions to indicate what actually went wrong.
    
    assert(0) is evil; see 642353ef06b3c2b49f74b71e0d5ecdfa866fe3de, 13
    August.
    
    Also remove junk whitespace.
    Also wrap some long lines.
---
 ChangeLog                 |  8 ++++++
 src/preproc/tbl/table.cpp | 73 ++++++++++++++++++++++++++---------------------
 2 files changed, 49 insertions(+), 32 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index b0aa742..3968d82 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2020-10-09  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       * src/preproc/tbl/table.cpp (simple_entry::position_vertically):
+       (block_entry::position_vertically):
+       (table::determine_row_type):
+       (printfs): Update assertions to indicate what actually went
+       wrong.
+
 2020-10-02  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        * src/roff/troff/node.cpp: Make diagnostics slightly more
diff --git a/src/preproc/tbl/table.cpp b/src/preproc/tbl/table.cpp
index 108e198..a4cf162 100644
--- a/src/preproc/tbl/table.cpp
+++ b/src/preproc/tbl/table.cpp
@@ -412,15 +412,16 @@ void simple_entry::position_vertically()
       // Peform the motion in two stages so that the center is rounded
       // vertically upwards even if net vertical motion is upwards.
       printfs(".sp |\\n[%1]u\n", row_start_reg(start_row));
-      printfs(".sp \\n[" BOTTOM_REG "]u-\\n[%1]u-1v/2u\n", 
+      printfs(".sp \\n[" BOTTOM_REG "]u-\\n[%1]u-1v/2u\n",
              row_start_reg(start_row));
       break;
     case entry_modifier::BOTTOM:
-      printfs(".sp |\\n[%1]u+\\n[" BOTTOM_REG "]u-\\n[%1]u-1v\n", 
+      printfs(".sp |\\n[%1]u+\\n[" BOTTOM_REG "]u-\\n[%1]u-1v\n",
              row_start_reg(start_row));
       break;
     default:
-      assert(0);
+      assert(0 == "simple entry vertical position modifier not TOP,"
+                 " CENTER, or BOTTOM");
     }
 }
 
@@ -648,17 +649,18 @@ void block_entry::position_vertically()
       // Peform the motion in two stages so that the center is rounded
       // vertically upwards even if net vertical motion is upwards.
       printfs(".sp |\\n[%1]u\n", row_start_reg(start_row));
-      printfs(".sp \\n[" BOTTOM_REG "]u-\\n[%1]u-\\n[%2]u/2u\n", 
+      printfs(".sp \\n[" BOTTOM_REG "]u-\\n[%1]u-\\n[%2]u/2u\n",
              row_start_reg(start_row),
              block_height_reg(start_row, start_col));
       break;
     case entry_modifier::BOTTOM:
-      printfs(".sp |\\n[%1]u+\\n[" BOTTOM_REG "]u-\\n[%1]u-\\n[%2]u\n", 
+      printfs(".sp |\\n[%1]u+\\n[" BOTTOM_REG "]u-\\n[%1]u-\\n[%2]u\n",
              row_start_reg(start_row),
              block_height_reg(start_row, start_col));
       break;
     default:
-      assert(0);
+      assert(0 == "block entry vertical position modifier not TOP,"
+                 " CENTER, or BOTTOM");
     }
   if (mod->stagger)
     prints(".sp -.5v\n");
@@ -710,8 +712,8 @@ void block_entry::do_divert(int alphabetic, int ncols, 
const string *mw,
   else
     // Assign each column with a block entry 1/(n+1) of the line
     // width, where n is the column count.
-    printfs("(u;\\n[%1]>?(\\n[.l]*%2/%3))", 
-           span_width_reg(start_col, end_col), 
+    printfs("(u;\\n[%1]>?(\\n[.l]*%2/%3))",
+           span_width_reg(start_col, end_col),
            as_string(end_col - start_col + 1),
            as_string(ncols + 1));
   if (alphabetic)
@@ -864,13 +866,14 @@ void single_line_entry::simple_print(int dont_move)
   if (!dont_move)
     prints("\\v'" BAR_HEIGHT "'");
 }
-  
+
 single_line_entry *single_line_entry::to_single_line_entry()
 {
   return this;
 }
 
-double_line_entry::double_line_entry(const table *p, const entry_modifier *m)
+double_line_entry::double_line_entry(const table *p,
+                                    const entry_modifier *m)
 : line_entry(p, m)
 {
 }
@@ -1402,7 +1405,8 @@ void table::do_hspan(int r, int c)
     /*
       l l
       ^ s */
-    error("impossible horizontal span at row %1, column %2", r + 1, c + 1);
+    error("impossible horizontal span at row %1, column %2", r + 1,
+         c + 1);
   }
   else {
     e->end_col = c;
@@ -1432,7 +1436,8 @@ void table::do_vspan(int r, int c)
   if (e->start_col != c) {
     /* l s
        l ^ */
-    error("impossible vertical span at row %1, column %2", r + 1, c + 1);
+    error("impossible vertical span at row %1, column %2", r + 1,
+         c + 1);
   }
   else {
     for (int i = c; i <= e->end_col; i++) {
@@ -1486,8 +1491,8 @@ int find_decimal_point(const char *s, char 
decimal_point_char,
   return possible_pos;
 }
 
-void table::add_entry(int r, int c, const string &str, const entry_format *f,
-                     const char *fn, int ln)
+void table::add_entry(int r, int c, const string &str,
+                     const entry_format *f, const char *fn, int ln)
 {
   allocate(r);
   table_entry *e = 0;
@@ -1608,17 +1613,20 @@ void table::add_entry(int r, int c, const string &str, 
const entry_format *f,
     case FORMAT_HLINE:
       if (str.length() != 0)
        error_with_file_and_line(fn, ln,
-                                "non-empty data entry for '_' format ignored");
+                                "non-empty data entry for '_' format"
+                                " ignored");
       e = new single_line_entry(this, f);
       break;
     case FORMAT_DOUBLE_HLINE:
       if (str.length() != 0)
        error_with_file_and_line(fn, ln,
-                                "non-empty data entry for '=' format ignored");
+                                "non-empty data entry for '=' format"
+                                " ignored");
       e = new double_line_entry(this, f);
       break;
     default:
-      assert(0);
+      assert(0 == "table column format not in FORMAT_{SPAN,LEFT,CENTER,"
+                 "RIGHT,NUMERIC,ALPHABETIC,VSPAN,HLINE,DOUBLE_HLINE}");
     }
   }
   if (e) {
@@ -1626,7 +1634,8 @@ void table::add_entry(int r, int c, const string &str, 
const entry_format *f,
     if (preve) {
       /* c s
          ^ l */
-      error_with_file_and_line(fn, ln, "row %1, column %2 already spanned",
+      error_with_file_and_line(fn, ln, "row %1, column %2 already"
+                                      " spanned",
                               r + 1, c + 1);
       delete e;
     }
@@ -1710,7 +1719,7 @@ void table::determine_row_type()
            had_double = 1;
            break;
          default:
-           assert(0);
+           assert(0 == "table entry line type not in {-1, 0, 1, 2}");
          }
          if (had_non_line)
            break;
@@ -1965,14 +1974,14 @@ string row_start_reg(int row)
   static char name[sizeof(ROW_START_PREFIX)+INT_DIGITS];
   sprintf(name, ROW_START_PREFIX "%d", row);
   return string(name);
-}  
+}
 
 string column_start_reg(int col)
 {
   static char name[sizeof(COLUMN_START_PREFIX)+INT_DIGITS];
   sprintf(name, COLUMN_START_PREFIX "%d", col);
   return string(name);
-}  
+}
 
 string column_end_reg(int col)
 {
@@ -2007,7 +2016,7 @@ void init_span_reg(int start_col, int end_col)
 void compute_span_width(int start_col, int end_col)
 {
   printfs(".nr %1 \\n[%1]>?(\\n[%2]+\\n[%3])\n"
-         ".if \\n[%4] .nr %1 \\n[%1]>?(\\n[%4]+2n)\n", 
+         ".if \\n[%4] .nr %1 \\n[%1]>?(\\n[%4]+2n)\n",
          span_width_reg(start_col, end_col),
          span_left_numeric_width_reg(start_col, end_col),
          span_right_numeric_width_reg(start_col, end_col),
@@ -2021,7 +2030,7 @@ void compute_span_width(int start_col, int end_col)
 void table::divide_span(int start_col, int end_col)
 {
   assert(end_col > start_col);
-  printfs(".nr " NEEDED_REG " \\n[%1]-(\\n[%2]", 
+  printfs(".nr " NEEDED_REG " \\n[%1]-(\\n[%2]",
          span_width_reg(start_col, end_col),
          span_width_reg(start_col, start_col));
   int i;
@@ -2036,7 +2045,7 @@ void table::divide_span(int start_col, int end_col)
          as_string(end_col - start_col + 1));
   prints(".if \\n[" NEEDED_REG "] \\{");
   for (i = start_col; i <= end_col; i++)
-    printfs(".nr %1 +\\n[" NEEDED_REG "]\n", 
+    printfs(".nr %1 +\\n[" NEEDED_REG "]\n",
            span_width_reg(i, i));
   int equal_flag = 0;
   for (i = start_col; i <= end_col && !equal_flag; i++)
@@ -2045,7 +2054,7 @@ void table::divide_span(int start_col, int end_col)
   if (equal_flag) {
     for (i = 0; i < ncolumns; i++)
       if (i < start_col || i > end_col)
-       printfs(".nr %1 +\\n[" NEEDED_REG "]\n", 
+       printfs(".nr %1 +\\n[" NEEDED_REG "]\n",
            span_width_reg(i, i));
   }
   prints(".\\}\n");
@@ -2066,7 +2075,7 @@ void table::sum_columns(int start_col, int end_col, int 
do_expand)
     if (!do_expand)
       return;
   }
-  printfs(".nr %1 \\n[%2]", 
+  printfs(".nr %1 \\n[%2]",
          span_width_reg(start_col, end_col),
          span_width_reg(start_col, start_col));
   for (i = start_col + 1; i <= end_col; i++)
@@ -2259,7 +2268,7 @@ void table::make_columns_equal()
     prints('\n');
     for (i = first + 1; i < ncolumns; i++)
       if (equal[i])
-       printfs(".nr %1 \\n[%2]\n", 
+       printfs(".nr %1 \\n[%2]\n",
                span_width_reg(i, i),
                span_width_reg(first, first));
   }
@@ -2351,7 +2360,7 @@ void table::print_single_hline(int r)
   else {
     int start_col = 0;
     for (;;) {
-      while (start_col < ncolumns 
+      while (start_col < ncolumns
             && entry[r][start_col] != 0
             && entry[r][start_col]->start_row != r)
        start_col++;
@@ -2402,7 +2411,7 @@ void table::print_double_hline(int r)
   else {
     int start_col = 0;
     for (;;) {
-      while (start_col < ncolumns 
+      while (start_col < ncolumns
             && entry[r][start_col] != 0
             && entry[r][start_col]->start_row != r)
        start_col++;
@@ -2468,7 +2477,7 @@ void table::compute_vrule_top_adjust(int start_row, int 
col, string &result)
     if (start_row == 0)
       return;
     for (stuff *p = stuff_list; p && p->row <= start_row; p = p->next)
-      if (p->row == start_row 
+      if (p->row == start_row
          && (p->is_single_line() || p->is_double_line()))
        return;
   }
@@ -2609,7 +2618,7 @@ void table::build_vrule_list()
     for (col = 0; col < ncolumns+1; col++)
       if (vline[end_row][col] > 0
          && !vline_spanned(end_row, col)
-         && (end_row == nrows - 1 
+         && (end_row == nrows - 1
              || vline[end_row+1][col] != vline[end_row][col]
              || vline_spanned(end_row+1, col))) {
        int start_row;
@@ -3011,7 +3020,7 @@ void printfs(const char *s, const string &arg1, const 
string &arg2,
          prints('%');
          break;
        default:
-         assert(0);
+         assert(0 == "printfs format character not in [1-9%]");
        }
       }
       else



reply via email to

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