2 * $Id: zoom-opt.c,v 1.4 2002-01-28 09:27:48 adam Exp $
4 * ZOOM layer for C, options handling
7 #include <yaz/xmalloc.h>
12 ZOOM_options ZOOM_options_create (void)
14 return ZOOM_options_create_with_parent (0);
17 ZOOM_options ZOOM_options_create_with_parent (ZOOM_options parent)
19 ZOOM_options opt = (ZOOM_options) xmalloc (sizeof(*opt));
22 opt->callback_func = 0;
23 opt->callback_handle = 0;
31 void ZOOM_options_addref (ZOOM_options opt)
36 ZOOM_options_callback ZOOM_options_set_callback (
38 ZOOM_options_callback callback_func,
39 void *callback_handle)
41 ZOOM_options_callback callback_old;
44 callback_old = opt->callback_func;
45 opt->callback_func = callback_func;
46 opt->callback_handle = callback_handle;
50 void ZOOM_options_destroy (ZOOM_options opt)
55 if (opt->refcount == 0)
57 struct ZOOM_options_entry *e;
59 ZOOM_options_destroy (opt->parent);
63 struct ZOOM_options_entry *e0 = e;
73 void ZOOM_options_set (ZOOM_options opt, const char *name, const char *value)
75 struct ZOOM_options_entry **e;
80 if (!strcmp((*e)->name, name))
83 (*e)->value = xstrdup(value);
88 *e = (struct ZOOM_options_entry *) xmalloc (sizeof(**e));
89 (*e)->name = xstrdup (name);
90 (*e)->value = xstrdup (value);
94 const char *ZOOM_options_get (ZOOM_options opt, const char *name)
99 if (opt->callback_func)
100 v = (*opt->callback_func)(opt->callback_handle, name);
103 struct ZOOM_options_entry *e;
104 for (e = opt->entries; e; e = e->next)
105 if (!strcmp(e->name, name))
112 return ZOOM_options_get(opt->parent, name);
116 int ZOOM_options_get_bool (ZOOM_options opt, const char *name, int defa)
118 const char *v = ZOOM_options_get (opt, name);
122 if (!strcmp (v, "1") || !strcmp(v, "T"))
127 int ZOOM_options_get_int (ZOOM_options opt, const char *name, int defa)
129 const char *v = ZOOM_options_get (opt, name);
136 void ZOOM_options_set_int(ZOOM_options opt, const char *name, int value)
140 sprintf (s, "%d", value);
141 ZOOM_options_set (opt, name, s);