File: SysLists.h

package info (click to toggle)
xmail 1.22-5
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,840 kB
  • ctags: 3,857
  • sloc: cpp: 33,585; sh: 625; makefile: 102; perl: 56; sql: 31
file content (105 lines) | stat: -rw-r--r-- 3,274 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
 *  XMail by Davide Libenzi ( Intranet and Internet mail server )
 *  Copyright (C) 1999,..,2004  Davide Libenzi
 *
 *  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
 *  (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.
 *
 *  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
 *
 *  Davide Libenzi <davidel@xmailserver.org>
 *
 */

#ifndef _SYSLISTS_H
#define _SYSLISTS_H

#define SYS_LIST_HEAD_INIT(name)        { &(name), &(name) }

#define SYS_LIST_HEAD(name)             struct SysListHead name = SYS_LIST_HEAD_INIT(name)

#define SYS_INIT_LIST_HEAD(ptr) \
do { \
    (ptr)->pNext = (ptr); (ptr)->pPrev = (ptr); \
} while (0)

#define SYS_INIT_LIST_LINK(ptr) \
do { \
    (ptr)->pNext = NULL; (ptr)->pPrev = NULL; \
} while (0)

#define SYS_LIST_ADD(new, prev, next) \
do { \
    struct SysListHead *    pPrev = prev; \
    struct SysListHead *    pNext = next; \
    pNext->pPrev = new; \
	(new)->pNext = pNext; \
	(new)->pPrev = pPrev; \
	pPrev->pNext = new; \
} while (0)

#define SYS_LIST_ADDH(new, head)        SYS_LIST_ADD(new, head, (head)->pNext)

#define SYS_LIST_ADDT(new, head)        SYS_LIST_ADD(new, (head)->pPrev, head)

#define SYS_LIST_UNLINK(prev, next) \
do { \
    (next)->pPrev = prev; \
    (prev)->pNext = next; \
} while (0)

#define SYS_LIST_DEL(entry) \
do { \
    SYS_LIST_UNLINK((entry)->pPrev, (entry)->pNext); \
    (entry)->pPrev = NULL; \
    (entry)->pNext = NULL; \
} while (0)

#define SYS_LIST_EMTPY(head)            ((head)->pNext == head)

#define SYS_LIST_SPLICE(list, head) \
do { \
    struct SysListHead *    first = (list)->pNext; \
    if (first != list) { \
        struct SysListHead *    last = (list)->pPrev; \
        struct SysListHead *    at = (head)->pNext; \
        (first)->pPrev = head; \
        (head)->pNext = first; \
        (last)->pNext = at; \
        (at)->pPrev = last; \
    } \
} while (0)

#define SYS_LIST_ENTRY(ptr, type, member)   ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))

#define SYS_LIST_FOR_EACH(pos, head)        for (pos = (head)->pNext; pos != (head); pos = (pos)->pNext)

#define SYS_LIST_FIRST(head)                (((head)->pNext != (head)) ? (head)->pNext: NULL)

#define SYS_LIST_LAST(head)                 (((head)->pPrev != (head)) ? (head)->pPrev: NULL)

#define SYS_LIST_LINKED(ptr)                (((ptr)->pPrev != NULL) && ((ptr)->pNext != NULL))

#define SYS_COPY_HEAD(dsth, srch) \
do { \
    (dsth)->pPrev = (srch)->pPrev; \
    (dsth)->pNext = (srch)->pNext; \
    if ((srch)->pNext != NULL) (srch)->pNext->pPrev = dsth; \
    if ((srch)->pPrev != NULL) (srch)->pPrev->pNext = dsth; \
} while (0)

struct SysListHead {
	struct SysListHead *pNext;
	struct SysListHead *pPrev;
};

#endif