chiark / gitweb /
Switch to GPL v3
[disorder] / lib / selection.c
index c69e83d2310ed1b48fb6e68fbb2db9416f70e035..caa0e3f09fca8b2a64f352c2159cfaa5ee5e9e15 100644 (file)
@@ -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 <http://www.gnu.org/licenses/>.
  */
 /** @file lib/selection.c
  * @brief Select management for Disobedience
  */
 
-#include <config.h>
-#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);