+static void insert_field(WRBUF w, const char *field, size_t length,
+ const char *attr)
+{
+ const char *cp0 = wrbuf_cstr(w);
+ const char *cp = cp0;
+
+ while (1)
+ {
+ const char *cp2 = strstr(cp, "@attr 1=");
+ if (!cp2)
+ break;
+ cp = cp2 + 8;
+ if (!strncmp(cp, field, length) &&
+ (cp[length] == ' ' || cp[length] == ',' || cp[length] == '\0'))
+ {
+ /* found the field */
+
+ cp += length;
+ wrbuf_insert(w, cp - cp0, attr, strlen(attr));
+ wrbuf_insert(w, cp - cp0, " ", 1);
+ return;
+ }
+ while (*cp && *cp != ',')
+ cp++;
+ }
+ if (wrbuf_len(w))
+ wrbuf_puts(w, ",");
+ wrbuf_puts(w, "@attr 1=");
+ wrbuf_write(w, field, length);
+ wrbuf_puts(w, " ");
+ wrbuf_puts(w, attr);
+}
+
+void yaz_sru_facet_request(ODR o, Z_FacetList **facetList, const char **limit,
+ const char **start, const char **sort)