2 * lists.c -- Functions to implement a double linked list
\r
3 * XBoard $Id: lists.c,v 2.1 2003/10/27 19:21:00 mann Exp $
\r
5 * Copyright 1995 Free Software Foundation, Inc.
\r
7 * ------------------------------------------------------------------------
\r
8 * This program is free software; you can redistribute it and/or modify
\r
9 * it under the terms of the GNU General Public License as published by
\r
10 * the Free Software Foundation; either version 2 of the License, or
\r
11 * (at your option) any later version.
\r
13 * This program is distributed in the hope that it will be useful,
\r
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
16 * GNU General Public License for more details.
\r
18 * You should have received a copy of the GNU General Public License
\r
19 * along with this program; if not, write to the Free Software
\r
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
\r
21 * ------------------------------------------------------------------------
\r
23 * This file could well be a part of backend.c, but I prefer it this
\r
31 # include <stdlib.h>
\r
32 #endif /* not STDC_HEADERS */
\r
39 /* Check, if List l is empty; returns TRUE, if it is, FALSE
\r
45 return(l->head == (ListNode *) &l->tail);
\r
49 /* Initialize a list. Must be executed before list is used.
\r
54 l->head = (ListNode *) &l->tail;
\r
56 l->tailPred = (ListNode *) l;
\r
60 /* Remove node n from the list it is inside.
\r
65 if (n->succ != NULL) { /* Be safe */
\r
66 n->pred->succ = n->succ;
\r
67 n->succ->pred = n->pred;
\r
68 n->succ = NULL; /* Mark node as no longer being member */
\r
69 n->pred = NULL; /* of a list. */
\r
76 void ListNodeFree(n)
\r
86 /* Create a list node with size s. Returns NULL, if out of memory.
\r
88 ListNode *ListNodeCreate(s)
\r
93 if ((n = (ListNode*) malloc(s))) {
\r
94 n->succ = NULL; /* Mark node as not being member of a list. */
\r
101 /* Insert node n into the list of node m after m.
\r
103 void ListInsert(m, n)
\r
113 /* Add node n to the head of list l.
\r
115 void ListAddHead(l, n)
\r
119 ListInsert((ListNode *) &l->head, n);
\r
123 /* Add node n to the tail of list l.
\r
125 void ListAddTail(l, n)
\r
129 ListInsert((ListNode *) l->tailPred, n);
\r
133 /* Return element with number n of list l. (NULL, if n doesn't exist.)
\r
134 * Counting starts with 0.
\r
136 ListNode *ListElem(l, n)
\r
142 for (ln = l->head; ln->succ; ln = ln->succ) {
\r