=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/options.c,v retrieving revision 1.4 retrieving revision 1.5 diff -c -r1.4 -r1.5 *** src/usr.bin/tmux/options.c 2009/09/21 14:56:03 1.4 --- src/usr.bin/tmux/options.c 2009/09/22 12:38:10 1.5 *************** *** 1,4 **** ! /* $OpenBSD: options.c,v 1.4 2009/09/21 14:56:03 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: options.c,v 1.5 2009/09/22 12:38:10 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott *************** *** 54,59 **** --- 54,61 ---- xfree(o->name); if (o->type == OPTIONS_STRING) xfree(o->str); + else if (o->type == OPTIONS_DATA) + o->freefn(o->data); xfree(o); } } *************** *** 95,100 **** --- 97,104 ---- xfree(o->name); if (o->type == OPTIONS_STRING) xfree(o->str); + else if (o->type == OPTIONS_DATA) + o->freefn(o->data); xfree(o); } *************** *** 110,115 **** --- 114,121 ---- SPLAY_INSERT(options_tree, &oo->tree, o); } else if (o->type == OPTIONS_STRING) xfree(o->str); + else if (o->type == OPTIONS_DATA) + o->freefn(o->data); va_start(ap, fmt); o->type = OPTIONS_STRING; *************** *** 141,146 **** --- 147,154 ---- SPLAY_INSERT(options_tree, &oo->tree, o); } else if (o->type == OPTIONS_STRING) xfree(o->str); + else if (o->type == OPTIONS_DATA) + o->freefn(o->data); o->type = OPTIONS_NUMBER; o->num = value; *************** *** 157,160 **** --- 165,201 ---- if (o->type != OPTIONS_NUMBER) fatalx("option not a number"); return (o->num); + } + + struct options_entry * + options_set_data( + struct options *oo, const char *name, void *value, void (*freefn)(void *)) + { + struct options_entry *o; + + if ((o = options_find1(oo, name)) == NULL) { + o = xmalloc(sizeof *o); + o->name = xstrdup(name); + SPLAY_INSERT(options_tree, &oo->tree, o); + } else if (o->type == OPTIONS_STRING) + xfree(o->str); + else if (o->type == OPTIONS_DATA) + o->freefn(o->data); + + o->type = OPTIONS_DATA; + o->data = value; + o->freefn = freefn; + return (o); + } + + void * + options_get_data(struct options *oo, const char *name) + { + struct options_entry *o; + + if ((o = options_find(oo, name)) == NULL) + fatalx("missing option"); + if (o->type != OPTIONS_DATA) + fatalx("option not data"); + return (o->data); }