We've had a mix of min, max from libpspp/misc.h and MIN, MAX from
[pspp-builds.git] / src / data / sys-file-writer.c
index 000534c4844a2dd6bd2237c658add8f66c949109..517cf416607419c45612be23df38da0386963683 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - computes sample statistics.
-   Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
+   Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc.
    Written by Ben Pfaff <blp@gnu.org>.
 
    This program is free software; you can redistribute it and/or
    02110-1301, USA. */
 
 #include <config.h>
+
 #include "sys-file-writer.h"
 #include "sfm-private.h"
-#include <libpspp/message.h>
-#include <stdlib.h>
+
 #include <ctype.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <stdlib.h>
 #include <sys/stat.h>
 #include <time.h>
 #include <unistd.h>
+
 #include <libpspp/alloc.h>
-#include "case.h"
-#include "dictionary.h"
-#include <libpspp/message.h>
-#include "file-handle-def.h"
 #include <libpspp/hash.h>
 #include <libpspp/magic.h>
+#include <libpspp/message.h>
 #include <libpspp/misc.h>
-#include "settings.h"
-#include "stat-macros.h"
 #include <libpspp/str.h>
+#include <libpspp/version.h>
+
+#include "case.h"
+#include "dictionary.h"
+#include "file-handle-def.h"
+#include "settings.h"
 #include "value-labels.h"
 #include "variable.h"
-#include <libpspp/version.h>
-#include <minmax.h>
+
+#include "stat-macros.h"
+#include "minmax.h"
 
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
@@ -372,7 +376,7 @@ write_header (struct sfm_writer *w, const struct dictionary *d)
 
   if (dict_get_weight (d) != NULL)
     {
-      struct variable *weight_var;
+      const struct variable *weight_var;
       int recalc_weight_idx = 1;
       int i;
 
@@ -437,8 +441,8 @@ write_header (struct sfm_writer *w, const struct dictionary *d)
 static inline void
 write_format_spec (const struct fmt_spec *src, int32_t *dest)
 {
-  assert(check_output_specifier(src, true));
-  *dest = (formats[src->type].spss << 16) | (src->w << 8) | src->d;
+  assert (fmt_check_output (src));
+  *dest = (fmt_to_io (src->type) << 16) | (src->w << 8) | src->d;
 }
 
 /* Write the variable record(s) for primary variable P and secondary
@@ -454,7 +458,7 @@ write_variable (struct sfm_writer *w, const struct variable *v)
   int nm;               /* Number of missing values, possibly negative. */
 
   sv.rec_type = 2;
-  sv.type = min(v->width, MAX_LONG_STRING);
+  sv.type = MIN(v->width, MAX_LONG_STRING);
   sv.has_var_label = (v->label != NULL);
 
   mv_copy (&mv, &v->miss);
@@ -496,7 +500,7 @@ write_variable (struct sfm_writer *w, const struct variable *v)
 
       int ext_len;
 
-      l.label_len = min (strlen (v->label), 255);
+      l.label_len = MIN (strlen (v->label), 255);
       ext_len = ROUND_UP (l.label_len, sizeof l.label_len);
       memcpy (l.label, v->label, l.label_len);
       memset (&l.label[l.label_len], ' ', ext_len - l.label_len);
@@ -519,7 +523,7 @@ write_variable (struct sfm_writer *w, const struct variable *v)
       memset (&sv.write, 0, sizeof sv.write);
       memset (&sv.name, 0, sizeof sv.name);
 
-      pad_count = DIV_RND_UP (min(v->width, MAX_LONG_STRING),
+      pad_count = DIV_RND_UP (MIN(v->width, MAX_LONG_STRING),
                              (int) sizeof (flt64)) - 1;
       for (i = 0; i < pad_count; i++)
        buf_write (w, &sv, sizeof sv);
@@ -835,7 +839,7 @@ buf_write (struct sfm_writer *w, const void *buf, size_t nbytes)
 static char *
 append_string_max (char *dest, const char *src, const char *end)
 {
-  int nbytes = min (end - dest, (int) strlen (src));
+  int nbytes = MIN (end - dest, (int) strlen (src));
   memcpy (dest, src, nbytes);
   return dest + nbytes;
 }