From: Patrick M. <ume...@us...> - 2007-05-29 23:17:51
|
Update of /cvsroot/radmind/radmind In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv29985 Modified Files: list.c list.h Log Message: Added list_remove(), list_size() and no longer printing head and tail info in list_print(). Index: list.h =================================================================== RCS file: /cvsroot/radmind/radmind/list.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** list.h 26 Apr 2005 14:48:13 -0000 1.5 --- list.h 29 May 2007 23:17:48 -0000 1.6 *************** *** 18,21 **** --- 18,23 ---- }; + #define list_size( list ) ((list)->l_count) + struct list * list_new( void ); void list_clear( struct list *list ); *************** *** 26,29 **** --- 28,32 ---- int list_insert_head( struct list *list, char *path ); int list_insert_tail( struct list *list, char *path ); + int list_remove( struct list *list, char *path ); void list_remove_head( struct list *list ); void list_remove_tail( struct list *list ); Index: list.c =================================================================== RCS file: /cvsroot/radmind/radmind/list.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** list.c 26 Apr 2005 14:48:13 -0000 1.9 --- list.c 29 May 2007 23:17:48 -0000 1.10 *************** *** 71,84 **** u_int i; - if ( list->l_head != NULL ) { - printf( "head -> %s\n", list->l_head->n_path ); - } else { - printf( "head -> NULL\n" ); - } - if ( list->l_tail != NULL ) { - printf( "tail -> %s\n", list->l_tail->n_path ); - } else { - printf( "tail -> NULL\n" ); - } printf( "count: %d\n", list->l_count ); for ( cur = list->l_head, i = 1; cur != NULL; cur = cur->n_next, i++ ) { --- 71,74 ---- *************** *** 166,169 **** --- 156,190 ---- } + int + list_remove( struct list *list, char *path ) + { + int count = 0; + struct node *cur; + + for ( cur = list->l_head; cur != NULL; cur = cur->n_next ) { + if ( pathcmp( cur->n_path, path ) == 0 ) { + + if ( list->l_head == cur ) { + list_remove_head( list ); + count++; + + } else if ( list->l_tail == cur ) { + list_remove_tail( list ); + count++; + + } else { + /* Remove item */ + cur->n_prev->n_next = cur->n_next; + cur->n_next->n_prev = cur->n_prev; + free( cur ); + list->l_count--; + count++; + } + } + } + + return( count ); + } + void list_remove_tail( struct list *list ) |