src/java.desktop/unix/native/libawt_xawt/awt/list.c
author phh
Sat, 30 Nov 2019 14:33:05 -0800
changeset 59330 5b96c12f909d
parent 52542 8c7638601045
permissions -rw-r--r--
8234541: C1 emits an empty message when it inlines successfully Summary: Use "inline" as the message when successfull Reviewed-by: thartmann, mdoerr Contributed-by: navy.xliu@gmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
52542
8c7638601045 8210776: Upgrade X Window System 6.8.2 to the latest XWD 1.0.7
prr
parents: 47216
diff changeset
     2
 * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
/** ------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
        This file contains routines for manipulating generic lists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
        Lists are implemented with a "harness".  In other words, each
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
        node in the list consists of two pointers, one to the data item
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
        and one to the next node in the list.  The head of the list is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
        the same struct as each node, but the "item" ptr is used to point
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
        to the current member of the list (used by the first_in_list and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
        next_in_list functions).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 This file is available under and governed by the GNU General Public
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 License version 2 only, as published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 However, the following notice accompanied the original version of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 file:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
52542
8c7638601045 8210776: Upgrade X Window System 6.8.2 to the latest XWD 1.0.7
prr
parents: 47216
diff changeset
    39
Copyright 1994 Hewlett-Packard Co.
8c7638601045 8210776: Upgrade X Window System 6.8.2 to the latest XWD 1.0.7
prr
parents: 47216
diff changeset
    40
Copyright 1996, 1998  The Open Group
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
52542
8c7638601045 8210776: Upgrade X Window System 6.8.2 to the latest XWD 1.0.7
prr
parents: 47216
diff changeset
    42
Permission to use, copy, modify, distribute, and sell this software and its
8c7638601045 8210776: Upgrade X Window System 6.8.2 to the latest XWD 1.0.7
prr
parents: 47216
diff changeset
    43
documentation for any purpose is hereby granted without fee, provided that
8c7638601045 8210776: Upgrade X Window System 6.8.2 to the latest XWD 1.0.7
prr
parents: 47216
diff changeset
    44
the above copyright notice appear in all copies and that both that
8c7638601045 8210776: Upgrade X Window System 6.8.2 to the latest XWD 1.0.7
prr
parents: 47216
diff changeset
    45
copyright notice and this permission notice appear in supporting
8c7638601045 8210776: Upgrade X Window System 6.8.2 to the latest XWD 1.0.7
prr
parents: 47216
diff changeset
    46
documentation.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
The above copyright notice and this permission notice shall be included
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
in all copies or substantial portions of the Software.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
52542
8c7638601045 8210776: Upgrade X Window System 6.8.2 to the latest XWD 1.0.7
prr
parents: 47216
diff changeset
    54
IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
OTHER DEALINGS IN THE SOFTWARE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
52542
8c7638601045 8210776: Upgrade X Window System 6.8.2 to the latest XWD 1.0.7
prr
parents: 47216
diff changeset
    59
Except as contained in this notice, the name of The Open Group shall
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
not be used in advertising or otherwise to promote the sale, use or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
other dealings in this Software without prior written authorization
52542
8c7638601045 8210776: Upgrade X Window System 6.8.2 to the latest XWD 1.0.7
prr
parents: 47216
diff changeset
    62
from The Open Group.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
  ----------------------------------------------------------------------- **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
#include <stdio.h>
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
    67
#include <stdlib.h>
52542
8c7638601045 8210776: Upgrade X Window System 6.8.2 to the latest XWD 1.0.7
prr
parents: 47216
diff changeset
    68
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
#include "list.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
/** ------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        Sets the pointers of the specified list to NULL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    --------------------------------------------------------------------- **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
void zero_list(list_ptr lp)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    lp->next = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    lp->ptr.item = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
/** ------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        Adds item to the list pointed to by lp.  Finds the end of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        list, then mallocs a new list node onto the end of the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        The item pointer in the new node is set to "item" passed in,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        and the next pointer in the new node is set to NULL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        Returns 1 if successful, 0 if the malloc failed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    -------------------------------------------------------------------- **/
52542
8c7638601045 8210776: Upgrade X Window System 6.8.2 to the latest XWD 1.0.7
prr
parents: 47216
diff changeset
    89
int add_to_list(list_ptr lp, void *item)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    while (lp->next) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        lp = lp->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    if ((lp->next = (list_ptr) malloc( sizeof( list_item))) == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    lp->next->ptr.item = item;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    lp->next->next = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
/** ------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        Creates a new list and sets its pointers to NULL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        Returns a pointer to the new list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    -------------------------------------------------------------------- **/
52542
8c7638601045 8210776: Upgrade X Window System 6.8.2 to the latest XWD 1.0.7
prr
parents: 47216
diff changeset
   109
list_ptr new_list (void)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    list_ptr lp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
52542
8c7638601045 8210776: Upgrade X Window System 6.8.2 to the latest XWD 1.0.7
prr
parents: 47216
diff changeset
   113
    if ((lp = (list_ptr) malloc( sizeof( list_item)))) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        lp->next = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        lp->ptr.item = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    return lp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
/** ------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        Creates a new list head, pointing to the same list as the one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        passed in.  If start_at_curr is TRUE, the new list's first item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        is the "current" item (as set by calls to first/next_in_list()).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        If start_at_curr is FALSE, the first item in the new list is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        same as the first item in the old list.  In either case, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        curr pointer in the new list is the same as in the old list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        Returns a pointer to the new list head.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    -------------------------------------------------------------------- **/
52542
8c7638601045 8210776: Upgrade X Window System 6.8.2 to the latest XWD 1.0.7
prr
parents: 47216
diff changeset
   131
list_ptr dup_list_head(list_ptr lp, int start_at_curr)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
{
52542
8c7638601045 8210776: Upgrade X Window System 6.8.2 to the latest XWD 1.0.7
prr
parents: 47216
diff changeset
   133
    list_ptr new_listp;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
52542
8c7638601045 8210776: Upgrade X Window System 6.8.2 to the latest XWD 1.0.7
prr
parents: 47216
diff changeset
   135
    if ((new_listp = (list_ptr) malloc( sizeof( list_item))) == NULL) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        return (list_ptr)NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
52542
8c7638601045 8210776: Upgrade X Window System 6.8.2 to the latest XWD 1.0.7
prr
parents: 47216
diff changeset
   139
    new_listp->next = start_at_curr ? lp->ptr.curr : lp->next;
8c7638601045 8210776: Upgrade X Window System 6.8.2 to the latest XWD 1.0.7
prr
parents: 47216
diff changeset
   140
    new_listp->ptr.curr = lp->ptr.curr;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
52542
8c7638601045 8210776: Upgrade X Window System 6.8.2 to the latest XWD 1.0.7
prr
parents: 47216
diff changeset
   142
    return new_listp;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
/** ------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        Returns the number of items in the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    -------------------------------------------------------------------- **/
52542
8c7638601045 8210776: Upgrade X Window System 6.8.2 to the latest XWD 1.0.7
prr
parents: 47216
diff changeset
   149
unsigned int list_length(list_ptr lp)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
{
52542
8c7638601045 8210776: Upgrade X Window System 6.8.2 to the latest XWD 1.0.7
prr
parents: 47216
diff changeset
   151
    unsigned int count = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    while (lp->next) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        lp = lp->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    return count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
/** ------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        Scans thru list, looking for a node whose ptr.item is equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        the "item" passed in.  "Equal" here means the same address - no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        attempt is made to match equivalent values stored in different
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        locations.  If a match is found, that node is deleted from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        list.  Storage for the node is freed, but not for the item itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        Returns a pointer to the item, so the caller can free it if it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        so desires.  If a match is not found, returns NULL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    -------------------------------------------------------------------- **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
void *delete_from_list(list_ptr lp, void *item)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    list_ptr new_next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    while (lp->next) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        if (lp->next->ptr.item == item) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            new_next = lp->next->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            free (lp->next);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            lp->next = new_next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            return item;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        lp = lp->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
/** ------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        Deletes each node in the list *except the head*.  This allows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        the deletion of lists where the head is not malloced or created
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        with new_list().  If free_items is true, each item pointed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        from the node is freed, in addition to the node itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    -------------------------------------------------------------------- **/
52542
8c7638601045 8210776: Upgrade X Window System 6.8.2 to the latest XWD 1.0.7
prr
parents: 47216
diff changeset
   196
void delete_list(list_ptr lp, int free_items)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    list_ptr del_node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    void *item;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    while (lp->next) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        del_node = lp->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        item = del_node->ptr.item;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        lp->next = del_node->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        free (del_node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        if (free_items) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            free( item);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
void delete_list_destroying(list_ptr lp, void destructor(void *item))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    list_ptr del_node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    void *item;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    while (lp->next) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        del_node = lp->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        item = del_node->ptr.item;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        lp->next = del_node->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        free( del_node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        if (destructor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            destructor( item);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
/** ------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        Returns a ptr to the first *item* (not list node) in the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        Sets the list head node's curr ptr to the first node in the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        Returns NULL if the list is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    -------------------------------------------------------------------- **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
void * first_in_list(list_ptr lp)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    if (! lp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    lp->ptr.curr = lp->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    return lp->ptr.curr ? lp->ptr.curr->ptr.item : NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
/** ------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        Returns a ptr to the next *item* (not list node) in the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        Sets the list head node's curr ptr to the next node in the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        first_in_list must have been called prior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        Returns NULL if no next item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    -------------------------------------------------------------------- **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
void * next_in_list(list_ptr lp)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    if (! lp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    if (lp->ptr.curr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        lp->ptr.curr = lp->ptr.curr->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    return lp->ptr.curr ? lp->ptr.curr->ptr.item : NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
52542
8c7638601045 8210776: Upgrade X Window System 6.8.2 to the latest XWD 1.0.7
prr
parents: 47216
diff changeset
   264
int list_is_empty(list_ptr lp)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    return (lp == NULL || lp->next == NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
}
52542
8c7638601045 8210776: Upgrade X Window System 6.8.2 to the latest XWD 1.0.7
prr
parents: 47216
diff changeset
   268