< prev index next >

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

Print this page




  86 
  87 
  88 /** ------------------------------------------------------------------------
  89         Adds item to the list pointed to by lp.  Finds the end of the
  90         list, then mallocs a new list node onto the end of the list.
  91         The item pointer in the new node is set to "item" passed in,
  92         and the next pointer in the new node is set to NULL.
  93         Returns 1 if successful, 0 if the malloc failed.
  94     -------------------------------------------------------------------- **/
  95 #if NeedFunctionPrototypes
  96 int32_t add_to_list(list_ptr lp, void *item)
  97 #else
  98 int32_t add_to_list(lp, item)
  99     list_ptr lp;
 100     void *item;
 101 #endif
 102 {
 103     while (lp->next) {
 104         lp = lp->next;
 105     }
 106     if ((lp->next = (list_ptr) malloc( sizeof( list_item))) == NULL) {
 107 


 108         return 0;
 109     }
 110     lp->next->ptr.item = item;
 111     lp->next->next = NULL;
 112 
 113     return 1;
 114 }
 115 
 116 
 117 /** ------------------------------------------------------------------------
 118         Creates a new list and sets its pointers to NULL.
 119         Returns a pointer to the new list.
 120     -------------------------------------------------------------------- **/
 121 list_ptr new_list ()
 122 {
 123     list_ptr lp;
 124 
 125     if (lp = (list_ptr) malloc( sizeof( list_item))) {

 126         lp->next = NULL;
 127         lp->ptr.item = NULL;
 128     }
 129 
 130     return lp;
 131 }
 132 
 133 
 134 /** ------------------------------------------------------------------------
 135         Creates a new list head, pointing to the same list as the one
 136         passed in.  If start_at_curr is TRUE, the new list's first item
 137         is the "current" item (as set by calls to first/next_in_list()).
 138         If start_at_curr is FALSE, the first item in the new list is the
 139         same as the first item in the old list.  In either case, the
 140         curr pointer in the new list is the same as in the old list.
 141         Returns a pointer to the new list head.
 142     -------------------------------------------------------------------- **/
 143 #if NeedFunctionPrototypes
 144 list_ptr dup_list_head(list_ptr lp, int32_t start_at_curr)
 145 #else




  86 
  87 
  88 /** ------------------------------------------------------------------------
  89         Adds item to the list pointed to by lp.  Finds the end of the
  90         list, then mallocs a new list node onto the end of the list.
  91         The item pointer in the new node is set to "item" passed in,
  92         and the next pointer in the new node is set to NULL.
  93         Returns 1 if successful, 0 if the malloc failed.
  94     -------------------------------------------------------------------- **/
  95 #if NeedFunctionPrototypes
  96 int32_t add_to_list(list_ptr lp, void *item)
  97 #else
  98 int32_t add_to_list(lp, item)
  99     list_ptr lp;
 100     void *item;
 101 #endif
 102 {
 103     while (lp->next) {
 104         lp = lp->next;
 105     }

 106     
 107     lp->next = (list_ptr) malloc(sizeof(list_item));
 108     if (lp->next == NULL) {
 109         return 0;
 110     }
 111     lp->next->ptr.item = item;
 112     lp->next->next = NULL;
 113 
 114     return 1;
 115 }
 116 
 117 
 118 /** ------------------------------------------------------------------------
 119         Creates a new list and sets its pointers to NULL.
 120         Returns a pointer to the new list.
 121     -------------------------------------------------------------------- **/
 122 list_ptr new_list ()
 123 {
 124     list_ptr lp;
 125 
 126     lp = (list_ptr) malloc(sizeof(list_item));
 127     if (lp) {
 128         lp->next = NULL;
 129         lp->ptr.item = NULL;
 130     }
 131 
 132     return lp;
 133 }
 134 
 135 
 136 /** ------------------------------------------------------------------------
 137         Creates a new list head, pointing to the same list as the one
 138         passed in.  If start_at_curr is TRUE, the new list's first item
 139         is the "current" item (as set by calls to first/next_in_list()).
 140         If start_at_curr is FALSE, the first item in the new list is the
 141         same as the first item in the old list.  In either case, the
 142         curr pointer in the new list is the same as in the old list.
 143         Returns a pointer to the new list head.
 144     -------------------------------------------------------------------- **/
 145 #if NeedFunctionPrototypes
 146 list_ptr dup_list_head(list_ptr lp, int32_t start_at_curr)
 147 #else


< prev index next >