-tab_joint_text (struct tab_table *table, int x1, int y1, int x2, int y2,
- unsigned opt, const char *text)
-{
- do_tab_joint_text (table, x1, y1, x2, y2, opt,
- pool_strdup (table->container, text));
-}
-
-/* Joins cells (X1,X2)-(Y1,Y2) inclusive in TABLE, and sets them
- with options OPT to have text value FORMAT, which is formatted
- as if passed to printf. */
-void
-tab_joint_text_format (struct tab_table *table, int x1, int y1, int x2, int y2,
- unsigned opt, const char *format, ...)
-{
- va_list args;
-
- va_start (args, format);
- do_tab_joint_text (table, x1, y1, x2, y2, opt,
- pool_vasprintf (table->container, format, args));
- va_end (args);
-}
-
-/* Sets cell (C,R) in TABLE, with options OPT, to contents STRING. */
-void
-tab_raw (struct tab_table *table, int c, int r, unsigned opt,
- struct substring *string)
-{
- assert (table != NULL && string != NULL);
-
-#if DEBUGGING
- if (c + table->col_ofs < 0 || r + table->row_ofs < 0
- || c + table->col_ofs >= tab_nc (table)
- || r + table->row_ofs >= tab_nr (table))
- {
- printf ("tab_raw(): bad cell (%d+%d=%d,%d+%d=%d) in table size "
- "(%d,%d)\n",
- c, table->col_ofs, c + table->col_ofs,
- r, table->row_ofs, r + table->row_ofs,
- tab_nc (table), tab_nr (table));
- return;
- }
-#endif
-
- table->cc[c + r * table->cf] = *string;
- table->ct[c + r * table->cf] = opt;
-}
-\f
-/* Miscellaneous. */
-
-/* Sets the widths of all the columns and heights of all the rows in
- table T for driver D. */
-static void
-nowrap_dim (struct tab_rendering *r, void *aux UNUSED)
-{
- r->w[0] = tab_natural_width (r, 0);
- r->h[0] = r->driver->font_height;
-}
-
-/* Sets the widths of all the columns and heights of all the rows in
- table T for driver D. */
-static void
-wrap_dim (struct tab_rendering *r, void *aux UNUSED)
-{
- r->w[0] = tab_natural_width (r, 0);
- r->h[0] = tab_natural_height (r, 0);
-}
-
-static void
-do_tab_output_text (struct tab_table *t, int options, char *text)
-{
- do_tab_text (t, 0, 0, options, text);
- tab_flags (t, SOMF_NO_TITLE | SOMF_NO_SPACING);
- tab_dim (t, options & TAT_NOWRAP ? nowrap_dim : wrap_dim, NULL, NULL);
- tab_submit (t);
-}
-
-/* Outputs TEXT as a table with a single cell having cell options
- OPTIONS, which is a combination of the TAB_* and TAT_*
- constants. */
-void
-tab_output_text (int options, const char *text)
-{
- struct tab_table *table = tab_create (1, 1);
- do_tab_output_text (table, options, pool_strdup (table->container, text));
-}
-
-/* Outputs FORMAT as a table with a single cell having cell
- options OPTIONS, which is a combination of the TAB_* and TAT_*
- constants. FORMAT is formatted as if it was passed through
- printf. */
-void
-tab_output_text_format (int options, const char *format, ...)
-{
- struct tab_table *table;
- va_list args;
-
- table = tab_create (1, 1);
-
- va_start (args, format);
- do_tab_output_text (table, options,
- pool_vasprintf (table->container, format, args));
- va_end (args);
-}
-
-/* Set table flags to FLAGS. */
-void
-tab_flags (struct tab_table *t, unsigned flags)
-{
- assert (t != NULL);
- t->flags = flags;
-}
-
-/* Easy, type-safe way to submit a tab table to som. */
-void
-tab_submit (struct tab_table *t)
-{
- struct som_entity s;
-
- assert (t != NULL);
- s.class = &tab_table_class;
- s.ext = t;
- s.type = SOM_TABLE;
- som_submit (&s);
- tab_destroy (t);
-}
-\f
-/* Editing. */
-
-/* Set table row and column offsets for all functions that affect
- cells or rules. */
-void
-tab_offset (struct tab_table *t, int col, int row)
-{
- int diff = 0;
-
- assert (t != NULL);
-#if DEBUGGING
- if (row < -1 || row > tab_nr (t))
- {
- printf ("tab_offset(): row=%d in %d-row table\n", row, tab_nr (t));
- NOT_REACHED ();
- }
- if (col < -1 || col > tab_nc (t))
- {
- printf ("tab_offset(): col=%d in %d-column table\n", col, tab_nc (t));
- NOT_REACHED ();
- }
-#endif
-
- if (row != -1)
- diff += (row - t->row_ofs) * t->cf, t->row_ofs = row;
- if (col != -1)
- diff += (col - t->col_ofs), t->col_ofs = col;
-
- t->cc += diff;
- t->ct += diff;
-}
-
-/* Increment the row offset by one. If the table is too small,
- increase its size. */
-void
-tab_next_row (struct tab_table *t)
-{
- assert (t != NULL);
- t->cc += t->cf;
- t->ct += t->cf;
- if (++t->row_ofs >= tab_nr (t))
- tab_realloc (t, -1, tab_nr (t) * 4 / 3);
-}
-\f
-/* Return the number of columns and rows in the table into N_COLUMNS
- and N_ROWS, respectively. */
-static void
-tabi_count (struct som_entity *t_, int *n_columns, int *n_rows)
-{
- struct tab_table *t = t_->ext;
- *n_columns = t->nc;
- *n_rows = t->nr;
-}
-
-/* Return the column style for this table into STYLE. */
-static void
-tabi_columns (struct som_entity *t_, int *style)
-{
- struct tab_table *t = t_->ext;
- *style = t->col_style;
-}
-
-/* Return the number of header rows/columns on the left, right, top,
- and bottom sides into HL, HR, HT, and HB, respectively. */
-static void
-tabi_headers (struct som_entity *t_, int *hl, int *hr, int *ht, int *hb)
-{
- struct tab_table *t = t_->ext;
- *hl = t->l;
- *hr = t->r;
- *ht = t->t;
- *hb = t->b;
-}
-
-/* Return flags set for the current table into FLAGS. */
-static void
-tabi_flags (struct som_entity *t_, unsigned *flags)
-{
- struct tab_table *t = t_->ext;
- *flags = t->flags;
-}
-
-/* Returns the line style to use for spacing purposes for a rule
- of the given TYPE. */
-static enum outp_line_style
-rule_to_spacing_type (unsigned char type)
-{
- switch (type)
- {
- case TAL_0:
- return OUTP_L_NONE;
- case TAL_GAP:
- case TAL_1:
- return OUTP_L_SINGLE;
- case TAL_2:
- return OUTP_L_DOUBLE;
- default:
- NOT_REACHED ();
- }
-}
-
-static void *
-tabi_render_init (struct som_entity *t_, struct outp_driver *driver,
- int hl, int hr, int ht, int hb)
-{
- const struct tab_table *t = t_->ext;
- struct tab_rendering *r;
- int col, row;
- int i;
-
- tab_offset (t_->ext, 0, 0);
-
- r = xmalloc (sizeof *r);
- r->table = t;
- r->driver = driver;
- r->w = xnmalloc (tab_nc (t), sizeof *r->w);
- r->h = xnmalloc (tab_nr (t), sizeof *r->h);
- r->hrh = xnmalloc (tab_nr (t) + 1, sizeof *r->hrh);
- r->wrv = xnmalloc (tab_nc (t) + 1, sizeof *r->wrv);
- r->l = hl;
- r->r = hr;
- r->t = ht;
- r->b = hb;
-
- /* Figure out sizes of rules. */
- for (row = 0; row <= tab_nr (t); row++)
- {
- int width = 0;
- for (col = 0; col < tab_nc (t); col++)
- {
- unsigned char rh = t->rh[col + row * t->cf];
- int w = driver->horiz_line_width[rule_to_spacing_type (rh)];
- if (w > width)
- width = w;
- }
- r->hrh[row] = width;
- }
-
- for (col = 0; col <= tab_nc (t); col++)
- {
- int width = 0;
- for (row = 0; row < tab_nr (t); row++)
- {
- unsigned char *rv = &t->rv[col + row * (t->cf + 1)];
- int w;
- if (*rv == UCHAR_MAX)
- *rv = col != 0 && col != tab_nc (t) ? TAL_GAP : TAL_0;
- w = driver->vert_line_width[rule_to_spacing_type (*rv)];
- if (w > width)
- width = w;
- }
- r->wrv[col] = width;
- }
-
- /* Determine row heights and columns widths. */
- for (i = 0; i < tab_nr (t); i++)
- r->h[i] = -1;
- for (i = 0; i < tab_nc (t); i++)
- r->w[i] = -1;
-
- t->dim (r, t->dim_aux);
-
- for (i = 0; i < tab_nr (t); i++)
- if (r->h[i] < 0)
- error (0, 0, "height of table row %d is %d (not initialized?)",
- i, r->h[i]);
- for (i = 0; i < tab_nc (t); i++)
- if (r->w[i] < 0)
- error (0, 0, "width of table column %d is %d (not initialized?)",
- i, r->w[i]);
-
- /* Add up header sizes. */
- for (i = 0, r->wl = r->wrv[0]; i < r->l; i++)
- r->wl += r->w[i] + r->wrv[i + 1];
- for (i = 0, r->ht = r->hrh[0]; i < r->t; i++)
- r->ht += r->h[i] + r->hrh[i + 1];
- for (i = tab_nc (t) - r->r, r->wr = r->wrv[i]; i < tab_nc (t); i++)
- r->wr += r->w[i] + r->wrv[i + 1];
- for (i = tab_nr (t) - r->b, r->hb = r->hrh[i]; i < tab_nr (t); i++)
- r->hb += r->h[i] + r->hrh[i + 1];
-
- /* Title. */
- if (!(t->flags & SOMF_NO_TITLE))
- r->ht += driver->font_height;
-
- return r;
-}
-
-static void
-tabi_render_free (void *r_)