+ /* Dict_ptr subptr */
+ /* Dict_char sub char */
+ /* unsigned char length of information */
+ /* char * information */
+ info = (char*)p - indxp[-mid];
+ memcpy (&dc, info+sizeof(Dict_ptr), sizeof(Dict_char));
+ cmp = dc- *str;
+ if (!cmp)
+ {
+ memcpy (&subptr, info, sizeof(Dict_ptr));
+ if (*++str == DICT_EOS)
+ {
+ int xlen;
+
+ 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;
+ }
+ if (DICT_size(p)+sizeof(Dict_char)+sizeof(Dict_ptr)+
+ userlen >=
+ DICT_pagesize(dict) - (1+DICT_nodir(p))*sizeof(short))
+ {
+ 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))
+ {
+ log (LOG_FATAL, "Unable to split page %d\n", ptr);
+ abort ();
+ }
+ return dict_ins (dict, str-1, ptr, userlen, userinfo);
+ }
+ else
+ {
+ 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 >=
+ DICT_pagesize(dict) - (1+DICT_nodir(p))*sizeof(short)) /* overflow? */
+ {
+ 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_pagesize(dict)
+ - 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;