X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fdictionary.c;h=ff5f8ec027f16cbe3907ac5ab47acecb1e338425;hb=e2f99612bf4f4691623f16730eed3e55afdc54f0;hp=0b930d579c3defc7ec19dc0b81de6bb10a07b3d9;hpb=b6d66ec3f328d0e8bf35b71f29332695121f7173;p=pspp diff --git a/src/data/dictionary.c b/src/data/dictionary.c index 0b930d579c..ff5f8ec027 100644 --- a/src/data/dictionary.c +++ b/src/data/dictionary.c @@ -74,6 +74,11 @@ struct dictionary struct mrset **mrsets; /* Multiple response sets. */ size_t n_mrsets; /* Number of multiple response sets. */ + /* Whether variable names must be valid identifiers. Normally, this is + true, but sometimes a dictionary is prepared for external use + (e.g. output to a CSV file) where names don't have to be valid. */ + bool names_must_be_ids; + char *encoding; /* Character encoding of string data */ const struct dict_callbacks *callbacks; /* Callbacks on dictionary @@ -102,7 +107,8 @@ bool dict_id_is_valid (const struct dictionary *dict, const char *id, bool issue_error) { - return id_is_valid (id, dict->encoding, issue_error); + return (!dict->names_must_be_ids + || id_is_valid (id, dict->encoding, issue_error)); } void @@ -170,6 +176,7 @@ dict_create (const char *encoding) struct dictionary *d = xzalloc (sizeof *d); d->encoding = xstrdup (encoding); + d->names_must_be_ids = true; hmap_init (&d->name_map); attrset_init (&d->attributes); @@ -193,6 +200,7 @@ dict_clone (const struct dictionary *s) size_t i; d = dict_create (s->encoding); + dict_set_names_must_be_ids (d, dict_get_names_must_be_ids (s)); for (i = 0; i < s->var_cnt; i++) { @@ -994,6 +1002,27 @@ dict_make_unique_var_name (const struct dictionary *dict, const char *hint, return make_numeric_name (dict, num_start); } +/* Returns whether variable names must be valid identifiers. Normally, this is + true, but sometimes a dictionary is prepared for external use (e.g. output + to a CSV file) where names don't have to be valid. */ +bool +dict_get_names_must_be_ids (const struct dictionary *d) +{ + return d->names_must_be_ids; +} + +/* Sets whether variable names must be valid identifiers. Normally, this is + true, but sometimes a dictionary is prepared for external use (e.g. output + to a CSV file) where names don't have to be valid. + + Changing this setting from false to true doesn't make the dictionary check + all the existing variable names, so it can cause an invariant violation. */ +void +dict_set_names_must_be_ids (struct dictionary *d, bool names_must_be_ids) +{ + d->names_must_be_ids = names_must_be_ids; +} + /* Returns the weighting variable in dictionary D, or a null pointer if the dictionary is unweighted. */ struct variable *