X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Foutput%2Fpivot-table.c;h=924a14cc9b1490eff01f5f50b82ae5c55e31445d;hb=56e6166660c0f1388cad4cb4d3189e026bc84dd5;hp=cce72ef1defabaafad9bf2af6b60c25b3b9830bc;hpb=086c00aa4c7e11ef10cdb20a3afc2ba9caa464ec;p=pspp diff --git a/src/output/pivot-table.c b/src/output/pivot-table.c index cce72ef1de..924a14cc9b 100644 --- a/src/output/pivot-table.c +++ b/src/output/pivot-table.c @@ -62,8 +62,8 @@ pivot_area_to_string (enum pivot_area area) } } -void -pivot_area_get_default_style (enum pivot_area area, struct area_style *style) +const struct area_style * +pivot_area_get_default_style (enum pivot_area area) { #define STYLE(BOLD, H, V, L, R, T, B) { \ .cell_style = { \ @@ -77,6 +77,7 @@ pivot_area_get_default_style (enum pivot_area area, struct area_style *style) .fg = { [0] = CELL_COLOR_BLACK, [1] = CELL_COLOR_BLACK}, \ .bg = { [0] = CELL_COLOR_WHITE, [1] = CELL_COLOR_WHITE}, \ .size = 9, \ + .typeface = (char *) "Sans Serif", \ }, \ } static const struct area_style default_area_styles[PIVOT_N_AREAS] = { @@ -91,8 +92,7 @@ pivot_area_get_default_style (enum pivot_area area, struct area_style *style) }; #undef STYLE - *style = default_area_styles[area]; - style->font_style.typeface = xstrdup ("SansSerif"); + return &default_area_styles[area]; } void @@ -701,12 +701,11 @@ pivot_table_create__ (struct pivot_value *title, const char *subtype) { struct pivot_table *table = xzalloc (sizeof *table); table->ref_cnt = 1; + table->show_caption = true; table->weight_format = (struct fmt_spec) { FMT_F, 40, 0 }; table->title = title; - table->subtype = pivot_value_new_text (subtype); - - const char *command_id = output_get_command_name (); - table->command_c = command_id ? xstrdup (command_id) : NULL; + table->subtype = subtype ? pivot_value_new_text (subtype) : NULL; + table->command_c = output_get_command_name (); table->sizing[TABLE_HORZ].range[0] = 50; table->sizing[TABLE_HORZ].range[1] = 72; @@ -714,7 +713,7 @@ pivot_table_create__ (struct pivot_value *title, const char *subtype) table->sizing[TABLE_VERT].range[1] = 120; for (size_t i = 0; i < PIVOT_N_AREAS; i++) - pivot_area_get_default_style (i, &table->areas[i]); + area_style_copy (NULL, &table->areas[i], pivot_area_get_default_style (i)); /* Set default border styles. */ static const enum table_stroke default_strokes[PIVOT_N_BORDERS] = { @@ -1058,6 +1057,7 @@ pivot_table_create_footnote__ (struct pivot_table *table, size_t idx, f->marker = pivot_make_default_footnote_marker ( f->idx, table->show_numeric_markers); f->content = NULL; + f->show = true; table->footnotes[table->n_footnotes++] = f; } @@ -1487,8 +1487,11 @@ pivot_table_dump (const struct pivot_table *table, int indentation) if (table->date) { indent (indentation); - char buf[26]; - printf ("date: %s", ctime_r (&table->date, buf)); + + struct tm *tm = localtime (&table->date); + printf ("date: %d-%02d-%02d %d:%02d:%02d\n", tm->tm_year + 1900, + tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, + tm->tm_sec); } indent (indentation); @@ -1891,8 +1894,11 @@ pivot_value_format (const struct pivot_value *value, { pivot_value_format_body ( value, show_values, show_variables, out); - if (value->subscript) - ds_put_format (out, "_%s", value->subscript); + if (value->n_subscripts) + { + for (size_t i = 0; i < value->n_subscripts; i++) + ds_put_format (out, "%c%s", i ? ',' : '_', value->subscripts[i]); + } if (value->superscript) ds_put_format (out, "^%s", value->superscript); @@ -1929,7 +1935,12 @@ pivot_value_destroy (struct pivot_value *value) /* Do not free the elements of footnotes because VALUE does not own them. */ free (value->footnotes); - free (value->subscript); + + for (size_t i = 0; i < value->n_subscripts; i++) + free (value->subscripts[i]); + free (value->subscripts); + + free (value->superscript); switch (value->type) { @@ -1975,15 +1986,16 @@ pivot_value_destroy (struct pivot_value *value) DEFAULT_STYLE for the parts of the style that VALUE doesn't override. */ void pivot_value_get_style (struct pivot_value *value, - const struct area_style *default_style, + const struct font_style *base_font_style, + const struct cell_style *base_cell_style, struct area_style *area) { font_style_copy (NULL, &area->font_style, (value->font_style ? value->font_style - : &default_style->font_style)); - area->cell_style = (value->cell_style - ? *value->cell_style - : default_style->cell_style); + : base_font_style)); + area->cell_style = *(value->cell_style + ? value->cell_style + : base_cell_style); } /* Copies AREA into VALUE's style. */ @@ -2218,6 +2230,12 @@ void pivot_value_add_footnote (struct pivot_value *v, const struct pivot_footnote *footnote) { + /* Some legacy tables include numerous duplicate footnotes. Suppress + them. */ + for (size_t i = 0; i < v->n_footnotes; i++) + if (v->footnotes[i] == footnote) + return; + v->footnotes = xrealloc (v->footnotes, (v->n_footnotes + 1) * sizeof *v->footnotes); v->footnotes[v->n_footnotes++] = footnote;