2 * lists.c -- Functions to implement a double linked list
3 * XBoard $Id: lists.c,v 2.1 2003/10/27 19:21:00 mann Exp $
5 * Copyright 1995,2009 Free Software Foundation, Inc.
7 * ------------------------------------------------------------------------
9 * GNU XBoard is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or (at
12 * your option) any later version.
14 * GNU XBoard is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see http://www.gnu.org/licenses/. *
22 *------------------------------------------------------------------------
23 ** See the file ChangeLog for a revision history. */
26 * This file could well be a part of backend.c, but I prefer it this
35 #endif /* not STDC_HEADERS */
42 /* Check, if List l is empty; returns TRUE, if it is, FALSE
48 return(l->head == (ListNode *) &l->tail);
52 /* Initialize a list. Must be executed before list is used.
57 l->head = (ListNode *) &l->tail;
59 l->tailPred = (ListNode *) l;
63 /* Remove node n from the list it is inside.
68 if (n->succ != NULL) { /* Be safe */
69 n->pred->succ = n->succ;
70 n->succ->pred = n->pred;
71 n->succ = NULL; /* Mark node as no longer being member */
72 n->pred = NULL; /* of a list. */
89 /* Create a list node with size s. Returns NULL, if out of memory.
91 ListNode *ListNodeCreate(s)
96 if ((n = (ListNode*) malloc(s))) {
97 n->succ = NULL; /* Mark node as not being member of a list. */
104 /* Insert node n into the list of node m after m.
106 void ListInsert(m, n)
116 /* Add node n to the head of list l.
118 void ListAddHead(l, n)
122 ListInsert((ListNode *) &l->head, n);
126 /* Add node n to the tail of list l.
128 void ListAddTail(l, n)
132 ListInsert((ListNode *) l->tailPred, n);
136 /* Return element with number n of list l. (NULL, if n doesn't exist.)
137 * Counting starts with 0.
139 ListNode *ListElem(l, n)
145 for (ln = l->head; ln->succ; ln = ln->succ) {