- va_list args;
-
- assert (table != NULL && text != NULL);
-
- assert (c >= 0 );
- assert (r >= 0 );
- assert (c < table->nc);
- assert (r < table->nr);
-
-
-#if DEBUGGING
- if (c + table->col_ofs < 0 || r + table->row_ofs < 0
- || c + table->col_ofs >= table->nc
- || r + table->row_ofs >= table->nr)
- {
- printf ("tab_text(): 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,
- table->nc, table->nr);
- return;
- }
-#endif
-
- va_start (args, text);
- table->cc[c + r * table->cf] = text_format (table, opt, text, args);
- table->ct[c + r * table->cf] = opt;
- va_end (args);
-}
-
-/* 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,
- unsigned opt, const char *text, ...)
-{
- struct tab_joined_cell *j;
-
- assert (table != NULL && text != NULL);
-
- assert (x1 + table->col_ofs >= 0);
- assert (y1 + table->row_ofs >= 0);
- assert (y2 >= y1);
- assert (x2 >= x1);
- assert (y2 + table->row_ofs < table->nr);
- assert (x2 + table->col_ofs < table->nc);
-
-#if DEBUGGING
- if (x1 + table->col_ofs < 0 || x1 + table->col_ofs >= table->nc
- || y1 + table->row_ofs < 0 || y1 + table->row_ofs >= table->nr
- || x2 < x1 || x2 + table->col_ofs >= table->nc
- || y2 < y2 || y2 + table->row_ofs >= table->nr)
- {
- printf ("tab_joint_text(): bad cell "
- "(%d+%d=%d,%d+%d=%d)-(%d+%d=%d,%d+%d=%d) in table size (%d,%d)\n",
- x1, table->col_ofs, x1 + table->col_ofs,
- y1, table->row_ofs, y1 + table->row_ofs,
- x2, table->col_ofs, x2 + table->col_ofs,
- y2, table->row_ofs, y2 + table->row_ofs,
- table->nc, table->nr);
- return;
- }
-#endif
-
- tab_box (table, -1, -1, TAL_0, TAL_0, x1, y1, x2, y2);
-
- j = pool_alloc (table->container, sizeof *j);
- j->hit = 0;
- j->x1 = x1 + table->col_ofs;
- j->y1 = y1 + table->row_ofs;
- j->x2 = ++x2 + table->col_ofs;
- j->y2 = ++y2 + table->row_ofs;
-
- {
- va_list args;
-
- va_start (args, text);
- j->contents = text_format (table, opt, text, args);
- va_end (args);
- }
-
- opt |= TAB_JOIN;
-
- {
- struct substring *cc = &table->cc[x1 + y1 * table->cf];
- unsigned char *ct = &table->ct[x1 + y1 * table->cf];
- const int ofs = table->cf - (x2 - x1);
-
- int y;
-
- for (y = y1; y < y2; y++)
- {
- int x;
-
- for (x = x1; x < x2; x++)
- {
- *cc++ = ss_buffer ((char *) j, 0);
- *ct++ = opt;
- }
-
- cc += ofs;
- ct += ofs;
- }
- }
-}
-
-/* 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 >= table->nc
- || r + table->row_ofs >= table->nr)
- {
- 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,
- table->nc, table->nr);
- 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);
-}
-
-/* Outputs text BUF 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 *buf, ...)
-{
- struct tab_table *t = tab_create (1, 1, 0);
- char *tmp_buf = NULL;
-
- if (options & TAT_PRINTF)
- {
- va_list args;
-
- va_start (args, buf);
- buf = tmp_buf = xvasprintf (buf, args);
- va_end (args);
- }
-
- tab_text (t, 0, 0, options & ~TAT_PRINTF, buf);
- tab_flags (t, SOMF_NO_TITLE | SOMF_NO_SPACING);
- tab_dim (t, options & TAT_NOWRAP ? nowrap_dim : wrap_dim, NULL);
- tab_submit (t);
-
- free (tmp_buf);
-}
-
-/* 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);