*** /dev/null Sat Nov 23 01:34:52 2024
--- - Sat Nov 23 01:35:13 2024
***************
*** 0 ****
--- 1,160 ----
+ /*
+ ** OSSP al -- Assembly Line
+ ** Copyright (c) 2002 The OSSP Project <http://www.ossp.org/>
+ ** Copyright (c) 2002 Cable & Wireless Deutschland <http://www.cw.com/de/>
+ ** Copyright (c) 2002 Ralf S. Engelschall <rse@engelschall.com>
+ ** Copyright (c) 2002 Michael van Elst <mlelstv@dev.de.cw.net>
+ **
+ ** This file is part of OSSP al, an abstract datatype of a data buffer
+ ** that can assemble, move and truncate data but avoids actual copying.
+ **
+ ** Permission to use, copy, modify, and distribute this software for
+ ** any purpose with or without fee is hereby granted, provided that
+ ** the above copyright notice and this permission notice appear in all
+ ** copies.
+ **
+ ** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 AUTHORS AND COPYRIGHT HOLDERS AND THEIR
+ ** 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.
+ **
+ ** list.h: generic double-linked list macros
+ */
+
+ #define LIST(elem) \
+ struct { elem *head, *tail; }
+ #define NODE(elem) \
+ struct { elem *next, *prev; }
+
+ #define HEAD(q,l) ((q)->l.head)
+ #define TAIL(q,l) ((q)->l.tail)
+ #define NEXT(n,l) ((n)->l.next)
+ #define PREV(n,l) ((n)->l.prev)
+
+ #define ISEMPTY(q,l) (HEAD(q,l) == NULL)
+
+ #define LISTINIT(q,l) \
+ do { \
+ HEAD(q,l) = NULL; \
+ TAIL(q,l) = NULL; \
+ } while(0)
+
+ #define NODEINIT(n,l) \
+ do { \
+ NEXT(n,l) = NULL; \
+ PREV(n,l) = NULL; \
+ } while(0)
+
+ #define ADDTAIL(q,l,n) \
+ do { \
+ if (TAIL(q,l)) { \
+ NEXT(TAIL(q,l),l) = (n); \
+ PREV(n,l) = TAIL(q,l); \
+ } else { \
+ PREV(n,l) = NULL; \
+ HEAD(q,l) = (n); \
+ } \
+ TAIL(q,l) = (n); \
+ NEXT(n,l) = NULL; \
+ } while (0)
+
+ #define ADDHEAD(q,l,n) \
+ do { \
+ if (HEAD(q,l)) { \
+ PREV(HEAD(q,l),l) = (n); \
+ NEXT(n,l) = HEAD(q,l); \
+ } else { \
+ NEXT(n,l) = NULL; \
+ TAIL(q,l) = (n); \
+ } \
+ HEAD(q,l) = (n); \
+ PREV(n,l) = NULL; \
+ } while (0)
+
+ #define REMHEAD(q,l,n) \
+ do { \
+ (n) = HEAD(q,l); \
+ if (n) { \
+ HEAD(q,l) = NEXT(n,l); \
+ if (HEAD(q,l)) \
+ PREV(HEAD(q,l),l) = NULL; \
+ else \
+ TAIL(q,l) = NULL; \
+ } \
+ } while(0)
+
+ #define REMTAIL(q,l,n) \
+ do { \
+ (n) = TAIL(q,l); \
+ if (n) { \
+ TAIL(q,l) = PREV(n,l); \
+ if (TAIL(q,l)) \
+ NEXT(TAIL(q,l),l) = NULL; \
+ else \
+ HEAD(q,l) = NULL; \
+ } \
+ } while(0)
+
+ #define REMOVE(q,l,n) \
+ do { \
+ if (PREV(n,l)) \
+ NEXT(PREV(n,l),l) = NEXT(n,l); \
+ else \
+ HEAD(q,l) = NEXT(n,l); \
+ if (NEXT(n,l)) \
+ PREV(NEXT(n,l),l) = PREV(n,l); \
+ else \
+ TAIL(q,l) = PREV(n,l); \
+ NEXT(n,l) = NULL; \
+ PREV(n,l) = NULL; \
+ } while (0)
+
+ #define INSERT(q,l,i,n) \
+ do { \
+ if (PREV(i,l)) { \
+ NEXT(PREV(i,l),l) = (n); \
+ } else { \
+ HEAD(q,l) = (n); \
+ } \
+ PREV(n,l) = PREV(i,l); \
+ PREV(i,l) = (n); \
+ NEXT(n,l) = (i); \
+ } while (0)
+
+ #define APPENDLIST(q1,l,q2) \
+ do { \
+ if (TAIL(q1,l)) { \
+ NEXT(TAIL(q1,l),l) = HEAD(q2,l); \
+ PREV(HEAD(q2,l),l) = TAIL(q1,l); \
+ } else { \
+ HEAD(q1,l) = HEAD(q2,l); \
+ } \
+ TAIL(q1,l) = TAIL(q2,l); \
+ LISTINIT(q2,l); \
+ } while(0)
+
+ #define INSERTLIST(q1,l,i,q2) \
+ do { \
+ if (PREV(i,l)) { \
+ NEXT(PREV(i,l),l) = HEAD(q2,l); \
+ } else { \
+ HEAD(q1,l) = HEAD(q2,l); \
+ } \
+ PREV(HEAD(q2,l),l) = PREV(i,l); \
+ NEXT(TAIL(q2,l),l) = (i); \
+ PREV(i,l) = TAIL(q2,l); \
+ LISTINIT(q2,l); \
+ } while(0)
+
+ #define FOREACH(q,l,n) for (n = HEAD(q,l); n; n = NEXT(n,l))
+ #define FOREACHR(q,l,n) for (n = TAIL(q,l); n; n = PREV(n,l))
+ #define FOREACHD(q,l,n,r) for (n = TAIL(q,l); n && (r = PREV(n,l), 1); n = r)
+
|