+
+/* Returns true if TYPE may be used as an input format,
+ false otherwise. */
+bool
+fmt_usable_for_input (enum fmt_type type)
+{
+ assert (is_fmt_type (type));
+ return fmt_get_category (type) != FMT_CAT_CUSTOM;
+}
+
+/* For time and date formats, returns a template used for input
+ and output. */
+const char *
+fmt_date_template (enum fmt_type type)
+{
+ switch (type)
+ {
+ case FMT_DATE:
+ return "dd-mmm-yy";
+ case FMT_ADATE:
+ return "mm/dd/yy";
+ case FMT_EDATE:
+ return "dd.mm.yy";
+ case FMT_JDATE:
+ return "yyddd";
+ case FMT_SDATE:
+ return "yy/mm/dd";
+ case FMT_QYR:
+ return "q Q yy";
+ case FMT_MOYR:
+ return "mmmXyy";
+ case FMT_WKYR:
+ return "ww WK yy";
+ case FMT_DATETIME:
+ return "dd-mmm-yyyy HH:MM";
+ case FMT_TIME:
+ return "H:MM";
+ case FMT_DTIME:
+ return "D HH:MM";
+ default:
+ NOT_REACHED ();
+ }
+}
+
+\f
+/* Returns true if TYPE is a valid format type,
+ false otherwise. */
+bool
+is_fmt_type (enum fmt_type type)
+{
+ return type < FMT_NUMBER_OF_FORMATS;
+}
+
+/* Returns true if WIDTH is a valid width for the given format
+ TYPE,
+ for input if FOR_INPUT is true,
+ for output otherwise. */
+static bool
+valid_width (enum fmt_type type, int width, bool for_input)
+{
+ return (width >= fmt_min_width (type, for_input)
+ && width <= fmt_max_width (type, for_input));
+}
+
+/* Returns the maximum number of decimal digits in an unsigned
+ binary number that is BYTES bytes long. */
+static int
+max_digits_for_bytes (int bytes)
+{
+ int map[8] = {3, 5, 8, 10, 13, 15, 17, 20};
+ assert (bytes > 0 && bytes <= sizeof map / sizeof *map);
+ return map[bytes - 1];
+}
+\f
+static void
+fmt_number_style_init (struct fmt_number_style *style)
+{
+ style->neg_prefix = ss_empty ();
+ style->prefix = ss_empty ();
+ style->suffix = ss_empty ();
+ style->neg_suffix = ss_empty ();
+ style->decimal = '.';
+ style->grouping = 0;
+}
+
+static void
+fmt_number_style_clone (struct fmt_number_style *new,
+ const struct fmt_number_style *old)
+{
+ ss_alloc_substring (&new->neg_prefix, old->neg_prefix);
+ ss_alloc_substring (&new->prefix, old->prefix);
+ ss_alloc_substring (&new->suffix, old->suffix);
+ ss_alloc_substring (&new->neg_suffix, old->neg_suffix);
+ new->decimal = old->decimal;
+ new->grouping = old->grouping;
+}
+
+/* Destroys a struct fmt_number_style. */
+static 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);
+ }
+}
+
+/* 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);
+}
+
+/* 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};