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

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

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

revision 1.16 by jmd, Fri Apr 29 01:02:16 2005 UTC revision 1.17 by blp, Mon May 2 06:21:21 2005 UTC
# Line 134  parse_variables (const struct dictionary Line 134  parse_variables (const struct dictionary
134    assert (var != NULL);    assert (var != NULL);
135    assert (cnt != NULL);    assert (cnt != NULL);
136    
   
137    vs = var_set_create_from_dict (d);    vs = var_set_create_from_dict (d);
138    success = parse_var_set_vars (vs, var, cnt, opts);    success = parse_var_set_vars (vs, var, cnt, opts);
139    if ( success == 0 )    if ( success == 0 )
# Line 267  parse_var_set_vars (const struct var_set Line 266  parse_var_set_vars (const struct var_set
266    else    else
267      included = NULL;      included = NULL;
268    
269  if (lex_match (T_ALL))    if (lex_match (T_ALL))
270      add_variables (v, nv, &mv, included, pv_opts,      add_variables (v, nv, &mv, included, pv_opts,
271                     vs, 0, var_set_get_cnt (vs) - 1, DC_ORDINARY);                     vs, 0, var_set_get_cnt (vs) - 1, DC_ORDINARY);
272    else    else
# Line 303  if (lex_match (T_ALL)) Line 302  if (lex_match (T_ALL))
302                         first_var->name, last_var->name);                         first_var->name, last_var->name);
303                    goto fail;                    goto fail;
304                  }                  }
305    
306                if (class != last_class)                if (class != last_class)
307                  {                  {
308                    msg (SE, _("When using the TO keyword to specify several "                    msg (SE, _("When using the TO keyword to specify several "
# Line 391  parse_DATA_LIST_vars (char ***names, int Line 391  parse_DATA_LIST_vars (char ***names, int
391    int d1, d2;    int d1, d2;
392    int n;    int n;
393    int nvar, mvar;    int nvar, mvar;
394    char *name1, *name2;    char name1[LONG_NAME_LEN + 1], name2[LONG_NAME_LEN + 1];
395    char *root1, *root2;    char root1[LONG_NAME_LEN + 1], root2[LONG_NAME_LEN + 1];
396    int success = 0;    int success = 0;
397    
398    assert (names != NULL);    assert (names != NULL);
# Line 409  parse_DATA_LIST_vars (char ***names, int Line 409  parse_DATA_LIST_vars (char ***names, int
409        *names = NULL;        *names = NULL;
410      }      }
411    
   name1 = xmalloc (4 * (SHORT_NAME_LEN + 1));  
   name2 = &name1[1 * SHORT_NAME_LEN + 1];  
   root1 = &name1[2 * SHORT_NAME_LEN + 1];  
   root2 = &name1[3 * SHORT_NAME_LEN + 1];  
412    do    do
413      {      {
414        if (token != T_ID)        if (token != T_ID)
# Line 443  parse_DATA_LIST_vars (char ***names, int Line 439  parse_DATA_LIST_vars (char ***names, int
439                || !extract_num (name2, root2, &n2, &d2))                || !extract_num (name2, root2, &n2, &d2))
440              goto fail;              goto fail;
441    
442            if (strcmp (root1, root2))            if (strcasecmp (root1, root2))
443              {              {
444                msg (SE, _("Prefixes don't match in use of TO convention."));                msg (SE, _("Prefixes don't match in use of TO convention."));
445                goto fail;                goto fail;
# Line 464  parse_DATA_LIST_vars (char ***names, int Line 460  parse_DATA_LIST_vars (char ***names, int
460    
461            for (n = n1; n <= n2; n++)            for (n = n1; n <= n2; n++)
462              {              {
463                (*names)[nvar] = xmalloc (SHORT_NAME_LEN + 1);                char name[LONG_NAME_LEN + 1];
464                sprintf ((*names)[nvar], "%s%0*d", root1, d1, n);                sprintf (name, "%s%0*d", root1, d1, n);
465                  (*names)[nvar] = xstrdup (name);
466                nvar++;                nvar++;
467              }              }
468          }          }
# Line 489  parse_DATA_LIST_vars (char ***names, int Line 486  parse_DATA_LIST_vars (char ***names, int
486    
487  fail:  fail:
488    *nnames = nvar;    *nnames = nvar;
   free (name1);  
489    if (!success)    if (!success)
490      {      {
491        int i;        int i;
# Line 662  struct array_var_set Line 658  struct array_var_set
658      struct variable *const *var;/* Array of variables. */      struct variable *const *var;/* Array of variables. */
659      size_t var_cnt;             /* Number of elements in var. */      size_t var_cnt;             /* Number of elements in var. */
660      struct hsh_table *name_tab; /* Hash from variable names to variables. */      struct hsh_table *name_tab; /* Hash from variable names to variables. */
     struct hsh_table *longname_tab; /* Hash of short names indexed by long names */  
661    };    };
662    
663  /* Returns the number of variables in VS. */  /* Returns the number of variables in VS. */
# Line 689  array_var_set_get_var (const struct var_ Line 684  array_var_set_get_var (const struct var_
684  static int  static int
685  array_var_set_lookup_var_idx (const struct var_set *vs, const char *name)  array_var_set_lookup_var_idx (const struct var_set *vs, const char *name)
686  {  {
   char *short_name ;  
687    struct array_var_set *avs = vs->aux;    struct array_var_set *avs = vs->aux;
688    struct variable v, *vp, *const *vpp;    struct variable v, *vp, *const *vpp;
689    
690    struct name_table_entry key;    strcpy (v.name, name);
   key.longname = name;  
   
   struct name_table_entry *nte;  
   
   assert (avs->longname_tab);  
   
   
   nte = hsh_find (avs->longname_tab, &key);  
   
   if (!nte)  
     return -1;  
   
   short_name = nte->name;  
   
   strcpy (v.name, short_name);  
691    vp = &v;    vp = &v;
692    vpp = hsh_find (avs->name_tab, &vp);    vpp = hsh_find (avs->name_tab, &vp);
693    return vpp != NULL ? vpp - avs->var : -1;    return vpp != NULL ? vpp - avs->var : -1;
# Line 721  array_var_set_destroy (struct var_set *v Line 700  array_var_set_destroy (struct var_set *v
700    struct array_var_set *avs = vs->aux;    struct array_var_set *avs = vs->aux;
701    
702    hsh_destroy (avs->name_tab);    hsh_destroy (avs->name_tab);
   hsh_destroy (avs->longname_tab);  
703    free (avs);    free (avs);
704    free (vs);    free (vs);
705  }  }
# Line 744  var_set_create_from_array (struct variab Line 722  var_set_create_from_array (struct variab
722    avs->var = var;    avs->var = var;
723    avs->var_cnt = var_cnt;    avs->var_cnt = var_cnt;
724    avs->name_tab = hsh_create (2 * var_cnt,    avs->name_tab = hsh_create (2 * var_cnt,
725                                compare_var_ptr_names, hash_var_ptr_name,                                compare_var_ptr_names, hash_var_ptr_name, NULL,
726                                NULL, NULL);                                NULL);
   
   avs->longname_tab = hsh_create (2 * var_cnt,  
                                    compare_long_names, hash_long_name,  
                                    (hsh_free_func *) free_nte,  
                                    NULL);  
     
727    for (i = 0; i < var_cnt; i++)    for (i = 0; i < var_cnt; i++)
728      {      if (hsh_insert (avs->name_tab, (void *) &var[i]) != NULL)
729        struct name_table_entry *nte ;        {
730            var_set_destroy (vs);
731        if (hsh_insert (avs->name_tab, &var[i]) != NULL)          return NULL;
732          {        }
733            var_set_destroy (vs);    
           return NULL;  
         }  
   
       nte = xmalloc (sizeof (*nte));  
       nte->name = strdup(var[i]->name);  
       nte->longname = strdup(var[i]->longname);  
   
       if (hsh_insert (avs->longname_tab, nte) != NULL)  
         {  
           var_set_destroy (vs);  
           free (nte);  
           return NULL;  
         }  
   
     }  
   
734    return vs;    return vs;
735  }  }

Legend:
Removed from v.1.16  
changed lines
  Added in v.1.17

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