1 /* $Id: open.c,v 1.29 2007-01-15 15:10:15 adam Exp $
2 Copyright (C) 1995-2007
5 This file is part of the Zebra server.
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31 void dict_clean(Dict dict)
33 int page_size = dict->head.page_size;
35 int compact_flag = dict->head.compact_flag;
37 memset (dict->head.magic_str, 0, sizeof(dict->head.magic_str));
38 strcpy (dict->head.magic_str, DICT_MAGIC);
41 dict->head.freelist = 0;
42 dict->head.page_size = page_size;
43 dict->head.compact_flag = compact_flag;
45 /* create header with information (page 0) */
47 dict_bf_newp (dict->dbf, 0, &head_buf, page_size);
50 Dict dict_open (BFiles bfs, const char *name, int cache, int rw,
51 int compact_flag, int page_size)
56 dict = (Dict) xmalloc (sizeof(*dict));
61 dict->grep_cmap = NULL;
62 page_size = DICT_DEFAULT_PAGESIZE;
65 yaz_log (YLOG_WARN, "Page size for dict %s %d<2048. Set to 2048",
69 dict->dbf = dict_bf_open (bfs, name, page_size, cache, rw);
77 yaz_log (YLOG_WARN, "Cannot open `%s'", name);
81 if (dict_bf_readp (dict->dbf, 0, &head_buf) <= 0)
83 dict->head.page_size = page_size;
84 dict->head.compact_flag = compact_flag;
87 else /* header was there, check magic and page size */
89 memcpy (&dict->head, head_buf, sizeof(dict->head));
90 if (strcmp (dict->head.magic_str, DICT_MAGIC))
92 yaz_log (YLOG_WARN, "Bad magic of `%s'", name);
93 dict_bf_close(dict->dbf);
97 if (dict->head.page_size != page_size)
99 yaz_log (YLOG_WARN, "Page size for existing dict %s is %d. Current is %d",
100 name, dict->head.page_size, page_size);
103 if (dict->head.compact_flag)
104 dict_bf_compact(dict->dbf);
108 int dict_strcmp (const Dict_char *s1, const Dict_char *s2)
110 return strcmp ((const char *) s1, (const char *) s2);
113 int dict_strncmp (const Dict_char *s1, const Dict_char *s2, size_t n)
115 return strncmp ((const char *) s1, (const char *) s2, n);
118 int dict_strlen (const Dict_char *s)
120 return strlen((const char *) s);
123 zint dict_get_no_lookup(Dict dict)
125 return dict->no_lookup;
128 zint dict_get_no_insert(Dict dict)
130 return dict->no_insert;
133 zint dict_get_no_split(Dict dict)
135 return dict->no_split;
141 * indent-tabs-mode: nil
143 * vim: shiftwidth=4 tabstop=8 expandtab