/[pspp]/pspp/src/dictionary.c
ViewVC logotype

Diff of /pspp/src/dictionary.c

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

revision 1.30 by jmd, Mon Oct 24 05:41:45 2005 UTC revision 1.31 by blp, Wed Oct 26 05:06:14 2005 UTC
# Line 100  dict_clone (const struct dictionary *s) Line 100  dict_clone (const struct dictionary *s)
100    d->split_cnt = s->split_cnt;    d->split_cnt = s->split_cnt;
101    if (d->split_cnt > 0)    if (d->split_cnt > 0)
102      {      {
103        d->split = xmalloc (d->split_cnt * sizeof *d->split);        d->split = xnmalloc (d->split_cnt, sizeof *d->split);
104        for (i = 0; i < d->split_cnt; i++)        for (i = 0; i < d->split_cnt; i++)
105          d->split[i] = dict_lookup_var_assert (d, s->split[i]->name);          d->split[i] = dict_lookup_var_assert (d, s->split[i]->name);
106      }      }
# Line 116  dict_clone (const struct dictionary *s) Line 116  dict_clone (const struct dictionary *s)
116    dict_set_documents (d, dict_get_documents (s));    dict_set_documents (d, dict_get_documents (s));
117    
118    d->vector_cnt = s->vector_cnt;    d->vector_cnt = s->vector_cnt;
119    d->vector = xmalloc (d->vector_cnt * sizeof *d->vector);    d->vector = xnmalloc (d->vector_cnt, sizeof *d->vector);
120    for (i = 0; i < s->vector_cnt; i++)    for (i = 0; i < s->vector_cnt; i++)
121      {      {
122        struct vector *sv = s->vector[i];        struct vector *sv = s->vector[i];
# Line 126  dict_clone (const struct dictionary *s) Line 126  dict_clone (const struct dictionary *s)
126        dv->idx = i;        dv->idx = i;
127        strcpy (dv->name, sv->name);        strcpy (dv->name, sv->name);
128        dv->cnt = sv->cnt;        dv->cnt = sv->cnt;
129        dv->var = xmalloc (dv->cnt * sizeof *dv->var);        dv->var = xnmalloc (dv->cnt, sizeof *dv->var);
130        for (j = 0; j < dv->cnt; j++)        for (j = 0; j < dv->cnt; j++)
131          dv->var[j] = d->var[sv->var[j]->index];          dv->var[j] = d->var[sv->var[j]->index];
132      }      }
# Line 240  dict_get_vars (const struct dictionary * Line 240  dict_get_vars (const struct dictionary *
240      if (!(exclude_classes & (1u << dict_class_from_id (d->var[i]->name))))      if (!(exclude_classes & (1u << dict_class_from_id (d->var[i]->name))))
241        count++;        count++;
242    
243    *vars = xmalloc (count * sizeof **vars);    *vars = xnmalloc (count, sizeof **vars);
244    *cnt = 0;    *cnt = 0;
245    for (i = 0; i < d->var_cnt; i++)    for (i = 0; i < d->var_cnt; i++)
246      if (!(exclude_classes & (1u << dict_class_from_id (d->var[i]->name))))      if (!(exclude_classes & (1u << dict_class_from_id (d->var[i]->name))))
# Line 304  dict_create_var (struct dictionary *d, c Line 304  dict_create_var (struct dictionary *d, c
304    if (d->var_cnt >= d->var_cap)    if (d->var_cnt >= d->var_cap)
305      {      {
306        d->var_cap = 8 + 2 * d->var_cap;        d->var_cap = 8 + 2 * d->var_cap;
307        d->var = xrealloc (d->var, d->var_cap * sizeof *d->var);        d->var = xnrealloc (d->var, d->var_cap, sizeof *d->var);
308      }      }
309    d->var[v->index] = v;    d->var[v->index] = v;
310    d->var_cnt++;    d->var_cnt++;
# Line 545  dict_reorder_vars (struct dictionary *d, Line 545  dict_reorder_vars (struct dictionary *d,
545    assert (count == 0 || order != NULL);    assert (count == 0 || order != NULL);
546    assert (count <= d->var_cnt);    assert (count <= d->var_cnt);
547    
548    new_var = xmalloc (d->var_cnt * sizeof *new_var);    new_var = xnmalloc (d->var_cnt, sizeof *new_var);
549    memcpy (new_var, order, count * sizeof *new_var);    memcpy (new_var, order, count * sizeof *new_var);
550    for (i = 0; i < count; i++)    for (i = 0; i < count; i++)
551      {      {
# Line 609  dict_rename_vars (struct dictionary *d, Line 609  dict_rename_vars (struct dictionary *d,
609    
610    /* Remove the variables to be renamed from the name hash,    /* Remove the variables to be renamed from the name hash,
611       save their names, and rename them. */       save their names, and rename them. */
612    old_names = xmalloc (count * sizeof *old_names);    old_names = xnmalloc (count, sizeof *old_names);
613    for (i = 0; i < count; i++)    for (i = 0; i < count; i++)
614      {      {
615        assert (d->var[vars[i]->index] == vars[i]);        assert (d->var[vars[i]->index] == vars[i]);
# Line 854  dict_get_compacted_idx_to_fv (const stru Line 854  dict_get_compacted_idx_to_fv (const stru
854    size_t next_value_idx;    size_t next_value_idx;
855    int *idx_to_fv;    int *idx_to_fv;
856        
857    idx_to_fv = xmalloc (d->var_cnt * sizeof *idx_to_fv);    idx_to_fv = xnmalloc (d->var_cnt, sizeof *idx_to_fv);
858    next_value_idx = 0;    next_value_idx = 0;
859    for (i = 0; i < d->var_cnt; i++)    for (i = 0; i < d->var_cnt; i++)
860      {      {
# Line 901  dict_set_split_vars (struct dictionary * Line 901  dict_set_split_vars (struct dictionary *
901    assert (cnt == 0 || split != NULL);    assert (cnt == 0 || split != NULL);
902    
903    d->split_cnt = cnt;    d->split_cnt = cnt;
904    d->split = xrealloc (d->split, cnt * sizeof *d->split);    d->split = xnrealloc (d->split, cnt, sizeof *d->split);
905    memcpy (d->split, split, cnt * sizeof *d->split);    memcpy (d->split, split, cnt * sizeof *d->split);
906  }  }
907    
# Line 979  dict_create_vector (struct dictionary *d Line 979  dict_create_vector (struct dictionary *d
979    if (dict_lookup_vector (d, name) != NULL)    if (dict_lookup_vector (d, name) != NULL)
980      return 0;      return 0;
981    
982    d->vector = xrealloc (d->vector, (d->vector_cnt + 1) * sizeof *d->vector);    d->vector = xnrealloc (d->vector, d->vector_cnt + 1, sizeof *d->vector);
983    vector = d->vector[d->vector_cnt] = xmalloc (sizeof *vector);    vector = d->vector[d->vector_cnt] = xmalloc (sizeof *vector);
984    vector->idx = d->vector_cnt++;    vector->idx = d->vector_cnt++;
985    str_copy_trunc (vector->name, sizeof vector->name, name);    str_copy_trunc (vector->name, sizeof vector->name, name);
986    vector->var = xmalloc (cnt * sizeof *var);    vector->var = xnmalloc (cnt, sizeof *var);
987    for (i = 0; i < cnt; i++)    for (i = 0; i < cnt; i++)
988      {      {
989        assert (dict_contains_var (d, var[i]));        assert (dict_contains_var (d, var[i]));

Legend:
Removed from v.1.30  
changed lines
  Added in v.1.31

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