{
/* FIXME? Should we really clear case_limit, label, documents?
Others are necessarily cleared by deleting all the variables.*/
- int i;
-
assert (d != NULL);
- for (i = 0; i < d->var_cnt; i++)
+ while (d->var_cnt > 0 )
{
- if (d->callbacks && d->callbacks->var_deleted )
- d->callbacks->var_deleted (d, i, d->cb_data);
+ var_clear_vardict (d->var[d->var_cnt - 1]);
+ var_destroy (d->var[d->var_cnt -1]);
- var_clear_vardict (d->var[i]);
- var_destroy (d->var[i]);
+ d->var_cnt--;
+
+ if (d->callbacks && d->callbacks->var_deleted )
+ d->callbacks->var_deleted (d, d->var_cnt, d->cb_data);
}
free (d->var);
d->var = NULL;
hsh_force_insert (d->name_tab, v);
if ( d->callbacks && d->callbacks->var_added )
- d->callbacks->var_added (d, d->next_value_idx, d->cb_data);
+ d->callbacks->var_added (d, var_get_dict_index (v), d->cb_data);
d->next_value_idx += var_get_value_cnt (v);
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;
}
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 *