From: Ben Pfaff Date: Wed, 25 Dec 2019 22:33:37 +0000 (+0000) Subject: table: Require headers to be set at table creation. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;ds=sidebyside;h=ada0a9f1d1ed94079e90fd2f0fe673ccddccceae;p=pspp table: Require headers to be set at table creation. It used to be important for these to be adjustable, but no longer. --- diff --git a/src/output/pivot-output.c b/src/output/pivot-output.c index d805f42bb3..aca56e7be4 100644 --- a/src/output/pivot-output.c +++ b/src/output/pivot-output.c @@ -310,8 +310,8 @@ pivot_table_submit_layer (const struct pivot_table *pt, [V] = pt->axes[PIVOT_AXIS_COLUMN].label_depth, }; struct tab_table *table = tab_create (body[H] + stub[H], - body[V] + stub[V]); - tab_headers (table, stub[H], 0, stub[V], 0); + body[V] + stub[V], + stub[H], 0, stub[V], 0); for (size_t i = 0; i < PIVOT_N_AREAS; i++) table->styles[i] = area_style_override (table->container, &pt->areas[i], diff --git a/src/output/render.c b/src/output/render.c index e6ce53164e..94782882ce 100644 --- a/src/output/render.c +++ b/src/output/render.c @@ -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); + struct tab_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", @@ -1528,7 +1528,7 @@ add_text_page (struct render_pager *p, const struct table_item_text *t, if (!t) return; - struct tab_table *tab = tab_create (1, 1); + struct tab_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]); @@ -1544,7 +1544,7 @@ add_layers_page (struct render_pager *p, if (!layers) return; - struct tab_table *tab = tab_create (1, layers->n_layers); + struct tab_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]; diff --git a/src/output/tab.c b/src/output/tab.c index 0166b97808..defdf09add 100644 --- a/src/output/tab.c +++ b/src/output/tab.c @@ -64,17 +64,26 @@ struct tab_joined_cell }; /* Creates and returns a new table with NC columns and NR rows and initially no - header rows or columns. The table's cells are initially empty. */ + header rows or columns. + + Sets the number of header rows on each side of TABLE to HL on the + left, HR on the right, HT on the top, HB on the bottom. Header rows + are repeated when a table is broken across multiple columns or + multiple pages. + + The table's cells are initially empty. */ struct tab_table * -tab_create (int nc, int nr) +tab_create (int nc, int nr, int hl, int hr, int ht, int hb) { struct tab_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] = t->table.h[TABLE_HORZ][1] = 0; - t->table.h[TABLE_VERT][0] = t->table.h[TABLE_VERT][1] = 0; + 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->cc = pool_calloc (t->container, nr * nc, sizeof *t->cc); @@ -91,20 +100,6 @@ tab_create (int nc, int nr) return t; } - - -/* Sets the number of header rows on each side of TABLE to L on the - left, R on the right, T on the top, B on the bottom. Header rows - are repeated when a table is broken across multiple columns or - multiple pages. */ -void -tab_headers (struct tab_table *table, int l, int r, int t, int b) -{ - table_set_hl (&table->table, l); - table_set_hr (&table->table, r); - table_set_ht (&table->table, t); - table_set_hb (&table->table, b); -} /* Rules. */ diff --git a/src/output/tab.h b/src/output/tab.h index 3f99ac6d07..e931b8304a 100644 --- a/src/output/tab.h +++ b/src/output/tab.h @@ -81,19 +81,9 @@ static inline int tab_nr (const struct tab_table *table) static inline int tab_nc (const struct tab_table *table) { return table_nc (&table->table); } -/* Number of left/right/top/bottom header columns/rows in TABLE. */ -static inline int tab_l (const struct tab_table *table) - { return table_hl (&table->table); } -static inline int tab_r (const struct tab_table *table) - { return table_hr (&table->table); } -static inline int tab_t (const struct tab_table *table) - { return table_ht (&table->table); } -static inline int tab_b (const struct tab_table *table) - { return table_hb (&table->table); } - /* Tables. */ -struct tab_table *tab_create (int nc, int nr); -void tab_headers (struct tab_table *, int l, int r, int t, int b); +struct tab_table *tab_create (int nc, int nr, + int l, int r, int t, int b); /* Rules. */ void tab_hline (struct tab_table *, int style, int x1, int x2, int y); diff --git a/src/output/table.c b/src/output/table.c index 01e2acd118..7b229eb6b8 100644 --- a/src/output/table.c +++ b/src/output/table.c @@ -65,38 +65,6 @@ table_is_shared (const struct table *table) { return table->ref_cnt > 1; } - -/* Sets the number of left header columns in TABLE to HL. */ -void -table_set_hl (struct table *table, int hl) -{ - assert (!table_is_shared (table)); - table->h[TABLE_HORZ][0] = hl; -} - -/* Sets the number of right header columns in TABLE to HR. */ -void -table_set_hr (struct table *table, int hr) -{ - assert (!table_is_shared (table)); - table->h[TABLE_HORZ][1] = hr; -} - -/* Sets the number of top header rows in TABLE to HT. */ -void -table_set_ht (struct table *table, int ht) -{ - assert (!table_is_shared (table)); - table->h[TABLE_VERT][0] = ht; -} - -/* Sets the number of top header rows in TABLE to HB. */ -void -table_set_hb (struct table *table, int hb) -{ - assert (!table_is_shared (table)); - table->h[TABLE_VERT][1] = hb; -} struct area_style * area_style_clone (struct pool *pool, const struct area_style *old) @@ -271,7 +239,7 @@ table_collect_footnotes (const struct table_item *item, struct table * table_from_string (const char *text) { - struct tab_table *t = tab_create (1, 1); + struct tab_table *t = tab_create (1, 1, 0, 0, 0, 0); tab_text (t, 0, 0, TAB_LEFT, text); return &t->table; } diff --git a/src/output/table.h b/src/output/table.h index aa1edc107c..6caec33ff7 100644 --- a/src/output/table.h +++ b/src/output/table.h @@ -254,12 +254,6 @@ static inline int table_ht (const struct table *t) { return t->h[TABLE_VERT][0]; } static inline int table_hb (const struct table *t) { return t->h[TABLE_VERT][1]; } - -/* Set headers. */ -void table_set_hl (struct table *, int hl); -void table_set_hr (struct table *, int hr); -void table_set_ht (struct table *, int ht); -void table_set_hb (struct table *, int hb); /* Table classes. */ diff --git a/src/output/text-item.c b/src/output/text-item.c index 7ef12de247..20b424732b 100644 --- a/src/output/text-item.c +++ b/src/output/text-item.c @@ -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); + struct tab_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__, diff --git a/tests/output/render-test.c b/tests/output/render-test.c index 4c559a53d9..961ff59a86 100644 --- a/tests/output/render-test.c +++ b/tests/output/render-test.c @@ -381,8 +381,7 @@ read_table (FILE *stream) ht = n_input >= 5 ? input[4] : 0; hb = n_input >= 6 ? input[5] : 0; - tab = tab_create (nc, nr); - tab_headers (tab, hl, hr, ht, hb); + tab = tab_create (nc, nr, hl, hr, ht, hb); for (r = 0; r < nr; r++) for (c = 0; c < nc; c++) if (tab_cell_is_empty (tab, c, r))