* Sebastian Hammer, Adam Dickmeiss
*
* $Log: close.c,v $
- * Revision 1.2 1994-08-17 13:32:19 adam
+ * Revision 1.3 1994-08-18 12:40:52 adam
+ * Some development of dictionary. Not finished at all!
+ *
+ * Revision 1.2 1994/08/17 13:32:19 adam
* Use cache in dict - not in bfile.
*
* Revision 1.1 1994/08/16 16:26:47 adam
assert (dict);
dict_bf_close (dict->dbf);
- free (dict);
+ xfree (dict);
return 0;
}
int i;
dict_bf_flush_blocks (dbf, -1);
- free (dbf->all_blocks);
- free (dbf->all_data);
- free (dbf->hash_array);
+ xfree (dbf->all_blocks);
+ xfree (dbf->all_data);
+ xfree (dbf->hash_array);
i = bf_close (dbf->bf);
- free (dbf);
+ xfree (dbf);
return i;
}
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: dicttest.c,v $
- * Revision 1.1 1994-08-16 16:26:47 adam
+ * Revision 1.2 1994-08-18 12:40:54 adam
+ * Some development of dictionary. Not finished at all!
+ *
+ * Revision 1.1 1994/08/16 16:26:47 adam
* Added dict.
*
*/
#include <stdio.h>
#include <dict.h>
-#include <options.h>
char *prog;
Dict dict;
int rw = 0;
int cache = 10;
int ret;
- int verbose = 0;
char *arg;
prog = argv[0];
+ log_init (LOG_DEFAULT_LEVEL, prog, NULL);
if (argc < 2)
{
fprintf (stderr, "usage:\n"
{
if (name)
{
- fprintf (stderr, "%s: too many files specified\n", prog);
+ log (LOG_FATAL, "too many files specified\n");
exit (1);
}
name = arg;
rw = 1;
}
else if (ret == 'v')
- verbose = atoi(arg);
+ {
+ log_init (atoi(arg), prog, NULL);
+ }
else
{
- fprintf (stderr, "%s: unknown option\n", prog);
+ log (LOG_FATAL, "unknown option");
exit (1);
}
}
if (!name)
{
- fprintf (stderr, "%s: no dictionary file given\n", prog);
+ log (LOG_FATAL, "no dictionary file given");
exit (1);
}
dict = dict_open (name, cache, rw);
if (!dict)
{
- fprintf (stderr, "%s: dict_open fail\n", prog);
+ log (LOG_FATAL, "dict_open fail");
exit (1);
}
if (inputfile)
if (!(ipf = fopen(inputfile, "r")))
{
- fprintf (stderr, "%s: cannot open %s\n", prog, inputfile);
+ log (LOG_FATAL|LOG_ERRNO, "cannot open %s", inputfile);
exit (1);
}
bf->lru_front = p;
}
-int bf_readp (Dict_BFile bf, int no, void **bufp)
+int dict_bf_readp (Dict_BFile bf, int no, void **bufp)
{
struct Dict_file_block *p;
int i;
return i;
}
-int bf_newp (Dict_BFile bf, int no, void **bufp)
+int dict_bf_newp (Dict_BFile bf, int no, void **bufp)
{
struct Dict_file_block *p;
if (!(p = find_block (bf, no)))
return 1;
}
-int bf_touch (Dict_BFile bf, int no)
+int dict_bf_touch (Dict_BFile bf, int no)
{
struct Dict_file_block *p;
if ((p = find_block (bf, no)))
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: insert.c,v $
- * Revision 1.2 1994-08-17 13:32:19 adam
+ * Revision 1.3 1994-08-18 12:40:56 adam
+ * Some development of dictionary. Not finished at all!
+ *
+ * Revision 1.2 1994/08/17 13:32:19 adam
* Use cache in dict - not in bfile.
*
* Revision 1.1 1994/08/16 16:26:48 adam
DICT_backptr(p) = back_ptr;
DICT_nextptr(p) = 0;
DICT_nodir(p) = 0;
- DICT_size(p) = 0;
+ DICT_size(p) = DICT_infoffset;
*pp = p;
return ptr;
}
static int dict_ins (Dict dict, const Dict_char *str, Dict_ptr back_ptr,
void *p, void *userinfo)
{
+ int i;
Dict_ptr ptr = back_ptr, subptr;
- short *indxp, *indxp1, *indxp2;
+ short *indxp, *indxp1;
short newsize;
+
if (ptr == 0)
ptr = new_page (dict, back_ptr, &p);
assert (p);
assert (ptr);
indxp = (short*) ((char*) p+DICT_PAGESIZE);
- while (*str != DICT_EOS)
+ for (i = DICT_nodir (p); --i >= 0; )
{
char *info;
+ int cmp;
if (*--indxp > 0) /* tail string here! */
{
- int cmp;
- info = DICT_info(p) + *indxp;
+ info = p + *indxp;
cmp = dict_strcmp ((Dict_char*)
(info+sizeof(Dict_info)+sizeof(Dict_ptr)),
str);
}
else if(cmp < 0)
break;
-
}
- else if(*indxp < 0) /* tail of string in sub page */
+ else /* tail of string in sub page */
{
- int cmp;
- info = DICT_info(p) - *indxp;
+ assert (*indxp < 0);
+ info = p - *indxp;
cmp = memcmp (info+sizeof(Dict_info)+sizeof(Dict_ptr), str,
- sizeof(Dict_char));
+ sizeof(Dict_char));
if (!cmp)
{
Dict_ptr subptr;
else if(cmp < 0)
break;
}
- else
- break;
}
newsize = DICT_size(p);
subptr = 0;
- memcpy (DICT_info(p) + newsize, &subptr, sizeof(subptr));
- memcpy (DICT_info(p) + newsize + sizeof(Dict_ptr), userinfo,
- sizeof(Dict_info));
- memcpy (DICT_info(p) + newsize + sizeof(Dict_ptr)+sizeof(Dict_info),
- str, dict_strlen (str));
- newsize = DICT_size(p) +
- sizeof(Dict_info) + sizeof(Dict_ptr) + dict_strlen (str);
- DICT_size (p) = newsize;
-
- DICT_nodir(p) = DICT_nodir(p)+1;
- indxp2 = (short*)((char*) p + DICT_PAGESIZE - DICT_nodir(p)*sizeof(short));
- for (indxp1 = indxp2; indxp1 != indxp; indxp1++)
- indxp[0] = indxp[1];
+ memcpy (p+newsize, &subptr, sizeof(subptr));
+ memcpy (p+newsize + sizeof(Dict_ptr), userinfo, sizeof(Dict_info));
+ memcpy (p+newsize + sizeof(Dict_ptr)+sizeof(Dict_info), str,
+ dict_strlen (str)+1);
+ (DICT_nodir(p))++;
+ indxp1 = (short*)((char*) p + DICT_PAGESIZE - DICT_nodir(p)*sizeof(short));
+ for (; indxp1 != indxp; indxp1++)
+ indxp1[0] = indxp1[1];
*indxp = -newsize;
+
+ DICT_size(p) = newsize + sizeof(Dict_info)+sizeof(Dict_ptr)
+ +dict_strlen (str)+1;
return 0;
}
int dict_insert (Dict dict, const Dict_char *str, void *userinfo)
{
- dict_ins (dict, str, 0, NULL, userinfo);
+ void *p;
+ if (dict->head.last == 1)
+ dict_ins (dict, str, 0, NULL, userinfo);
+ else
+ {
+ dict_bf_readp (dict->dbf, 1, &p);
+ dict_ins (dict, str, 1, p, userinfo);
+ }
return 0;
}
-
-
-
-
-
-
-
-
-
-
-
-
-
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: open.c,v $
- * Revision 1.2 1994-08-17 13:32:20 adam
+ * Revision 1.3 1994-08-18 12:40:58 adam
+ * Some development of dictionary. Not finished at all!
+ *
+ * Revision 1.2 1994/08/17 13:32:20 adam
* Use cache in dict - not in bfile.
*
* Revision 1.1 1994/08/16 16:26:49 adam
*
*/
-
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
if(!dict->dbf)
{
- free (dict);
+ xfree (dict);
return NULL;
}
if (dict_bf_readp (dict->dbf, 0, &head_buf) <= 0)
if (!strcmp (dh->magic_str, DICT_MAGIC))
{
dict_bf_close (dict->dbf);
- free (dict);
+ xfree (dict);
return NULL;
}
if (dh->page_size != DICT_PAGESIZE)
{
dict_bf_close (dict->dbf);
- free (dict);
+ xfree (dict);
return NULL;
}
memcpy (&dict->head, dh, sizeof(*dh));
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: dict.h,v $
- * Revision 1.2 1994-08-17 13:32:33 adam
+ * Revision 1.3 1994-08-18 12:41:12 adam
+ * Some development of dictionary. Not finished at all!
+ *
+ * Revision 1.2 1994/08/17 13:32:33 adam
* Use cache in dict - not in bfile.
*
* Revision 1.1 1994/08/16 16:26:53 adam
#define DICT_nextptr(x) 2[(Dict_ptr*) x]
#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_info(x) ((char*)(x)+3*sizeof(Dict_ptr)+2*sizeof(short))
+#define DICT_infoffset (3*sizeof(Dict_ptr)+2*sizeof(short))
#define DICT_to_str(x) sizeof(Dict_info)+sizeof(Dict_ptr)