Add scratch file handles.
[pspp-builds.git] / src / var.h
index 1d36467b09534ef7a30221cfcbb823534cda000f..f4930eea0e65b61a279033d6ae4335b03fb6e7c5 100644 (file)
--- a/src/var.h
+++ b/src/var.h
 
 #include <stddef.h>
 #include "config.h"
-#include "bool.h"
+#include <stdbool.h>
+#include "cat.h"
 #include "format.h"
-#include "val.h"
-
-
+#include "missing-values.h"
 
 /* Script variables. */
 
 /* Variable type. */
-enum
+enum var_type
   {
     NUMERIC,                   /* A numeric variable. */
-    ALPHA                      /* A string variable.
-                                   (STRING is pre-empted by lexer.h.) */
-  };
-
-/* Types of missing values.  Order is significant, see
-   mis-val.c:parse_numeric(), sfm-read.c, sfm-write.c,
-   sysfile-info.c:cmd_sysfile_info(), mis-val.c:copy_missing_values(),
-   pfm-read.c:read_variables(), pfm-write.c:write_variables(),
-   apply-dict.c:cmd_apply_dictionary(), and more (?). */
-enum
-  {
-    MISSING_NONE,              /* No user-missing values. */
-    MISSING_1,                 /* One user-missing value. */
-    MISSING_2,                 /* Two user-missing values. */
-    MISSING_3,                 /* Three user-missing values. */
-    MISSING_RANGE,             /* [a,b]. */
-    MISSING_LOW,               /* (-inf,a]. */
-    MISSING_HIGH,              /* (a,+inf]. */
-    MISSING_RANGE_1,           /* [a,b], c. */
-    MISSING_LOW_1,             /* (-inf,a], b. */
-    MISSING_HIGH_1,            /* (a,+inf), b. */
-    MISSING_COUNT
+    ALPHA                      /* A string variable. */
   };
 
+const char *var_type_adj (enum var_type);
+const char *var_type_noun (enum var_type);
 
 /* A variable's dictionary entry.  */
 struct variable
   {
-    /* Basic information. */
+    /* Dictionary information. */
     char name[LONG_NAME_LEN + 1]; /* Variable name.  Mixed case. */
-    int type;                   /* NUMERIC or ALPHA. */
+    enum var_type type;         /* NUMERIC or ALPHA. */
     int width;                 /* Size of string variables in chars. */
-    int fv, nv;                        /* Index into `value's, number of values. */
-    unsigned init : 1;          /* 1=VFM must init and possibly reinit. */
-    unsigned reinit : 1;        /* Cases are: 1=reinitialized; 0=left. */
-
-    /* Data for use by containing dictionary. */
-    int index;                 /* Dictionary index. */
-
-    /* Missing values. */
-    int miss_type;             /* One of the MISSING_* constants. */
-    union value missing[3];    /* User-missing value. */
-
-    /* Display formats. */
+    struct missing_values miss; /* Missing values. */
     struct fmt_spec print;     /* Default format for PRINT. */
     struct fmt_spec write;     /* Default format for WRITE. */
-
-    /* Labels. */
     struct val_labs *val_labs;  /* Value labels. */
     char *label;               /* Variable label. */
+    enum measure measure;       /* Nominal, ordinal, or continuous. */
+    int display_width;          /* Width of data editor column. */
+    enum alignment alignment;   /* Alignment of data in GUI. */
 
-    /* GUI display parameters. */
-    enum measure measure;       /* Nominal ordinal or continuous */
-    int display_width;          /* Width of data editor column */
-    enum alignment alignment;   /* Alignment of data in gui */
+    /* Case information. */
+    int fv, nv;                        /* Index into `value's, number of values. */
+    bool init;                  /* True if needs init and possibly reinit. */
+    bool reinit;                /* True: reinitialize; false: leave. */
+
+    /* Data for use by containing dictionary. */
+    int index;                 /* Dictionary index. */
 
     /* Short name, used only for system and portable file input
        and output.  Upper case only.  There is no index for short
@@ -98,9 +71,14 @@ struct variable
        string. */
     char short_name[SHORT_NAME_LEN + 1];
 
-    /* Per-command info. */
+    /* Each command may use these fields as needed. */
     void *aux;
     void (*aux_dtor) (struct variable *);
+
+    /* Values of a categorical variable.  Procedures need
+       vectors with binary entries, so any variable of type ALPHA will
+       have its values stored here. */
+    struct cat_vals *obs_vals;
   };
 
 /* Variable names. */
@@ -151,10 +129,6 @@ extern struct dictionary *default_dict;
 \f
 /* Transformation state. */
 
-/* Default file handle for DATA LIST, REREAD, REPEATING DATA
-   commands. */
-extern struct file_handle *default_handle;
-
 /* PROCESS IF expression. */
 extern struct expression *process_if_expr;
 \f
@@ -170,7 +144,7 @@ extern struct dictionary *temp_dict;
    gives the point at which data should be written out.  -1 means that
    the data shouldn't be changed since all transformations are
    temporary. */
-extern int temp_trns;
+extern size_t temp_trns;
 
 /* If FILTER is active, whether it was executed before or after
    TEMPORARY. */
@@ -178,44 +152,35 @@ extern int FILTER_before_TEMPORARY;
 
 void cancel_temporary (void);
 \f
-/* Functions. */
-
 struct ccase;
 void dump_split_vars (const struct ccase *);
-typedef int (* is_missing_func )(const union value *, const struct variable *);
-
-int is_num_user_missing (double, const struct variable *);
-int is_str_user_missing (const unsigned char[], const struct variable *);
-int is_missing (const union value *, const struct variable *);
-int is_system_missing (const union value *, const struct variable *);
-int is_user_missing (const union value *, const struct variable *);
-void copy_missing_values (struct variable *dest, const struct variable *src);
 \f
 /* Transformations. */
 
-struct trns_header;
-typedef int trns_proc_func (struct trns_header *, struct ccase *, int);
-typedef void trns_free_func (struct trns_header *);
+struct transformation;
+typedef int trns_proc_func (void *, struct ccase *, int);
+typedef void trns_free_func (void *);
 
-/* Header for all transformations. */
-struct trns_header
+/* A transformation. */
+struct transformation
   {
-    int index;                  /* Index into t_trns[]. */
     trns_proc_func *proc;       /* Transformation proc. */
     trns_free_func *free;       /* Garbage collector proc. */
+    void *private;              /* Private data. */
   };
 
 /* Array of transformations */
-extern struct trns_header **t_trns;
+extern struct transformation *t_trns;
 
 /* Number of transformations, maximum number in array currently. */
-extern int n_trns, m_trns;
+extern size_t n_trns, m_trns;
 
 /* Index of first transformation that is really a transformation.  Any
    transformations before this belong to INPUT PROGRAM. */
-extern int f_trns;
+extern size_t f_trns;
 
-void add_transformation (struct trns_header *trns);
+void add_transformation (trns_proc_func *, trns_free_func *, void *);
+size_t next_transformation (void);
 void cancel_transformations (void);
 \f
 struct var_set;
@@ -228,7 +193,8 @@ size_t var_set_get_cnt (const struct var_set *vs);
 struct variable *var_set_get_var (const struct var_set *vs, size_t idx);
 struct variable *var_set_lookup_var (const struct var_set *vs,
                                      const char *name);
-int var_set_lookup_var_idx (const struct var_set *vs, const char *name);
+bool var_set_lookup_var_idx (const struct var_set *vs, const char *name,
+                             size_t *idx);
 void var_set_destroy (struct var_set *vs);
 \f
 /* Variable parsers. */
@@ -246,15 +212,17 @@ enum
     PV_NO_SCRATCH = 00200      /* Disallow scratch variables. */
   };
 
+struct pool;
 struct variable *parse_variable (void);
 struct variable *parse_dict_variable (const struct dictionary *);
-int parse_variables (const struct dictionary *, struct variable ***, int *,
+int parse_variables (const struct dictionary *, struct variable ***, size_t *,
                      int opts);
-int parse_var_set_vars (const struct var_set *, struct variable ***, int *,
+int parse_var_set_vars (const struct var_set *, struct variable ***, size_t *,
                         int opts);
-int parse_DATA_LIST_vars (char ***names, int *cnt, int opts);
-int parse_mixed_vars (char ***names, int *cnt, int opts);
-
+int parse_DATA_LIST_vars (char ***names, size_t *cnt, int opts);
+int parse_mixed_vars (char ***names, size_t *cnt, int opts);
+int parse_mixed_vars_pool (struct pool *,
+                           char ***names, size_t *cnt, int opts);
 
 
 /* Return a string representing this variable, in the form most