fmt_number_style_destroy (settings->ccs[i]);
}
-void
-fmt_settings_copy (struct fmt_settings *new, const struct fmt_settings *old)
+struct fmt_settings
+fmt_settings_copy (const struct fmt_settings *old)
{
- new->epoch = old->epoch;
- new->decimal = old->decimal;
+ struct fmt_settings new = *old;
for (int i = 0; i < FMT_N_CCS; i++)
- new->ccs[i] = fmt_number_style_clone (old->ccs[i]);
+ new.ccs[i] = fmt_number_style_clone (old->ccs[i]);
+ return new;
}
static size_t
return style;
}
+static void
+format_cc (struct string *out, const char *in, char grouping)
+{
+ while (*in != '\0')
+ {
+ char c = *in++;
+ if (c == grouping || c == '\'')
+ ds_put_byte (out, '\'');
+ else if (c == '"')
+ ds_put_byte (out, '"');
+ ds_put_byte (out, c);
+ }
+}
+
+char *
+fmt_number_style_to_string (const struct fmt_number_style *cc)
+{
+ struct string out = DS_EMPTY_INITIALIZER;
+ format_cc (&out, cc->neg_prefix.s, cc->grouping);
+ ds_put_byte (&out, cc->grouping);
+ format_cc (&out, cc->prefix.s, cc->grouping);
+ ds_put_byte (&out, cc->grouping);
+ format_cc (&out, cc->suffix.s, cc->grouping);
+ ds_put_byte (&out, cc->grouping);
+ format_cc (&out, cc->neg_suffix.s, cc->grouping);
+ return ds_steal_cstr (&out);
+}
+
struct fmt_number_style *
fmt_number_style_clone (const struct fmt_number_style *old)
{
: xasprintf ("%.*g", DBL_DIG + 1, settings_get_blanks ()));
}
-static void
-format_cc (struct string *out, const char *in, char grouping)
-{
- while (*in != '\0')
- {
- char c = *in++;
- if (c == grouping || c == '\'')
- ds_put_byte (out, '\'');
- else if (c == '"')
- ds_put_byte (out, '"');
- ds_put_byte (out, c);
- }
-}
-
static char *
show_cc (enum fmt_type type)
{
- const struct fmt_number_style *cc = fmt_settings_get_style (
- settings_get_fmt_settings (), type);
- struct string out;
-
- ds_init_empty (&out);
- format_cc (&out, cc->neg_prefix.s, cc->grouping);
- ds_put_byte (&out, cc->grouping);
- format_cc (&out, cc->prefix.s, cc->grouping);
- ds_put_byte (&out, cc->grouping);
- format_cc (&out, cc->suffix.s, cc->grouping);
- ds_put_byte (&out, cc->grouping);
- format_cc (&out, cc->neg_suffix.s, cc->grouping);
-
- return ds_cstr (&out);
+ return fmt_number_style_to_string (fmt_settings_get_style (
+ settings_get_fmt_settings (), type));
}
static char *
table->subtype = subtype ? pivot_value_new_text (subtype) : NULL;
table->command_c = output_get_command_name ();
table->look = pivot_table_look_ref (pivot_table_look_get_default ());
+ table->settings = fmt_settings_copy (settings_get_fmt_settings ());
hmap_init (&table->cells);
[TABLE_VERT] = clone_sizing (&old->sizing[TABLE_VERT]),
},
- .epoch = old->epoch,
- .decimal = old->decimal,
+ .settings = fmt_settings_copy (&old->settings),
.grouping = old->grouping,
- .ccs = {
- [0] = xstrdup_if_nonnull (old->ccs[0]),
- [1] = xstrdup_if_nonnull (old->ccs[1]),
- [2] = xstrdup_if_nonnull (old->ccs[2]),
- [3] = xstrdup_if_nonnull (old->ccs[3]),
- [4] = xstrdup_if_nonnull (old->ccs[4]),
- },
.small = old->small,
.command_local = xstrdup_if_nonnull (old->command_local),
for (int i = 0; i < TABLE_N_AXES; i++)
pivot_table_sizing_uninit (&table->sizing[i]);
- for (int i = 0; i < sizeof table->ccs / sizeof *table->ccs; i++)
- free (table->ccs[i]);
+ fmt_settings_uninit (&table->settings);
free (table->command_local);
free (table->command_c);
}
static void
-pivot_value_dump (const struct pivot_value *value)
+pivot_value_dump (const struct pivot_value *value,
+ const struct pivot_table *pt)
{
- char *s = pivot_value_to_string_defaults (value);
+ char *s = pivot_value_to_string (value, pt);
fputs (s, stdout);
free (s);
}
static void
pivot_table_dump_value (const struct pivot_value *value, const char *name,
- int indentation)
+ const struct pivot_table *pt, int indentation)
{
if (value)
{
indent (indentation);
printf ("%s: ", name);
- pivot_value_dump (value);
+ pivot_value_dump (value, pt);
putchar ('\n');
}
}
}
static void
-pivot_category_dump (const struct pivot_category *c, int indentation)
+pivot_category_dump (const struct pivot_category *c,
+ const struct pivot_table *pt, int indentation)
{
indent (indentation);
printf ("%s \"", pivot_category_is_leaf (c) ? "leaf" : "group");
- pivot_value_dump (c->name);
+ pivot_value_dump (c->name, pt);
printf ("\" ");
if (pivot_category_is_leaf (c))
printf ("\n");
for (size_t i = 0; i < c->n_subs; i++)
- pivot_category_dump (c->subs[i], indentation + 1);
+ pivot_category_dump (c->subs[i], pt, indentation + 1);
}
}
void
-pivot_dimension_dump (const struct pivot_dimension *d, int indentation)
+pivot_dimension_dump (const struct pivot_dimension *d,
+ const struct pivot_table *pt, int indentation)
{
indent (indentation);
printf ("%s dimension %zu (where 0=innermost), label_depth=%d:\n",
pivot_axis_type_to_string (d->axis_type), d->level, d->label_depth);
- pivot_category_dump (d->root, indentation + 1);
+ pivot_category_dump (d->root, pt, indentation + 1);
}
static void
pivot_table_assign_label_depth (CONST_CAST (struct pivot_table *, table));
- int old_decimal = settings_get_fmt_settings ()->decimal;
- if (table->decimal == '.' || table->decimal == ',')
- settings_set_decimal_char (table->decimal);
-
- pivot_table_dump_value (table->title, "title", indentation);
- pivot_table_dump_value (table->subtype, "subtype", indentation);
+ pivot_table_dump_value (table->title, "title", table, indentation);
+ pivot_table_dump_value (table->subtype, "subtype", table, indentation);
pivot_table_dump_string (table->command_c, "command", indentation);
pivot_table_dump_string (table->dataset, "dataset", indentation);
pivot_table_dump_string (table->datafile, "datafile", indentation);
indentation + 1);
for (size_t i = 0; i < table->n_dimensions; i++)
- pivot_dimension_dump (table->dimensions[i], indentation);
+ pivot_dimension_dump (table->dimensions[i], table, indentation);
/* Presentation and data indexes. */
size_t *dindexes = XCALLOC (table->n_dimensions, size_t);
const struct pivot_dimension *d = layer_axis->dimensions[i];
fputs (i == 0 ? " " : ", ", stdout);
- pivot_value_dump (d->root->name);
+ pivot_value_dump (d->root->name, table);
fputs (" =", stdout);
struct pivot_value **names = xnmalloc (d->n_leaves, sizeof *names);
for (size_t i = n_names; i-- > 0;)
{
putchar (' ');
- pivot_value_dump (names[i]);
+ pivot_value_dump (names[i], table);
}
free (names);
}
const struct pivot_value *value = pivot_table_get (
table, dindexes);
if (value)
- pivot_value_dump (value);
+ pivot_value_dump (value, table);
}
printf ("\n");
free_headings (&table->axes[PIVOT_AXIS_ROW], row_headings);
}
- pivot_table_dump_value (table->caption, "caption", indentation);
+ pivot_table_dump_value (table->caption, "caption", table, indentation);
for (size_t i = 0; i < table->n_footnotes; i++)
{
indent (indentation);
putchar ('[');
if (f->marker)
- pivot_value_dump (f->marker);
+ pivot_value_dump (f->marker, table);
else
printf ("%zu", f->idx);
putchar (']');
- pivot_value_dump (f->content);
+ pivot_value_dump (f->content, table);
putchar ('\n');
}
free (dindexes);
- settings_set_decimal_char (old_decimal);
}
\f
static const char *
if (show & SETTINGS_VALUE_SHOW_VALUE)
{
char *s = data_out (&(union value) { .f = value->numeric.x },
- "UTF-8", &value->numeric.format,
- settings_get_fmt_settings ());
+ "UTF-8", &value->numeric.format, &pt->settings);
ds_put_cstr (out, s + strspn (s, " "));
free (s);
}