+
+
+/* Destroys a struct fmt_number_style. */
+void
+fmt_number_style_destroy (struct fmt_number_style *style)
+{
+ if (style != NULL)
+ {
+ ss_dealloc (&style->neg_prefix);
+ ss_dealloc (&style->prefix);
+ ss_dealloc (&style->suffix);
+ ss_dealloc (&style->neg_suffix);
+ }
+}
+
+/* Returns the number formatting style associated with the given
+ format TYPE. */
+const struct fmt_number_style *
+fmt_get_style (const struct fmt_number_style *styles, enum fmt_type type)
+{
+ assert (is_fmt_type (type));
+ return &styles[type];
+}
+
+
+/* Checks that style is STYLE sane */
+void
+fmt_check_style (const struct fmt_number_style *style)
+{
+ assert (ss_length (style->neg_prefix) <= FMT_STYLE_AFFIX_MAX);
+ assert (ss_length (style->prefix) <= FMT_STYLE_AFFIX_MAX);
+ assert (ss_length (style->suffix) <= FMT_STYLE_AFFIX_MAX);
+ assert (ss_length (style->neg_suffix) <= FMT_STYLE_AFFIX_MAX);
+ assert (style->decimal == '.' || style->decimal == ',');
+ assert (style->grouping == '.' || style->grouping == ','
+ || style->grouping == 0);
+ assert (style->grouping != style->decimal);
+}
+
+
+/* Returns the total width of the standard prefix and suffix for
+ STYLE. */
+int
+fmt_affix_width (const struct fmt_number_style *style)
+{
+ return ss_length (style->prefix) + ss_length (style->suffix);
+}
+
+/* Returns the total width of the negative prefix and suffix for
+ STYLE. */
+int
+fmt_neg_affix_width (const struct fmt_number_style *style)
+{
+ return ss_length (style->neg_prefix) + ss_length (style->neg_suffix);
+}
+
+
+/* Sets the number style for TYPE to have the given standard
+ PREFIX and SUFFIX, "-" as prefix suffix, an empty negative
+ suffix, DECIMAL as the decimal point character, and GROUPING
+ as the grouping character. */
+static void
+set_style (struct fmt_number_style *styles, enum fmt_type type,
+ const char *prefix, const char *suffix,
+ char decimal, char grouping)
+{
+ struct fmt_number_style *style;
+
+ assert (is_fmt_type (type));
+
+ style = &styles[type] ;
+
+ fmt_number_style_destroy (style);
+
+ ss_alloc_substring (&style->neg_prefix, ss_cstr ("-"));
+ ss_alloc_substring (&style->prefix, ss_cstr (prefix));
+ ss_alloc_substring (&style->suffix, ss_cstr (suffix));
+ style->decimal = decimal;
+ style->grouping = grouping;
+}
+
+/* Sets the decimal point character to DECIMAL. */
+void
+fmt_set_decimal (struct fmt_number_style *styles, char decimal)
+{
+ int grouping = decimal == '.' ? ',' : '.';
+ assert (decimal == '.' || decimal == ',');
+
+ set_style (styles, FMT_F, "", "", decimal, 0);
+ set_style (styles, FMT_E, "", "", decimal, 0);
+ set_style (styles, FMT_COMMA, "", "", decimal, grouping);
+ set_style (styles, FMT_DOT, "", "", grouping, decimal);
+ set_style (styles, FMT_DOLLAR, "$", "", decimal, grouping);
+ set_style (styles, FMT_PCT, "", "%", decimal, 0);
+}
+\f
+/* Returns the struct fmt_desc for the given format TYPE. */
+static const struct fmt_desc *
+get_fmt_desc (enum fmt_type type)
+{
+ static const struct fmt_desc formats[FMT_NUMBER_OF_FORMATS] =
+ {
+#define FMT(NAME, METHOD, IMIN, OMIN, IO, CATEGORY) \
+ {#NAME, IMIN, OMIN, IO, CATEGORY},
+#include "format.def"
+ };
+
+ assert (is_fmt_type (type));
+ return &formats[type];
+}
+
+const struct fmt_spec F_8_0 = {FMT_F, 8, 0};