< prev index next >

src/java.desktop/unix/native/libawt_xawt/awt/list.c

Print this page

        

*** 1,6 **** --- 1,7 ---- /* + * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 19,29 **** * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ - /* $XConsortium: list.c /main/4 1996/10/14 15:03:56 swick $ */ /** ------------------------------------------------------------------------ This file contains routines for manipulating generic lists. Lists are implemented with a "harness". In other words, each node in the list consists of two pointers, one to the data item and one to the next node in the list. The head of the list is --- 20,29 ----
*** 34,86 **** This file is available under and governed by the GNU General Public License version 2 only, as published by the Free Software Foundation. However, the following notice accompanied the original version of this file: ! Copyright (c) 1994 Hewlett-Packard Co. ! Copyright (c) 1996 X Consortium ! Permission is hereby granted, free of charge, to any person obtaining ! a copy of this software and associated documentation files (the ! "Software"), to deal in the Software without restriction, including ! without limitation the rights to use, copy, modify, merge, publish, ! distribute, sublicense, and sell copies of the Software, and to ! permit persons to whom the Software is furnished to do so, subject to ! the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. ! IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ! Except as contained in this notice, the name of the X Consortium shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization ! from the X Consortium. ----------------------------------------------------------------------- **/ #include <stdio.h> #include <stdlib.h> #include "list.h" /** ------------------------------------------------------------------------ Sets the pointers of the specified list to NULL. --------------------------------------------------------------------- **/ - #if NeedFunctionPrototypes void zero_list(list_ptr lp) - #else - void zero_list(lp) - list_ptr lp; - #endif { lp->next = NULL; lp->ptr.item = NULL; } --- 34,80 ---- This file is available under and governed by the GNU General Public License version 2 only, as published by the Free Software Foundation. However, the following notice accompanied the original version of this file: ! Copyright 1994 Hewlett-Packard Co. ! Copyright 1996, 1998 The Open Group ! Permission to use, copy, modify, distribute, and sell this software and its ! documentation for any purpose is hereby granted without fee, provided that ! the above copyright notice appear in all copies and that both that ! copyright notice and this permission notice appear in supporting ! documentation. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. ! IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ! Except as contained in this notice, the name of The Open Group shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization ! from The Open Group. ----------------------------------------------------------------------- **/ #include <stdio.h> #include <stdlib.h> + #include "list.h" /** ------------------------------------------------------------------------ Sets the pointers of the specified list to NULL. --------------------------------------------------------------------- **/ void zero_list(list_ptr lp) { lp->next = NULL; lp->ptr.item = NULL; }
*** 90,106 **** list, then mallocs a new list node onto the end of the list. The item pointer in the new node is set to "item" passed in, and the next pointer in the new node is set to NULL. Returns 1 if successful, 0 if the malloc failed. -------------------------------------------------------------------- **/ ! #if NeedFunctionPrototypes ! int32_t add_to_list(list_ptr lp, void *item) ! #else ! int32_t add_to_list(lp, item) ! list_ptr lp; ! void *item; ! #endif { while (lp->next) { lp = lp->next; } if ((lp->next = (list_ptr) malloc( sizeof( list_item))) == NULL) { --- 84,94 ---- list, then mallocs a new list node onto the end of the list. The item pointer in the new node is set to "item" passed in, and the next pointer in the new node is set to NULL. Returns 1 if successful, 0 if the malloc failed. -------------------------------------------------------------------- **/ ! int add_to_list(list_ptr lp, void *item) { while (lp->next) { lp = lp->next; } if ((lp->next = (list_ptr) malloc( sizeof( list_item))) == NULL) {
*** 116,130 **** /** ------------------------------------------------------------------------ Creates a new list and sets its pointers to NULL. Returns a pointer to the new list. -------------------------------------------------------------------- **/ ! list_ptr new_list () { list_ptr lp; ! if (lp = (list_ptr) malloc( sizeof( list_item))) { lp->next = NULL; lp->ptr.item = NULL; } return lp; --- 104,118 ---- /** ------------------------------------------------------------------------ Creates a new list and sets its pointers to NULL. Returns a pointer to the new list. -------------------------------------------------------------------- **/ ! list_ptr new_list (void) { list_ptr lp; ! if ((lp = (list_ptr) malloc( sizeof( list_item)))) { lp->next = NULL; lp->ptr.item = NULL; } return lp;
*** 138,179 **** If start_at_curr is FALSE, the first item in the new list is the same as the first item in the old list. In either case, the curr pointer in the new list is the same as in the old list. Returns a pointer to the new list head. -------------------------------------------------------------------- **/ ! #if NeedFunctionPrototypes ! list_ptr dup_list_head(list_ptr lp, int32_t start_at_curr) ! #else ! list_ptr dup_list_head(lp, start_at_curr) ! list_ptr lp; ! int32_t start_at_curr; ! #endif { ! list_ptr new_list; ! if ((new_list = (list_ptr) malloc( sizeof( list_item))) == NULL) { return (list_ptr)NULL; } ! new_list->next = start_at_curr ? lp->ptr.curr : lp->next; ! new_list->ptr.curr = lp->ptr.curr; ! return new_list; } /** ------------------------------------------------------------------------ Returns the number of items in the list. -------------------------------------------------------------------- **/ ! #if NeedFunctionPrototypes ! uint32_t list_length(list_ptr lp) ! #else ! uint32_t list_length(lp) ! list_ptr lp; ! #endif { ! uint32_t count = 0; while (lp->next) { count++; lp = lp->next; } --- 126,156 ---- If start_at_curr is FALSE, the first item in the new list is the same as the first item in the old list. In either case, the curr pointer in the new list is the same as in the old list. Returns a pointer to the new list head. -------------------------------------------------------------------- **/ ! list_ptr dup_list_head(list_ptr lp, int start_at_curr) { ! list_ptr new_listp; ! if ((new_listp = (list_ptr) malloc( sizeof( list_item))) == NULL) { return (list_ptr)NULL; } ! new_listp->next = start_at_curr ? lp->ptr.curr : lp->next; ! new_listp->ptr.curr = lp->ptr.curr; ! return new_listp; } /** ------------------------------------------------------------------------ Returns the number of items in the list. -------------------------------------------------------------------- **/ ! unsigned int list_length(list_ptr lp) { ! unsigned int count = 0; while (lp->next) { count++; lp = lp->next; }
*** 189,205 **** locations. If a match is found, that node is deleted from the list. Storage for the node is freed, but not for the item itself. Returns a pointer to the item, so the caller can free it if it so desires. If a match is not found, returns NULL. -------------------------------------------------------------------- **/ - #if NeedFunctionPrototypes void *delete_from_list(list_ptr lp, void *item) - #else - void *delete_from_list(lp, item) - list_ptr lp; - void *item; - #endif { list_ptr new_next; while (lp->next) { if (lp->next->ptr.item == item) { --- 166,176 ----
*** 220,236 **** Deletes each node in the list *except the head*. This allows the deletion of lists where the head is not malloced or created with new_list(). If free_items is true, each item pointed to from the node is freed, in addition to the node itself. -------------------------------------------------------------------- **/ ! #if NeedFunctionPrototypes ! void delete_list(list_ptr lp, int32_t free_items) ! #else ! void delete_list(lp, free_items) ! list_ptr lp; ! int32_t free_items; ! #endif { list_ptr del_node; void *item; while (lp->next) { --- 191,201 ---- Deletes each node in the list *except the head*. This allows the deletion of lists where the head is not malloced or created with new_list(). If free_items is true, each item pointed to from the node is freed, in addition to the node itself. -------------------------------------------------------------------- **/ ! void delete_list(list_ptr lp, int free_items) { list_ptr del_node; void *item; while (lp->next) {
*** 242,258 **** free( item); } } } - #if NeedFunctionPrototypes void delete_list_destroying(list_ptr lp, void destructor(void *item)) - #else - void delete_list_destroying(lp, destructor) - list_ptr lp; - void (*destructor)(); - #endif { list_ptr del_node; void *item; while (lp->next) { --- 207,217 ----
*** 270,285 **** /** ------------------------------------------------------------------------ Returns a ptr to the first *item* (not list node) in the list. Sets the list head node's curr ptr to the first node in the list. Returns NULL if the list is empty. -------------------------------------------------------------------- **/ - #if NeedFunctionPrototypes void * first_in_list(list_ptr lp) - #else - void * first_in_list(lp) - list_ptr lp; - #endif { if (! lp) { return NULL; } --- 229,239 ----
*** 292,307 **** Returns a ptr to the next *item* (not list node) in the list. Sets the list head node's curr ptr to the next node in the list. first_in_list must have been called prior. Returns NULL if no next item. -------------------------------------------------------------------- **/ - #if NeedFunctionPrototypes void * next_in_list(list_ptr lp) - #else - void * next_in_list(lp) - list_ptr lp; - #endif { if (! lp) { return NULL; } --- 246,256 ----
*** 310,323 **** } return lp->ptr.curr ? lp->ptr.curr->ptr.item : NULL; } ! #if NeedFunctionPrototypes ! int32_t list_is_empty(list_ptr lp) ! #else ! int32_t list_is_empty(lp) ! list_ptr lp; ! #endif { return (lp == NULL || lp->next == NULL); } --- 259,268 ---- } return lp->ptr.curr ? lp->ptr.curr->ptr.item : NULL; } ! int list_is_empty(list_ptr lp) { return (lp == NULL || lp->next == NULL); } +
< prev index next >