other-licenses/android/list.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/other-licenses/android/list.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,124 @@
     1.4 +/*	$NetBSD: list.h,v 1.2 2004/05/20 19:51:55 christos Exp $	*/
     1.5 +
     1.6 +/*
     1.7 + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
     1.8 + * Copyright (c) 1997,1999 by Internet Software Consortium.
     1.9 + *
    1.10 + * Permission to use, copy, modify, and distribute this software for any
    1.11 + * purpose with or without fee is hereby granted, provided that the above
    1.12 + * copyright notice and this permission notice appear in all copies.
    1.13 + *
    1.14 + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
    1.15 + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
    1.16 + * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR
    1.17 + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
    1.18 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
    1.19 + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
    1.20 + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
    1.21 + */
    1.22 +
    1.23 +/*
    1.24 + * This version of this file is derived from Android 2.3 "Gingerbread",
    1.25 + * which contains uncredited changes by Android/Google developers.  It has
    1.26 + * been modified in 2011 for use in the Android build of Mozilla Firefox by
    1.27 + * Mozilla contributors (including Michael Edwards <m.k.edwards@gmail.com>,
    1.28 + * and Steve Workman <sjhworkman@gmail.com>).
    1.29 + * These changes are offered under the same license as the original NetBSD
    1.30 + * file, whose copyright and license are unchanged above.
    1.31 + */
    1.32 +
    1.33 +#ifndef LIST_H
    1.34 +#define LIST_H 1
    1.35 +#include "assertions.h"
    1.36 +
    1.37 +#define LIST(type) struct { type *head, *tail; }
    1.38 +#define INIT_LIST(list) \
    1.39 +	do { (list).head = NULL; (list).tail = NULL; } while (/*CONSTCOND*/0)
    1.40 +
    1.41 +#define LINK(type) struct { type *prev, *next; }
    1.42 +#define INIT_LINK_TYPE(elt, link, type) \
    1.43 +	do { \
    1.44 +		(elt)->link.prev = (type *)(-1); \
    1.45 +		(elt)->link.next = (type *)(-1); \
    1.46 +	} while (/*CONSTCOND*/0)
    1.47 +#define INIT_LINK(elt, link) \
    1.48 +	INIT_LINK_TYPE(elt, link, void)
    1.49 +#define LINKED(elt, link) ((void *)((elt)->link.prev) != (void *)(-1))
    1.50 +
    1.51 +#define HEAD(list) ((list).head)
    1.52 +#define TAIL(list) ((list).tail)
    1.53 +#define EMPTY(list) ((list).head == NULL)
    1.54 +
    1.55 +#define PREPEND(list, elt, link) \
    1.56 +	do { \
    1.57 +		INSIST(!LINKED(elt, link));\
    1.58 +		if ((list).head != NULL) \
    1.59 +			(list).head->link.prev = (elt); \
    1.60 +		else \
    1.61 +			(list).tail = (elt); \
    1.62 +		(elt)->link.prev = NULL; \
    1.63 +		(elt)->link.next = (list).head; \
    1.64 +		(list).head = (elt); \
    1.65 +	} while (/*CONSTCOND*/0)
    1.66 +
    1.67 +#define APPEND(list, elt, link) \
    1.68 +	do { \
    1.69 +		INSIST(!LINKED(elt, link));\
    1.70 +		if ((list).tail != NULL) \
    1.71 +			(list).tail->link.next = (elt); \
    1.72 +		else \
    1.73 +			(list).head = (elt); \
    1.74 +		(elt)->link.prev = (list).tail; \
    1.75 +		(elt)->link.next = NULL; \
    1.76 +		(list).tail = (elt); \
    1.77 +	} while (/*CONSTCOND*/0)
    1.78 +
    1.79 +#define UNLINK_TYPE(list, elt, link, type) \
    1.80 +	do { \
    1.81 +		INSIST(LINKED(elt, link));\
    1.82 +		if ((elt)->link.next != NULL) \
    1.83 +			(elt)->link.next->link.prev = (elt)->link.prev; \
    1.84 +		else \
    1.85 +			(list).tail = (elt)->link.prev; \
    1.86 +		if ((elt)->link.prev != NULL) \
    1.87 +			(elt)->link.prev->link.next = (elt)->link.next; \
    1.88 +		else \
    1.89 +			(list).head = (elt)->link.next; \
    1.90 +		INIT_LINK_TYPE(elt, link, type); \
    1.91 +	} while (/*CONSTCOND*/0)
    1.92 +#define UNLINK(list, elt, link) \
    1.93 +	UNLINK_TYPE(list, elt, link, void)
    1.94 +
    1.95 +#define PREV(elt, link) ((elt)->link.prev)
    1.96 +#define NEXT(elt, link) ((elt)->link.next)
    1.97 +
    1.98 +#define INSERT_BEFORE(list, before, elt, link) \
    1.99 +	do { \
   1.100 +		INSIST(!LINKED(elt, link));\
   1.101 +		if ((before)->link.prev == NULL) \
   1.102 +			PREPEND(list, elt, link); \
   1.103 +		else { \
   1.104 +			(elt)->link.prev = (before)->link.prev; \
   1.105 +			(before)->link.prev = (elt); \
   1.106 +			(elt)->link.prev->link.next = (elt); \
   1.107 +			(elt)->link.next = (before); \
   1.108 +		} \
   1.109 +	} while (/*CONSTCOND*/0)
   1.110 +
   1.111 +#define INSERT_AFTER(list, after, elt, link) \
   1.112 +	do { \
   1.113 +		INSIST(!LINKED(elt, link));\
   1.114 +		if ((after)->link.next == NULL) \
   1.115 +			APPEND(list, elt, link); \
   1.116 +		else { \
   1.117 +			(elt)->link.next = (after)->link.next; \
   1.118 +			(after)->link.next = (elt); \
   1.119 +			(elt)->link.next->link.prev = (elt); \
   1.120 +			(elt)->link.prev = (after); \
   1.121 +		} \
   1.122 +	} while (/*CONSTCOND*/0)
   1.123 +
   1.124 +#define ENQUEUE(list, elt, link) APPEND(list, elt, link)
   1.125 +#define DEQUEUE(list, elt, link) UNLINK(list, elt, link)
   1.126 +
   1.127 +#endif /* LIST_H */

mercurial