tab: Merge struct tab_table into struct table.
authorBen Pfaff <blp@cs.stanford.edu>
Wed, 25 Dec 2019 23:02:42 +0000 (23:02 +0000)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 29 Dec 2019 05:28:10 +0000 (05:28 +0000)
src/output/pivot-output.c
src/output/render.c
src/output/tab.c
src/output/tab.h
src/output/table.c
src/output/table.h
src/output/text-item.c
tests/output/render-test.c

index aca56e7be405f8346875f186a2bb8236cd942f72..1325234f35c909a1973e00e804fa9adb93e09559 100644 (file)
@@ -91,7 +91,7 @@ area_style_override (struct pool *pool,
 }
 
 static void
-fill_cell (struct tab_table *t, int x1, int y1, int x2, int y2,
+fill_cell (struct table *t, int x1, int y1, int x2, int y2,
            const struct area_style *style, int style_idx,
            const struct pivot_value *value, struct footnote **footnotes,
            enum settings_value_show show_values,
@@ -164,7 +164,7 @@ get_table_rule (const struct table_border_style *styles,
 }
 
 static void
-draw_line (struct tab_table *t, const struct table_border_style *styles,
+draw_line (struct table *t, const struct table_border_style *styles,
            enum pivot_border style_idx,
            enum table_axis axis, int a, int b0, int b1)
 {
@@ -176,7 +176,7 @@ draw_line (struct tab_table *t, const struct table_border_style *styles,
 }
 
 static void
-compose_headings (struct tab_table *t,
+compose_headings (struct table *t,
                   const struct pivot_axis *a_axis, enum table_axis a,
                   const struct pivot_axis *b_axis,
                   const struct table_border_style *borders,
@@ -252,7 +252,7 @@ compose_headings (struct tab_table *t,
                            ? dim_col_vert
                            : cat_col_vert);
                       draw_line (t, borders, style, b, x2 + a_ofs, y1,
-                                 t->table.n[b] - 1);
+                                 t->n[b] - 1);
                     }
                   if (pivot_category_is_leaf (c) && x1 > 0)
                     {
@@ -261,7 +261,7 @@ compose_headings (struct tab_table *t,
                            ? dim_col_vert
                            : cat_col_vert);
                       draw_line (t, borders, style, b, x1 + a_ofs, y1,
-                                 t->table.n[b] - 1);
+                                 t->n[b] - 1);
                     }
                 }
               if (c->parent && c->parent->show_label)
@@ -286,7 +286,7 @@ compose_headings (struct tab_table *t,
 
       if (dim_index > 1)
         draw_line (t, borders, dim_col_horz, a, bottom_row + 1, a_ofs,
-                   t->table.n[a] - 1);
+                   t->n[a] - 1);
 
       bottom_row -= d->label_depth;
     }
@@ -309,7 +309,7 @@ pivot_table_submit_layer (const struct pivot_table *pt,
     [H] = pt->axes[PIVOT_AXIS_ROW].label_depth,
     [V] = pt->axes[PIVOT_AXIS_COLUMN].label_depth,
   };
-  struct tab_table *table = tab_create (body[H] + stub[H],
+  struct table *table = tab_create (body[H] + stub[H],
                                         body[V] + stub[V],
                                         stub[H], 0, stub[V], 0);
 
@@ -405,35 +405,35 @@ pivot_table_submit_layer (const struct pivot_table *pt,
                pt->corner_text, footnotes,
                pt->show_values, pt->show_variables, false);
 
-  if (tab_nc (table) && tab_nr (table))
+  if (table_nc (table) && table_nr (table))
     {
       tab_hline (
         table, get_table_rule (pt->borders, PIVOT_BORDER_INNER_TOP),
-        0, tab_nc (table) - 1, 0);
+        0, table_nc (table) - 1, 0);
       tab_hline (
         table, get_table_rule (pt->borders, PIVOT_BORDER_INNER_BOTTOM),
-        0, tab_nc (table) - 1, tab_nr (table));
+        0, table_nc (table) - 1, table_nr (table));
       tab_vline (
         table, get_table_rule (pt->borders, PIVOT_BORDER_INNER_LEFT),
-        0, 0, tab_nr (table) - 1);
+        0, 0, table_nr (table) - 1);
       tab_vline (
         table, get_table_rule (pt->borders, PIVOT_BORDER_INNER_RIGHT),
-        tab_nc (table), 0, tab_nr (table) - 1);
+        table_nc (table), 0, table_nr (table) - 1);
 
       if (stub[V])
         tab_hline (
           table, get_table_rule (pt->borders, PIVOT_BORDER_DATA_TOP),
-          0, tab_nc (table) - 1, stub[V]);
+          0, table_nc (table) - 1, stub[V]);
       if (stub[H])
         tab_vline (
           table, get_table_rule (pt->borders, PIVOT_BORDER_DATA_LEFT),
-          stub[H], 0, tab_nr (table) - 1);
+          stub[H], 0, table_nr (table) - 1);
 
     }
   free (column_enumeration);
   free (row_enumeration);
 
-  struct table_item *ti = table_item_create (&table->table, NULL, NULL);
+  struct table_item *ti = table_item_create (table, NULL, NULL);
 
   if (pt->title)
     {
index 94782882cee857cb496a2dae0476b21147c1075a..9c09023a5798f2f7bef931949d0f0c15f7f3ad0d 100644 (file)
@@ -1508,7 +1508,7 @@ add_footnote_page (struct render_pager *p, const struct table_item *item)
   if (!n_footnotes)
     return;
 
-  struct tab_table *t = tab_create (1, n_footnotes, 0, 0, 0, 0);
+  struct table *t = tab_create (1, n_footnotes, 0, 0, 0, 0);
   for (size_t i = 0; i < n_footnotes; i++)
     {
       tab_text_format (t, 0, i, TAB_LEFT, "%s. %s",
@@ -1516,7 +1516,7 @@ add_footnote_page (struct render_pager *p, const struct table_item *item)
       if (f[i]->style)
         tab_add_style (t, 0, i, f[i]->style);
     }
-  render_pager_add_table (p, &t->table, 0);
+  render_pager_add_table (p, t, 0);
 
   free (f);
 }
@@ -1528,13 +1528,13 @@ add_text_page (struct render_pager *p, const struct table_item_text *t,
   if (!t)
     return;
 
-  struct tab_table *tab = tab_create (1, 1, 0, 0, 0, 0);
+  struct table *tab = tab_create (1, 1, 0, 0, 0, 0);
   tab_text (tab, 0, 0, 0, t->content);
   for (size_t i = 0; i < t->n_footnotes; i++)
     tab_add_footnote (tab, 0, 0, t->footnotes[i]);
   if (t->style)
     tab->styles[0] = area_style_clone (tab->container, t->style);
-  render_pager_add_table (p, &tab->table, min_width);
+  render_pager_add_table (p, tab, min_width);
 }
 
 static void
@@ -1544,7 +1544,7 @@ add_layers_page (struct render_pager *p,
   if (!layers)
     return;
 
-  struct tab_table *tab = tab_create (1, layers->n_layers, 0, 0, 0, 0);
+  struct table *tab = tab_create (1, layers->n_layers, 0, 0, 0, 0);
   for (size_t i = 0; i < layers->n_layers; i++)
     {
       const struct table_item_layer *layer = &layers->layers[i];
@@ -1554,7 +1554,7 @@ add_layers_page (struct render_pager *p,
     }
   if (layers->style)
     tab->styles[0] = area_style_clone (tab->container, layers->style);
-  render_pager_add_table (p, &tab->table, min_width);
+  render_pager_add_table (p, tab, min_width);
 }
 
 /* Creates and returns a new render_pager for rendering TABLE_ITEM on the
index defdf09add29bea05ee1b6f147889f19887a5b18..c7df7713e2560d84fd5e7922346689af0f5417fe 100644 (file)
 
 static const bool debugging = true;
 
-
-/* Cell options. */
-#define TAB_JOIN     (1u << TAB_FIRST_AVAILABLE)
-
 /* Joined cell. */
 struct tab_joined_cell
 {
@@ -72,19 +68,19 @@ struct tab_joined_cell
    multiple pages.
 
    The table's cells are initially empty. */
-struct tab_table *
+struct table *
 tab_create (int nc, int nr, int hl, int hr, int ht, int hb)
 {
-  struct tab_table *t;
+  struct table *t;
 
-  t = pool_create_container (struct tab_table, container);
-  t->table.n[TABLE_HORZ] = nc;
-  t->table.n[TABLE_VERT] = nr;
-  t->table.h[TABLE_HORZ][0] = hl;
-  t->table.h[TABLE_HORZ][1] = hr;
-  t->table.h[TABLE_VERT][0] = ht;
-  t->table.h[TABLE_VERT][1] = hb;
-  t->table.ref_cnt = 1;
+  t = pool_create_container (struct table, container);
+  t->n[TABLE_HORZ] = nc;
+  t->n[TABLE_VERT] = nr;
+  t->h[TABLE_HORZ][0] = hl;
+  t->h[TABLE_HORZ][1] = hr;
+  t->h[TABLE_VERT][0] = ht;
+  t->h[TABLE_VERT][1] = hb;
+  t->ref_cnt = 1;
 
   t->cc = pool_calloc (t->container, nr * nc, sizeof *t->cc);
   t->ct = pool_calloc (t->container, nr * nc, sizeof *t->ct);
@@ -106,62 +102,62 @@ tab_create (int nc, int nr, int hl, int hr, int ht, int hb)
 /* Draws a vertical line to the left of cells at horizontal position X
    from Y1 to Y2 inclusive in style STYLE, if style is not -1. */
 void
-tab_vline (struct tab_table *t, int style, int x, int y1, int y2)
+tab_vline (struct table *t, int style, int x, int y1, int y2)
 {
   if (debugging)
     {
-      if (x < 0 || x > tab_nc (t)
-          || y1 < 0 || y1 >= tab_nr (t)
-          || y2 < 0 || y2 >= tab_nr (t))
+      if (x < 0 || x > table_nc (t)
+          || y1 < 0 || y1 >= table_nr (t)
+          || y2 < 0 || y2 >= table_nr (t))
         {
           printf (_("bad vline: x=%d y=(%d,%d) in table size (%d,%d)\n"),
-                  x, y1, y2, tab_nc (t), tab_nr (t));
+                  x, y1, y2, table_nc (t), table_nr (t));
           return;
         }
     }
 
   assert (x >= 0);
-  assert (x <= tab_nc (t));
+  assert (x <= table_nc (t));
   assert (y1 >= 0);
   assert (y2 >= y1);
-  assert (y2 <= tab_nr (t));
+  assert (y2 <= table_nr (t));
 
   if (style != -1)
     {
       int y;
       for (y = y1; y <= y2; y++)
-        t->rv[x + (tab_nc (t) + 1) * y] = style;
+        t->rv[x + (table_nc (t) + 1) * y] = style;
     }
 }
 
 /* Draws a horizontal line above cells at vertical position Y from X1
    to X2 inclusive in style STYLE, if style is not -1. */
 void
-tab_hline (struct tab_table *t, int style, int x1, int x2, int y)
+tab_hline (struct table *t, int style, int x1, int x2, int y)
 {
   if (debugging)
     {
-      if (y < 0 || y > tab_nr (t)
-          || x1 < 0 || x1 >= tab_nc (t)
-          || x2 < 0 || x2 >= tab_nc (t))
+      if (y < 0 || y > table_nr (t)
+          || x1 < 0 || x1 >= table_nc (t)
+          || x2 < 0 || x2 >= table_nc (t))
         {
           printf (_("bad hline: x=(%d,%d) y=%d in table size (%d,%d)\n"),
-                  x1, x2, y, tab_nc (t), tab_nr (t));
+                  x1, x2, y, table_nc (t), table_nr (t));
           return;
         }
     }
 
   assert (y >= 0);
-  assert (y <= tab_nr (t));
+  assert (y <= table_nr (t));
   assert (x2 >= x1);
   assert (x1 >= 0);
-  assert (x2 < tab_nc (t));
+  assert (x2 < table_nc (t));
 
   if (style != -1)
     {
       int x;
       for (x = x1; x <= x2; x++)
-        t->rh[x + tab_nc (t) * y] = style;
+        t->rh[x + table_nc (t) * y] = style;
     }
 }
 
@@ -172,18 +168,18 @@ tab_hline (struct tab_table *t, int style, int x1, int x2, int y)
    drawing those lines.  This is distinct from 0, which draws a null
    line. */
 void
-tab_box (struct tab_table *t, int f_h, int f_v, int i_h, int i_v,
+tab_box (struct table *t, int f_h, int f_v, int i_h, int i_v,
          int x1, int y1, int x2, int y2)
 {
   if (debugging)
     {
-      if (x1 < 0 || x1 >= tab_nc (t)
-          || x2 < 0 || x2 >= tab_nc (t)
-          || y1 < 0 || y1 >= tab_nr (t)
-          || y2 < 0 || y2 >= tab_nr (t))
+      if (x1 < 0 || x1 >= table_nc (t)
+          || x2 < 0 || x2 >= table_nc (t)
+          || y1 < 0 || y1 >= table_nr (t)
+          || y2 < 0 || y2 >= table_nr (t))
         {
           printf (_("bad box: (%d,%d)-(%d,%d) in table size (%d,%d)\n"),
-                  x1, y1, x2, y2, tab_nc (t), tab_nr (t));
+                  x1, y1, x2, y2, table_nc (t), table_nr (t));
           NOT_REACHED ();
         }
     }
@@ -192,16 +188,16 @@ tab_box (struct tab_table *t, int f_h, int f_v, int i_h, int i_v,
   assert (y2 >= y1);
   assert (x1 >= 0);
   assert (y1 >= 0);
-  assert (x2 < tab_nc (t));
-  assert (y2 < tab_nr (t));
+  assert (x2 < table_nc (t));
+  assert (y2 < table_nr (t));
 
   if (f_h != -1)
     {
       int x;
       for (x = x1; x <= x2; x++)
         {
-          t->rh[x + tab_nc (t) * y1] = f_h;
-          t->rh[x + tab_nc (t) * (y2 + 1)] = f_h;
+          t->rh[x + table_nc (t) * y1] = f_h;
+          t->rh[x + table_nc (t) * (y2 + 1)] = f_h;
         }
     }
   if (f_v != -1)
@@ -209,8 +205,8 @@ tab_box (struct tab_table *t, int f_h, int f_v, int i_h, int i_v,
       int y;
       for (y = y1; y <= y2; y++)
         {
-          t->rv[x1 + (tab_nc (t) + 1) * y] = f_v;
-          t->rv[(x2 + 1) + (tab_nc (t) + 1) * y] = f_v;
+          t->rv[x1 + (table_nc (t) + 1) * y] = f_v;
+          t->rv[(x2 + 1) + (table_nc (t) + 1) * y] = f_v;
         }
     }
 
@@ -223,7 +219,7 @@ tab_box (struct tab_table *t, int f_h, int f_v, int i_h, int i_v,
           int x;
 
           for (x = x1; x <= x2; x++)
-            t->rh[x + tab_nc (t) * y] = i_h;
+            t->rh[x + table_nc (t) * y] = i_h;
         }
     }
   if (i_v != -1)
@@ -235,7 +231,7 @@ tab_box (struct tab_table *t, int f_h, int f_v, int i_h, int i_v,
           int y;
 
           for (y = y1; y <= y2; y++)
-            t->rv[x + (tab_nc (t) + 1) * y] = i_v;
+            t->rv[x + (table_nc (t) + 1) * y] = i_v;
         }
     }
 }
@@ -243,31 +239,31 @@ tab_box (struct tab_table *t, int f_h, int f_v, int i_h, int i_v,
 /* Cells. */
 
 static void
-do_tab_text (struct tab_table *table, int c, int r, unsigned opt, char *text)
+do_tab_text (struct table *table, int c, int r, unsigned opt, char *text)
 {
   assert (c >= 0);
   assert (r >= 0);
-  assert (c < tab_nc (table));
-  assert (r < tab_nr (table));
+  assert (c < table_nc (table));
+  assert (r < table_nr (table));
 
   if (debugging)
     {
-      if (c < 0 || r < 0 || c >= tab_nc (table) || r >= tab_nr (table))
+      if (c < 0 || r < 0 || c >= table_nc (table) || r >= table_nr (table))
         {
           printf ("tab_text(): bad cell (%d,%d) in table size (%d,%d)\n",
-                  c, r, tab_nc (table), tab_nr (table));
+                  c, r, table_nc (table), table_nr (table));
           return;
         }
     }
 
-  table->cc[c + r * tab_nc (table)] = text;
-  table->ct[c + r * tab_nc (table)] = opt;
+  table->cc[c + r * table_nc (table)] = text;
+  table->ct[c + r * table_nc (table)] = opt;
 }
 
 /* Sets cell (C,R) in TABLE, with options OPT, to have text value
    TEXT. */
 void
-tab_text (struct tab_table *table, int c, int r, unsigned opt,
+tab_text (struct table *table, int c, int r, unsigned opt,
           const char *text)
 {
   do_tab_text (table, c, r, opt, pool_strdup (table->container, text));
@@ -276,7 +272,7 @@ tab_text (struct tab_table *table, int c, int r, unsigned opt,
 /* Sets cell (C,R) in TABLE, with options OPT, to have text value
    FORMAT, which is formatted as if passed to printf. */
 void
-tab_text_format (struct tab_table *table, int c, int r, unsigned opt,
+tab_text_format (struct table *table, int c, int r, unsigned opt,
                  const char *format, ...)
 {
   va_list args;
@@ -288,7 +284,7 @@ tab_text_format (struct tab_table *table, int c, int r, unsigned opt,
 }
 
 static struct tab_joined_cell *
-add_joined_cell (struct tab_table *table, int x1, int y1, int x2, int y2,
+add_joined_cell (struct table *table, int x1, int y1, int x2, int y2,
                  unsigned opt)
 {
   struct tab_joined_cell *j;
@@ -297,19 +293,19 @@ add_joined_cell (struct tab_table *table, int x1, int y1, int x2, int y2,
   assert (y1 >= 0);
   assert (y2 >= y1);
   assert (x2 >= x1);
-  assert (y2 < tab_nr (table));
-  assert (x2 < tab_nc (table));
+  assert (y2 < table_nr (table));
+  assert (x2 < table_nc (table));
 
   if (debugging)
     {
-      if (x1 < 0 || x1 >= tab_nc (table)
-          || y1 < 0 || y1 >= tab_nr (table)
-          || x2 < x1 || x2 >= tab_nc (table)
-          || y2 < y1 || y2 >= tab_nr (table))
+      if (x1 < 0 || x1 >= table_nc (table)
+          || y1 < 0 || y1 >= table_nr (table)
+          || x2 < x1 || x2 >= table_nc (table)
+          || y2 < y1 || y2 >= table_nr (table))
         {
           printf ("tab_joint_text(): bad cell "
                   "(%d,%d)-(%d,%d) in table size (%d,%d)\n",
-                  x1, y1, x2, y2, tab_nc (table), tab_nr (table));
+                  x1, y1, x2, y2, table_nc (table), table_nr (table));
           return NULL;
         }
     }
@@ -326,9 +322,9 @@ add_joined_cell (struct tab_table *table, int x1, int y1, int x2, int y2,
   j->style = NULL;
 
   {
-    void **cc = &table->cc[x1 + y1 * tab_nc (table)];
-    unsigned short *ct = &table->ct[x1 + y1 * tab_nc (table)];
-    const int ofs = tab_nc (table) - (x2 - x1);
+    void **cc = &table->cc[x1 + y1 * table_nc (table)];
+    unsigned short *ct = &table->ct[x1 + y1 * table_nc (table)];
+    const int ofs = table_nc (table) - (x2 - x1);
 
     int y;
 
@@ -353,7 +349,7 @@ add_joined_cell (struct tab_table *table, int x1, int y1, int x2, int y2,
 /* Joins cells (X1,X2)-(Y1,Y2) inclusive in TABLE, and sets them with
    options OPT to have text value TEXT. */
 void
-tab_joint_text (struct tab_table *table, int x1, int y1, int x2, int y2,
+tab_joint_text (struct table *table, int x1, int y1, int x2, int y2,
                 unsigned opt, const char *text)
 {
   char *s = pool_strdup (table->container, text);
@@ -364,7 +360,7 @@ tab_joint_text (struct tab_table *table, int x1, int y1, int x2, int y2,
 }
 
 struct footnote *
-tab_create_footnote (struct tab_table *table, size_t idx, const char *content,
+tab_create_footnote (struct table *table, size_t idx, const char *content,
                      const char *marker, struct area_style *style)
 {
   struct footnote *f = pool_alloc (table->container, sizeof *f);
@@ -376,10 +372,10 @@ tab_create_footnote (struct tab_table *table, size_t idx, const char *content,
 }
 
 void
-tab_add_footnote (struct tab_table *table, int x, int y,
+tab_add_footnote (struct table *table, int x, int y,
                   const struct footnote *f)
 {
-  int index = x + y * tab_nc (table);
+  int index = x + y * table_nc (table);
   unsigned short opt = table->ct[index];
   struct tab_joined_cell *j;
 
@@ -400,10 +396,10 @@ tab_add_footnote (struct tab_table *table, int x, int y,
 }
 
 void
-tab_add_style (struct tab_table *table, int x, int y,
+tab_add_style (struct table *table, int x, int y,
                const struct area_style *style)
 {
-  int index = x + y * tab_nc (table);
+  int index = x + y * table_nc (table);
   unsigned short opt = table->ct[index];
   struct tab_joined_cell *j;
 
@@ -421,9 +417,9 @@ tab_add_style (struct tab_table *table, int x, int y,
 }
 
 bool
-tab_cell_is_empty (const struct tab_table *table, int c, int r)
+tab_cell_is_empty (const struct table *table, int c, int r)
 {
-  return table->cc[c + r * tab_nc (table)] == NULL;
+  return table->cc[c + r * table_nc (table)] == NULL;
 }
 \f
 /* Editing. */
@@ -461,16 +457,13 @@ tab_output_text_format (int options, const char *format, ...)
 void
 tab_destroy (struct table *table)
 {
-  struct tab_table *t = tab_cast (table);
-  pool_destroy (t->container);
+  pool_destroy (table->container);
 }
 
 void
-tab_get_cell (const struct table *table, int x, int y,
-              struct table_cell *cell)
+tab_get_cell (const struct table *t, int x, int y, struct table_cell *cell)
 {
-  const struct tab_table *t = tab_cast (table);
-  int index = x + y * tab_nc (t);
+  int index = x + y * table_nc (t);
   unsigned short opt = t->ct[index];
   const void *cc = t->cc[index];
 
@@ -537,22 +530,15 @@ tab_get_cell (const struct table *table, int x, int y,
 }
 
 int
-tab_get_rule (const struct table *table, enum table_axis axis, int x, int y,
+tab_get_rule (const struct table *t, enum table_axis axis, int x, int y,
               struct cell_color *color)
 {
-  const struct tab_table *t = tab_cast (table);
   uint8_t raw = (axis == TABLE_VERT
-                 ? t->rh[x + tab_nc (t) * y]
-                 : t->rv[x + (tab_nc (t) + 1) * y]);
+                 ? t->rh[x + table_nc (t) * y]
+                 : t->rv[x + (table_nc (t) + 1) * y]);
   struct cell_color *p = t->rule_colors[(raw & TAB_RULE_STYLE_MASK)
                                         >> TAB_RULE_STYLE_SHIFT];
   if (p)
     *color = *p;
   return (raw & TAB_RULE_TYPE_MASK) >> TAB_RULE_TYPE_SHIFT;
 }
-
-struct tab_table *
-tab_cast (const struct table *table)
-{
-  return UP_CAST (table, struct tab_table, table);
-}
index e931b8304a1269533c40dfb8d0a896fd9b5cfc4f..9beefc73d412bab89017d1e2c4f565b410e0d83e 100644 (file)
 #include "output/table.h"
 #include "data/format.h"
 
-#define TAB_STYLE_MASK (7u << (TAB_FIRST_AVAILABLE + 1))
-#define TAB_STYLE_SHIFT (TAB_FIRST_AVAILABLE + 1)
-
-enum
-  {
-    /* Horizontal alignment of cell contents. */
-    TAB_RIGHT      = 0 << (TAB_FIRST_AVAILABLE + 4),
-    TAB_LEFT       = 1 << (TAB_FIRST_AVAILABLE + 4),
-    TAB_CENTER     = 2 << (TAB_FIRST_AVAILABLE + 4),
-    TAB_HALIGN     = 3 << (TAB_FIRST_AVAILABLE + 4), /* Alignment mask. */
-
-    /* Vertical alignment of cell contents. */
-    TAB_TOP        = 0 << (TAB_FIRST_AVAILABLE + 6),
-    TAB_MIDDLE     = 1 << (TAB_FIRST_AVAILABLE + 6),
-    TAB_BOTTOM     = 2 << (TAB_FIRST_AVAILABLE + 6),
-    TAB_VALIGN     = 3 << (TAB_FIRST_AVAILABLE + 6), /* Alignment mask. */
-  };
-
 /* Rule masks. */
 #define TAB_RULE_TYPE_MASK   7
 #define TAB_RULE_TYPE_SHIFT  0
 #define TAB_RULE_STYLE_MASK  (31 << TAB_RULE_STYLE_SHIFT)
 #define TAB_RULE_STYLE_SHIFT 3
 
-/* A table. */
-struct tab_table
-  {
-    struct table table;
-    struct pool *container;
-
-    /* Table contents.
-
-       Each array element in cc[] is ordinarily a "char *" pointer to a
-       string.  If TAB_JOIN (defined in tab.c) is set in ct[] for the element,
-       however, it is a joined cell and the corresponding element of cc[]
-       points to a struct tab_joined_cell. */
-    void **cc;                  /* Cell contents; void *[nr][nc]. */
-    unsigned short *ct;                /* Cell types; unsigned short[nr][nc]. */
-    struct area_style *styles[8];
-
-    /* Rules. */
-    unsigned char *rh;         /* Horiz rules; unsigned char[nr+1][nc]. */
-    unsigned char *rv;         /* Vert rules; unsigned char[nr][nc+1]. */
-    struct cell_color *rule_colors[32];
-  };
-
-struct tab_table *tab_cast (const struct table *);
-
-/* Number of rows or columns in TABLE. */
-static inline int tab_nr (const struct tab_table *table)
-        { return table_nr (&table->table); }
-static inline int tab_nc (const struct tab_table *table)
-        { return table_nc (&table->table); }
-
 /* Tables. */
-struct tab_table *tab_create (int nc, int nr,
-                              int l, int r, int t, int b);
+struct table *tab_create (int nc, int nr, int hl, int hr, int ht, int hb);
 
 /* Rules. */
-void tab_hline (struct tab_table *, int style, int x1, int x2, int y);
-void tab_vline (struct tab_table *, int style, int x, int y1, int y2);
-void tab_box (struct tab_table *, int f_h, int f_v, int i_h, int i_v,
+void tab_hline (struct table *, int style, int x1, int x2, int y);
+void tab_vline (struct table *, int style, int x, int y1, int y2);
+void tab_box (struct table *, int f_h, int f_v, int i_h, int i_v,
              int x1, int y1, int x2, int y2);
 
 /* Cells. */
-void tab_text (struct tab_table *, int c, int r, unsigned opt, const char *);
-void tab_text_format (struct tab_table *, int c, int r, unsigned opt,
+void tab_text (struct table *, int c, int r, unsigned opt, const char *);
+void tab_text_format (struct table *, int c, int r, unsigned opt,
                       const char *, ...)
-     PRINTF_FORMAT (5, 6);
+  PRINTF_FORMAT (5, 6);
 
-void tab_joint_text (struct tab_table *, int x1, int y1, int x2, int y2,
+void tab_joint_text (struct table *, int x1, int y1, int x2, int y2,
                     unsigned opt, const char *);
 
-struct footnote *tab_create_footnote (struct tab_table *, size_t idx,
+struct footnote *tab_create_footnote (struct table *, size_t idx,
                                       const char *content, const char *marker,
                                       struct area_style *);
-void tab_add_footnote (struct tab_table *, int x, int y,
+void tab_add_footnote (struct table *, int x, int y,
                        const struct footnote *);
 
-void tab_add_style (struct tab_table *, int x, int y,
+void tab_add_style (struct table *, int x, int y,
                     const struct area_style *);
 
-bool tab_cell_is_empty (const struct tab_table *, int c, int r);
+bool tab_cell_is_empty (const struct table *, int c, int r);
 
 /* Simple output. */
 void tab_output_text (int options, const char *string);
index 7b229eb6b8c2341639de59535326249e619c4109..9c0286e6f5dd3aa5b17f77ccc8d726f9b83a418d 100644 (file)
@@ -239,9 +239,9 @@ table_collect_footnotes (const struct table_item *item,
 struct table *
 table_from_string (const char *text)
 {
-  struct tab_table *t = tab_create (1, 1, 0, 0, 0, 0);
+  struct table *t = tab_create (1, 1, 0, 0, 0, 0);
   tab_text (t, 0, 0, TAB_LEFT, text);
-  return &t->table;
+  return t;
 }
 \f
 const char *
index 6caec33ff74306766b406e502ceb1629ff284edc..ea3594b33d7aac1c8c1ea2db1a7091f408072f27 100644 (file)
@@ -28,7 +28,7 @@
 
    Every table is an instance of a particular table class that is responsible
    for keeping track of cell data.  By far the most common table class is
-   struct tab_table (see output/tab.h).  This header also declares some other
+   struct table (see output/tab.h).  This header also declares some other
    kinds of table classes, near the end of the file.
 
    A table is not itself an output_item, and thus a table cannot by itself be
@@ -176,10 +176,23 @@ enum
     TAB_NUMERIC    = 1 << 3,    /* Cell contents are numeric. */
     TAB_ROTATE     = 1 << 4,    /* Rotate cell contents 90 degrees. */
 
-    /* Bits with values (1 << TAB_FIRST_AVAILABLE) and higher are
-       not used, so they are available for subclasses to use as
-       they wish. */
-    TAB_FIRST_AVAILABLE = 5
+    TAB_STYLE_SHIFT = 5,
+    TAB_STYLE_MASK = 7 << TAB_STYLE_SHIFT,
+
+    /* Horizontal alignment of cell contents. */
+    TAB_RIGHT      = 0 << 10,
+    TAB_LEFT       = 1 << 10,
+    TAB_CENTER     = 2 << 10,
+    TAB_HALIGN     = 3 << 10, /* Alignment mask. */
+
+    /* Vertical alignment of cell contents. */
+    TAB_TOP        = 0 << 12,
+    TAB_MIDDLE     = 1 << 12,
+    TAB_BOTTOM     = 2 << 12,
+    TAB_VALIGN     = 3 << 12, /* Alignment mask. */
+
+    /* Internal use by tab.c only. */
+    TAB_JOIN = 1 << 14,
   };
 
 /* Styles for the rules around table cells. */
@@ -208,6 +221,8 @@ static inline int table_rule_combine (int a, int b)
 /* A table. */
 struct table
   {
+    struct pool *container;
+
     /* Table size.
 
        n[TABLE_HORZ]: Number of columns.
@@ -231,6 +246,21 @@ struct table
        indicated by a reference count greater than 1.  When this is the case,
        the table must not be modified. */
     int ref_cnt;
+
+    /* Table contents.
+
+       Each array element in cc[] is ordinarily a "char *" pointer to a
+       string.  If TAB_JOIN (defined in tab.c) is set in ct[] for the element,
+       however, it is a joined cell and the corresponding element of cc[]
+       points to a struct tab_joined_cell. */
+    void **cc;                  /* Cell contents; void *[nr][nc]. */
+    unsigned short *ct;                /* Cell types; unsigned short[nr][nc]. */
+    struct area_style *styles[8];
+
+    /* Rules. */
+    unsigned char *rh;         /* Horiz rules; unsigned char[nr+1][nc]. */
+    unsigned char *rv;         /* Vert rules; unsigned char[nr][nc+1]. */
+    struct cell_color *rule_colors[32];
   };
 
 /* Reference counting. */
index 20b424732b605af3093b9d80ec62ff4674248d95..cfd6cc8a9022788d67093552e968f3587c129556 100644 (file)
@@ -119,7 +119,7 @@ text_item_submit (struct text_item *item)
 struct table_item *
 text_item_to_table_item (struct text_item *text_item)
 {
-  struct tab_table *tab = tab_create (1, 1, 0, 0, 0, 0);
+  struct table *tab = tab_create (1, 1, 0, 0, 0, 0);
 
   struct area_style *style = pool_alloc (tab->container, sizeof *style);
   *style = (struct area_style) { AREA_STYLE_INITIALIZER__,
@@ -140,7 +140,7 @@ text_item_to_table_item (struct text_item *text_item)
   if (text_item->type == TEXT_ITEM_SYNTAX || text_item->type == TEXT_ITEM_LOG)
     opts |= TAB_FIX;
   tab_text (tab, 0, 0, opts, text_item_get_text (text_item));
-  struct table_item *table_item = table_item_create (&tab->table, NULL, NULL);
+  struct table_item *table_item = table_item_create (tab, NULL, NULL);
   text_item_unref (text_item);
   return table_item;
 }
index 961ff59a86142f111853a40f8c56cf68b646d60f..506afbf09176501e2c44b6c00cd23c41adb922e9 100644 (file)
@@ -360,7 +360,7 @@ replace_newlines (char *p)
 static struct table *
 read_table (FILE *stream)
 {
-  struct tab_table *tab;
+  struct table *tab;
   char buffer[1024];
   int input[6];
   int n_input = 0;
@@ -476,7 +476,7 @@ read_table (FILE *stream)
               }
         }
 
-  return &tab->table;
+  return tab;
 }
 
 static void