+ int ch = 0;
+ struct it_key key_out;
+ zint *keyp = key_out.mem;
+
+ assert(key_in.len == 4);
+
+ /* check for buffer overflow */
+ if (zh->reg->key_buf_used + 1024 >
+ (zh->reg->ptr_top -zh->reg->ptr_i)*sizeof(char*))
+ extract_flushWriteKeys (zh, 0);
+
+ ++(zh->reg->ptr_i);
+ assert(zh->reg->ptr_i > 0);
+ (zh->reg->key_buf)[zh->reg->ptr_top - zh->reg->ptr_i] =
+ (char*)zh->reg->key_buf + zh->reg->key_buf_used;
+
+ /* encode the ordinal value (field/use/attribute) .. */
+ ch = CAST_ZINT_TO_INT(key_in.mem[0]);
+ zh->reg->key_buf_used +=
+ key_SU_encode(ch, (char*)zh->reg->key_buf +
+ zh->reg->key_buf_used);
+
+ /* copy the 0-terminated stuff from str to output */
+ memcpy((char*)zh->reg->key_buf + zh->reg->key_buf_used, str, slen);
+ zh->reg->key_buf_used += slen;
+ ((char*)zh->reg->key_buf)[(zh->reg->key_buf_used)++] = '\0';
+
+ /* the delete/insert indicator */
+ ((char*)zh->reg->key_buf)[(zh->reg->key_buf_used)++] = cmd;
+
+ if (zh->m_staticrank) /* rank config enabled ? */
+ {
+ if (staticrank < 0)
+ {
+ yaz_log(YLOG_WARN, "staticrank = %ld. Setting to 0",
+ (long) staticrank);
+ staticrank = 0;
+ }
+ *keyp++ = staticrank;
+ key_out.len = 4;
+ }
+ else
+ key_out.len = 3;
+
+ if (key_in.mem[1]) /* filter specified record ID */
+ *keyp++ = key_in.mem[1];
+ else
+ *keyp++ = sysno;
+ *keyp++ = key_in.mem[2]; /* section_id */
+ *keyp++ = key_in.mem[3]; /* sequence .. */
+
+ memcpy((char*)zh->reg->key_buf + zh->reg->key_buf_used,
+ &key_out, sizeof(key_out));
+ (zh->reg->key_buf_used) += sizeof(key_out);