Adopt use of gnulib for portability.
[pspp-builds.git] / src / format.c
index 9c6bbea48e77bfd0163384b289fe37c1219ac672..a37f71e814082bc6fadc02df4ce778f724baf162 100644 (file)
@@ -28,6 +28,9 @@
 #include "str.h"
 #include "var.h"
 
+#include "gettext.h"
+#define _(msgid) gettext (msgid)
+
 #define DEFFMT(LABEL, NAME, N_ARGS, IMIN_W, IMAX_W, OMIN_W, OMAX_W, CAT, \
               OUTPUT, SPSS_FMT) \
        {NAME, N_ARGS, IMIN_W, IMAX_W, OMIN_W, OMAX_W, CAT, OUTPUT, SPSS_FMT},
@@ -37,6 +40,9 @@ struct fmt_desc formats[FMT_NUMBER_OF_FORMATS + 1] =
   {"",         -1, -1,  -1, -1,   -1, 0000, -1, -1},
 };
 
+/* Common formats. */
+const struct fmt_spec f8_2 = {FMT_F, 8, 2};
+
 /* Parses the alphabetic prefix of the current token as a format
    specifier name.  Returns the corresponding format specifier
    type if successful, or -1 on failure.  If ALLOW_XT is zero,
@@ -59,7 +65,7 @@ parse_format_specifier_name (const char **cp, enum fmt_parse_flags flags)
       /* Find format. */
       for (idx = 0; idx < FMT_NUMBER_OF_FORMATS; idx++)
         if (strlen (formats[idx].name) == ep - sp
-            && !mm_case_compare (formats[idx].name, sp, ep - sp))
+            && !buf_compare_case (formats[idx].name, sp, ep - sp))
           break;
 
       /* Check format. */
@@ -126,8 +132,8 @@ check_common_specifier (const struct fmt_spec *spec, bool emit_error)
     {
       if (emit_error)
         msg (SE, _("Format %s specifies an odd width %d, but "
-                   "format %s requires an even width."),
-             str, spec->w, f->name, f->Imin_w, f->Imax_w);
+                   "an even width is required."),
+             str, spec->w);
       return false;
     }
   if (f->n_args > 1 && (spec->d < 0 || spec->d > 16))
@@ -210,7 +216,7 @@ check_output_specifier (const struct fmt_spec *spec, int emit_error)
                    "many decimal places as the field width, which "
                    "fails to allow space for a decimal point.  "
                    "Try %s%d.%d instead."),
-             str, f->name, f->name, spec->d + 1, spec->d);
+             str, f->name, spec->d + 1, spec->d);
       return 0;
     }
   return 1;
@@ -442,3 +448,29 @@ translate_fmt (int spss)
       return type;
   return -1;
 }
+
+/* Returns an input format specification with type TYPE, width W,
+   and D decimals. */
+struct fmt_spec
+make_input_format (int type, int w, int d) 
+{
+  struct fmt_spec f;
+  f.type = type;
+  f.w = w;
+  f.d = d;
+  assert (check_input_specifier (&f, 0));
+  return f;
+}
+
+/* Returns an output format specification with type TYPE, width
+   W, and D decimals. */
+struct fmt_spec
+make_output_format (int type, int w, int d)
+{
+  struct fmt_spec f;
+  f.type = type;
+  f.w = w;
+  f.d = d;
+  assert (check_output_specifier (&f, 0));
+  return f;
+}