+ int xlen = info[sizeof(Dict_ptr)+sizeof(Dict_char)];
+ if (xlen == userlen)
+ {
+ if (memcmp (info+sizeof(Dict_ptr)+sizeof(Dict_char)+1,
+ userinfo, userlen))
+ {
+ dict_bf_touch (dict->dbf, ptr);
+ memcpy (info+sizeof(Dict_ptr)+sizeof(Dict_char)+1,
+ userinfo, userlen);
+ return 1;
+ }
+ return 2;
+ }
+ else if (xlen > userlen)
+ {
+ DICT_type(p) = 1;
+ info[sizeof(Dict_ptr)+sizeof(Dict_char)] = userlen;
+ memcpy (info+sizeof(Dict_ptr)+sizeof(Dict_char)+1,
+ userinfo, userlen);
+ dict_bf_touch (dict->dbf, ptr);
+ return 1;
+ }
+ /* xlen < userlen, expanding needed ... */
+ if (DICT_size(p)+sizeof(Dict_char)+sizeof(Dict_ptr)+
+ userlen >=
+ DICT_bsize(p) - (1+DICT_nodir(p))*sizeof(short))
+ {
+ /* not enough room - split needed ... */
+ if (DICT_type(p) == 1)
+ {
+ clean_page (dict, ptr, p, NULL, 0, NULL);
+ return dict_ins (dict, str-1, ptr,
+ userlen, userinfo);
+ }
+ if (split_page (dict, ptr, p))
+ {
+ yaz_log (YLOG_FATAL, "Unable to split page %d\n", ptr);
+ abort ();
+ }
+ return dict_ins (dict, str-1, ptr, userlen, userinfo);
+ }
+ else
+ { /* enough room - no split needed ... */
+ info = (char*)p + DICT_size(p);
+ memcpy (info, &subptr, sizeof(subptr));
+ memcpy (info+sizeof(Dict_ptr), &dc, sizeof(Dict_char));
+ info[sizeof(Dict_char)+sizeof(Dict_ptr)] = userlen;
+ memcpy (info+sizeof(Dict_char)+sizeof(Dict_ptr)+1,
+ userinfo, userlen);
+ indxp[-mid] = -DICT_size(p);
+ DICT_size(p) += sizeof(Dict_char)+sizeof(Dict_ptr)
+ +1+userlen;
+ DICT_type(p) = 1;
+ dict_bf_touch (dict->dbf, ptr);
+ }
+ if (xlen)
+ return 1;
+ return 0;
+ }
+ else
+ {
+ if (subptr == 0)
+ {
+ subptr = new_page (dict, ptr, NULL);
+ memcpy (info, &subptr, sizeof(subptr));
+ dict_bf_touch (dict->dbf, ptr);
+ }
+ return dict_ins (dict, str, subptr, userlen, userinfo);
+ }
+ }
+ }
+ if (cmp < 0)
+ lo = mid+1;
+ else
+ hi = mid-1;
+ }
+ indxp = indxp-mid;
+ if (lo>hi && cmp < 0)
+ --indxp;
+ slen = (dict_strlen(str)+1)*sizeof(Dict_char);
+ if (DICT_size(p)+slen+userlen >=
+ (int)(DICT_bsize(p) - (1+DICT_nodir(p))*sizeof(short)))/* overflow? */
+ {
+ if (DICT_type(p))
+ {
+ clean_page (dict, ptr, p, NULL, 0, NULL);
+ return dict_ins (dict, str, ptr, userlen, userinfo);
+ }
+ split_page (dict, ptr, p);
+ return dict_ins (dict, str, ptr, userlen, userinfo);
+ }
+ if (cmp)
+ {
+ short *indxp1;
+ (DICT_nodir(p))++;
+ indxp1 = (short*)((char*) p + DICT_bsize(p)
+ - DICT_nodir(p)*sizeof(short));
+ for (; indxp1 != indxp; indxp1++)
+ indxp1[0] = indxp1[1];
+#if CHECK
+ indxp1 = (short*) ((char*) p+DICT_pagesize(dict)-sizeof(short));
+ for (i = DICT_nodir (p); --i >= 0; --indxp1)
+ {
+ if (*indxp1 < 0)
+ {
+ info = (char*)p - *indxp1;
+ assert (info[sizeof(Dict_ptr)] > ' ');
+ }
+ }
+#endif
+ }
+ else
+ DICT_type(p) = 1;
+ info = (char*)p + DICT_size(p);
+ memcpy (info, str, slen);
+ info += slen;
+ *info++ = userlen;
+ memcpy (info, userinfo, userlen);
+ info += userlen;
+
+ *indxp = DICT_size(p);
+ DICT_size(p) = info- (char*) p;
+ dict_bf_touch (dict->dbf, ptr);
+ if (cmp)
+ return 0;
+ return 1;
+}