X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fdictionary.c;h=0b930d579c3defc7ec19dc0b81de6bb10a07b3d9;hb=7bf210c4fd179a22dd8c6a071f0b23f7ae4e14c2;hp=6dd1b99f876f52dec0204ab495f1ce801eaa518a;hpb=3dd0f6ae0d5eb73a2270a243e443c4ae03c2c16e;p=pspp diff --git a/src/data/dictionary.c b/src/data/dictionary.c index 6dd1b99f87..0b930d579c 100644 --- a/src/data/dictionary.c +++ b/src/data/dictionary.c @@ -285,7 +285,7 @@ dict_destroy (struct dictionary *d) { if (d != NULL) { - /* In general, we don't want callbacks occuring, if the dictionary + /* In general, we don't want callbacks occurring, if the dictionary is being destroyed */ d->callbacks = NULL ; @@ -756,17 +756,18 @@ rename_var (struct variable *v, const char *new_name) var_set_vardict (v, vardict); } -/* Changes the name of V in D to name NEW_NAME. Assert-fails if - a variable named NEW_NAME is already in D, except that - NEW_NAME may be the same as V's existing name. */ -void -dict_rename_var (struct dictionary *d, struct variable *v, - const char *new_name) +/* Tries to changes the name of V in D to name NEW_NAME. Returns true if + successful, false if a variable (other than V) with the given name already + exists in D. */ +bool +dict_try_rename_var (struct dictionary *d, struct variable *v, + const char *new_name) { - struct variable *old = var_clone (v); - assert (!utf8_strcasecmp (var_get_name (v), new_name) - || dict_lookup_var (d, new_name) == NULL); + struct variable *conflict = dict_lookup_var (d, new_name); + if (conflict && v != conflict) + return false; + struct variable *old = var_clone (v); unindex_var (d, var_get_vardict (v)); rename_var (v, new_name); reindex_var (d, var_get_vardict (v)); @@ -779,6 +780,19 @@ dict_rename_var (struct dictionary *d, struct variable *v, d->callbacks->var_changed (d, var_get_dict_index (v), VAR_TRAIT_NAME, old, d->cb_data); var_destroy (old); + + return true; +} + +/* Changes the name of V in D to name NEW_NAME. Assert-fails if + a variable named NEW_NAME is already in D, except that + NEW_NAME may be the same as V's existing name. */ +void +dict_rename_var (struct dictionary *d, struct variable *v, + const char *new_name) +{ + bool ok UNUSED = dict_try_rename_var (d, v, new_name); + assert (ok); } /* Renames COUNT variables specified in VARS to the names given