Annotation of gcc/objc/list.h, revision 1.1.1.2

1.1       root        1: /* Generic single linked list to keep various information 
1.1.1.2 ! root        2:    Copyright (C) 1993, 1994 Free Software Foundation, Inc.
1.1       root        3: 
                      4: Author: Kresten Krab Thorup
                      5: 
                      6: This file is part of GNU CC.
                      7: 
1.1.1.2 ! root        8: GNU CC is free software; you can redistribute it and/or modify
        !             9: it under the terms of the GNU General Public License as published by
        !            10: the Free Software Foundation; either version 2, or (at your option)
        !            11: any later version.
        !            12: 
        !            13: GNU CC is distributed in the hope that it will be useful,
        !            14: but WITHOUT ANY WARRANTY; without even the implied warranty of
        !            15: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        !            16: GNU General Public License for more details.
        !            17: 
        !            18: You should have received a copy of the GNU General Public License
        !            19: along with GNU CC; see the file COPYING.  If not, write to
        !            20: the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
1.1       root       21: 
                     22: /* As a special exception, if you link this library with files compiled with
                     23:    GCC to produce an executable, this does not cause the resulting executable
                     24:    to be covered by the GNU General Public License. This exception does not
                     25:    however invalidate any other reasons why the executable file might be
                     26:    covered by the GNU General Public License.  */
                     27: 
1.1.1.2 ! root       28: #ifndef __GNU_OBJC_LIST_H
        !            29: #define __GNU_OBJC_LIST_H
1.1       root       30: void * __objc_xrealloc (void *optr, size_t size);
                     31: void * __objc_xmalloc (size_t size);
                     32: 
                     33: struct objc_list {
                     34:   void *head;
                     35:   struct objc_list *tail;
                     36: };
                     37: 
                     38: /* Return a cons cell produced from (head . tail) */
                     39: 
                     40: static inline struct objc_list* 
                     41: list_cons(void* head, struct objc_list* tail)
                     42: {
                     43:   struct objc_list* cell;
                     44: 
                     45:   cell = (struct objc_list*)__objc_xmalloc(sizeof(struct objc_list));
                     46:   cell->head = head;
                     47:   cell->tail = tail;
                     48:   return cell;
                     49: }
                     50: 
                     51: /* Return the length of a list, list_length(NULL) returns zero */
                     52: 
                     53: static inline int
                     54: list_length(struct objc_list* list)
                     55: {
                     56:   int i = 0;
                     57:   while(list)
                     58:     {
                     59:       i += 1;
                     60:       list = list->tail;
                     61:     }
                     62:   return i;
                     63: }
                     64: 
                     65: /* Return the Nth element of LIST, where N count from zero.  If N 
                     66:    larger than the list length, NULL is returned  */
                     67: 
                     68: static inline void*
                     69: list_nth(int index, struct objc_list* list)
                     70: {
                     71:   while(index-- != 0)
                     72:     {
                     73:       if(list->tail)
                     74:        list = list->tail;
                     75:       else
                     76:        return 0;
                     77:     }
                     78:   return list->head;
                     79: }
                     80: 
                     81: /* Remove the element at the head by replacing it by its successor */
                     82: 
                     83: static inline void
                     84: list_remove_head(struct objc_list** list)
                     85: {
                     86:   if ((*list)->tail)
                     87:     {
                     88:       struct objc_list* tail = (*list)->tail; /* fetch next */
                     89:       *(*list) = *tail;                /* copy next to list head */
                     90:       free(tail);                      /* free next */
                     91:     }
                     92:   else                         /* only one element in list */
                     93:     {
                     94:       free (*list);
                     95:       (*list) = 0;
                     96:     }
                     97: }
                     98: 
                     99: 
                    100: /* Remove the element with `car' set to ELEMENT */
                    101: 
                    102: static inline void
                    103: list_remove_elem(struct objc_list** list, void* elem)
                    104: {
                    105:   while (*list) {
                    106:     if ((*list)->head == elem)
                    107:       list_remove_head(list);
                    108:     list = &((*list)->tail);
                    109:   }
                    110: }
                    111: 
                    112: /* Map FUNCTION over all elements in LIST */
                    113: 
                    114: static inline void
                    115: list_mapcar(struct objc_list* list, void(*function)(void*))
                    116: {
                    117:   while(list)
                    118:     {
                    119:       (*function)(list->head);
                    120:       list = list->tail;
                    121:     }
                    122: }
                    123: 
                    124: /* Return element that has ELEM as car */
                    125: 
                    126: static inline struct objc_list**
                    127: list_find(struct objc_list** list, void* elem)
                    128: {
                    129:   while(*list)
                    130:     {
                    131:     if ((*list)->head == elem)
                    132:       return list;
                    133:     list = &((*list)->tail);
                    134:     }
                    135:   return NULL;
                    136: }
                    137: 
                    138: /* Free list (backwards recursive) */
                    139: 
                    140: static void
                    141: list_free(struct objc_list* list)
                    142: {
                    143:   if(list)
                    144:     {
                    145:       list_free(list->tail);
                    146:       free(list);
                    147:     }
                    148: }
1.1.1.2 ! root      149: #endif __GNU_OBJC_LIST_H

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.