-
-/*
- Change SUGGESTION until it's a valid name that can be added to DICT.
-*/
-static void
-devise_name (const struct dictionary *dict, struct string *name, int *x)
-{
- struct string basename;
- if ( ds_is_empty (name))
- ds_init_cstr (&basename, "var");
- else
- ds_init_string (&basename, name);
- do
- {
- ds_clear (name);
- ds_put_format (name, "%s%d", ds_cstr (&basename), ++(*x));
- }
- while (NULL != dict_lookup_var (dict, ds_cstr (name)) );
-
- ds_destroy (&basename);
-}
-
-/*
- Mutate NAME of a variable, which is gauranteed to be valid for the
- dictionary DICT.
-*/
-static void
-munge_name (const struct dictionary *dict, struct string *name)
-{
- int x = 0;
-
- if (! ds_is_empty (name))
- {
- /* Change all the invalid characters to valid ones */
- char *s;
-
- s = ds_data (name);
-
- if ( !lex_is_id1 (*s))
- *s = '@';
-
- s++;
-
- while (s < ds_data (name) + ds_length (name))
- {
- if ( !lex_is_idn (*s))
- *s = '_';
- s++;
- }
-
- assert (var_is_valid_name (ds_cstr (name), false));
- }
-
- while (ds_is_empty (name) || NULL != dict_lookup_var (dict, ds_cstr (name)) )
- {
- devise_name (dict, name, &x);
- }
-}
-
-