X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Foutput%2Ftable.c;h=8f717ead5679359b4f5c8529811e7b731d9c307d;hb=f967d0e36a2193c1249799f463ea9109b753f7a8;hp=aafc2f6db0fbfa30a784ed8ef6812eed38cdee30;hpb=5cab4cf3322f29c0ed7134d23740e07382914f20;p=pspp diff --git a/src/output/table.c b/src/output/table.c index aafc2f6db0..8f717ead56 100644 --- a/src/output/table.c +++ b/src/output/table.c @@ -30,6 +30,7 @@ #include "libpspp/pool.h" #include "libpspp/str.h" #include "output/table-item.h" +#include "output/tab.h" #include "gl/xalloc.h" @@ -297,160 +298,15 @@ table_collect_footnotes (const struct table_item *item, return n; } -struct table_unshared - { - struct table table; - struct table *subtable; - }; - -static const struct table_class table_unshared_class; - -/* Takes ownership of TABLE and returns a table with the same contents but - which is guaranteed not to be shared (as returned by table_is_shared()). - - If TABLE is unshared, just returns TABLE. - - The only real use for this function is to create a copy of TABLE in which - the headers can be adjusted, which is a pretty specialized use case. */ -struct table * -table_unshare (struct table *table) -{ - if (!table_is_shared (table)) - return table; - else - { - struct table_unshared *tiu = xmalloc (sizeof *tiu); - table_init (&tiu->table, &table_unshared_class); - table_set_nc (&tiu->table, table_nc (table)); - table_set_nr (&tiu->table, table_nr (table)); - table_set_hl (&tiu->table, table_hl (table)); - table_set_hr (&tiu->table, table_hr (table)); - table_set_ht (&tiu->table, table_ht (table)); - table_set_hb (&tiu->table, table_hb (table)); - tiu->subtable = table; - return &tiu->table; - } -} - -static struct table_unshared * -table_unshared_cast (const struct table *table) -{ - assert (table->klass == &table_unshared_class); - return UP_CAST (table, struct table_unshared, table); -} - -static void -table_unshared_destroy (struct table *tiu_) -{ - struct table_unshared *tiu = table_unshared_cast (tiu_); - table_unref (tiu->subtable); - free (tiu); -} - -static void -table_unshared_get_cell (const struct table *tiu_, int x, int y, - struct table_cell *cell) -{ - struct table_unshared *tiu = table_unshared_cast (tiu_); - table_get_cell (tiu->subtable, x, y, cell); -} - -static int -table_unshared_get_rule (const struct table *tiu_, - enum table_axis axis, int x, int y, - struct cell_color *color) -{ - struct table_unshared *tiu = table_unshared_cast (tiu_); - return table_get_rule (tiu->subtable, axis, x, y, color); -} - -static const struct table_class table_unshared_class = - { - table_unshared_destroy, - table_unshared_get_cell, - table_unshared_get_rule, - NULL, /* paste */ - NULL, /* select */ - }; - -struct table_string - { - struct table table; - char *string; - enum table_halign halign; - }; - -static const struct table_class table_string_class; - -/* Returns a table that contains a single cell, whose contents are S with - options OPTIONS (a combination of TAB_* values). */ +/* Returns a table that contains a single cell, whose contents are the + left-aligned TEXT. */ struct table * -table_from_string (enum table_halign halign, const char *s) -{ - struct table_string *ts = xmalloc (sizeof *ts); - table_init (&ts->table, &table_string_class); - ts->table.n[TABLE_HORZ] = ts->table.n[TABLE_VERT] = 1; - ts->string = xstrdup (s); - ts->halign = halign; - return &ts->table; -} - -static struct table_string * -table_string_cast (const struct table *table) -{ - assert (table->klass == &table_string_class); - return UP_CAST (table, struct table_string, table); -} - -static void -table_string_destroy (struct table *ts_) -{ - struct table_string *ts = table_string_cast (ts_); - free (ts->string); - free (ts); -} - -static void -table_string_get_cell (const struct table *ts_, int x UNUSED, int y UNUSED, - struct table_cell *cell) +table_from_string (const char *text) { - static const struct area_style styles[] = { -#define S(H) [H] = { AREA_STYLE_INITIALIZER__, .cell_style.halign = H } - S(TABLE_HALIGN_LEFT), - S(TABLE_HALIGN_CENTER), - S(TABLE_HALIGN_RIGHT), - S(TABLE_HALIGN_MIXED), - S(TABLE_HALIGN_DECIMAL), - }; - struct table_string *ts = table_string_cast (ts_); - cell->d[TABLE_HORZ][0] = 0; - cell->d[TABLE_HORZ][1] = 1; - cell->d[TABLE_VERT][0] = 0; - cell->d[TABLE_VERT][1] = 1; - cell->options = 0; - cell->style = &styles[table_halign_interpret (ts->halign, false)]; - cell->text = ts->string; - cell->n_footnotes = 0; - cell->destructor = NULL; + struct tab_table *t = tab_create (1, 1); + tab_text (t, 0, 0, TAB_LEFT, text); + return &t->table; } - - -static int -table_string_get_rule (const struct table *ts UNUSED, - enum table_axis axis UNUSED, int x UNUSED, int y UNUSED, - struct cell_color *color UNUSED) -{ - return TAL_0; -} - -static const struct table_class table_string_class = - { - table_string_destroy, - table_string_get_cell, - table_string_get_rule, - NULL, /* paste */ - NULL, /* select */ - }; const char * table_halign_to_string (enum table_halign halign)