256 |
if (length < 1) |
if (length < 1) |
257 |
{ |
{ |
258 |
if (issue_error) |
if (issue_error) |
259 |
msg (SE, _("Variable names must be at least 1 character long.")); |
msg (SE, _("Variable name cannot be empty string.")); |
260 |
return false; |
return false; |
261 |
} |
} |
262 |
else if (length > SHORT_NAME_LEN) |
else if (length > LONG_NAME_LEN) |
263 |
{ |
{ |
264 |
if (issue_error) |
if (issue_error) |
265 |
msg (SE, _("Variable name %s exceeds %d-character limit."), |
msg (SE, _("Variable name %s exceeds %d-character limit."), |
266 |
(int) SHORT_NAME_LEN); |
(int) LONG_NAME_LEN); |
267 |
return false; |
return false; |
268 |
} |
} |
269 |
|
|
304 |
const struct variable *a = a_; |
const struct variable *a = a_; |
305 |
const struct variable *b = b_; |
const struct variable *b = b_; |
306 |
|
|
307 |
return strcmp (a->name, b->name); |
return strcasecmp (a->name, b->name); |
308 |
} |
} |
309 |
|
|
310 |
/* A hsh_hash_func that hashes variable V based on its name. */ |
/* A hsh_hash_func that hashes variable V based on its name. */ |
313 |
{ |
{ |
314 |
const struct variable *v = v_; |
const struct variable *v = v_; |
315 |
|
|
316 |
return hsh_hash_string (v->name); |
return hsh_hash_case_string (v->name); |
317 |
} |
} |
318 |
|
|
319 |
/* A hsh_compare_func that orders pointers to variables A and B |
/* A hsh_compare_func that orders pointers to variables A and B |
324 |
struct variable *const *a = a_; |
struct variable *const *a = a_; |
325 |
struct variable *const *b = b_; |
struct variable *const *b = b_; |
326 |
|
|
327 |
return strcmp ((*a)->name, (*b)->name); |
return strcasecmp ((*a)->name, (*b)->name); |
328 |
} |
} |
329 |
|
|
330 |
/* A hsh_hash_func that hashes pointer to variable V based on its |
/* A hsh_hash_func that hashes pointer to variable V based on its |
334 |
{ |
{ |
335 |
struct variable *const *v = v_; |
struct variable *const *v = v_; |
336 |
|
|
337 |
return hsh_hash_string ((*v)->name); |
return hsh_hash_case_string ((*v)->name); |
338 |
|
} |
339 |
|
|
340 |
|
/* Sets V's short_name to SHORT_NAME, truncating it to |
341 |
|
SHORT_NAME_LEN characters and converting it to uppercase in |
342 |
|
the process. */ |
343 |
|
void |
344 |
|
var_set_short_name (struct variable *v, const char *short_name) |
345 |
|
{ |
346 |
|
assert (v != NULL); |
347 |
|
assert (short_name[0] == '\0' || var_is_valid_name (short_name, false)); |
348 |
|
|
349 |
|
st_trim_copy (v->short_name, short_name, sizeof v->short_name); |
350 |
|
st_uppercase (v->short_name); |
351 |
|
} |
352 |
|
|
353 |
|
/* Clears V's short name. */ |
354 |
|
void |
355 |
|
var_clear_short_name (struct variable *v) |
356 |
|
{ |
357 |
|
assert (v != NULL); |
358 |
|
|
359 |
|
v->short_name[0] = '\0'; |
360 |
|
} |
361 |
|
|
362 |
|
/* Sets V's short name to BASE, followed by a suffix of the form |
363 |
|
_A, _B, _C, ..., _AA, _AB, etc. according to the value of |
364 |
|
SUFFIX. Truncates BASE as necessary to fit. */ |
365 |
|
void |
366 |
|
var_set_short_name_suffix (struct variable *v, const char *base, int suffix) |
367 |
|
{ |
368 |
|
char string[SHORT_NAME_LEN + 1]; |
369 |
|
char *start, *end; |
370 |
|
int len, ofs; |
371 |
|
|
372 |
|
assert (v != NULL); |
373 |
|
assert (suffix >= 0); |
374 |
|
assert (strlen (v->short_name) > 0); |
375 |
|
|
376 |
|
/* Set base name. */ |
377 |
|
var_set_short_name (v, base); |
378 |
|
|
379 |
|
/* Compose suffix_string. */ |
380 |
|
start = end = string + sizeof string - 1; |
381 |
|
*end = '\0'; |
382 |
|
do |
383 |
|
{ |
384 |
|
*--start = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[suffix % 26]; |
385 |
|
if (start <= string + 1) |
386 |
|
msg (SE, _("Variable suffix too large.")); |
387 |
|
suffix /= 26; |
388 |
|
} |
389 |
|
while (suffix > 0); |
390 |
|
*--start = '_'; |
391 |
|
|
392 |
|
/* Append suffix_string to V's short name. */ |
393 |
|
len = end - start; |
394 |
|
if (len + strlen (v->short_name) > SHORT_NAME_LEN) |
395 |
|
ofs = SHORT_NAME_LEN - len; |
396 |
|
else |
397 |
|
ofs = strlen (v->short_name); |
398 |
|
strcpy (v->short_name + ofs, start); |
399 |
} |
} |