1 /* This file is part of the Zebra server.
2 Copyright (C) 2004-2013 Index Data
3
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
7 version.
8
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
12 for more details.
13
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
17
18 */
19
20 #if HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23 #include <assert.h>
24 #include <yaz/wrbuf.h>
25 #include "index.h"
26
zebra_mk_ord_str(int ord,const char * str)27 WRBUF zebra_mk_ord_str(int ord, const char *str)
28 {
29 char pref[20];
30 WRBUF w = wrbuf_alloc();
31 int len;
32
33 assert(ord >= 0);
34
35 len = key_SU_encode(ord, pref);
36
37 wrbuf_write(w, pref, len);
38 wrbuf_puts(w, str);
39 return w;
40 }
41
dict_lookup_ord(Dict d,int ord,const char * str)42 char *dict_lookup_ord(Dict d, int ord, const char *str)
43 {
44 WRBUF w = zebra_mk_ord_str(ord, str);
45 char *rinfo = dict_lookup(d, wrbuf_cstr(w));
46 wrbuf_destroy(w);
47 return rinfo;
48 }
49
dict_insert_ord(Dict d,int ord,const char * p,int userlen,void * userinfo)50 int dict_insert_ord(Dict d, int ord, const char *p,
51 int userlen, void *userinfo)
52 {
53 WRBUF w = zebra_mk_ord_str(ord, p);
54 int r = dict_insert(d, wrbuf_cstr(w), userlen, userinfo);
55 wrbuf_destroy(w);
56 return r;
57 }
58
dict_delete_ord(Dict d,int ord,const char * p)59 int dict_delete_ord(Dict d, int ord, const char *p)
60 {
61 WRBUF w = zebra_mk_ord_str(ord, p);
62 int r = dict_delete(d, wrbuf_cstr(w));
63 wrbuf_destroy(w);
64 return r;
65 }
66
dict_delete_subtree_ord(Dict d,int ord,void * client,int (* f)(const char * info,void * client))67 int dict_delete_subtree_ord(Dict d, int ord, void *client,
68 int (*f)(const char *info, void *client))
69 {
70 WRBUF w = zebra_mk_ord_str(ord, "");
71 int r = dict_delete_subtree(d, wrbuf_cstr(w), client, f);
72 wrbuf_destroy(w);
73 return r;
74 }
75 /*
76 * Local variables:
77 * c-basic-offset: 4
78 * c-file-style: "Stroustrup"
79 * indent-tabs-mode: nil
80 * End:
81 * vim: shiftwidth=4 tabstop=8 expandtab
82 */
83
84