* Sebastian Hammer, Adam Dickmeiss
*
* $Log: insert.c,v $
- * Revision 1.9 1994-09-16 15:39:13 adam
+ * Revision 1.10 1994-10-05 12:16:48 adam
+ * Pagesize is a resource now.
+ *
+ * Revision 1.9 1994/09/16 15:39:13 adam
* Initial code of lookup - not tested yet.
*
* Revision 1.8 1994/09/16 12:35:01 adam
int best_no = -1, no_current = 1;
/* determine splitting char... */
- indxp = (short*) ((char*) p+DICT_PAGESIZE-sizeof(short));
+ indxp = (short*) ((char*) p+DICT_pagesize(dict)-sizeof(short));
for (i = DICT_nodir (p); --i >= 0; --indxp)
{
if (*indxp > 0) /* tail string here! */
short *indxp1, *indxp2;
char *info1, *info2;
- indxp1 = (short*) ((char*) p+DICT_PAGESIZE-sizeof(short));
- indxp2 = (short*) ((char*) np+DICT_PAGESIZE);
+ indxp1 = (short*) ((char*) p+DICT_pagesize(dict)-sizeof(short));
+ indxp2 = (short*) ((char*) np+DICT_pagesize(dict));
info2 = (char*) np + DICT_infoffset;
for (i = DICT_nodir (p); --i >= 0; --indxp1)
{
++no;
}
memcpy ((char*)p+DICT_infoffset, (char*)np+DICT_infoffset,
- DICT_PAGESIZE-DICT_infoffset);
+ DICT_pagesize(dict)-DICT_infoffset);
DICT_size(p) = info2 - np;
DICT_type(p) = 0;
DICT_nodir(p) = no;
mid = lo = 0;
hi = DICT_nodir(p)-1;
- indxp = (short*) ((char*) p+DICT_PAGESIZE-sizeof(short));
+ indxp = (short*) ((char*) p+DICT_pagesize(dict)-sizeof(short));
while (lo <= hi)
{
mid = (lo+hi)/2;
}
if (DICT_size(p)+sizeof(Dict_char)+sizeof(Dict_ptr)+
userlen >=
- DICT_PAGESIZE - (1+DICT_nodir(p))*sizeof(short))
+ DICT_pagesize(dict) - (1+DICT_nodir(p))*sizeof(short))
{
if (DICT_type(p) == 1)
{
--indxp;
slen = (dict_strlen(str)+1)*sizeof(Dict_char);
if (DICT_size(p)+slen+userlen >=
- DICT_PAGESIZE - (1+DICT_nodir(p))*sizeof(short)) /* overflow? */
+ DICT_pagesize(dict) - (1+DICT_nodir(p))*sizeof(short)) /* overflow? */
{
split_page (dict, ptr, p);
return dict_ins (dict, str, ptr, userlen, userinfo);
{
short *indxp1;
(DICT_nodir(p))++;
- indxp1 = (short*)((char*) p + DICT_PAGESIZE
+ 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-sizeof(short));
+ indxp1 = (short*) ((char*) p+DICT_pagesize(dict)-sizeof(short));
for (i = DICT_nodir (p); --i >= 0; --indxp1)
{
if (*indxp1 < 0)
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: lookgrep.c,v $
- * Revision 1.2 1994-10-04 12:08:07 adam
+ * Revision 1.3 1994-10-05 12:16:50 adam
+ * Pagesize is a resource now.
+ *
+ * Revision 1.2 1994/10/04 12:08:07 adam
* Some bug fixes and some optimizations.
*
* Revision 1.1 1994/10/03 17:23:04 adam
dict_bf_readp (dict->dbf, ptr, &p);
lo = 0;
hi = DICT_nodir(p)-1;
- indxp = (short*) ((char*) p+DICT_PAGESIZE-sizeof(short));
+ indxp = (short*) ((char*) p+DICT_pagesize(dict)-sizeof(short));
while (lo <= hi)
{
dict_grep (dict, subptr, mc, Rj1, pos+1,
userfunc, prefix, dfas);
dict_bf_readp (dict->dbf, ptr, &p);
- indxp = (short*) ((char*) p+DICT_PAGESIZE-sizeof(short));
+ indxp = (short*) ((char*) p+DICT_pagesize(dict)
+ -sizeof(short));
}
}
}
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: lookup.c,v $
- * Revision 1.3 1994-09-26 10:17:25 adam
+ * Revision 1.4 1994-10-05 12:16:51 adam
+ * Pagesize is a resource now.
+ *
+ * Revision 1.3 1994/09/26 10:17:25 adam
* Minor changes.
*
* Revision 1.2 1994/09/16 15:39:14 adam
dict_bf_readp (dict->dbf, ptr, &p);
mid = lo = 0;
hi = DICT_nodir(p)-1;
- indxp = (short*) ((char*) p+DICT_PAGESIZE-sizeof(short));
+ indxp = (short*) ((char*) p+DICT_pagesize(dict)-sizeof(short));
while (lo <= hi)
{
mid = (lo+hi)/2;
dict_bf_readp (dict->dbf, ptr, &p);
mid = lo = 0;
hi = DICT_nodir(p)-1;
- indxp = (short*) ((char*) p+DICT_PAGESIZE-sizeof(short));
+ indxp = (short*) ((char*) p+DICT_pagesize(dict)
+ -sizeof(short));
continue;
}
}
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: lookupec.c,v $
- * Revision 1.3 1994-09-26 16:31:06 adam
+ * Revision 1.4 1994-10-05 12:16:51 adam
+ * Pagesize is a resource now.
+ *
+ * Revision 1.3 1994/09/26 16:31:06 adam
* Minor changes.
*
* Revision 1.2 1994/09/22 14:43:57 adam
dict_bf_readp (dict->dbf, ptr, &p);
lo = 0;
hi = DICT_nodir(p)-1;
- indxp = (short*) ((char*) p+DICT_PAGESIZE-sizeof(short));
+ indxp = (short*) ((char*) p+DICT_pagesize(dict)-sizeof(short));
while (lo <= hi)
{
if (indxp[-lo] > 0)
dict_look_ec (dict, subptr, mi, ri, pos+1,
userfunc, range, prefix);
dict_bf_readp (dict->dbf, ptr, &p);
- indxp = (short*) ((char*) p+DICT_PAGESIZE-sizeof(short));
+ indxp = (short*) ((char*) p+DICT_pagesize(dict)-sizeof(short));
}
}
}
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: open.c,v $
- * Revision 1.5 1994-09-01 17:49:39 adam
+ * Revision 1.6 1994-10-05 12:16:52 adam
+ * Pagesize is a resource now.
+ *
+ * Revision 1.5 1994/09/01 17:49:39 adam
* Removed stupid line. Work on insertion in dictionary. Not finished yet.
*
* Revision 1.4 1994/09/01 17:44:10 adam
Dict dict;
void *head_buf;
struct Dict_head *dh;
+ char resource_str[80];
+ int page_size;
dict = xmalloc (sizeof(*dict));
- dict->dbf = dict_bf_open (name, DICT_PAGESIZE, cache, rw);
+ sprintf (resource_str, "dict.%s.pagesize", name);
+
+ page_size = atoi (res_get_def (common_resource, resource_str,
+ DICT_DEFAULT_PAGESIZE));
+ if (page_size < 1024)
+ {
+ log (LOG_WARN, "Resource %s was too small. Set to 1024", resource_str);
+ page_size = 1024;
+ }
+ dict->dbf = dict_bf_open (name, page_size, cache, rw);
dict->rw = rw;
if(!dict->dbf)
{
- log (LOG_LOG, "cannot open `%s'", name);
+ log (LOG_WARN, "Cannot open `%s'", name);
xfree (dict);
return NULL;
}
dh = (struct Dict_head *) head_buf;
strcpy(dh->magic_str, DICT_MAGIC);
dh->free_list = dh->last = 1;
- dh->page_size = DICT_PAGESIZE;
+ dh->page_size = page_size;
memcpy (&dict->head, dh, sizeof(*dh));
}
else
{ /* no header present, i.e. no dictionary at all */
dict->head.free_list = dict->head.last = 0;
- dict->head.page_size = DICT_PAGESIZE;
+ dict->head.page_size = page_size;
}
}
else /* header was there, check magic and page size */
dh = (struct Dict_head *) head_buf;
if (strcmp (dh->magic_str, DICT_MAGIC))
{
- log (LOG_LOG, "bad magic of `%s'", name);
+ log (LOG_WARN, "Bad magic of `%s'", name);
dict_bf_close (dict->dbf);
xfree (dict);
return NULL;
}
- if (dh->page_size != DICT_PAGESIZE)
+ if (dh->page_size != page_size)
{
- log (LOG_LOG, "page size mismatch of `%s'", name);
+ log (LOG_WARN, "Resource %s is %d and pagesize of `%s' is %d",
+ resource_str, page_size, name, dh->page_size);
dict_bf_close (dict->dbf);
xfree (dict);
return NULL;
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: dict.h,v $
- * Revision 1.9 1994-10-04 12:08:19 adam
+ * Revision 1.10 1994-10-05 12:16:58 adam
+ * Pagesize is a resource now.
+ *
+ * Revision 1.9 1994/10/04 12:08:19 adam
* Minor changes.
*
* Revision 1.8 1994/10/03 17:23:11 adam
*
* Revision 1.4 1994/09/01 17:44:40 adam
* Work on insertion in dictionary. Not finished yet.
- * CVS ----------------------------------------------------------------------
*
* Revision 1.3 1994/08/18 12:41:12 adam
* Some development of dictionary. Not finished at all!
#define DICT_MAGIC "dict00"
-#define DICT_PAGESIZE 8192
+#define DICT_DEFAULT_PAGESIZE "8192"
int dict_bf_readp (Dict_BFile bf, int no, void **bufp);
int dict_bf_newp (Dict_BFile bf, int no, void **bufp);
#define DICT_nodir(x) 0[(short*)((char*)(x)+3*sizeof(Dict_ptr))]
#define DICT_size(x) 1[(short*)((char*)(x)+3*sizeof(Dict_ptr))]
#define DICT_infoffset (3*sizeof(Dict_ptr)+2*sizeof(short))
+#define DICT_pagesize(x) ((x)->head.page_size)
#define DICT_to_str(x) sizeof(Dict_info)+sizeof(Dict_ptr)