src/java.desktop/unix/native/libawt_xawt/awt/list.c
author ihse
Sat, 03 Mar 2018 08:21:47 +0100
branchihse-warnings-cflags-branch
changeset 56230 489867818774
parent 47216 71c04702a3d5
permissions -rw-r--r--
No longer disable E_OLD_STYLE_FUNC_DEF.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * 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
     6
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     8
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/* $XConsortium: list.c /main/4 1996/10/14 15:03:56 swick $ */
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
Copyright (c) 1994 Hewlett-Packard Co.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
Copyright (c) 1996  X Consortium
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
Permission is hereby granted, free of charge, to any person obtaining
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
a copy of this software and associated documentation files (the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
"Software"), to deal in the Software without restriction, including
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
without limitation the rights to use, copy, modify, merge, publish,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
distribute, sublicense, and sell copies of the Software, and to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
permit persons to whom the Software is furnished to do so, subject to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
the following conditions:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
The above copyright notice and this permission notice shall be included
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
in all copies or substantial portions of the Software.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
OTHER DEALINGS IN THE SOFTWARE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
Except as contained in this notice, the name of the X Consortium shall
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
not be used in advertising or otherwise to promote the sale, use or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
other dealings in this Software without prior written authorization
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
from the X Consortium.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
  ----------------------------------------------------------------------- **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
#include <stdio.h>
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
    69
#include <stdlib.h>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
#include "list.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
/** ------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        Sets the pointers of the specified list to NULL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    --------------------------------------------------------------------- **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
void zero_list(list_ptr lp)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    lp->next = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    lp->ptr.item = NULL;
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
/** ------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        Adds item to the list pointed to by lp.  Finds the end of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        list, then mallocs a new list node onto the end of the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        The item pointer in the new node is set to "item" passed in,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        and the next pointer in the new node is set to NULL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        Returns 1 if successful, 0 if the malloc failed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    -------------------------------------------------------------------- **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
int32_t add_to_list(list_ptr lp, void *item)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    while (lp->next) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        lp = lp->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    if ((lp->next = (list_ptr) malloc( sizeof( list_item))) == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    lp->next->ptr.item = item;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    lp->next->next = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    return 1;
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
/** ------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        Creates a new list and sets its pointers to NULL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        Returns a pointer to the new list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    -------------------------------------------------------------------- **/
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 47216
diff changeset
   110
list_ptr new_list (void)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    list_ptr lp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    if (lp = (list_ptr) malloc( sizeof( list_item))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        lp->next = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        lp->ptr.item = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    return lp;
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
/** ------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        Creates a new list head, pointing to the same list as the one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        passed in.  If start_at_curr is TRUE, the new list's first item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        is the "current" item (as set by calls to first/next_in_list()).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        If start_at_curr is FALSE, the first item in the new list is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        same as the first item in the old list.  In either case, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        curr pointer in the new list is the same as in the old list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        Returns a pointer to the new list head.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    -------------------------------------------------------------------- **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
list_ptr dup_list_head(list_ptr lp, int32_t start_at_curr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    list_ptr new_list;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    if ((new_list = (list_ptr) malloc( sizeof( list_item))) == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        return (list_ptr)NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    new_list->next = start_at_curr ? lp->ptr.curr : lp->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    new_list->ptr.curr = lp->ptr.curr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    return new_list;
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
/** ------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        Returns the number of items in the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    -------------------------------------------------------------------- **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
uint32_t list_length(list_ptr lp)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    uint32_t count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    while (lp->next) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        lp = lp->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    return count;
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
/** ------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        Scans thru list, looking for a node whose ptr.item is equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        the "item" passed in.  "Equal" here means the same address - no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        attempt is made to match equivalent values stored in different
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        locations.  If a match is found, that node is deleted from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        list.  Storage for the node is freed, but not for the item itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        Returns a pointer to the item, so the caller can free it if it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        so desires.  If a match is not found, returns NULL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    -------------------------------------------------------------------- **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
void *delete_from_list(list_ptr lp, void *item)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    list_ptr new_next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    while (lp->next) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        if (lp->next->ptr.item == item) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            new_next = lp->next->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            free (lp->next);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            lp->next = new_next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            return item;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        lp = lp->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    return NULL;
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
/** ------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        Deletes each node in the list *except the head*.  This allows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        the deletion of lists where the head is not malloced or created
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        with new_list().  If free_items is true, each item pointed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        from the node is freed, in addition to the node itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    -------------------------------------------------------------------- **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
void delete_list(list_ptr lp, int32_t free_items)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    list_ptr del_node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    void *item;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    while (lp->next) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        del_node = lp->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        item = del_node->ptr.item;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        lp->next = del_node->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        free (del_node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        if (free_items) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            free( item);
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
void delete_list_destroying(list_ptr lp, void destructor(void *item))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    list_ptr del_node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    void *item;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    while (lp->next) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        del_node = lp->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        item = del_node->ptr.item;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        lp->next = del_node->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        free( del_node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        if (destructor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            destructor( item);
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
/** ------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        Returns a ptr to the first *item* (not list node) in the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        Sets the list head node's curr ptr to the first node in the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        Returns NULL if the list is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    -------------------------------------------------------------------- **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
void * first_in_list(list_ptr lp)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    if (! lp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    lp->ptr.curr = lp->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    return lp->ptr.curr ? lp->ptr.curr->ptr.item : NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
/** ------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        Returns a ptr to the next *item* (not list node) in the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        Sets the list head node's curr ptr to the next node in the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        first_in_list must have been called prior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        Returns NULL if no next item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    -------------------------------------------------------------------- **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
void * next_in_list(list_ptr lp)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    if (! lp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    if (lp->ptr.curr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        lp->ptr.curr = lp->ptr.curr->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    return lp->ptr.curr ? lp->ptr.curr->ptr.item : NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
int32_t list_is_empty(list_ptr lp)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    return (lp == NULL || lp->next == NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
}