X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fshort-names.c;h=1b8be927a69c70f918f47ba1505d59787ae6fa03;hb=e8b19bfb4e94185514f3e22d92da41cb4581b115;hp=3ed99c04c2417792696f2eafe72351fb571f47f7;hpb=6999c6d125665923b52ae15cbad83d06c92a8875;p=pspp-builds.git diff --git a/src/data/short-names.c b/src/data/short-names.c index 3ed99c04..1b8be927 100644 --- a/src/data/short-names.c +++ b/src/data/short-names.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007, 2009 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -39,9 +39,9 @@ compare_strings (const void *a, const void *b, const void *aux UNUSED) /* Hashes a string. */ static unsigned -hash_string (const void *s, const void *aux UNUSED) +do_hash_string (const void *s, const void *aux UNUSED) { - return hsh_hash_string (s); + return hash_string (s, 0); } /* Sets V's short name to BASE, followed by a suffix of the form @@ -53,7 +53,6 @@ set_var_short_name_suffix (struct variable *v, size_t i, { char suffix[SHORT_NAME_LEN + 1]; char short_name[SHORT_NAME_LEN + 1]; - char *start, *end; int len, ofs; assert (suffix_number >= 0); @@ -62,26 +61,18 @@ set_var_short_name_suffix (struct variable *v, size_t i, var_set_short_name (v, i, base); /* Compose suffix. */ - start = end = suffix + sizeof suffix - 1; - *end = '\0'; - do - { - *--start = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[suffix_number % 26]; - if (start <= suffix + 1) - msg (SE, _("Variable suffix too large.")); - suffix_number /= 26; - } - while (suffix_number > 0); - *--start = '_'; + suffix[0] = '_'; + if (!str_format_26adic (suffix_number, &suffix[1], sizeof suffix - 1)) + msg (SE, _("Variable suffix too large.")); + len = strlen (suffix); /* Append suffix to V's short name. */ str_copy_trunc (short_name, sizeof short_name, base); - len = end - start; - if (len + strlen (short_name) > SHORT_NAME_LEN) + if (strlen (short_name) + len > SHORT_NAME_LEN) ofs = SHORT_NAME_LEN - len; else ofs = strlen (short_name); - strcpy (short_name + ofs, start); + strcpy (short_name + ofs, suffix); /* Set name. */ var_set_short_name (v, i, short_name); @@ -111,7 +102,7 @@ assign_short_name (struct variable *v, size_t i, struct hsh_table *short_names) if (trial == 0) var_set_short_name (v, i, var_get_name (v)); else - set_var_short_name_suffix (v, i, var_get_name (v), trial - 1); + set_var_short_name_suffix (v, i, var_get_name (v), trial); if (hsh_insert (short_names, (char *) var_get_short_name (v, i)) == NULL) break; @@ -137,7 +128,7 @@ short_names_assign (struct dictionary *d) the hash table point to strings owned by dictionary variables, not by us, so we don't need to provide a free function. */ - short_names = hsh_create (var_cnt, compare_strings, hash_string, + short_names = hsh_create (var_cnt, compare_strings, do_hash_string, NULL, NULL); /* Clear short names that conflict with a variable name. */ @@ -181,7 +172,7 @@ short_names_assign (struct dictionary *d) struct variable *v = dict_get_var (d, i); int segment_cnt = sfm_width_to_segments (var_get_width (v)); for (j = 1; j < segment_cnt; j++) - claim_short_name (v, i, short_names); + claim_short_name (v, j, short_names); } /* Assign short names to first segment of remaining variables,