0a1,2
> #ifndef _LIST_H
> #define _LIST_H
2c4,5
< #include "list_defs.h"
---
> #include <stdio.h>
> #include <stdlib.h>
4,10c7,11
< extern LIST_PTR		*list_insert(LIST_PTR *l, void *data, int id);
< extern LIST_PTR		*list_reset(LIST_PTR *l);
< extern LIST_PTR		*list_remove(LIST_PTR *l, void *data);
< extern LIST_PTR		*list_done(LIST_PTR *l);
< extern void		*list_next(LIST_PTR *l);
< extern void		*list_find(LIST_PTR *l, int id);
< extern void		list_display(LIST_PTR *l);
---
> typedef struct LIST_REC {
> 	int		id;
> 	void		*data;
> 	struct LIST_REC	*next;
> } LIST_REC;
11a13,280
> typedef struct LIST_PTR {
> 	int		size;
> 	LIST_REC	*start;
> 	LIST_REC	*last;
> 	LIST_REC	*current;
> } LIST_PTR;
> 
> /*extern*/ LIST_PTR* list_insert(LIST_PTR* l, void *data, int id);
> /*extern*/ LIST_PTR* list_reset(LIST_PTR* l);
> /*extern*/ LIST_PTR* list_remove(LIST_PTR* l, void *data);
> /*extern*/ LIST_PTR* list_done(LIST_PTR* l);
> /*extern*/ void* list_next(LIST_PTR* l);
> /*extern*/ void* list_find(LIST_PTR* l, int id);
> /*extern*/ void list_display(LIST_PTR* l);
> 
> extern inline LIST_PTR* list_reset(LIST_PTR* l) {
> 	if (l == NULL) {
> 		return(NULL);
> 	} else if (l->start == NULL) {
> 		printf("\n\nERROR: list_reset(): l->start == NULL\n\n");
> 		exit(-2);
> 	} else {
> 		l->current = l->start;
> 		return(l);
> 	}
> 	printf("\n\nERROR: list_reset(): Reached procedure end without returning ...\n\n");
> 	exit(-2);
> }
> 
> extern inline LIST_PTR* list_insert(LIST_PTR* l, void *data, int id) {
> 	LIST_REC	*new, *tmp;
> 
> 	// create new list element
> 	new = (LIST_REC *)malloc(sizeof(LIST_REC));
> 	if (new == NULL) {
> 		printf("\n\nERROR: list_insert(): Could not allocate new LIST_REC structure\n");
> 		exit(-2);
> 	}
> 	new->id = id;
> 	new->data = data;
> 	new->next = NULL;
> 
> 	// if list is NULL, create new list with new element as only element
> 	if (l == NULL) {
> 		l = (LIST_PTR* )malloc(sizeof(LIST_PTR));
> 		if (l == NULL) {
> 			printf("\n\nERROR: list_insert(): Could not allocate new LIST_PTR structure\n");
> 			exit(-2);
> 		}
> 		l->start = new;
> 		l->last = new;
> 		l->current = new;
> 		l->size = 1;
> 		return(l);
> 	}  else if (l->start == NULL) {
> 		printf("\n\nERROR: list_insert(): l->start == NULL\n");
> 		exit(-2);
> 	}
> 
> 	// NEW FIRST ITEM
> 	if (l->start->id > new->id) {
> 		new->next = l->start;
> 		l->start = new;
> 		l->current = new;
> 		l->size++;
> 		return(l);
> 	}
> 
> 	// NEW LAST ITEM
> 	if (l->last->id <= new->id) {
> 		l->last->next = new;
> 		l->last = new;
> 		l->current = new;
> 		l->size++;
> 		return(l);
> 	}
> 
> 	// NEW MIDDLE ITEM
> 	// Use appropriate starting point; current or start
> 	if (l->current != NULL) {
> 		if (l->current->id <= new->id) {
> 			tmp = l->current;
> 		} else {
> 			tmp = l->start;
> 		}
> 	} else {
> 		tmp = l->start;
> 	}
> 	while (tmp != l->last) {
> 		if (tmp->next->id > new->id) {
> 			new->next = tmp->next;
> 			tmp->next = new;
> 			l->current = new;
> 			l->size++;
> 			return(l);
> 		}
> 		tmp = tmp->next;
> 	}
> 	printf("\n\nERROR: list_insert(): Reached procedure end without returning ...\n\n");
> 	exit(-2);
> }
> 
> extern inline void* list_next(LIST_PTR* l) {
> 	void	*tmp;
> 
> 	if (l == NULL) {
> 		return(NULL);
> 	} else if (l->current == NULL) {
> 		return(NULL);
> 	} else {
> 		tmp = l->current->data;
> 		l->current = l->current->next;
> 		return(tmp);
> 	}
> }
> 
> extern inline void* list_find(LIST_PTR* l, int id) {
> 	LIST_REC	*tmp;
> 
> 	if (l == NULL) {
> 		return(NULL);
> 	} else if (l->start == NULL) {
> 		return(NULL);
> 	} else {
> 		// Use appropriate starting point; current or start
> 		if (l->current != NULL) {
> 			if (l->current->id <= id) {
> 				tmp = l->current;
> 			} else {
> 				tmp = l->start;
> 			}
> 		} else {
> 			tmp = l->start;
> 		}
> 		while (tmp != NULL) {
> 			if (tmp->id==id) {
> 				l->current = tmp;
> 				return(tmp->data);
> 			}
> 			tmp = tmp->next;
> 		}
> 		return(NULL);
> 	}
> }
> 
> extern inline LIST_PTR* list_remove(LIST_PTR* l, void *data)
> {
> 	LIST_REC* tmp = NULL;
> 	LIST_REC* tmpNextNext = NULL;
> 
> 	if (l == NULL) {
> 		return(NULL);
> 	} else if (l->start == NULL) {
> 		printf("\n\nERROR: list_remove(): l->start == NULL\n");
> 		exit(-2);
> 	} else {
> 		if (l->current == NULL) {
> 			l->current = l->start;			// reset current if needed
> 		}
> 		if (l->current->data == data) {
> 			l->current = l->start;			// prevent current from being trashed
> 		}
> 		if (l->start->data == data) {			// first item
> 			if (l->size == 1) {
> 				l->size--;
> 				free(l->start);
> 				free(l);
> 				l = NULL;
> 				return(l);
> 			} else {
> 				tmp = l->start;
> 				l->start = l->start->next;
> 				l->current = l->start;
> 				l->size--;
> 				free(tmp);
> 				return(l);
> 			}
> 		} else if (l->last->data == data) { 		// last item
> 			tmp = l->start;
> 			while (tmp->next != l->last) {
> 				tmp = tmp->next;
> 			}
> 			l->size--;
> 			l->last = tmp;
> 			l->current = tmp;
> 			free(tmp->next);
> 			tmp->next = NULL;
> 			return(l);
> 		} else { 					// middle item
> 			tmp = l->start;
> 			while (tmp != l->last)
> 			{
> 				if (tmp->next->data == data)
> 				{
> 					l->size--;
> 					// steve dickson's original code with memory error
> 					// tmp2 = tmp->next;
> 					// free(tmp2);
> 					// tmp->next = tmp->next->next;
> 
> 					// corrected code
> 					tmpNextNext = tmp->next->next;
> 					free(tmp->next);
> 					// tmp->next = NULL
> 					tmp->next = tmpNextNext;
> 					return(l);
> 				}
> 				tmp = tmp->next;
> 			}
> 			return(l);
> 		}
> 	}
> 	printf("\n\nERROR: list_remove(): Reached procedure end without returning ...\n\n");
> 	exit(-2);
> }
> 
> extern inline void list_display(LIST_PTR* l) {
> 	LIST_REC	*tmp;
> 
> 	if (l == NULL) {
> 		printf("\n  list->size: %d - EMPTY LIST", 0);
> 		return;
> 	} else if (l->start == NULL) {
> 		printf("\n\nERROR: list_display(): l->start == NULL\n");
> 		exit(-2);
> 	} else {
> 		printf("\n  list->size: %d", l->size);
> 		printf("\n  Element Start Last Current");
> 		tmp = l->start;
> 		while (tmp != NULL) {
> 			printf("\n%6d %6d %6d", tmp->id, l->start->id, l->last->id);
> 			if (l->current == NULL) {
> 				printf(" NULL ");
> 			} else {
> 				printf(" %6d ", l->current->id);
> 			}
> 			tmp = tmp->next;
> 		}
> 	}
> }
> 
> extern inline LIST_PTR* list_done(LIST_PTR* l) {
> 	LIST_REC	*tmp;
> 
> 	if (l == NULL) {
> 		return(NULL);
> 	} else if (l->start == NULL) {
> 		printf("\n\nERROR: list_done(): l->start == NULL\n\n");
> 		exit(-2);
> 	} else {
> 		while (l->start->next != NULL) {
> 			tmp = l->start->next;
> 			l->start->next = tmp->next;
> 			free(tmp); tmp = NULL;
> 		}
> 		// ADDED FOR MEMORY LEAK 17/01/97
> 		free(l->start); l->start = NULL;
> 		free(l->current); l->current = NULL;
> 		free(l->last); l->last = NULL;
> 		// END ADDITION
> 		free(l); l = NULL;
> 		return(l);
> 	}
> 	printf("\n\nERROR: list_done(): Reached procedure end without returning ...\n\n");
> 	exit(-2);
> }
> 
> #endif
