+ {
+ rr->errcode = 30;
+ rr->errstring = rr->input_setnames[0];
+ return 0;
+ }
+ num_criteria = rr->sort_sequence->num_specs;
+ if (num_criteria > 3)
+ num_criteria = 3;
+ for (i = 0; i < num_criteria; i++)
+ {
+ Z_SortKeySpec *sks = rr->sort_sequence->specs[i];
+ Z_SortKey *sk;
+
+ if (*sks->sortRelation == Z_SortRelation_ascending)
+ sort_criteria[i].relation = 'A';
+ else if (*sks->sortRelation == Z_SortRelation_descending)
+ sort_criteria[i].relation = 'D';
+ else
+ {
+ rr->errcode = 214;
+ return 0;
+ }
+ if (sks->sortElement->which == Z_SortElement_databaseSpecific)
+ {
+ rr->errcode = 210;
+ return 0;
+ }
+ else if (sks->sortElement->which != Z_SortElement_generic)
+ {
+ rr->errcode = 237;
+ return 0;
+ }
+ sk = sks->sortElement->u.generic;
+ switch (sk->which)
+ {
+ case Z_SortKey_sortField:
+ logf (LOG_DEBUG, "Sort: key %d is of type sortField", i+1);
+ rr->errcode = 207;
+ return 0;
+ case Z_SortKey_elementSpec:
+ logf (LOG_DEBUG, "Sort: key %d is of type elementSpec", i+1);
+ return 0;
+ case Z_SortKey_sortAttributes:
+ logf (LOG_DEBUG, "Sort: key %d is of type sortAttributes", i+1);
+ sort_criteria[i].attrUse =
+ zebra_maps_sort (zi->zebra_maps, sk->u.sortAttributes);
+ logf (LOG_DEBUG, "use value = %d", sort_criteria[i].attrUse);
+ if (sort_criteria[i].attrUse == -1)
+ {
+ rr->errcode = 116;
+ return 0;
+ }
+ if (sortIdx_type (zi->sortIdx, sort_criteria[i].attrUse))
+ {
+ rr->errcode = 207;
+ return 0;
+ }
+ break;
+ }
+ }
+ if (strcmp (rr->output_setname, rr->input_setnames[0]))
+ {
+ rset = rset_dup (rset);
+ sset = resultSetAdd (zi, rr->output_setname, 1, rset);
+ }
+ resultSetSortReset (&sset->sort_info);
+
+ sset->sort_info = xmalloc (sizeof(*sset->sort_info));
+ sset->sort_info->max_entries = 10;
+ sset->sort_info->num_entries = 0;
+ sset->sort_info->entries = xmalloc (sizeof(*sset->sort_info->entries) *
+ sset->sort_info->max_entries);
+ for (i = 0; i<sset->sort_info->max_entries; i++)
+ sset->sort_info->entries[i] =
+ xmalloc (sizeof(*sset->sort_info->entries[i]));
+
+
+ rfd = rset_open (rset, RSETF_READ|RSETF_SORT_SYSNO);