spdx tags for c and h files
[protos/libecoli.git] / lib / ecoli_completed.c
index 0159797..a342105 100644 (file)
@@ -1,28 +1,5 @@
-/*
+/* SPDX-License-Identifier: BSD-3-Clause
  * Copyright (c) 2016, Olivier MATZ <zer0@droids-corp.org>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- *     * Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright
- *       notice, this list of conditions and the following disclaimer in the
- *       documentation and/or other materials provided with the distribution.
- *     * Neither the name of the University of California, Berkeley nor the
- *       names of its contributors may be used to endorse or promote products
- *       derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #include <stdio.h>
@@ -260,7 +237,7 @@ ec_completed_item(const struct ec_node *node, enum ec_completed_type type,
        return item;
 
 fail:
-       ec_keyval_free(item->attrs);
+       ec_keyval_free(attrs);
        ec_free(comp_cp);
        ec_free(start_cp);
        ec_free(full_cp);
@@ -355,10 +332,13 @@ ec_completed_item_add(struct ec_completed *completed,
 
        switch (item->type) {
        case EC_COMP_UNKNOWN:
+               completed->count_unknown++;
                break;
        case EC_COMP_FULL:
+               completed->count_full++;
+               break;
        case EC_COMP_PARTIAL:
-               completed->count_match++; //XXX
+               completed->count_partial++;
                break;
        default:
                return -EINVAL;
@@ -521,8 +501,9 @@ void ec_completed_dump(FILE *out, const struct ec_completed *completed)
                return;
        }
 
-       fprintf(out, "completion: count=%u match=%u\n",
-               completed->count, completed->count_match);
+       fprintf(out, "completion: count=%u full=%u partial=%u unknown=%u\n",
+               completed->count, completed->count_full,
+               completed->count_partial,  completed->count_unknown);
 
        TAILQ_FOREACH(grp, &completed->groups, next) {
                fprintf(out, "node=%p, node_type=%s\n",
@@ -555,7 +536,9 @@ int ec_completed_merge(struct ec_completed *to,
                TAILQ_INSERT_TAIL(&to->groups, grp, next);
        }
        to->count += from->count;
-       to->count_match += from->count_match;
+       to->count_full += from->count_full;
+       to->count_partial += from->count_partial;
+       to->count_unknown += from->count_unknown;
 
        ec_completed_free(from);
        return 0;
@@ -571,9 +554,11 @@ unsigned int ec_completed_count(
                return count;
 
        if (type & EC_COMP_FULL)
-               count += completed->count_match;
+               count += completed->count_full;
+       if (type & EC_COMP_PARTIAL)
+               count += completed->count_partial;
        if (type & EC_COMP_UNKNOWN)
-               count += (completed->count - completed->count_match); //XXX
+               count += completed->count_unknown;
 
        return count;
 }
@@ -599,10 +584,13 @@ ec_completed_iter(struct ec_completed *completed,
 struct ec_completed_item *ec_completed_iter_next(
        struct ec_completed_iter *iter)
 {
-       struct ec_completed *completed = iter->completed;
+       struct ec_completed *completed;
        struct ec_completed_group *cur_node;
        struct ec_completed_item *cur_match;
 
+       if (iter == NULL)
+               return NULL;
+       completed = iter->completed;
        if (completed == NULL)
                return NULL;