1 /* $Id: open.c,v 1.22 2004-12-08 12:23:08 adam Exp $
2 Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
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 Zebra; see the file LICENSE.zebra. If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
31 Dict dict_open (BFiles bfs, const char *name, int cache, int rw,
32 int compact_flag, int page_size)
37 dict = (Dict) xmalloc (sizeof(*dict));
42 dict->grep_cmap = NULL;
43 page_size = DICT_DEFAULT_PAGESIZE;
46 yaz_log (YLOG_WARN, "Page size for dict %s %d<2048. Set to 2048",
50 dict->dbf = dict_bf_open (bfs, name, page_size, cache, rw);
55 yaz_log (YLOG_WARN, "Cannot open `%s'", name);
59 if (dict_bf_readp (dict->dbf, 0, &head_buf) <= 0)
61 memset (dict->head.magic_str, 0, sizeof(dict->head.magic_str));
62 strcpy (dict->head.magic_str, DICT_MAGIC);
65 dict->head.freelist = 0;
66 dict->head.page_size = page_size;
67 dict->head.compact_flag = compact_flag;
69 /* create header with information (page 0) */
71 dict_bf_newp (dict->dbf, 0, &head_buf, page_size);
73 else /* header was there, check magic and page size */
75 memcpy (&dict->head, head_buf, sizeof(dict->head));
76 if (strcmp (dict->head.magic_str, DICT_MAGIC))
78 yaz_log (YLOG_WARN, "Bad magic of `%s'", name);
81 if (dict->head.page_size != page_size)
83 yaz_log (YLOG_WARN, "Page size for existing dict %s is %d. Current is %d",
84 name, dict->head.page_size, page_size);
87 if (dict->head.compact_flag)
88 dict_bf_compact(dict->dbf);
92 int dict_strcmp (const Dict_char *s1, const Dict_char *s2)
94 return strcmp ((const char *) s1, (const char *) s2);
97 int dict_strncmp (const Dict_char *s1, const Dict_char *s2, size_t n)
99 return strncmp ((const char *) s1, (const char *) s2, n);
102 int dict_strlen (const Dict_char *s)
104 return strlen((const char *) s);