+struct sort_term {
+ zint sysno;
+ char term[SORT_MAX_TERM];
+};
+
+
+static void sort_term_log_item(int level, const void *b, const char *txt)
+{
+ struct sort_term a1;
+
+ memcpy(&a1, b, sizeof(a1));
+
+ yaz_log(level, "%s " ZINT_FORMAT " %s", txt, a1.sysno, a1.term);
+}
+
+int sort_term_compare(const void *a, const void *b)
+{
+ struct sort_term a1, b1;
+
+ memcpy(&a1, a, sizeof(a1));
+ memcpy(&b1, b, sizeof(b1));
+
+ if (a1.sysno > b1.sysno)
+ return 1;
+ else if (a1.sysno < b1.sysno)
+ return -1;
+ return 0;
+}
+
+void *sort_term_code_start(void)
+{
+ return 0;
+}
+
+void sort_term_encode(void *p, char **dst, const char **src)
+{
+ struct sort_term a1;
+
+ memcpy(&a1, *src, sizeof(a1));
+ *src += sizeof(a1);
+
+ zebra_zint_encode(dst, a1.sysno); /* encode record id */
+ strcpy(*dst, a1.term); /* then sort term, 0 terminated */
+ *dst += strlen(a1.term) + 1;
+}
+
+void sort_term_decode(void *p, char **dst, const char **src)
+{
+ struct sort_term a1;
+
+ zebra_zint_decode(src, &a1.sysno);
+
+ strcpy(a1.term, *src);
+ *src += strlen(a1.term) + 1;
+
+ memcpy(*dst, &a1, sizeof(a1));
+ *dst += sizeof(a1);
+}
+
+void sort_term_code_reset(void *p)
+{
+}
+
+void sort_term_code_stop(void *p)
+{
+}
+
+
+struct sort_term_stream {
+ int no;
+ int insert_flag;
+ struct sort_term st;
+};
+
+int sort_term_code_read(void *vp, char **dst, int *insertMode)
+{
+ struct sort_term_stream *s = (struct sort_term_stream *) vp;
+
+ if (s->no == 0)
+ return 0;
+
+ (s->no)--;
+
+ *insertMode = s->insert_flag;
+ memcpy(*dst, &s->st, sizeof(s->st));
+ *dst += sizeof(s->st);
+ return 1;
+}
+
+