X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/blobdiff_plain/65bb0fff13f2099c2746d6b8c9ad2421e9419d07..5d22a5aeb435e90f20e5f8fd77c2256fd21d5f92:/lib/selection.c diff --git a/lib/selection.c b/lib/selection.c index c69e83d..caa0e3f 100644 --- a/lib/selection.c +++ b/lib/selection.c @@ -2,27 +2,24 @@ * This file is part of DisOrder * Copyright (C) 2006, 2007 Richard Kettlewell * - * This program is free software; you can redistribute it and/or modify + * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA + * along with this program. If not, see . */ /** @file lib/selection.c * @brief Select management for Disobedience */ -#include -#include "types.h" +#include "common.h" #include "mem.h" #include "hash.h" @@ -44,9 +41,11 @@ hash *selection_new(void) { * are not marked as live. */ void selection_set(hash *h, const char *key, int selected) { - if(selected) - hash_add(h, key, xmalloc_noptr(sizeof (int)), HASH_INSERT_OR_REPLACE); - else + if(selected) { + int *const liveness = xmalloc_noptr(sizeof (int)); + *liveness = 0; + hash_add(h, key, liveness, HASH_INSERT_OR_REPLACE); + } else hash_remove(h, key); } @@ -96,7 +95,7 @@ static int selection_cleanup_callback(const char *key, /** @brief Delete all non-live keys from a selection * @param h Hash representing selection * - * See selection_live(). + * After cleanup, no keys are marked as live. */ void selection_cleanup(hash *h) { hash_foreach(h, selection_cleanup_callback, h);