2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.4 1994-09-01 17:44:10 adam
8 * depend include change.
9 * CVS ----------------------------------------------------------------------
11 * Revision 1.3 1994/08/18 12:40:58 adam
12 * Some development of dictionary. Not finished at all!
14 * Revision 1.2 1994/08/17 13:32:20 adam
15 * Use cache in dict - not in bfile.
17 * Revision 1.1 1994/08/16 16:26:49 adam
28 Dict dict_open (const char *name, int cache, int rw)
34 dict = xmalloc (sizeof(*dict));
36 dict->dbf = dict_bf_open (name, DICT_PAGESIZE, cache, rw);
41 log (LOG_LOG, "cannot open `%s'", name);
45 if (dict_bf_readp (dict->dbf, 0, &head_buf) <= 0)
48 { /* create header with information (page 0) */
49 dict_bf_newp (dict->dbf, 0, &head_buf);
50 dh = (struct Dict_head *) head_buf;
51 strcpy(dh->magic_str, DICT_MAGIC);
52 dh->free_list = dh->last = 1;
53 dh->page_size = DICT_PAGESIZE;
54 memcpy (&dict->head, dh, sizeof(*dh));
57 { /* no header present, i.e. no dictionary at all */
58 dict->head.free_list = dict->head.last = 0;
59 dict->head.page_size = DICT_PAGESIZE;
62 else /* header was there, check magic and page size */
64 dh = (struct Dict_head *) head_buf;
65 if (strcmp (dh->magic_str, DICT_MAGIC))
67 log (LOG_LOG, "bad magic of `%s'", name);
68 dict_bf_close (dict->dbf);
72 if (dh->page_size != DICT_PAGESIZE)
74 log (LOG_LOG, "page size mismatch of `%s'", name);
75 dict_bf_close (dict->dbf);
79 memcpy (&dict->head, dh, sizeof(*dh));
84 int dict_strcmp (const Dict_char *s1, const Dict_char *s2)
86 return strcmp (s1, s2);
89 int dict_strlen (const Dict_char *s)