Miscellaneous cleanup to categorical values, linreg and design matrix code.
[pspp-builds.git] / src / data / dictionary.c
index d38ed5fc1326d15f8d75e565c3bc77c9034f0fbe..761b540b1f2f8be203a24a3aa5a2db91d33b9da3 100644 (file)
@@ -24,7 +24,6 @@
 #include <ctype.h>
 
 #include "case.h"
-#include "cat-routines.h"
 #include "category.h"
 #include "settings.h"
 #include "value-labels.h"
@@ -52,7 +51,7 @@ struct dictionary
     size_t var_cnt, var_cap;    /* Number of variables, capacity. */
     struct hsh_table *name_tab;        /* Variable index by name. */
     int next_value_idx;         /* Index of next `union value' to allocate. */
-    struct variable **split;    /* SPLIT FILE vars. */
+    const struct variable **split;    /* SPLIT FILE vars. */
     size_t split_cnt;           /* SPLIT FILE count. */
     struct variable *weight;    /* WEIGHT variable. */
     struct variable *filter;    /* FILTER variable. */
@@ -233,13 +232,20 @@ dict_get_var (const struct dictionary *d, size_t idx)
   return d->var[idx];
 }
 
+inline void
+dict_get_vars (const struct dictionary *d, const struct variable ***vars,
+               size_t *cnt, unsigned exclude_classes)
+{
+  dict_get_vars_mutable (d, (struct variable ***) vars, cnt, exclude_classes);
+}
+
 /* Sets *VARS to an array of pointers to variables in D and *CNT
    to the number of variables in *D.  All variables are returned
    if EXCLUDE_CLASSES is 0, or it may contain one or more of (1u
    << DC_ORDINARY), (1u << DC_SYSTEM), or (1u << DC_SCRATCH) to
    exclude the corresponding type of variable. */
 void
-dict_get_vars (const struct dictionary *d, struct variable ***vars,
+dict_get_vars_mutable (const struct dictionary *d, struct variable ***vars,
                size_t *cnt, unsigned exclude_classes)
 {
   size_t count;
@@ -352,9 +358,16 @@ dict_clone_var_assert (struct dictionary *d, const struct variable *old_var,
 struct variable *
 dict_lookup_var (const struct dictionary *d, const char *name)
 {
-  struct variable *target = var_create (name, 0);
-  struct variable *result = hsh_find (d->name_tab, target);
+  struct variable *target ;
+  struct variable *result ;
+
+  if ( ! var_is_valid_name (name, false))
+    return NULL;
+
+  target = var_create (name, 0);
+  result = hsh_find (d->name_tab, target);
   var_destroy (target);
+
   return result;
 }
 
@@ -1002,7 +1015,7 @@ dict_compactor_destroy (struct dict_compactor *compactor)
    dict_get_split_cnt() to determine how many SPLIT FILE vars
    there are.  Returns a null pointer if and only if there are no
    SPLIT FILE vars. */
-struct variable *const *
+const struct variable *const *
 dict_get_split_vars (const struct dictionary *d)
 {
   assert (d != NULL);
@@ -1130,6 +1143,18 @@ dict_create_vector (struct dictionary *d,
     return false;
 }
 
+/* Creates in D a vector named NAME that contains the CNT
+   variables in VAR.  A vector named NAME must not already exist
+   in D. */
+void
+dict_create_vector_assert (struct dictionary *d,
+                           const char *name,
+                           struct variable **var, size_t cnt)
+{
+  assert (dict_lookup_vector (d, name) == NULL);
+  dict_create_vector (d, name, var, cnt);
+}
+
 /* Returns the vector in D with index IDX, which must be less
    than dict_get_vector_cnt (D). */
 const struct vector *