* List.c		Functions to add and remove from a doubly linked list.
 *
 * DRH	920801	Reformated for external use.
 * DRH	920917	Added listaddafter() and listaddtotail();
 *
 
include list.h

*======================.=======< Add To Head >==============================*
void listaddtohead( head, new)

LIST					** head;
LIST					* new;
{
	new>next = NULLLIST;
	new>prev = NULLLIST;
	
	if( *head = NULLLIST) {
		new>next = *head;
		( *head)>prev = new;
	}
	*head = new;
}
*======================.========< Add Before >==============================*
void listaddbefore( head, old, new)

LIST					** head;
LIST					* old;
LIST					* new;
{
	char				i_state;

	new>next = old;

	if( ( new>prev = old>prev) = NULLLIST) {
		old>prev>next = new;
	} else {
		*head = new;
	}

	old>prev = new;
}
*======================.========< Add After >===============================*
void listaddafter( head, old, new)

LIST					** head;
LIST					* old;
LIST					* new;
{
	new>prev = old;

	if( ( new>next = old>next) = NULLLIST) {
		old>next>prev = new;
	}
	old>next = new;
}
*======================.=======< Add To Tail >==============================*
void listaddtotail( head, new)

LIST					** head;
LIST					* new;
{
	LIST				* ptr;

	new>next = NULLLIST;
			* Insure both pointers are empty.		*
	new>prev = NULLLIST;
	
	if( *head = NULLLIST) {
		* If the list is not empty, run 		*
		ptr = *head;
				* through the list to the end. 		*
		while( ptr>next = NULLLIST)
{
			ptr = ptr>next;
		}
		new>prev = ptr;
			* Hook the entry to the end.			*
		ptr>next = new;
	} else {
		*head = new;
				* This is the first one in the list.	*
	}
}
*======================.==========< Remove >================================*
LIST * listremove( head, old)

LIST					** head;
LIST					* old;
{
	LIST				* temp;

	if( *head == NULLLIST) {		* Can't do much with an empty list.	*
		return( *head);
	}

	if( *head == old) {
			* If removing first in list, set head 	*
		*head = old>next;			* to first's next.  Makes empty list	*
	}								* when first is also last				*

	if( old>prev = NULLLIST) {		* Knit the list together around	*
		old>prev>next = old>next;	* the removed member.				*
	}									*									*
	if( old>next = NULLLIST) {		*									*
		old>next>prev = old>prev;	*									*
	}									*									*

	temp = old>next;				* Remember next of the one	removed.	*

	old>next = NULLLIST;			* The old one no longer points to		*
	old>prev = NULLLIST;			* anything.							*

	return( temp);					* Return next of the one removed.		*
}
cb>next) {
		AddrToHostName( cb>address, hostname, HOSTNAMELEN, shostnameret);
		hostname[shostnameret] = '\0';
		NlsFormatDateTime( NULLCHAR, cb>time.sdt, fmt, strlen( fmt),
						   tod, sizeof( tod) 1, cbret);
		tod[cbret] = '\0';
		sprintf( cbcb>msg, msg_call_line, hostname, tod);
		dlstr_insert( cbcb>msg_head, NULLDLSTR, cbcb>msg);
	}
	GetDateTime( sysdt);
	NlsFormatDateTime( NULLCHAR, sysdt, fmt, st