2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.12 1997-09-17 12:19:07 adam
8 * Zebra version corresponds to YAZ version 1.4.
9 * Changed Zebra server so that it doesn't depend on global common_resource.
11 * Revision 1.11 1996/10/29 14:00:05 adam
12 * Page size given by DICT_DEFAULT_PAGESIZE in dict.h.
14 * Revision 1.10 1996/05/24 14:46:04 adam
15 * Added dict_grep_cmap function to define user-mapping in grep lookups.
17 * Revision 1.9 1996/02/02 13:43:51 adam
18 * The public functions simply use char instead of Dict_char to represent
19 * search strings. Dict_char is used internally only.
21 * Revision 1.8 1995/12/07 11:48:56 adam
22 * Insert operation obeys DICT_type = 1 (slack in page).
23 * Function dict_open exists if page size or magic aren't right.
25 * Revision 1.7 1995/09/04 12:33:32 adam
26 * Various cleanup. YAZ util used instead.
28 * Revision 1.6 1994/10/05 12:16:52 adam
29 * Pagesize is a resource now.
31 * Revision 1.5 1994/09/01 17:49:39 adam
32 * Removed stupid line. Work on insertion in dictionary. Not finished yet.
34 * Revision 1.4 1994/09/01 17:44:10 adam
35 * depend include change.
37 * Revision 1.3 1994/08/18 12:40:58 adam
38 * Some development of dictionary. Not finished at all!
40 * Revision 1.2 1994/08/17 13:32:20 adam
41 * Use cache in dict - not in bfile.
43 * Revision 1.1 1994/08/16 16:26:49 adam
54 Dict dict_open (BFiles bfs, const char *name, int cache, int rw)
59 char resource_str[80];
62 dict = xmalloc (sizeof(*dict));
64 sprintf (resource_str, "dict.%s.pagesize", name);
66 dict->grep_cmap = NULL;
67 page_size = DICT_DEFAULT_PAGESIZE;
70 logf (LOG_WARN, "Resource %s was too small. Set to 2048",
74 dict->dbf = dict_bf_open (bfs, name, page_size, cache, rw);
79 logf (LOG_WARN, "Cannot open `%s'", name);
83 if (dict_bf_readp (dict->dbf, 0, &head_buf) <= 0)
86 { /* create header with information (page 0) */
87 dict_bf_newp (dict->dbf, 0, &head_buf);
88 dh = (struct Dict_head *) head_buf;
89 strcpy(dh->magic_str, DICT_MAGIC);
90 dh->free_list = dh->last = 1;
91 dh->page_size = page_size;
92 memcpy (&dict->head, dh, sizeof(*dh));
95 { /* no header present, i.e. no dictionary at all */
96 dict->head.free_list = dict->head.last = 0;
97 dict->head.page_size = page_size;
100 else /* header was there, check magic and page size */
102 dh = (struct Dict_head *) head_buf;
103 if (strcmp (dh->magic_str, DICT_MAGIC))
105 logf (LOG_WARN, "Bad magic of `%s'", name);
108 if (dh->page_size != page_size)
110 logf (LOG_WARN, "Resource %s is %d and pagesize of `%s' is %d",
111 resource_str, page_size, name, dh->page_size);
114 memcpy (&dict->head, dh, sizeof(*dh));
119 int dict_strcmp (const Dict_char *s1, const Dict_char *s2)
121 return strcmp ((const char *) s1, (const char *) s2);
124 int dict_strlen (const Dict_char *s)
126 return strlen((const char *) s);