- va_list args;
-
- va_start (args, format);
- do_tab_text (table, c, r, opt,
- pool_vasprintf (table->container, format, args));
- va_end (args);
-}
-
-static void
-do_tab_joint_text (struct tab_table *table, int x1, int y1, int x2, int y2,
- unsigned opt, char *text)
-{
- struct tab_joined_cell *j;
-
- 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;
- j->contents = ss_cstr (text);
-
- 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;
- }
- }
-}
-
-/* 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)
-{
- 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 >= 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_table *t, struct outp_driver *d, void *aux UNUSED)
-{
- t->w[0] = tab_natural_width (t, d, 0);
- t->h[0] = d->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_table *t, struct outp_driver *d, void *aux UNUSED)
-{
- t->w[0] = tab_natural_width (t, d, 0);
- t->h[0] = tab_natural_height (t, d, 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);
- 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, 0);
- 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, 0);
-
- 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);