X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=zoom%2Fzoom-opt.c;h=19d1e49bb370879882ed669c3630f73d536a3647;hp=a7efdc76684e21823b88d16a42d573ba2c5a905e;hb=a0ff2572c63e4be9254b12d08b0166b6232477de;hpb=cd8a27308e5bb886f561b517d091437c7afbf53c diff --git a/zoom/zoom-opt.c b/zoom/zoom-opt.c index a7efdc7..19d1e49 100644 --- a/zoom/zoom-opt.c +++ b/zoom/zoom-opt.c @@ -1,5 +1,5 @@ /* - * $Id: zoom-opt.c,v 1.3 2002-01-03 12:18:38 adam Exp $ + * $Id: zoom-opt.c,v 1.7 2002-06-04 08:33:49 adam Exp $ * * ZOOM layer for C, options handling */ @@ -9,31 +9,45 @@ #include "zoom-p.h" -ZOOM_options ZOOM_options_create (void) +ZOOM_API(ZOOM_options) +ZOOM_options_create_with_parent (ZOOM_options parent) +{ + return ZOOM_options_create_with_parent2(parent, 0); +} + +ZOOM_API(ZOOM_options) +ZOOM_options_create (void) { return ZOOM_options_create_with_parent (0); } -ZOOM_options ZOOM_options_create_with_parent (ZOOM_options parent) + +ZOOM_API(ZOOM_options) +ZOOM_options_create_with_parent2 (ZOOM_options parent1, ZOOM_options parent2) { - ZOOM_options opt = xmalloc (sizeof(*opt)); + ZOOM_options opt = (ZOOM_options) xmalloc (sizeof(*opt)); opt->refcount = 1; opt->callback_func = 0; opt->callback_handle = 0; opt->entries = 0; - opt->parent= parent; - if (parent) - (parent->refcount)++; + opt->parent1= parent1; + if (parent1) + (parent1->refcount)++; + opt->parent2= parent2; + if (parent2) + (parent2->refcount)++; return opt; } + void ZOOM_options_addref (ZOOM_options opt) { (opt->refcount)++; } -ZOOM_options_callback ZOOM_options_set_callback ( +ZOOM_API(ZOOM_options_callback) +ZOOM_options_set_callback ( ZOOM_options opt, ZOOM_options_callback callback_func, void *callback_handle) @@ -47,7 +61,8 @@ ZOOM_options_callback ZOOM_options_set_callback ( return callback_old; } -void ZOOM_options_destroy (ZOOM_options opt) +ZOOM_API(void) +ZOOM_options_destroy (ZOOM_options opt) { if (!opt) return; @@ -56,7 +71,8 @@ void ZOOM_options_destroy (ZOOM_options opt) { struct ZOOM_options_entry *e; - ZOOM_options_destroy (opt->parent); + ZOOM_options_destroy (opt->parent1); + ZOOM_options_destroy (opt->parent2); e = opt->entries; while (e) { @@ -70,7 +86,9 @@ void ZOOM_options_destroy (ZOOM_options opt) } } -void ZOOM_options_set (ZOOM_options opt, const char *name, const char *value) +ZOOM_API(void) +ZOOM_options_setl (ZOOM_options opt, const char *name, const char *value, + int len) { struct ZOOM_options_entry **e; @@ -80,18 +98,37 @@ void ZOOM_options_set (ZOOM_options opt, const char *name, const char *value) if (!strcmp((*e)->name, name)) { xfree ((*e)->value); - (*e)->value = xstrdup(value); + (*e)->value = 0; + if (value) + { + (*e)->value = xmalloc (len+1); + memcpy ((*e)->value, value, len); + (*e)->value[len] = '\0'; + } return; } e = &(*e)->next; } - *e = xmalloc (sizeof(**e)); + *e = (struct ZOOM_options_entry *) xmalloc (sizeof(**e)); (*e)->name = xstrdup (name); - (*e)->value = xstrdup (value); + (*e)->value = 0; + if (value) + { + (*e)->value = xmalloc (len+1); + memcpy ((*e)->value, value, len); + (*e)->value[len] = '\0'; + } (*e)->next = 0; } -const char *ZOOM_options_get (ZOOM_options opt, const char *name) +ZOOM_API(void) +ZOOM_options_set (ZOOM_options opt, const char *name, const char *value) +{ + ZOOM_options_setl (opt, name, value, value ? strlen(value): 0); +} + +ZOOM_API(const char *) +ZOOM_options_get (ZOOM_options opt, const char *name) { const char *v = 0; if (!opt) @@ -109,11 +146,14 @@ const char *ZOOM_options_get (ZOOM_options opt, const char *name) } } if (!v) - return ZOOM_options_get(opt->parent, name); + v = ZOOM_options_get(opt->parent1, name); + if (!v) + v = ZOOM_options_get(opt->parent2, name); return v; } -int ZOOM_options_get_bool (ZOOM_options opt, const char *name, int defa) +ZOOM_API(int) +ZOOM_options_get_bool (ZOOM_options opt, const char *name, int defa) { const char *v = ZOOM_options_get (opt, name); @@ -124,7 +164,8 @@ int ZOOM_options_get_bool (ZOOM_options opt, const char *name, int defa) return 0; } -int ZOOM_options_get_int (ZOOM_options opt, const char *name, int defa) +ZOOM_API(int) +ZOOM_options_get_int (ZOOM_options opt, const char *name, int defa) { const char *v = ZOOM_options_get (opt, name); @@ -133,7 +174,8 @@ int ZOOM_options_get_int (ZOOM_options opt, const char *name, int defa) return atoi(v); } -void ZOOM_options_set_int(ZOOM_options opt, const char *name, int value) +ZOOM_API(void) +ZOOM_options_set_int(ZOOM_options opt, const char *name, int value) { char s[40];