/* PSPP - a program for statistical analysis.
- Copyright (C) 2008, 2009, 2011 Free Software Foundation, Inc.
+ Copyright (C) 2008, 2009, 2011, 2012 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
iterator->node = hmap_next (&set->map, iterator->node);
return iterator_data (iterator);
}
+
+static int
+compare_attribute_by_name (const void *a_, const void *b_)
+{
+ const struct attribute *const *a = a_;
+ const struct attribute *const *b = b_;
+
+ return strcmp ((*a)->name, (*b)->name);
+}
+
+/* Allocates and returns an array of pointers to attributes
+ that is sorted by attribute name. The array has
+ 'attrset_count (SET)' elements. The caller is responsible for
+ freeing the array. */
+struct attribute **
+attrset_sorted (const struct attrset *set)
+{
+ if (set != NULL && attrset_count (set) > 0)
+ {
+ struct attribute **attrs;
+ struct attribute *attr;
+ size_t i;
+
+ attrs = xmalloc (attrset_count (set) * sizeof *attrs);
+ i = 0;
+ HMAP_FOR_EACH (attr, struct attribute, node, &set->map)
+ attrs[i++] = attr;
+ assert (i == attrset_count (set));
+ qsort (attrs, attrset_count (set), sizeof *attrs,
+ compare_attribute_by_name);
+ return attrs;
+ }
+ else
+ return NULL;
+}
/* PSPP - a program for statistical analysis.
- Copyright (C) 2008, 2011 Free Software Foundation, Inc.
+ Copyright (C) 2008, 2011, 2012 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
struct attrset_iterator *);
struct attribute *attrset_next (const struct attrset *,
struct attrset_iterator *);
-
+struct attribute **attrset_sorted (const struct attrset *);
#endif /* data/attributes.h */
display_attributes (struct tab_table *t, const struct attrset *set, int flags,
int c, int r)
{
- struct attrset_iterator i;
- struct attribute *attr;
+ struct attribute **attrs;
+ size_t n_attrs;
+ size_t i;
- for (attr = attrset_first (set, &i); attr != NULL;
- attr = attrset_next (set, &i))
+ n_attrs = attrset_count (set);
+ attrs = attrset_sorted (set);
+ for (i = 0; i < n_attrs; i++)
{
+ const struct attribute *attr = attrs[i];
const char *name = attribute_get_name (attr);
size_t n_values;
size_t i;
r++;
}
}
+ free (attrs);
}
static void
AT_CHECK([cat pspp.csv], [0],
[[Variable,Description,
FirstVariable,Custom attributes:,
-,bert,123
,adèle[1],23
,adèle[2],34
+,bert,123
SécondVariable,Custom attributes:,
,xyzzy,quux
Table: Custom data file attributes.
Attribute,Value
-SécondAttr[1],123
-SécondAttr[2],456
Attr1[1],Value1
Attr1[2],'déclaration'
+SécondAttr[1],123
+SécondAttr[2],456
]])
done
AT_CLEANUP