2 * $Id: zoom-opt.c,v 1.1 2001-10-23 21:00:20 adam Exp $
4 * ZOOM layer for C, options handling
7 #include <yaz/xmalloc.h>
12 Z3950_options Z3950_options_create (void)
14 return Z3950_options_create_with_parent (0);
17 Z3950_options Z3950_options_create_with_parent (Z3950_options parent)
19 Z3950_options opt = xmalloc (sizeof(*opt));
22 opt->callback_func = 0;
23 opt->callback_handle = 0;
31 void Z3950_options_addref (Z3950_options opt)
36 Z3950_options_callback Z3950_options_set_callback (
38 Z3950_options_callback callback_func,
39 void *callback_handle)
41 Z3950_options_callback callback_old;
44 callback_old = opt->callback_func;
45 opt->callback_func = callback_func;
46 opt->callback_handle = callback_handle;
50 void Z3950_options_destroy (Z3950_options opt)
55 if (opt->refcount == 0)
57 struct Z3950_options_entry *e;
59 Z3950_options_destroy (opt->parent);
63 struct Z3950_options_entry *e0 = e;
73 void Z3950_options_set (Z3950_options opt, const char *name, const char *value)
75 struct Z3950_options_entry **e;
80 if (!strcmp((*e)->name, name))
83 (*e)->value = xstrdup(value);
88 *e = xmalloc (sizeof(**e));
89 (*e)->name = xstrdup (name);
90 (*e)->value = xstrdup (value);
94 const char *Z3950_options_get (Z3950_options opt, const char *name)
99 if (opt->callback_func)
100 v = (*opt->callback_func)(opt->callback_handle, name);
103 struct Z3950_options_entry *e;
104 for (e = opt->entries; e; e = e->next)
105 if (!strcmp(e->name, name))
112 return Z3950_options_get(opt->parent, name);
116 int Z3950_options_get_bool (Z3950_options opt, const char *name, int defa)
118 const char *v = Z3950_options_get (opt, name);
122 if (!strcmp (v, "1") || !strcmp(v, "T"))
127 int Z3950_options_get_int (Z3950_options opt, const char *name, int defa)
129 const char *v = Z3950_options_get (opt, name);