Rewrite system file reader code, to clean up and improve.
[pspp-builds.git] / src / data / sys-file-writer.c
index ddfb4ae75c47288ec4d4ff2683c89ed76c2091fd..e923b9d5e43e56b5975511e20e53bddc0f38b6f1 100644 (file)
@@ -20,7 +20,6 @@
 #include <config.h>
 
 #include "sys-file-writer.h"
-#include "sfm-private.h"
 #include "sys-file-private.h"
 
 #include <ctype.h>
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
 
+/* Find 64-bit floating-point type. */
+#if SIZEOF_FLOAT == 8
+  #define flt64 float
+  #define FLT64_MAX FLT_MAX
+#elif SIZEOF_DOUBLE == 8
+  #define flt64 double
+  #define FLT64_MAX DBL_MAX
+#elif SIZEOF_LONG_DOUBLE == 8
+  #define flt64 long double
+  #define FLT64_MAX LDBL_MAX
+#else
+  #error Which one of your basic types is 64-bit floating point?
+#endif
+
+/* Figure out SYSMIS value for flt64. */
+#include <libpspp/magic.h>
+#if SIZEOF_DOUBLE == 8
+#define second_lowest_flt64 second_lowest_value
+#else
+#error Must define second_lowest_flt64 for your architecture.
+#endif
+
+/* Record Type 1: General Information. */
+struct sysfile_header
+  {
+    char rec_type[4] ;         /* 00: Record-type code, "$FL2". */
+    char prod_name[60] ;       /* 04: Product identification. */
+    int32_t layout_code ;      /* 40: 2. */
+    int32_t nominal_case_size ;        /* 44: Number of `value's per case. 
+                                  Note: some systems set this to -1 */
+    int32_t compress ;         /* 48: 1=compressed, 0=not compressed. */
+    int32_t weight_idx ;         /* 4c: 1-based index of weighting var, or 0. */
+    int32_t case_cnt ;         /* 50: Number of cases, -1 if unknown. */
+    flt64 bias ;               /* 54: Compression bias (100.0). */
+    char creation_date[9] ;    /* 5c: `dd mmm yy' creation date of file. */
+    char creation_time[8] ;    /* 65: `hh:mm:ss' 24-hour creation time. */
+    char file_label[64] ;      /* 6d: File label. */
+    char padding[3] ;          /* ad: Ignored padding. */
+  } ATTRIBUTE((packed)) ;
+
+/* Record Type 2: Variable. */
+struct sysfile_variable
+  {
+    int32_t rec_type ;         /* 2. */
+    int32_t type ;             /* 0=numeric, 1-255=string width,
+                                  -1=continued string. */
+    int32_t has_var_label ;    /* 1=has a variable label, 0=doesn't. */
+    int32_t n_missing_values ; /* Missing value code of -3,-2,0,1,2, or 3. */
+    int32_t print ;            /* Print format. */
+    int32_t write ;            /* Write format. */
+    char name[SHORT_NAME_LEN] ; /* Variable name. */
+    /* The rest of the structure varies. */
+  } ATTRIBUTE((packed)) ;
+
 /* Compression bias used by PSPP.  Values between (1 -
    COMPRESSION_BIAS) and (251 - COMPRESSION_BIAS) inclusive can be
    compressed. */