1 /*
   2  * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 /** ------------------------------------------------------------------------
  26         This file contains routines for manipulating generic lists.
  27         Lists are implemented with a "harness".  In other words, each
  28         node in the list consists of two pointers, one to the data item
  29         and one to the next node in the list.  The head of the list is
  30         the same struct as each node, but the "item" ptr is used to point
  31         to the current member of the list (used by the first_in_list and
  32         next_in_list functions).
  33 
  34  This file is available under and governed by the GNU General Public
  35  License version 2 only, as published by the Free Software Foundation.
  36  However, the following notice accompanied the original version of this
  37  file:
  38 
  39 Copyright 1994 Hewlett-Packard Co.
  40 Copyright 1996, 1998  The Open Group
  41 
  42 Permission to use, copy, modify, distribute, and sell this software and its
  43 documentation for any purpose is hereby granted without fee, provided that
  44 the above copyright notice appear in all copies and that both that
  45 copyright notice and this permission notice appear in supporting
  46 documentation.
  47 
  48 The above copyright notice and this permission notice shall be included
  49 in all copies or substantial portions of the Software.
  50 
  51 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  52 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  53 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  54 IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
  55 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  56 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  57 OTHER DEALINGS IN THE SOFTWARE.
  58 
  59 Except as contained in this notice, the name of The Open Group shall
  60 not be used in advertising or otherwise to promote the sale, use or
  61 other dealings in this Software without prior written authorization
  62 from The Open Group.
  63 
  64     -------------------------------------------------------------------- **/
  65 
  66 #ifndef LIST_DEF
  67 #define LIST_DEF
  68 
  69 #include <X11/Xfuncproto.h>
  70 #define LESS    -1
  71 #define EQUAL   0
  72 #define GREATER 1
  73 #define DUP_WHOLE_LIST  0
  74 #define START_AT_CURR   1
  75 
  76 typedef struct _list_item {
  77     struct _list_item *next;
  78     union {
  79         void *item;              /* in normal list node, pts to data */
  80         struct _list_item *curr; /* in list head, pts to curr for 1st, next */
  81     } ptr;
  82 } list, list_item, *list_ptr;
  83 
  84 typedef void (*DESTRUCT_FUNC_PTR)(
  85 void *
  86 );
  87 
  88 void zero_list(
  89           list_ptr
  90     );
  91 int add_to_list (
  92           list_ptr , void *
  93     );
  94 list_ptr new_list (
  95           void
  96     );
  97 list_ptr dup_list_head (
  98           list_ptr , int
  99     );
 100 unsigned int list_length(
 101           list_ptr
 102     );
 103 void *delete_from_list (
 104           list_ptr , void *
 105     );
 106 void delete_list(
 107           list_ptr , int
 108     );
 109 void delete_list_destroying (
 110           list_ptr , DESTRUCT_FUNC_PTR
 111     );
 112 void *first_in_list (
 113           list_ptr
 114     );
 115 void *next_in_list (
 116           list_ptr
 117     );
 118 int list_is_empty (
 119           list_ptr
 120     );
 121 
 122 #endif