Stupid syntax error. ENGINE-463
authorKrista Bennett <krista@pep-project.org>
Tue, 02 Oct 2018 13:22:12 +0200
branchENGINE-463
changeset 29644f22b5bc7b9a
parent 2963 a80bc5f9167e
child 2965 a15e73c2a4e8
Stupid syntax error.
src/labeled_int_list.c
src/labeled_int_list.h
src/stringlist.c
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/labeled_int_list.c	Tue Oct 02 13:22:12 2018 +0200
     1.3 @@ -0,0 +1,121 @@
     1.4 +// This file is under GNU General Public License 3.0
     1.5 +// see LICENSE.txt
     1.6 +
     1.7 +#include <stdbool.h>
     1.8 +#include <stdlib.h>
     1.9 +#include <assert.h>
    1.10 +#include <string.h>
    1.11 +
    1.12 +#include "platform.h"
    1.13 +#include "labeled_int_list.h"
    1.14 +
    1.15 +labeled_int_list_t *new_labeled_int_list(int value, const char* label)
    1.16 +{
    1.17 +    assert(label);
    1.18 +    if (!label)
    1.19 +        return NULL;
    1.20 +        
    1.21 +    labeled_int_list_t * labeled_int_list = calloc(1, sizeof(labeled_int_list_t));
    1.22 +    assert(labeled_int_list);
    1.23 +    if (labeled_int_list == NULL)
    1.24 +        return NULL;
    1.25 +
    1.26 +    labeled_int_list->value = value;
    1.27 +    labeled_int_list->label = strdup(label);
    1.28 +    if (!labeled_int_list->label) {
    1.29 +        free(labeled_int_list);
    1.30 +        labeled_int_list = NULL;
    1.31 +    }
    1.32 +    return labeled_int_list;
    1.33 +}
    1.34 +
    1.35 +void free_labeled_int_list(labeled_int_list_t *labeled_int_list)
    1.36 +{
    1.37 +    labeled_int_list_t *curr = labeled_int_list;
    1.38 +
    1.39 +    while (curr) {
    1.40 +        labeled_int_list_t *next = curr->next;
    1.41 +        free(curr->label);
    1.42 +        free(curr);
    1.43 +        curr = next;
    1.44 +    }
    1.45 +}
    1.46 +
    1.47 +labeled_int_list_t *labeled_int_list_dup(const labeled_int_list_t *src)
    1.48 +{
    1.49 +    assert(src);
    1.50 +    if (src == NULL)
    1.51 +        return NULL;
    1.52 +    
    1.53 +    labeled_int_list_t *labeled_int_list = NULL;
    1.54 +
    1.55 +    labeled_int_list = new_labeled_int_list(src->value, src->label);
    1.56 +    if (labeled_int_list == NULL)
    1.57 +        goto enomem;
    1.58 +
    1.59 +    labeled_int_list_t* src_curr = src->next;
    1.60 +    labeled_int_list_t** dst_curr_ptr = &labeled_int_list->next;
    1.61 +
    1.62 +    // list
    1.63 +    while (src_curr) {
    1.64 +        *dst_curr_ptr = new_labeled_int_list(src_curr->value, src_curr->label);
    1.65 +        if (*dst_curr_ptr == NULL)
    1.66 +            goto enomem;
    1.67 +
    1.68 +        src_curr = src_curr->next;
    1.69 +        dst_curr_ptr = &((*dst_curr_ptr)->next);
    1.70 +    }
    1.71 +
    1.72 +    return labeled_int_list;
    1.73 +
    1.74 +enomem:
    1.75 +    free_labeled_int_list(labeled_int_list);
    1.76 +    return NULL;
    1.77 +}
    1.78 +
    1.79 +labeled_int_list_t *labeled_int_list_add(labeled_int_list_t *labeled_int_list, int value, const char* label)
    1.80 +{
    1.81 +    if (!label)
    1.82 +        return NULL;
    1.83 +        
    1.84 +    if (!labeled_int_list)
    1.85 +        return new_labeled_int_list(value, label);
    1.86 +
    1.87 +    if (!labeled_int_list->label) { // empty list
    1.88 +        assert(!labeled_int_list->next);
    1.89 +        if (labeled_int_list->next)
    1.90 +            return NULL; // invalid list
    1.91 +
    1.92 +        labeled_int_list->value = value;
    1.93 +        labeled_int_list->label = strdup(label);
    1.94 +        if (!labeled_int_list->label) {
    1.95 +            free(labeled_int_list);
    1.96 +            labeled_int_list = NULL;
    1.97 +        }
    1.98 +
    1.99 +        return labeled_int_list;
   1.100 +    }
   1.101 +
   1.102 +    labeled_int_list_t* list_curr = labeled_int_list;
   1.103 +
   1.104 +    while (list_curr->next)
   1.105 +        list_curr = list_curr->next;
   1.106 +
   1.107 +    list_curr->next = new_labeled_int_list(value, label);
   1.108 +
   1.109 +    assert(list_curr->next);
   1.110 +    if (!list_curr->next)
   1.111 +        return NULL;
   1.112 +
   1.113 +    return list_curr->next;
   1.114 +}
   1.115 +
   1.116 +int labeled_int_list_length(const labeled_int_list_t *labeled_int_list)
   1.117 +{
   1.118 +    int len = 0;
   1.119 +
   1.120 +    for (const labeled_int_list_t *_li = labeled_int_list; _li && _li->label; _li = _li->next)
   1.121 +        len++;
   1.122 +
   1.123 +    return len;
   1.124 +}
   1.125 \ No newline at end of file
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/labeled_int_list.h	Tue Oct 02 13:22:12 2018 +0200
     2.3 @@ -0,0 +1,31 @@
     2.4 +// This file is under GNU General Public License 3.0
     2.5 +// see LICENSE.txt
     2.6 +
     2.7 +#pragma once
     2.8 +
     2.9 +#include "dynamic_api.h"
    2.10 +#include "stringpair.h"
    2.11 +
    2.12 +#ifdef __cplusplus
    2.13 +extern "C" {
    2.14 +#endif
    2.15 +
    2.16 +typedef struct _labeled_int_list_t {
    2.17 +    int value;
    2.18 +    char* label;                                // UTF-8 string, null-terminated
    2.19 +    struct _labeled_int_list_t *next;           // this is a single linked list
    2.20 +} labeled_int_list_t;
    2.21 +
    2.22 +labeled_int_list_t *new_labeled_int_list(int value, const char* label);
    2.23 +
    2.24 +void free_labeled_int_list(labeled_int_list_t *labeled_int_list);
    2.25 +
    2.26 +labeled_int_list_t *labeled_int_list_dup(const labeled_int_list_t *src);
    2.27 +
    2.28 +labeled_int_list_t *labeled_int_list_add(labeled_int_list_t *labeled_int_list, int value, const char* label);
    2.29 +
    2.30 +int labeled_int_list_length(const labeled_int_list_t *labeled_int_list);
    2.31 +
    2.32 +#ifdef __cplusplus
    2.33 +}
    2.34 +#endif
     3.1 --- a/src/stringlist.c	Tue Oct 02 13:16:19 2018 +0200
     3.2 +++ b/src/stringlist.c	Tue Oct 02 13:22:12 2018 +0200
     3.3 @@ -118,7 +118,7 @@
     3.4          return NULL;
     3.5      stringlist_t* retval = head;
     3.6      for (; retval ; retval = retval->next) {
     3.7 -        if (strcmp(retval->value, value) == 0))
     3.8 +        if (strcmp(retval->value, value) == 0)
     3.9              break;
    3.10      }
    3.11      return retval;