1 /* This file is part of the Zebra server.
2 Copyright (C) 1994-2010 Index Data
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 void dict_clean(Dict dict)
30 int page_size = dict->head.page_size;
32 int compact_flag = dict->head.compact_flag;
34 memset(dict->head.magic_str, 0, sizeof(dict->head.magic_str));
35 strcpy(dict->head.magic_str, DICT_MAGIC);
38 dict->head.freelist = 0;
39 dict->head.page_size = page_size;
40 dict->head.compact_flag = compact_flag;
42 /* create header with information (page 0) */
44 dict_bf_newp(dict->dbf, 0, &head_buf, page_size);
47 Dict dict_open(BFiles bfs, const char *name, int cache, int rw,
48 int compact_flag, int page_size)
53 dict = (Dict) xmalloc(sizeof(*dict));
58 dict->grep_cmap = NULL;
59 page_size = DICT_DEFAULT_PAGESIZE;
62 yaz_log(YLOG_WARN, "Page size for dict %s %d<2048. Set to 2048",
66 dict->dbf = dict_bf_open(bfs, name, page_size, cache, rw);
74 yaz_log(YLOG_WARN, "Cannot open `%s'", name);
78 if (dict_bf_readp(dict->dbf, 0, &head_buf) <= 0)
80 dict->head.page_size = page_size;
81 dict->head.compact_flag = compact_flag;
84 else /* header was there, check magic and page size */
86 memcpy(&dict->head, head_buf, sizeof(dict->head));
87 if (strcmp(dict->head.magic_str, DICT_MAGIC))
89 yaz_log(YLOG_WARN, "Bad magic of `%s'", name);
90 dict_bf_close(dict->dbf);
94 if (dict->head.page_size != page_size)
96 yaz_log(YLOG_WARN, "Page size for existing dict %s is %d. Current is %d",
97 name, dict->head.page_size, page_size);
100 if (dict->head.compact_flag)
101 dict_bf_compact(dict->dbf);
105 int dict_strcmp(const Dict_char *s1, const Dict_char *s2)
107 return strcmp((const char *) s1, (const char *) s2);
110 int dict_strncmp(const Dict_char *s1, const Dict_char *s2, size_t n)
112 return strncmp((const char *) s1, (const char *) s2, n);
115 int dict_strlen(const Dict_char *s)
117 return strlen((const char *) s);
120 zint dict_get_no_lookup(Dict dict)
122 return dict->no_lookup;
125 zint dict_get_no_insert(Dict dict)
127 return dict->no_insert;
130 zint dict_get_no_split(Dict dict)
132 return dict->no_split;
138 * c-file-style: "Stroustrup"
139 * indent-tabs-mode: nil
141 * vim: shiftwidth=4 tabstop=8 expandtab