* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
* This code is derived from software contributed to Berkeley by
* %sccs.include.redist.c%
static char sccsid
[] = "@(#)lstInsert.c 5.3 (Berkeley) %G%";
* Insert a new datum before an old one
*-----------------------------------------------------------------------
* Insert a new node with the given piece of data before the given
* node in the given list.
* the firstPtr field will be changed if ln is the first node in the
*-----------------------------------------------------------------------
Lst l
; /* list to manipulate */
LstNode ln
; /* node before which to insert d */
ClientData d
; /* datum to be inserted */
register ListNode nLNode
; /* new lnode for d */
register ListNode lNode
= (ListNode
)ln
;
register List list
= (List
)l
;
* check validity of arguments
if (LstValid (l
) && (LstIsEmpty (l
) && ln
== NILLNODE
))
if (!LstValid (l
) || LstIsEmpty (l
) || !LstNodeValid (ln
, l
)) {
PAlloc (nLNode
, ListNode
);
nLNode
->useCount
= nLNode
->flags
= 0;
nLNode
->prevPtr
= nLNode
->nextPtr
= nLNode
;
nLNode
->prevPtr
= nLNode
->nextPtr
= NilListNode
;
list
->firstPtr
= list
->lastPtr
= nLNode
;
nLNode
->prevPtr
= lNode
->prevPtr
;
if (nLNode
->prevPtr
!= NilListNode
) {
nLNode
->prevPtr
->nextPtr
= nLNode
;
if (lNode
== list
->firstPtr
) {