--- ray/src/hd/sm_list.c 1998/08/19 17:45:24 3.1 +++ ray/src/hd/sm_list.c 2003/02/22 02:07:25 3.8 @@ -1,9 +1,6 @@ -/* Copyright (c) 1998 Silicon Graphics, Inc. */ - #ifndef lint -static char SCCSid[] = "$SunId$ SGI"; +static const char RCSid[] = "$Id: sm_list.c,v 3.8 2003/02/22 02:07:25 greg Exp $"; #endif - /* * sm_list.c * Routines for handling linked generic linked lists, stack, and @@ -20,12 +17,11 @@ static LIST *free_lists = NULL; extern int Malloc_cnt; #endif LIST +/* NOTE: Memory is not initialized */ *new_list() { LIST *l; - - /* check free list for available edges */ if( free_lists ) { @@ -38,9 +34,6 @@ LIST if( !(l = (LIST *)malloc(sizeof(LIST)))) error(SYSTEM,"new_list():Unable to allocate memory"); } - /* clear the memory */ - bzero(l, sizeof(LIST)); - return(l); } @@ -52,9 +45,6 @@ LIST *a,*b; { LIST * l; - if(!a) - return(b); - if(!b) return(a); @@ -67,6 +57,40 @@ LIST *a,*b; return(b); } +/* attaches list a at the end of list b */ +LIST +*add_data(l,d,end) +LIST *l; +int d; +LIST **end; + +{ + LIST *list,*lptr; + + list = new_list(); + SET_LIST_DATA(list,d); + SET_LIST_NEXT(list,NULL); + if(!l) + { + if(end) + *end = list; + return(list); + } + if(end) + lptr = *end; + else + { + lptr = l; + while(LIST_NEXT(lptr)) + lptr = LIST_NEXT(lptr); + } + LIST_NEXT(lptr) = list; + if(end) + *end = list; + + return(l); +} + /* Adds data to the end of a circular list. If set, "end" * is a pointer to the last element in the list */ @@ -95,22 +119,8 @@ int d; return(l); } -/* Pushes data element d at the top of the list- returns pointer - to new top of list - */ -LIST -*push_data(l,d) -LIST *l; -int d; -{ - LIST * list; - - list = new_list(); - SET_LIST_DATA(list,d); - SET_LIST_NEXT(list,l); - return(list); -} + /* frees the list */ LIST *free_list(l) @@ -118,11 +128,27 @@ LIST * l; { if(!l) return(NULL); + free_lists = append_list(free_lists,l); return(NULL); } +/* Pushes data element d at the top of the list- returns pointer + to new top of list + */ +LIST +*push_data(l,d) +LIST *l; +int d; +{ + LIST *list; + + list = new_list(); + SET_LIST_DATA(list,d); + SET_LIST_NEXT(list,l); + return(list); +} /* Returns data element d at the top of the list- returns pointer to new top of list */ @@ -131,7 +157,7 @@ pop_list(l) LIST **l; { LIST *p; - void *d; + int d; if(!l) return(NULL); @@ -179,6 +205,10 @@ LIST **list; } return(FALSE); } + + + +