~ubuntu-branches/ubuntu/wily/octave-ltfat/wily-proposed

« back to all changes in this revision

Viewing changes to src/utils/list.c

  • Committer: Package Import Robot
  • Author(s): Sébastien Villemot, Rafael Laboissiere
  • Date: 2015-07-18 23:36:41 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20150718233641-jhuf3f551a3523qc
Tags: 2.1.0+dfsg-1
* Team upload.

[ Rafael Laboissiere ]
* Imported Upstream version 2.1.0+dfsg
* d/rules: Prevent unit testing on armhf and mips.
  This avoids FTBFS on theses architectures (see Bug#765545).
* Unit testing does not need X-window anymore
  + d/rules: Do not use xfvb-run to run the tests.
  + d/control: Drop xauth, xvfb, and gnuplot-nox from Build-Depends.
    Also, the versioned dependency on octave-pkg-dev is relaxed.
* Drop .jar file from upstream tarball, complying with the Debian Policy
  + d/copyright: Exclude file blockproc.jar
  + d/rules: Add get-orig-source target
  + d/watch: Mangle upstream version to cope with "+dfsg" tag
* Build blockproc.jar, which is deleted from the upstream tarball
  + d/rules: Add commands for building blockproc.jar
  + d/control: Build-depend on default-jdk
  + d/p/fix-path-of-included-makefile.patch: New patch
* Bump Standard-Versions to 3.9.6 (no changes needed)
* d/p/autoload-yes.patch: Remove patch (deprecated upstream)
* Bump Build-Depends on octave to >> 4.0.0~rc4-1 (for sndfile support)
* d/check.m: Avoid verbose output of unit tests
* d/watch: Add the repacksuffix option
* d/p/add-hardening-flags.patch: Drop patch (applied upstream)
* d/p/fix-path-of-included-makefile.patch: Drop patch (applied upstream)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "lcthw_List.h"
 
2
#include "dbg.h"
 
3
 
 
4
List *List_create()
 
5
{
 
6
    return calloc(1, sizeof(List));
 
7
}
 
8
 
 
9
void List_destroy(List *list)
 
10
{
 
11
    LIST_FOREACH(list, first, next, cur) {
 
12
        if(cur->prev) {
 
13
            free(cur->prev);
 
14
        }
 
15
    }
 
16
 
 
17
    free(list->last);
 
18
    free(list);
 
19
}
 
20
 
 
21
 
 
22
void List_clear(List *list)
 
23
{
 
24
    LIST_FOREACH(list, first, next, cur) {
 
25
        free(cur->value);
 
26
    }
 
27
}
 
28
 
 
29
 
 
30
void List_clear_destroy(List *list)
 
31
{
 
32
    List_clear(list);
 
33
    List_destroy(list);
 
34
}
 
35
 
 
36
 
 
37
void List_push(List *list, void *value)
 
38
{
 
39
    ListNode *node = calloc(1, sizeof(ListNode));
 
40
    check_mem(node);
 
41
 
 
42
    node->value = value;
 
43
 
 
44
    if(list->last == NULL) {
 
45
        list->first = node;
 
46
        list->last = node;
 
47
    } else {
 
48
        list->last->next = node;
 
49
        node->prev = list->last;
 
50
        list->last = node;
 
51
    }
 
52
 
 
53
    list->count++;
 
54
 
 
55
error:
 
56
    return;
 
57
}
 
58
 
 
59
void *List_pop(List *list)
 
60
{
 
61
    ListNode *node = list->last;
 
62
    return node != NULL ? List_remove(list, node) : NULL;
 
63
}
 
64
 
 
65
void List_unshift(List *list, void *value)
 
66
{
 
67
    ListNode *node = calloc(1, sizeof(ListNode));
 
68
    check_mem(node);
 
69
 
 
70
    node->value = value;
 
71
 
 
72
    if(list->first == NULL) {
 
73
        list->first = node;
 
74
        list->last = node;
 
75
    } else {
 
76
        node->next = list->first;
 
77
        list->first->prev = node;
 
78
        list->first = node;
 
79
    }
 
80
 
 
81
    list->count++;
 
82
 
 
83
error:
 
84
    return;
 
85
}
 
86
 
 
87
void *List_shift(List *list)
 
88
{
 
89
    ListNode *node = list->first;
 
90
    return node != NULL ? List_remove(list, node) : NULL;
 
91
}
 
92
 
 
93
void *List_remove(List *list, ListNode *node)
 
94
{
 
95
    void *result = NULL;
 
96
 
 
97
    check(list->first && list->last, "List is empty.");
 
98
    check(node, "node can't be NULL");
 
99
 
 
100
    if(node == list->first && node == list->last) {
 
101
        list->first = NULL;
 
102
        list->last = NULL;
 
103
    } else if(node == list->first) {
 
104
        list->first = node->next;
 
105
        check(list->first != NULL, "Invalid list, somehow got a first that is NULL.");
 
106
        list->first->prev = NULL;
 
107
    } else if (node == list->last) {
 
108
        list->last = node->prev;
 
109
        check(list->last != NULL, "Invalid list, somehow got a next that is NULL.");
 
110
        list->last->next = NULL;
 
111
    } else {
 
112
        ListNode *after = node->next;
 
113
        ListNode *before = node->prev;
 
114
        after->prev = before;
 
115
        before->next = after;
 
116
    }
 
117
 
 
118
    list->count--;
 
119
    result = node->value;
 
120
    free(node);
 
121
 
 
122
error:
 
123
    return result;
 
124
}