-/*\r
- * lists.c -- Functions to implement a double linked list\r
- * XBoard $Id: lists.c,v 2.1 2003/10/27 19:21:00 mann Exp $\r
- *\r
- * Copyright 1995 Free Software Foundation, Inc.\r
- *\r
- * ------------------------------------------------------------------------\r
- * This program is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.\r
- * ------------------------------------------------------------------------\r
- *\r
- * This file could well be a part of backend.c, but I prefer it this\r
- * way.\r
- */\r
-\r
-#include "config.h"\r
-\r
-#include <stdio.h>\r
-#if STDC_HEADERS\r
-# include <stdlib.h>\r
-#endif /* not STDC_HEADERS */\r
-\r
-#include "common.h"\r
-#include "lists.h"\r
-\r
-\r
-\r
-/* Check, if List l is empty; returns TRUE, if it is, FALSE\r
- * otherwise.\r
- */\r
-int ListEmpty(l)\r
- List *l;\r
-{\r
- return(l->head == (ListNode *) &l->tail);\r
-}\r
-\r
-\r
-/* Initialize a list. Must be executed before list is used.\r
- */\r
-void ListNew(l)\r
- List *l;\r
-{\r
- l->head = (ListNode *) &l->tail;\r
- l->tail = NULL;\r
- l->tailPred = (ListNode *) l;\r
-}\r
-\r
-\r
-/* Remove node n from the list it is inside.\r
- */\r
-void ListRemove(n)\r
- ListNode *n;\r
-{\r
- if (n->succ != NULL) { /* Be safe */\r
- n->pred->succ = n->succ;\r
- n->succ->pred = n->pred;\r
- n->succ = NULL; /* Mark node as no longer being member */\r
- n->pred = NULL; /* of a list. */\r
- }\r
-}\r
-\r
-\r
-/* Delete node n.\r
- */\r
-void ListNodeFree(n)\r
- ListNode *n;\r
-{\r
- if (n) {\r
- ListRemove(n);\r
- free(n);\r
- }\r
-}\r
-\r
-\r
-/* Create a list node with size s. Returns NULL, if out of memory.\r
- */\r
-ListNode *ListNodeCreate(s)\r
- size_t s;\r
-{\r
- ListNode *n;\r
-\r
- if ((n = (ListNode*) malloc(s))) {\r
- n->succ = NULL; /* Mark node as not being member of a list. */\r
- n->pred = NULL;\r
- }\r
- return(n);\r
-}\r
-\r
-\r
-/* Insert node n into the list of node m after m.\r
- */\r
-void ListInsert(m, n)\r
- ListNode *m, *n;\r
-{\r
- n->succ = m->succ;\r
- n->pred = m;\r
- m->succ = n;\r
- n->succ->pred = n;\r
-}\r
-\r
-\r
-/* Add node n to the head of list l.\r
- */\r
-void ListAddHead(l, n)\r
- List *l;\r
- ListNode *n;\r
-{\r
- ListInsert((ListNode *) &l->head, n);\r
-}\r
-\r
-\r
-/* Add node n to the tail of list l.\r
- */\r
-void ListAddTail(l, n)\r
- List *l;\r
- ListNode *n;\r
-{\r
- ListInsert((ListNode *) l->tailPred, n);\r
-}\r
-\r
-\r
-/* Return element with number n of list l. (NULL, if n doesn't exist.)\r
- * Counting starts with 0.\r
- */\r
-ListNode *ListElem(l, n)\r
- List *l;\r
- int n;\r
-{\r
- ListNode *ln;\r
-\r
- for (ln = l->head; ln->succ; ln = ln->succ) {\r
- if (!n--) {\r
- return (ln);\r
- }\r
- }\r
-\r
- return(NULL);\r
-}\r
+/*
+ * lists.c -- Functions to implement a double linked list XBoard
+ *
+ * Copyright 1995, 2009, 2010, 2011, 2012, 2013, 2014 Free Software Foundation, Inc.
+ *
+ * Enhancements Copyright 2005 Alessandro Scotti
+ *
+ * ------------------------------------------------------------------------
+ *
+ * GNU XBoard 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 3 of the License, or (at
+ * your option) any later version.
+ *
+ * GNU XBoard 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, see http://www.gnu.org/licenses/. *
+ *
+ *------------------------------------------------------------------------
+ ** See the file ChangeLog for a revision history. */
+
+/*
+ * This file could well be a part of backend.c, but I prefer it this
+ * way.
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+#if STDC_HEADERS
+# include <stdlib.h>
+#endif /* not STDC_HEADERS */
+
+#include "common.h"
+#include "lists.h"
+
+
+
+/* Check, if List l is empty; returns TRUE, if it is, FALSE
+ * otherwise.
+ */
+int
+ListEmpty (List *l)
+{
+ return(l->head == (ListNode *) &l->tail);
+}
+
+
+/* Initialize a list. Must be executed before list is used.
+ */
+void
+ListNew (List *l)
+{
+ l->head = (ListNode *) &l->tail;
+ l->tail = NULL;
+ l->tailPred = (ListNode *) l;
+}
+
+
+/* Remove node n from the list it is inside.
+ */
+void
+ListRemove (ListNode *n)
+{
+ if (n->succ != NULL) { /* Be safe */
+ n->pred->succ = n->succ;
+ n->succ->pred = n->pred;
+ n->succ = NULL; /* Mark node as no longer being member */
+ n->pred = NULL; /* of a list. */
+ }
+}
+
+
+/* Delete node n.
+ */
+void
+ListNodeFree (ListNode *n)
+{
+ if (n) {
+ ListRemove(n);
+ free(n);
+ }
+}
+
+
+/* Create a list node with size s. Returns NULL, if out of memory.
+ */
+ListNode *
+ListNodeCreate (size_t s)
+{
+ ListNode *n;
+
+ if ((n = (ListNode*) malloc(s))) {
+ n->succ = NULL; /* Mark node as not being member of a list. */
+ n->pred = NULL;
+ }
+ return(n);
+}
+
+
+/* Insert node n into the list of node m after m.
+ */
+void
+ListInsert (ListNode *m, ListNode *n)
+{
+ n->succ = m->succ;
+ n->pred = m;
+ m->succ = n;
+ n->succ->pred = n;
+}
+
+
+/* Add node n to the head of list l.
+ */
+void
+ListAddHead (List *l, ListNode *n)
+{
+ ListInsert((ListNode *) &l->head, n);
+}
+
+
+/* Add node n to the tail of list l.
+ */
+void
+ListAddTail (List *l, ListNode *n)
+{
+ ListInsert((ListNode *) l->tailPred, n);
+}
+
+
+/* Return element with number n of list l. (NULL, if n doesn't exist.)
+ * Counting starts with 0.
+ */
+ListNode *
+ListElem (List *l, int n)
+{
+ ListNode *ln;
+
+ for (ln = l->head; ln->succ; ln = ln->succ) {
+ if (!n--) {
+ return (ln);
+ }
+ }
+
+ return(NULL);
+}