~vcs-imports/gmime/master

« back to all changes in this revision

Viewing changes to util/list.c

  • Committer: Jeffrey Stedfast
  • Author(s): Jeffrey Stedfast
  • Date: 2004-02-27 01:25:58 UTC
  • Revision ID: git-v1:2ca4d3eaca7cc0ce213eb8d6fe2ccb935872a007
Moved here from gmime/

2004-02-26  Jeffrey Stedfast  <fejj@ximian.com>

        * util/*.[c,h]: Moved here from gmime/

        * gmime/*.h: Fixed #includes

        * gmime/cache.[c,h]: Moved to util/

        * gmime/gtrie.[c,h]: Moved to util/

        * gmime/list.[c,h]: Moved to util/

        * gmime/md5-utils.[c,h]: Moved to util/

        * gmime/memchunk.[c,h]: Moved to util/

        * gmime/url-scanner.[c,h]: Moved to util/

        * gmime/gmime-parser.c: Don't use gobject macro casts.

        * gmime/gmime-filter-md5.c: Move the MD5Context into a private
        structure so that we don't need to install md5-utils.h

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 
2
/*
 
3
 *  Authors: Jeffrey Stedfast <fejj@ximian.com>
 
4
 *
 
5
 *  Copyright 2003-2004 Ximian, Inc. (www.ximian.com)
 
6
 *
 
7
 *  This program is free software; you can redistribute it and/or modify
 
8
 *  it under the terms of the GNU General Public License as published by
 
9
 *  the Free Software Foundation; either version 2 of the License, or
 
10
 *  (at your option) any later version.
 
11
 *
 
12
 *  This program is distributed in the hope that it will be useful,
 
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 *  GNU General Public License for more details.
 
16
 *
 
17
 *  You should have received a copy of the GNU General Public License
 
18
 *  along with this program; if not, write to the Free Software
 
19
 *  Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
 
20
 *
 
21
 */
 
22
 
 
23
 
 
24
#ifdef HAVE_CONFIG_H
 
25
#include <config.h>
 
26
#endif
 
27
 
 
28
#include "list.h"
 
29
 
 
30
void
 
31
list_init (List *list)
 
32
{
 
33
        list->head = (ListNode *) &list->tail;
 
34
        list->tail = NULL;
 
35
        list->tailpred = (ListNode *) &list->head;
 
36
}
 
37
 
 
38
int
 
39
list_is_empty (List *list)
 
40
{
 
41
        return list->head == (ListNode *) &list->tail;
 
42
}
 
43
 
 
44
int
 
45
list_length (List *list)
 
46
{
 
47
        ListNode *node;
 
48
        int n = 0;
 
49
        
 
50
        node = list->head;
 
51
        while (node->next) {
 
52
                node = node->next;
 
53
                n++;
 
54
        }
 
55
        
 
56
        return n;
 
57
}
 
58
 
 
59
ListNode *
 
60
list_unlink_head (List *list)
 
61
{
 
62
        ListNode *n, *nn;
 
63
        
 
64
        n = list->head;
 
65
        nn = n->next;
 
66
        if (nn) {
 
67
                nn->prev = n->prev;
 
68
                list->head = nn;
 
69
                return n;
 
70
        }
 
71
        
 
72
        return NULL;
 
73
}
 
74
 
 
75
ListNode *
 
76
list_unlink_tail (List *list)
 
77
{
 
78
        ListNode *n, *np;
 
79
        
 
80
        n = list->tailpred;
 
81
        np = n->prev;
 
82
        if (np) {
 
83
                np->next = n->next;
 
84
                list->tailpred = np;
 
85
                return n;
 
86
        }
 
87
        
 
88
        return NULL;
 
89
}
 
90
 
 
91
ListNode *
 
92
list_prepend_node (List *list, ListNode *node)
 
93
{
 
94
        node->next = list->head;
 
95
        node->prev = (ListNode *) &list->head;
 
96
        list->head->prev = node;
 
97
        list->head = node;
 
98
        
 
99
        return node;
 
100
}
 
101
 
 
102
ListNode *
 
103
list_append_node (List *list, ListNode *node)
 
104
{
 
105
        node->next = (ListNode *) &list->tail;
 
106
        node->prev = list->tailpred;
 
107
        list->tailpred->next = node;
 
108
        list->tailpred = node;
 
109
        
 
110
        return node;
 
111
}
 
112
 
 
113
ListNode *
 
114
list_node_unlink  (ListNode *node)
 
115
{
 
116
        node->next->prev = node->prev;
 
117
        node->prev->next = node->next;
 
118
        
 
119
        return node;
 
120
}