/[pspp]/pspp/src/vars-atr.c
ViewVC logotype

Diff of /pspp/src/vars-atr.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.21 by blp, Fri Apr 29 21:32:18 2005 UTC revision 1.22 by blp, Mon May 2 06:21:21 2005 UTC
# Line 256  var_is_valid_name (const char *name, boo Line 256  var_is_valid_name (const char *name, boo
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    
# Line 304  compare_var_names (const void *a_, const Line 304  compare_var_names (const void *a_, const
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. */
# Line 313  hash_var_name (const void *v_, void *foo Line 313  hash_var_name (const void *v_, void *foo
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
# Line 324  compare_var_ptr_names (const void *a_, c Line 324  compare_var_ptr_names (const void *a_, c
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
# Line 334  hash_var_ptr_name (const void *v_, void Line 334  hash_var_ptr_name (const void *v_, void
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  }  }

Legend:
Removed from v.1.21  
changed lines
  Added in v.1.22

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26