+ (p->seqno)++;
+}
+
+static void addSortString (RecWord *p, const char *string, int length)
+{
+ struct sortKey *sk;
+
+ for (sk = sortKeys; sk; sk = sk->next)
+ if (sk->attrSet == p->attrSet && sk->attrUse == p->attrUse)
+ return;
+
+ sk = xmalloc (sizeof(*sk));
+ sk->next = sortKeys;
+ sortKeys = sk;
+
+ sk->string = xmalloc (p->length);
+ sk->length = p->length;
+ memcpy (sk->string, p->string, p->length);
+ sk->attrSet = p->attrSet;
+ sk->attrUse = p->attrUse;
+}
+
+static void addString (RecWord *p, const char *string, int length)
+{
+ assert (length > 0);
+ if (zebra_maps_is_sort (p->zebra_maps, p->reg_type))
+ addSortString (p, string, length);
+ else
+ addIndexString (p, string, length);
+}
+
+static void addIncompleteField (RecWord *p)
+{
+ const char *b = p->string;
+ int remain = p->length;
+ const char **map = 0;
+
+ if (remain > 0)
+ map = zebra_maps_input(p->zebra_maps, p->reg_type, &b, remain);
+
+ while (map)
+ {
+ char buf[IT_MAX_WORD+1];
+ int i, remain;
+
+ /* Skip spaces */
+ while (map && *map && **map == *CHR_SPACE)
+ {
+ remain = p->length - (b - p->string);
+ if (remain > 0)
+ map = zebra_maps_input(p->zebra_maps, p->reg_type, &b, remain);
+ else
+ map = 0;
+ }
+ if (!map)
+ break;
+ i = 0;
+ while (map && *map && **map != *CHR_SPACE)
+ {
+ const char *cp = *map;
+
+ while (i < IT_MAX_WORD && *cp)
+ buf[i++] = *(cp++);
+ remain = p->length - (b - p->string);
+ if (remain > 0)
+ map = zebra_maps_input(p->zebra_maps, p->reg_type, &b, remain);
+ else
+ map = 0;
+ }
+ if (!i)
+ return;
+ addString (p, buf, i);
+ }
+}
+
+static void addCompleteField (RecWord *p)
+{
+ const char *b = p->string;
+ char buf[IT_MAX_WORD+1];
+ const char **map = 0;
+ int i = 0, remain = p->length;
+
+ if (remain > 0)
+ map = zebra_maps_input (p->zebra_maps, p->reg_type, &b, remain);
+
+ while (remain > 0 && i < IT_MAX_WORD)
+ {
+ while (map && *map && **map == *CHR_SPACE)
+ {
+ remain = p->length - (b - p->string);
+ if (remain > 0)
+ map = zebra_maps_input(p->zebra_maps, p->reg_type, &b, remain);
+ else
+ map = 0;
+ }
+ if (!map)
+ break;
+
+ if (i && i < IT_MAX_WORD)
+ buf[i++] = *CHR_SPACE;
+ while (map && *map && **map != *CHR_SPACE)
+ {
+ const char *cp = *map;
+
+ if (i >= IT_MAX_WORD)
+ break;
+ while (i < IT_MAX_WORD && *cp)
+ buf[i++] = *(cp++);
+ remain = p->length - (b - p->string);
+ if (remain > 0)
+ map = zebra_maps_input (p->zebra_maps, p->reg_type, &b,
+ remain);
+ else
+ map = 0;
+ }
+ }
+ if (!i)
+ return;
+ addString (p, buf, i);
+}
+
+static void addRecordKey (RecWord *p)
+{
+ if (zebra_maps_is_complete (p->zebra_maps, p->reg_type))
+ addCompleteField (p);
+ else
+ addIncompleteField(p);
+}
+
+static void flushSortKeys (SYSNO sysno, int cmd)
+{
+ struct sortKey *sk = sortKeys;
+
+ sortIdx_sysno (sortIdx, sysno);
+ while (sk)
+ {
+ struct sortKey *sk_next = sk->next;
+ sortIdx_type (sortIdx, sk->attrUse);
+ sortIdx_add (sortIdx, sk->string, sk->length);
+ xfree (sk->string);
+ xfree (sk);
+ sk = sk_next;
+ }
+ sortKeys = NULL;