home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-09-19 | 14.4 KB | 75 lines | [TEXT/R*ch] |
- /************************************************************************
- *************************************************************************
- ** **
- ** Generic List Library **
- ** **
- ** by Keith Pomakis **
- ** kppomaki@jeeves.uwaterlo !(*fn)(element->pointer, args)) {
- element = element->previous;
- }
-
- if (element->pointer)
- list.info->current = element;
-
- return element->pointer;
- }
-
- /****************************************************************************/
-
- Generic_list
- all_such_that(Generic_list list,
- int (*fn)(const void *pointer, const void *args),
- const void *args)
- {
- Generic_list list_copy;
- Generic_list_element *element;
-
- initialize_sorted_list(&list_copy, list.info->lt);
- element = list.info->pre_element.next;
- while (element != &list.info->post_element) {
- if ((*fn)(element->pointer, args))
- add_to_end(list_copy, element->pointer);
- element = element->next;
- }
-
- return list_copy;
- }
-
- /****************************************************************************/
-
- void
- remove_all_such_that(Generic_list list,
- int (*fn)(const void *pointer, const void *args),
- const void *args)
- {
- void *obj;
-
- reset_to_beginning(list);
- while (obj = next_in_list(list))
- if ((*fn)(obj, args))
- remove_current(list);
- }
-
-
-
- /****************************************************************************/
- /****************************************************************************/
- /** **/
- /** Internal functions **/
- /** **/
- /****************************************************************************/
- /****************************************************************************/
-
- static void *
- emalloc(unsigned int n)
- {
- void *ptr;
-
- ptr = (void *) malloc(n);
- if ( ptr == NULL ) {
- fprintf(stderr,"%s: error allocating memory\n", module);
- exit(EXIT_FAILURE);
- }
- return ptr;
- }
-