2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.5 1994-09-01 17:49:39 adam
8 * Removed stupid line. Work on insertion in dictionary. Not finished yet.
10 * Revision 1.4 1994/09/01 17:44:10 adam
11 * depend include change.
13 * Revision 1.3 1994/08/18 12:40:58 adam
14 * Some development of dictionary. Not finished at all!
16 * Revision 1.2 1994/08/17 13:32:20 adam
17 * Use cache in dict - not in bfile.
19 * Revision 1.1 1994/08/16 16:26:49 adam
30 Dict dict_open (const char *name, int cache, int rw)
36 dict = xmalloc (sizeof(*dict));
38 dict->dbf = dict_bf_open (name, DICT_PAGESIZE, cache, rw);
43 log (LOG_LOG, "cannot open `%s'", name);
47 if (dict_bf_readp (dict->dbf, 0, &head_buf) <= 0)
50 { /* create header with information (page 0) */
51 dict_bf_newp (dict->dbf, 0, &head_buf);
52 dh = (struct Dict_head *) head_buf;
53 strcpy(dh->magic_str, DICT_MAGIC);
54 dh->free_list = dh->last = 1;
55 dh->page_size = DICT_PAGESIZE;
56 memcpy (&dict->head, dh, sizeof(*dh));
59 { /* no header present, i.e. no dictionary at all */
60 dict->head.free_list = dict->head.last = 0;
61 dict->head.page_size = DICT_PAGESIZE;
64 else /* header was there, check magic and page size */
66 dh = (struct Dict_head *) head_buf;
67 if (strcmp (dh->magic_str, DICT_MAGIC))
69 log (LOG_LOG, "bad magic of `%s'", name);
70 dict_bf_close (dict->dbf);
74 if (dh->page_size != DICT_PAGESIZE)
76 log (LOG_LOG, "page size mismatch of `%s'", name);
77 dict_bf_close (dict->dbf);
81 memcpy (&dict->head, dh, sizeof(*dh));
86 int dict_strcmp (const Dict_char *s1, const Dict_char *s2)
88 return strcmp (s1, s2);
91 int dict_strlen (const Dict_char *s)