1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 1997-9, 2000, 2006, 2010, 2011, 2012 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
25 #include "data/identifier.h"
26 #include "data/settings.h"
27 #include "data/value.h"
28 #include "data/variable.h"
29 #include "libpspp/assertion.h"
30 #include "libpspp/cast.h"
31 #include "libpspp/compiler.h"
32 #include "libpspp/message.h"
33 #include "libpspp/misc.h"
34 #include "libpspp/str.h"
36 #include "gl/c-strcase.h"
37 #include "gl/minmax.h"
38 #include "gl/xalloc.h"
41 #define _(msgid) gettext (msgid)
45 struct fmt_number_style styles[FMT_NUMBER_OF_FORMATS];
48 bool is_fmt_type (enum fmt_type);
50 static bool valid_width (enum fmt_type, int width, enum fmt_use);
52 static int max_digits_for_bytes (int bytes);
53 static void fmt_clamp_width (struct fmt_spec *, enum fmt_use);
54 static void fmt_clamp_decimals (struct fmt_spec *, enum fmt_use);
56 static void fmt_affix_set (struct fmt_affix *, const char *);
57 static void fmt_affix_free (struct fmt_affix *);
59 static void fmt_number_style_init (struct fmt_number_style *);
60 static void fmt_number_style_clone (struct fmt_number_style *,
61 const struct fmt_number_style *);
62 static void fmt_number_style_destroy (struct fmt_number_style *);
64 /* Creates and returns a new struct fmt_settings with default format styles. */
66 fmt_settings_create (void)
68 struct fmt_settings *settings;
71 settings = xzalloc (sizeof *settings);
72 for (t = 0 ; t < FMT_NUMBER_OF_FORMATS ; ++t )
73 fmt_number_style_init (&settings->styles[t]);
74 fmt_settings_set_decimal (settings, '.');
79 /* Destroys SETTINGS. */
81 fmt_settings_destroy (struct fmt_settings *settings)
87 for (t = 0 ; t < FMT_NUMBER_OF_FORMATS ; ++t )
88 fmt_number_style_destroy (&settings->styles[t]);
90 free (settings->styles);
94 /* Returns a copy of SETTINGS. */
96 fmt_settings_clone (const struct fmt_settings *old)
98 struct fmt_settings *new;
101 new = xmalloc (sizeof *new);
102 for (t = 0 ; t < FMT_NUMBER_OF_FORMATS ; ++t )
103 fmt_number_style_clone (&new->styles[t], &old->styles[t]);
108 /* Returns the number formatting style associated with the given
110 const struct fmt_number_style *
111 fmt_settings_get_style (const struct fmt_settings *settings,
114 assert (is_fmt_type (type));
115 return &settings->styles[type];
118 /* Sets the number style for TYPE to have the given DECIMAL and GROUPING
119 characters, negative prefix NEG_PREFIX, prefix PREFIX, suffix SUFFIX, and
120 negative suffix NEG_SUFFIX. All of the strings are UTF-8 encoded. */
122 fmt_settings_set_style (struct fmt_settings *settings, enum fmt_type type,
123 char decimal, char grouping,
124 const char *neg_prefix, const char *prefix,
125 const char *suffix, const char *neg_suffix)
127 struct fmt_number_style *style = &settings->styles[type];
128 int total_bytes, total_width;
130 assert (grouping == '.' || grouping == ',' || grouping == 0);
131 assert (decimal == '.' || decimal == ',');
132 assert (decimal != grouping);
134 fmt_number_style_destroy (style);
136 fmt_affix_set (&style->neg_prefix, neg_prefix);
137 fmt_affix_set (&style->prefix, prefix);
138 fmt_affix_set (&style->suffix, suffix);
139 fmt_affix_set (&style->neg_suffix, neg_suffix);
140 style->decimal = decimal;
141 style->grouping = grouping;
143 total_bytes = (strlen (neg_prefix) + strlen (prefix)
144 + strlen (suffix) + strlen (neg_suffix));
145 total_width = (style->neg_prefix.width + style->prefix.width
146 + style->suffix.width + style->neg_suffix.width);
147 style->extra_bytes = MAX (0, total_bytes - total_width);
150 /* Sets the decimal point character for the settings in S to DECIMAL.
152 This has no effect on custom currency formats. */
154 fmt_settings_set_decimal (struct fmt_settings *s, char decimal)
156 int grouping = decimal == '.' ? ',' : '.';
157 assert (decimal == '.' || decimal == ',');
159 fmt_settings_set_style (s, FMT_F, decimal, 0, "-", "", "", "");
160 fmt_settings_set_style (s, FMT_E, decimal, 0, "-", "", "", "");
161 fmt_settings_set_style (s, FMT_COMMA, decimal, grouping, "-", "", "", "");
162 fmt_settings_set_style (s, FMT_DOT, grouping, decimal, "-", "", "", "");
163 fmt_settings_set_style (s, FMT_DOLLAR, decimal, grouping, "-", "$", "", "");
164 fmt_settings_set_style (s, FMT_PCT, decimal, 0, "-", "", "%", "");
167 /* Returns an input format specification with type TYPE, width W,
170 fmt_for_input (enum fmt_type type, int w, int d)
176 assert (fmt_check_input (&f));
180 /* Returns an output format specification with type TYPE, width
181 W, and D decimals. */
183 fmt_for_output (enum fmt_type type, int w, int d)
189 assert (fmt_check_output (&f));
193 /* Returns the output format specifier corresponding to input
194 format specifier INPUT. */
196 fmt_for_output_from_input (const struct fmt_spec *input)
198 struct fmt_spec output;
200 assert (fmt_check_input (input));
202 output.type = fmt_input_to_output (input->type);
204 if (output.w > fmt_max_output_width (output.type))
205 output.w = fmt_max_output_width (output.type);
206 else if (output.w < fmt_min_output_width (output.type))
207 output.w = fmt_min_output_width (output.type);
224 const struct fmt_number_style *style =
225 settings_get_style (input->type);
227 output.w += fmt_affix_width (style);
228 if (style->grouping != 0 && input->w - input->d >= 3)
229 output.w += (input->w - input->d - 1) / 3;
241 output.d = MAX (input->d, 3);
242 output.w = MAX (input->w, output.d + 7);
246 output.w = max_digits_for_bytes (input->w / 2) + 1;
257 output.w = 2 * input->w + (input->d > 0);
262 output.w = max_digits_for_bytes (input->w) + 1;
278 output.w = input->w / 2;
300 if (output.w > fmt_max_output_width (output.type))
301 output.w = fmt_max_output_width (output.type);
303 assert (fmt_check_output (&output));
307 /* Returns the default format for the given WIDTH: F8.2 format
308 for a numeric value, A format for a string value. */
310 fmt_default_for_width (int width)
313 ? fmt_for_output (FMT_F, 8, 2)
314 : fmt_for_output (FMT_A, width, 0));
317 /* Checks whether SPEC is valid for USE and returns nonzero if so.
318 Otherwise, emits an error message and returns zero. */
320 fmt_check (const struct fmt_spec *spec, enum fmt_use use)
323 char str[FMT_STRING_LEN_MAX + 1];
324 int min_w, max_w, max_d;
326 assert (is_fmt_type (spec->type));
327 fmt_to_string (spec, str);
329 io_fmt = use == FMT_FOR_INPUT ? _("Input format") : _("Output format");
330 if (use == FMT_FOR_INPUT && !fmt_usable_for_input (spec->type))
332 msg (SE, _("Format %s may not be used for input."), str);
336 if (spec->w % fmt_step_width (spec->type))
338 assert (fmt_step_width (spec->type) == 2);
339 msg (SE, _("%s specifies width %d, but %s requires an even width."),
340 str, spec->w, fmt_name (spec->type));
344 min_w = fmt_min_width (spec->type, use);
345 max_w = fmt_max_width (spec->type, use);
346 if (spec->w < min_w || spec->w > max_w)
348 msg (SE, _("%s %s specifies width %d, but "
349 "%s requires a width between %d and %d."),
350 io_fmt, str, spec->w, fmt_name (spec->type), min_w, max_w);
354 max_d = fmt_max_decimals (spec->type, spec->w, use);
355 if (!fmt_takes_decimals (spec->type) && spec->d != 0)
357 msg (SE, ngettext ("%s %s specifies %d decimal place, but "
358 "%s does not allow any decimals.",
359 "%s %s specifies %d decimal places, but "
360 "%s does not allow any decimals.",
362 io_fmt, str, spec->d, fmt_name (spec->type));
365 else if (spec->d > max_d)
368 msg (SE, ngettext ("%s %s specifies %d decimal place, but "
369 "the given width allows at most %d decimals.",
370 "%s %s specifies %d decimal places, but "
371 "the given width allows at most %d decimals.",
373 io_fmt, str, spec->d, max_d);
375 msg (SE, ngettext ("%s %s specifies %d decimal place, but "
376 "the given width does not allow for any decimals.",
377 "%s %s specifies %d decimal places, but "
378 "the given width does not allow for any decimals.",
380 io_fmt, str, spec->d);
387 /* Checks whether SPEC is valid as an input format and returns
388 nonzero if so. Otherwise, emits an error message and returns
391 fmt_check_input (const struct fmt_spec *spec)
393 return fmt_check (spec, FMT_FOR_INPUT);
396 /* Checks whether SPEC is valid as an output format and returns
397 true if so. Otherwise, emits an error message and returns false. */
399 fmt_check_output (const struct fmt_spec *spec)
401 return fmt_check (spec, FMT_FOR_OUTPUT);
404 /* Checks that FORMAT is appropriate for a variable of the given
405 VAR_TYPE and returns true if so. Otherwise returns false and
406 emits an error message. */
408 fmt_check_type_compat (const struct fmt_spec *format, enum val_type var_type)
410 assert (val_type_is_valid (var_type));
411 if ((var_type == VAL_STRING) != (fmt_is_string (format->type) != 0))
413 char str[FMT_STRING_LEN_MAX + 1];
414 msg (SE, _("%s variables are not compatible with %s format %s."),
415 var_type == VAL_STRING ? _("String") : _("Numeric"),
416 var_type == VAL_STRING ? _("numeric") : _("string"),
417 fmt_to_string (format, str));
423 /* Checks that FORMAT is appropriate for a variable of the given
424 WIDTH and returns true if so. Otherwise returns false and
425 emits an error message. */
427 fmt_check_width_compat (const struct fmt_spec *format, int width)
429 if (!fmt_check_type_compat (format, val_type_from_width (width)))
431 if (fmt_var_width (format) != width)
433 char str[FMT_STRING_LEN_MAX + 1];
434 msg (SE, _("String variable with width %d is not compatible with "
436 width, fmt_to_string (format, str));
442 /* Returns the width corresponding to FORMAT. The return value
443 is the width of the `union value's required by FORMAT. */
445 fmt_var_width (const struct fmt_spec *format)
447 return (format->type == FMT_AHEX ? format->w / 2
448 : format->type == FMT_A ? format->w
452 /* Converts F to its string representation (for instance, "F8.2")
453 in BUFFER. Returns BUFFER.
455 If F has decimals, they are included in the output string,
456 even if F's format type does not allow decimals, to allow
457 accurately presenting incorrect formats to the user. */
459 fmt_to_string (const struct fmt_spec *f, char buffer[FMT_STRING_LEN_MAX + 1])
461 if (fmt_takes_decimals (f->type) || f->d > 0)
462 snprintf (buffer, FMT_STRING_LEN_MAX + 1,
463 "%s%d.%d", fmt_name (f->type), f->w, f->d);
465 snprintf (buffer, FMT_STRING_LEN_MAX + 1,
466 "%s%d", fmt_name (f->type), f->w);
470 /* Returns true if A and B are identical formats,
473 fmt_equal (const struct fmt_spec *a, const struct fmt_spec *b)
475 return a->type == b->type && a->w == b->w && a->d == b->d;
478 /* Adjusts FMT to be valid for a value of the given WIDTH if necessary.
479 If nothing needed to be changed the return value is false
482 fmt_resize (struct fmt_spec *fmt, int width)
484 if ((width > 0) != fmt_is_string (fmt->type))
486 /* Changed from numeric to string or vice versa. Set to
487 default format for new width. */
488 *fmt = fmt_default_for_width (width);
492 /* Changed width of string. Preserve format type, adjust
494 fmt->w = fmt->type == FMT_AHEX ? width * 2 : width;
504 /* Adjusts FMT's width and decimal places to be valid for USE. */
506 fmt_fix (struct fmt_spec *fmt, enum fmt_use use)
508 /* Clamp width to those allowed by format. */
509 fmt_clamp_width (fmt, use);
511 /* If FMT has more decimal places than allowed, attempt to increase FMT's
512 width until that number of decimal places can be achieved. */
513 if (fmt->d > fmt_max_decimals (fmt->type, fmt->w, use)
514 && fmt_takes_decimals (fmt->type))
516 int max_w = fmt_max_width (fmt->type, use);
517 for (; fmt->w < max_w; fmt->w++)
518 if (fmt->d <= fmt_max_decimals (fmt->type, fmt->w, use))
522 /* Clamp decimals to those allowed by format and width. */
523 fmt_clamp_decimals (fmt, use);
526 /* Adjusts FMT's width and decimal places to be valid for an
529 fmt_fix_input (struct fmt_spec *fmt)
531 fmt_fix (fmt, FMT_FOR_INPUT);
534 /* Adjusts FMT's width and decimal places to be valid for an
537 fmt_fix_output (struct fmt_spec *fmt)
539 fmt_fix (fmt, FMT_FOR_OUTPUT);
542 /* Sets FMT's width to WIDTH (or the nearest width allowed by FMT's type) and
543 reduces its decimal places as necessary (if necessary) for that width. */
545 fmt_change_width (struct fmt_spec *fmt, int width, enum fmt_use use)
548 fmt_clamp_width (fmt, use);
549 fmt_clamp_decimals (fmt, use);
552 /* Sets FMT's decimal places to DECIMALS (or the nearest number of decimal
553 places allowed by FMT's type) and increases its width as necessary (if
554 necessary) for that number of decimal places. */
556 fmt_change_decimals (struct fmt_spec *fmt, int decimals, enum fmt_use use)
562 /* Describes a display format. */
566 int min_input_width, min_output_width;
568 enum fmt_category category;
571 static const struct fmt_desc *get_fmt_desc (enum fmt_type type);
573 /* Returns the name of the given format TYPE. */
575 fmt_name (enum fmt_type type)
577 return get_fmt_desc (type)->name;
580 /* Tries to parse NAME as a format type.
581 If successful, stores the type in *TYPE and returns true.
582 On failure, returns false. */
584 fmt_from_name (const char *name, enum fmt_type *type)
588 for (i = 0; i < FMT_NUMBER_OF_FORMATS; i++)
589 if (!c_strcasecmp (name, get_fmt_desc (i)->name))
597 /* Returns true if TYPE accepts decimal places,
600 fmt_takes_decimals (enum fmt_type type)
602 return fmt_max_output_decimals (type, fmt_max_output_width (type)) > 0;
605 /* Returns the minimum width of the given format TYPE for the given USE. */
607 fmt_min_width (enum fmt_type type, enum fmt_use use)
609 return (use == FMT_FOR_INPUT
610 ? fmt_min_input_width (type)
611 : fmt_min_output_width (type));
614 /* Returns the maximum width of the given format TYPE,
615 for input if FOR_INPUT is true,
616 for output otherwise. */
618 fmt_max_width (enum fmt_type type, enum fmt_use use UNUSED)
620 /* Maximum width is actually invariant of whether the format is
621 for input or output, so FOR_INPUT is unused. */
622 assert (is_fmt_type (type));
640 return 2 * MAX_STRING;
647 /* Returns the maximum number of decimal places allowed for the
648 given format TYPE with a width of WIDTH places, for the given USE. */
650 fmt_max_decimals (enum fmt_type type, int width, enum fmt_use use)
659 max_d = use == FMT_FOR_INPUT ? width : width - 1;
664 max_d = use == FMT_FOR_INPUT ? width : width - 2;
668 max_d = use == FMT_FOR_INPUT ? width : width - 7;
676 assert (use == FMT_FOR_OUTPUT);
686 max_d = width * 2 - 1;
695 max_d = max_digits_for_bytes (width);
748 /* Returns the minimum acceptable width for an input field
749 formatted with the given TYPE. */
751 fmt_min_input_width (enum fmt_type type)
753 return get_fmt_desc (type)->min_input_width;
756 /* Returns the maximum acceptable width for an input field
757 formatted with the given TYPE. */
759 fmt_max_input_width (enum fmt_type type)
761 return fmt_max_width (type, FMT_FOR_INPUT);
764 /* Returns the maximum number of decimal places allowed in an
765 input field of the given TYPE and WIDTH. */
767 fmt_max_input_decimals (enum fmt_type type, int width)
769 assert (valid_width (type, width, true));
770 return fmt_max_decimals (type, width, FMT_FOR_INPUT);
773 /* Returns the minimum acceptable width for an output field
774 formatted with the given TYPE. */
776 fmt_min_output_width (enum fmt_type type)
778 return get_fmt_desc (type)->min_output_width;
781 /* Returns the maximum acceptable width for an output field
782 formatted with the given TYPE. */
784 fmt_max_output_width (enum fmt_type type)
786 return fmt_max_width (type, FMT_FOR_OUTPUT);
789 /* Returns the maximum number of decimal places allowed in an
790 output field of the given TYPE and WIDTH. */
792 fmt_max_output_decimals (enum fmt_type type, int width)
794 assert (valid_width (type, width, false));
795 return fmt_max_decimals (type, width, FMT_FOR_OUTPUT);
798 /* Returns the width step for a field formatted with the given
799 TYPE. Field width must be a multiple of the width step. */
801 fmt_step_width (enum fmt_type type)
803 return (fmt_get_category (type) == FMT_CAT_HEXADECIMAL || type == FMT_AHEX
807 /* Returns true if TYPE is used for string fields,
808 false if it is used for numeric fields. */
810 fmt_is_string (enum fmt_type type)
812 return fmt_get_category (type) == FMT_CAT_STRING;
815 /* Returns true if TYPE is used for numeric fields,
816 false if it is used for string fields. */
818 fmt_is_numeric (enum fmt_type type)
820 return !fmt_is_string (type);
823 /* Returns the format TYPE's category.
824 Each format type is in exactly one category,
825 and each category's value is bitwise disjoint from every other
826 category. Thus, the return value may be tested for equality
827 or compared bitwise against a mask of FMT_CAT_* values. */
829 fmt_get_category (enum fmt_type type)
831 return get_fmt_desc (type)->category;
834 /* Returns the output format selected by default when TYPE is
835 used as an input format. */
837 fmt_input_to_output (enum fmt_type type)
839 switch (fmt_get_category (type))
846 case FMT_CAT_HEXADECIMAL:
854 /* Returns the SPSS format type corresponding to the given PSPP
857 fmt_to_io (enum fmt_type type)
859 return get_fmt_desc (type)->io;
862 /* Determines the PSPP format corresponding to the given SPSS
863 format type. If successful, sets *FMT_TYPE to the PSPP format
864 and returns true. On failure, return false. */
866 fmt_from_io (int io, enum fmt_type *fmt_type)
870 #define FMT(NAME, METHOD, IMIN, OMIN, IO, CATEGORY) \
872 *fmt_type = FMT_##NAME; \
874 #include "format.def"
880 /* Returns true if TYPE may be used as an input format,
883 fmt_usable_for_input (enum fmt_type type)
885 assert (is_fmt_type (type));
886 return fmt_get_category (type) != FMT_CAT_CUSTOM;
889 /* For time and date formats, returns a template used for input and output in a
890 field of the given WIDTH.
892 WIDTH only affects whether a 2-digit year or a 4-digit year is used, that
893 is, whether the returned string contains "yy" or "yyyy", and whether seconds
894 are include, that is, whether the returned string contains ":SS". A caller
895 that doesn't care whether the returned string contains "yy" or "yyyy" or
896 ":SS" can just specify 0 to omit them. */
898 fmt_date_template (enum fmt_type type, int width)
945 s1 = "dd-mmm-yyyy HH:MM";
946 s2 = "dd-mmm-yyyy HH:MM:SS";
963 return width >= strlen (s2) ? s2 : s1;
966 /* Returns a string representing the format TYPE for use in a GUI dialog. */
968 fmt_gui_name (enum fmt_type type)
982 return _("Scientific");
1013 return fmt_name (type);
1017 /* Returns true if TYPE is a valid format type,
1020 is_fmt_type (enum fmt_type type)
1022 return type < FMT_NUMBER_OF_FORMATS;
1025 /* Returns true if WIDTH is a valid width for the given format
1026 TYPE, for the given USE. */
1028 valid_width (enum fmt_type type, int width, enum fmt_use use)
1030 return (width >= fmt_min_width (type, use)
1031 && width <= fmt_max_width (type, use));
1034 /* Returns the maximum number of decimal digits in an unsigned
1035 binary number that is BYTES bytes long. */
1037 max_digits_for_bytes (int bytes)
1039 int map[8] = {3, 5, 8, 10, 13, 15, 17, 20};
1040 assert (bytes > 0 && bytes <= sizeof map / sizeof *map);
1041 return map[bytes - 1];
1044 /* Clamp FMT's width to the range and values allowed by FMT's type. */
1046 fmt_clamp_width (struct fmt_spec *fmt, enum fmt_use use)
1051 min_w = fmt_min_width (fmt->type, use);
1052 max_w = fmt_max_width (fmt->type, use);
1055 else if (fmt->w > max_w)
1058 /* Round width to step. */
1059 step = fmt_step_width (fmt->type);
1060 fmt->w = ROUND_DOWN (fmt->w, step);
1063 /* Clamp FMT's decimal places to the range allowed by FMT's type and width. */
1065 fmt_clamp_decimals (struct fmt_spec *fmt, enum fmt_use use)
1069 max_d = fmt_max_decimals (fmt->type, fmt->w, use);
1072 else if (fmt->d > max_d)
1076 /* Sets AFFIX's string value to S, a UTF-8 encoded string. */
1078 fmt_affix_set (struct fmt_affix *affix, const char *s)
1080 affix->s = s[0] == '\0' ? CONST_CAST (char *, "") : xstrdup (s);
1081 affix->width = u8_strwidth (CHAR_CAST (const uint8_t *, s), "UTF-8");
1084 /* Frees data in AFFIX. */
1086 fmt_affix_free (struct fmt_affix *affix)
1093 fmt_number_style_init (struct fmt_number_style *style)
1095 fmt_affix_set (&style->neg_prefix, "");
1096 fmt_affix_set (&style->prefix, "");
1097 fmt_affix_set (&style->suffix, "");
1098 fmt_affix_set (&style->neg_suffix, "");
1099 style->decimal = '.';
1100 style->grouping = 0;
1104 fmt_number_style_clone (struct fmt_number_style *new,
1105 const struct fmt_number_style *old)
1107 fmt_affix_set (&new->neg_prefix, old->neg_prefix.s);
1108 fmt_affix_set (&new->prefix, old->prefix.s);
1109 fmt_affix_set (&new->suffix, old->suffix.s);
1110 fmt_affix_set (&new->neg_suffix, old->neg_suffix.s);
1111 new->decimal = old->decimal;
1112 new->grouping = old->grouping;
1113 new->extra_bytes = old->extra_bytes;
1116 /* Destroys a struct fmt_number_style. */
1118 fmt_number_style_destroy (struct fmt_number_style *style)
1122 fmt_affix_free (&style->neg_prefix);
1123 fmt_affix_free (&style->prefix);
1124 fmt_affix_free (&style->suffix);
1125 fmt_affix_free (&style->neg_suffix);
1129 /* Returns the total width of the standard prefix and suffix for STYLE, in
1130 display columns (e.g. as returned by u8_strwidth()). */
1132 fmt_affix_width (const struct fmt_number_style *style)
1134 return style->prefix.width + style->suffix.width;
1137 /* Returns the total width of the negative prefix and suffix for STYLE, in
1138 display columns (e.g. as returned by u8_strwidth()). */
1140 fmt_neg_affix_width (const struct fmt_number_style *style)
1142 return style->neg_prefix.width + style->neg_suffix.width;
1145 /* Returns the struct fmt_desc for the given format TYPE. */
1146 static const struct fmt_desc *
1147 get_fmt_desc (enum fmt_type type)
1149 static const struct fmt_desc formats[FMT_NUMBER_OF_FORMATS] =
1151 #define FMT(NAME, METHOD, IMIN, OMIN, IO, CATEGORY) \
1152 {#NAME, IMIN, OMIN, IO, CATEGORY},
1153 #include "format.def"
1156 assert (is_fmt_type (type));
1157 return &formats[type];
1160 const struct fmt_spec F_8_0 = {FMT_F, 8, 0};
1161 const struct fmt_spec F_8_2 = {FMT_F, 8, 2};
1162 const struct fmt_spec F_4_3 = {FMT_F, 4, 3};
1163 const struct fmt_spec F_5_1 = {FMT_F, 5, 1};