2 * $Id: zoom-opt.c,v 1.5 2002-05-17 12:48:30 adam Exp $
4 * ZOOM layer for C, options handling
7 #include <yaz/xmalloc.h>
12 ZOOM_API(ZOOM_options)
13 ZOOM_options_create (void)
15 return ZOOM_options_create_with_parent (0);
18 ZOOM_API(ZOOM_options)
19 ZOOM_options_create_with_parent (ZOOM_options parent)
21 ZOOM_options opt = (ZOOM_options) xmalloc (sizeof(*opt));
24 opt->callback_func = 0;
25 opt->callback_handle = 0;
33 void ZOOM_options_addref (ZOOM_options opt)
38 ZOOM_API(ZOOM_options_callback)
39 ZOOM_options_set_callback (
41 ZOOM_options_callback callback_func,
42 void *callback_handle)
44 ZOOM_options_callback callback_old;
47 callback_old = opt->callback_func;
48 opt->callback_func = callback_func;
49 opt->callback_handle = callback_handle;
54 ZOOM_options_destroy (ZOOM_options opt)
59 if (opt->refcount == 0)
61 struct ZOOM_options_entry *e;
63 ZOOM_options_destroy (opt->parent);
67 struct ZOOM_options_entry *e0 = e;
78 ZOOM_options_set (ZOOM_options opt, const char *name, const char *value)
80 struct ZOOM_options_entry **e;
85 if (!strcmp((*e)->name, name))
88 (*e)->value = xstrdup(value);
93 *e = (struct ZOOM_options_entry *) xmalloc (sizeof(**e));
94 (*e)->name = xstrdup (name);
95 (*e)->value = xstrdup (value);
99 ZOOM_API(const char *)
100 ZOOM_options_get (ZOOM_options opt, const char *name)
105 if (opt->callback_func)
106 v = (*opt->callback_func)(opt->callback_handle, name);
109 struct ZOOM_options_entry *e;
110 for (e = opt->entries; e; e = e->next)
111 if (!strcmp(e->name, name))
118 return ZOOM_options_get(opt->parent, name);
123 ZOOM_options_get_bool (ZOOM_options opt, const char *name, int defa)
125 const char *v = ZOOM_options_get (opt, name);
129 if (!strcmp (v, "1") || !strcmp(v, "T"))
135 ZOOM_options_get_int (ZOOM_options opt, const char *name, int defa)
137 const char *v = ZOOM_options_get (opt, name);
145 ZOOM_options_set_int(ZOOM_options opt, const char *name, int value)
149 sprintf (s, "%d", value);
150 ZOOM_options_set (opt, name, s);