From 01c08a39bb4b393b0f21de5582ddc781adb6cf94 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Fri, 7 Mar 2008 06:03:51 +0000 Subject: [PATCH] (var_name_is_insertable): New function. (make_hinted_name): Don't accept variable names that match PSPP keywords. Thanks to Jason Stover for reporting the problem. --- src/data/ChangeLog | 6 ++++++ src/data/dictionary.c | 16 ++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/data/ChangeLog b/src/data/ChangeLog index f209233b..75313fee 100644 --- a/src/data/ChangeLog +++ b/src/data/ChangeLog @@ -1,3 +1,9 @@ +2008-03-06 Ben Pfaff + + * dictionary.c (var_name_is_insertable): New function. + (make_hinted_name): Don't accept variable names that match PSPP + keywords. Thanks to Jason Stover for reporting the problem. + 2008-03-06 Ben Pfaff * format-guesser.c (syntax): Require month names to be spelled out diff --git a/src/data/dictionary.c b/src/data/dictionary.c index 0856df93..526bb280 100644 --- a/src/data/dictionary.c +++ b/src/data/dictionary.c @@ -729,6 +729,18 @@ dict_rename_vars (struct dictionary *d, return true; } +/* Returns true if a variable named NAME may be inserted in DICT; + that is, if there is not already a variable with that name in + DICT and if NAME is not a reserved word. (The caller's checks + have already verified that NAME is otherwise acceptable as a + variable name.) */ +static bool +var_name_is_insertable (const struct dictionary *dict, const char *name) +{ + return (dict_lookup_var (dict, name) == NULL + && lex_id_to_token (ss_cstr (name)) == T_ID); +} + static bool make_hinted_name (const struct dictionary *dict, const char *hint, char name[VAR_NAME_LEN + 1]) @@ -760,7 +772,7 @@ make_hinted_name (const struct dictionary *dict, const char *hint, size_t len = strlen (name); unsigned long int i; - if (dict_lookup_var (dict, name) == NULL) + if (var_name_is_insertable (dict, name)) return true; for (i = 0; i < ULONG_MAX; i++) @@ -775,7 +787,7 @@ make_hinted_name (const struct dictionary *dict, const char *hint, ofs = MIN (VAR_NAME_LEN - strlen (suffix), len); strcpy (&name[ofs], suffix); - if (dict_lookup_var (dict, name) == NULL) + if (var_name_is_insertable (dict, name)) return true; } } -- 2.30.2