X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fzoom-opt.c;h=c8d70e5c7a7f75e19197a9f2d927882e21d01f7b;hp=631f467c1494f0eb094a8a487188c3c0bf34449f;hb=8a980f7051e22ca1e4fac0395ed7f8647cd9eda3;hpb=3ca2b225d05541f30950ed1d6a0da315d7832bed diff --git a/src/zoom-opt.c b/src/zoom-opt.c index 631f467..c8d70e5 100644 --- a/src/zoom-opt.c +++ b/src/zoom-opt.c @@ -1,8 +1,6 @@ -/* - * Copyright (C) 1995-2007, Index Data ApS +/* This file is part of the YAZ toolkit. + * Copyright (C) 1995-2009 Index Data * See the file LICENSE for details. - * - * $Id: zoom-opt.c,v 1.7 2007-05-04 17:16:21 adam Exp $ */ /** * \file zoom-opt.c @@ -13,6 +11,52 @@ #include +static void set_value(struct ZOOM_options_entry **e, + const char *value, int len) +{ + (*e)->value = 0; + (*e)->len = 0; + if (value) + { + (*e)->value = (char *) xmalloc(len+1); + memcpy((*e)->value, value, len); + (*e)->value[len] = '\0'; + (*e)->len = len; + } +} + +static void append_entry(struct ZOOM_options_entry **e, + const char *name, const char *value, int len) +{ + *e = (struct ZOOM_options_entry *) xmalloc(sizeof(**e)); + (*e)->name = xstrdup(name); + set_value(e, value, len); + (*e)->next = 0; +} + +ZOOM_API(ZOOM_options) + ZOOM_options_dup(ZOOM_options src) +{ + if (!src) + return 0; + else + { + ZOOM_options dst = ZOOM_options_create(); + struct ZOOM_options_entry *src_e = src->entries; + struct ZOOM_options_entry **dst_e = &dst->entries; + + while(src_e) + { + append_entry(dst_e, src_e->name, src_e->value, src_e->len); + dst_e = &(*dst_e)->next; + src_e = src_e->next; + } + dst->parent1 = ZOOM_options_dup(src->parent1); + dst->parent2 = ZOOM_options_dup(src->parent2); + return dst; + } +} + ZOOM_API(ZOOM_options) ZOOM_options_create_with_parent(ZOOM_options parent) { @@ -91,20 +135,6 @@ ZOOM_API(void) } } -/* PRIVATE to ZOOM_options_setl() */ -static void -_set_value(struct ZOOM_options_entry **e, const char *value, int len) -{ - (*e)->value = 0; - (*e)->len = 0; - if (value) - { - (*e)->value = (char *) xmalloc(len+1); - memcpy((*e)->value, value, len); - (*e)->value[len] = '\0'; - (*e)->len = len; - } -} ZOOM_API(void) ZOOM_options_setl(ZOOM_options opt, const char *name, const char *value, @@ -118,15 +148,12 @@ ZOOM_API(void) if (!strcmp((*e)->name, name)) { xfree((*e)->value); - _set_value(e, value, len); + set_value(e, value, len); return; } e = &(*e)->next; } - *e = (struct ZOOM_options_entry *) xmalloc(sizeof(**e)); - (*e)->name = xstrdup(name); - _set_value(e, value, len); - (*e)->next = 0; + append_entry(e, name, value, len); } ZOOM_API(void) @@ -142,7 +169,11 @@ ZOOM_API(const char *) if (!opt) return 0; if (opt->callback_func) + { v = (*opt->callback_func)(opt->callback_handle, name); + if (v) + *lenp = strlen(v); + } if (!v) { struct ZOOM_options_entry *e; @@ -201,6 +232,7 @@ ZOOM_options_set_int(ZOOM_options opt, const char *name, int value) /* * Local variables: * c-basic-offset: 4 + * c-file-style: "Stroustrup" * indent-tabs-mode: nil * End: * vim: shiftwidth=4 tabstop=8 expandtab