projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
psppire: Deal properly with inverted variable selections.
[pspp]
/
src
/
output
/
pivot-table.c
diff --git
a/src/output/pivot-table.c
b/src/output/pivot-table.c
index bab2a8d6aefab9886c06d02967e4435917997e48..924a14cc9b1490eff01f5f50b82ae5c55e31445d 100644
(file)
--- a/
src/output/pivot-table.c
+++ b/
src/output/pivot-table.c
@@
-26,6
+26,7
@@
#include "data/variable.h"
#include "libpspp/hash-functions.h"
#include "libpspp/i18n.h"
#include "data/variable.h"
#include "libpspp/hash-functions.h"
#include "libpspp/i18n.h"
+#include "output/driver.h"
#include "gl/c-ctype.h"
#include "gl/intprops.h"
#include "gl/c-ctype.h"
#include "gl/intprops.h"
@@
-61,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 = { \
{
#define STYLE(BOLD, H, V, L, R, T, B) { \
.cell_style = { \
@@
-76,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, \
.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] = {
}, \
}
static const struct area_style default_area_styles[PIVOT_N_AREAS] = {
@@
-90,8
+92,7
@@
pivot_area_get_default_style (enum pivot_area area, struct area_style *style)
};
#undef STYLE
};
#undef STYLE
- *style = default_area_styles[area];
- style->font_style.typeface = xstrdup ("SansSerif");
+ return &default_area_styles[area];
}
void
}
void
@@
-655,7
+656,8
@@
pivot_result_class_change (const char *s_, const struct fmt_spec *format)
/* Creates and returns a new pivot table with the given TITLE. TITLE should be
a text string marked for translation but not actually translated yet,
/* Creates and returns a new pivot table with the given TITLE. TITLE should be
a text string marked for translation but not actually translated yet,
- e.g. N_("Descriptive Statistics").
+ e.g. N_("Descriptive Statistics"). The un-translated text string is used as
+ the pivot table's subtype.
Operations commonly performed on the new pivot_table:
Operations commonly performed on the new pivot_table:
@@
-667,18
+669,22
@@
pivot_result_class_change (const char *s_, const struct fmt_spec *format)
This function is a shortcut for pivot_table_create__() for the most common
case. Use pivot_table_create__() directly if the title should be some kind
This function is a shortcut for pivot_table_create__() for the most common
case. Use pivot_table_create__() directly if the title should be some kind
- of value other than an ordinary text string.
+ of value other than an ordinary text string, or if the subtype should be
+different from the title.
See the large comment at the top of pivot-table.h for general advice on
creating pivot tables. */
struct pivot_table *
pivot_table_create (const char *title)
{
See the large comment at the top of pivot-table.h for general advice on
creating pivot tables. */
struct pivot_table *
pivot_table_create (const char *title)
{
- return pivot_table_create__ (pivot_value_new_text (title));
+ return pivot_table_create__ (pivot_value_new_text (title)
, title
);
}
/* Creates and returns a new pivot table with the given TITLE, and takes
}
/* Creates and returns a new pivot table with the given TITLE, and takes
- ownership of TITLE.
+ ownership of TITLE. The new pivot table's subtype is SUBTYPE, which
+ should be an untranslated English string that describes the contents of
+ the table at a high level without being specific about the variables or
+ other context involved.
Operations commonly performed on the new pivot_table:
Operations commonly performed on the new pivot_table:
@@
-691,12
+697,15
@@
pivot_table_create (const char *title)
See the large comment at the top of pivot-table.h for general advice on
creating pivot tables. */
struct pivot_table *
See the large comment at the top of pivot-table.h for general advice on
creating pivot tables. */
struct pivot_table *
-pivot_table_create__ (struct pivot_value *title)
+pivot_table_create__ (struct pivot_value *title
, const char *subtype
)
{
struct pivot_table *table = xzalloc (sizeof *table);
table->ref_cnt = 1;
{
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->weight_format = (struct fmt_spec) { FMT_F, 40, 0 };
table->title = title;
+ 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;
table->sizing[TABLE_HORZ].range[0] = 50;
table->sizing[TABLE_HORZ].range[1] = 72;
@@
-704,7
+713,7
@@
pivot_table_create__ (struct pivot_value *title)
table->sizing[TABLE_VERT].range[1] = 120;
for (size_t i = 0; i < PIVOT_N_AREAS; i++)
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] = {
/* Set default border styles. */
static const enum table_stroke default_strokes[PIVOT_N_BORDERS] = {
@@
-748,7
+757,7
@@
struct pivot_table *
pivot_table_create_for_text (struct pivot_value *title,
struct pivot_value *content)
{
pivot_table_create_for_text (struct pivot_value *title,
struct pivot_value *content)
{
- struct pivot_table *table = pivot_table_create__ (title);
+ struct pivot_table *table = pivot_table_create__ (title
, "Error"
);
struct pivot_dimension *d = pivot_dimension_create (
table, PIVOT_AXIS_ROW, N_("Error"));
struct pivot_dimension *d = pivot_dimension_create (
table, PIVOT_AXIS_ROW, N_("Error"));
@@
-1048,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->marker = pivot_make_default_footnote_marker (
f->idx, table->show_numeric_markers);
f->content = NULL;
+ f->show = true;
table->footnotes[table->n_footnotes++] = f;
}
table->footnotes[table->n_footnotes++] = f;
}
@@
-1477,8
+1487,11
@@
pivot_table_dump (const struct pivot_table *table, int indentation)
if (table->date)
{
indent (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);
}
indent (indentation);
@@
-1860,7
+1873,7
@@
pivot_value_format_body (const struct pivot_value *value,
break;
case PIVOT_VALUE_TEMPLATE:
break;
case PIVOT_VALUE_TEMPLATE:
- pivot_format_template (out, value->template.
s
, value->template.args,
+ pivot_format_template (out, value->template.
local
, value->template.args,
value->template.n_args, show_values,
show_variables);
break;
value->template.n_args, show_values,
show_variables);
break;
@@
-1881,8
+1894,11
@@
pivot_value_format (const struct pivot_value *value,
{
pivot_value_format_body ( value, show_values, show_variables, out);
{
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);
if (value->superscript)
ds_put_format (out, "^%s", value->superscript);
@@
-1919,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);
/* 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)
{
switch (value->type)
{
@@
-1949,7
+1970,9
@@
pivot_value_destroy (struct pivot_value *value)
break;
case PIVOT_VALUE_TEMPLATE:
break;
case PIVOT_VALUE_TEMPLATE:
- free (value->template.s);
+ free (value->template.local);
+ if (value->template.id != value->template.local)
+ free (value->template.id);
for (size_t i = 0; i < value->template.n_args; i++)
pivot_argument_uninit (&value->template.args[i]);
free (value->template.args);
for (size_t i = 0; i < value->template.n_args; i++)
pivot_argument_uninit (&value->template.args[i]);
free (value->template.args);
@@
-1963,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,
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)
{
struct area_style *area)
{
- font_style_copy (&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);
+ font_style_copy (
NULL,
&area->font_style, (value->font_style
+
? value->font_style
+
: base_
font_style));
+ area->cell_style =
*
(value->cell_style
+
?
value->cell_style
+
: base_
cell_style);
}
/* Copies AREA into VALUE's style. */
}
/* Copies AREA into VALUE's style. */
@@
-1983,7
+2007,7
@@
pivot_value_set_style (struct pivot_value *value,
font_style_uninit (value->font_style);
else
value->font_style = xmalloc (sizeof *value->font_style);
font_style_uninit (value->font_style);
else
value->font_style = xmalloc (sizeof *value->font_style);
- font_style_copy (value->font_style, &area->font_style);
+ font_style_copy (
NULL,
value->font_style, &area->font_style);
if (!value->cell_style)
value->cell_style = xmalloc (sizeof *value->cell_style);
if (!value->cell_style)
value->cell_style = xmalloc (sizeof *value->cell_style);
@@
-2206,6
+2230,12
@@
void
pivot_value_add_footnote (struct pivot_value *v,
const struct pivot_footnote *footnote)
{
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;
v->footnotes = xrealloc (v->footnotes,
(v->n_footnotes + 1) * sizeof *v->footnotes);
v->footnotes[v->n_footnotes++] = footnote;