+ for (t = 0 ; t < FMT_NUMBER_OF_FORMATS ; ++t )
+ fmt_number_style_destroy (&settings->styles[t]);
+
+ free (settings->styles);
+ }
+}
+
+/* Returns a copy of SETTINGS. */
+struct fmt_settings *
+fmt_settings_clone (const struct fmt_settings *old)
+{
+ struct fmt_settings *new;
+ int t;
+
+ new = xmalloc (sizeof *new);
+ for (t = 0 ; t < FMT_NUMBER_OF_FORMATS ; ++t )
+ fmt_number_style_clone (&new->styles[t], &old->styles[t]);
+
+ return new;
+}
+
+/* Returns the number formatting style associated with the given
+ format TYPE. */
+const struct fmt_number_style *
+fmt_settings_get_style (const struct fmt_settings *settings,
+ enum fmt_type type)
+{
+ assert (is_fmt_type (type));
+ return &settings->styles[type];
+}
+
+/* Sets the number style for TYPE to have the given DECIMAL and GROUPING
+ characters, negative prefix NEG_PREFIX, prefix PREFIX, suffix SUFFIX, and
+ negative suffix NEG_SUFFIX. */
+void
+fmt_settings_set_style (struct fmt_settings *settings, enum fmt_type type,
+ char decimal, char grouping,
+ const char *neg_prefix, const char *prefix,
+ const char *suffix, const char *neg_suffix)
+{
+ struct fmt_number_style *style = &settings->styles[type];
+
+ assert (grouping == '.' || grouping == ',' || grouping == 0);
+ assert (decimal == '.' || decimal == ',');
+ assert (decimal != grouping);
+
+ fmt_number_style_destroy (style);
+
+ fmt_affix_set (&style->neg_prefix, neg_prefix);
+ fmt_affix_set (&style->prefix, prefix);
+ fmt_affix_set (&style->suffix, suffix);
+ fmt_affix_set (&style->neg_suffix, neg_suffix);
+ style->decimal = decimal;
+ style->grouping = grouping;
+}
+
+/* Sets the decimal point character for the settings in S to DECIMAL.
+
+ This has no effect on custom currency formats. */
+void
+fmt_settings_set_decimal (struct fmt_settings *s, char decimal)
+{
+ int grouping = decimal == '.' ? ',' : '.';
+ assert (decimal == '.' || decimal == ',');
+
+ fmt_settings_set_style (s, FMT_F, decimal, 0, "-", "", "", "");
+ fmt_settings_set_style (s, FMT_E, decimal, 0, "-", "", "", "");
+ fmt_settings_set_style (s, FMT_COMMA, decimal, grouping, "-", "", "", "");
+ fmt_settings_set_style (s, FMT_DOT, grouping, decimal, "-", "", "", "");
+ fmt_settings_set_style (s, FMT_DOLLAR, decimal, grouping, "-", "$", "", "");
+ fmt_settings_set_style (s, FMT_PCT, decimal, 0, "-", "", "%", "");
+}
+
+/* Returns an input format specification with type TYPE, width W,
+ and D decimals. */
+struct fmt_spec
+fmt_for_input (enum fmt_type type, int w, int d)
+{
+ struct fmt_spec f;
+ f.type = type;
+ f.w = w;
+ f.d = d;
+ assert (fmt_check_input (&f));
+ return f;
+}
+
+/* Returns an output format specification with type TYPE, width
+ W, and D decimals. */
+struct fmt_spec
+fmt_for_output (enum fmt_type type, int w, int d)
+{
+ struct fmt_spec f;
+ f.type = type;
+ f.w = w;
+ f.d = d;
+ assert (fmt_check_output (&f));
+ return f;
+}
+
+/* Returns the output format specifier corresponding to input
+ format specifier INPUT. */
+struct fmt_spec
+fmt_for_output_from_input (const struct fmt_spec *input)
+{
+ struct fmt_spec output;
+
+ assert (fmt_check_input (input));
+
+ output.type = fmt_input_to_output (input->type);
+ output.w = input->w;
+ if (output.w > fmt_max_output_width (output.type))
+ output.w = fmt_max_output_width (output.type);
+ else if (output.w < fmt_min_output_width (output.type))
+ output.w = fmt_min_output_width (output.type);
+ output.d = input->d;
+
+ switch (input->type)
+ {
+ case FMT_Z:
+ output.w++;
+ if (output.d > 0)
+ output.w++;
+ break;
+
+ case FMT_F:
+ case FMT_COMMA:
+ case FMT_DOT:
+ case FMT_DOLLAR:
+ case FMT_PCT: