xref: /csrg-svn/usr.bin/make/lst.lib/lstMove.c (revision 40411)
1 /*-
2  * LstMove.c --
3  *	Move an existing node after or before one in the same or different
4  *	list.
5  *
6  * Copyright (c) 1988 by University of California Regents
7  *
8  * Permission to use, copy, modify, and distribute this
9  * software and its documentation for any purpose and without
10  * fee is hereby granted, provided that the above copyright
11  * notice appears in all copies.  Neither the University of California nor
12  * Adam de Boor makes any representations about the suitability of this
13  * software for any purpose.  It is provided "as is" without
14  * express or implied warranty.
15  */
16 #ifndef lint
17 static char *rcsid =
18 "$Id: lstMove.c,v 1.6 89/06/13 15:01:48 adam Exp $ SPRITE (Berkeley)";
19 #endif lint
20 
21 #include	"lstInt.h"
22 
23 /*-
24  *-----------------------------------------------------------------------
25  * Lst_Move --
26  *	Move a node after or before a destination node. The nodes do not
27  *	need to be in the same list, of course.
28  *
29  * Results:
30  *	SUCCESS or FAILURE.
31  *
32  * Side Effects:
33  *	The firstPtr and lastPtr fields of either or both of the involved
34  *	lists may be altered to reflect reality.
35  *
36  *-----------------------------------------------------------------------
37  */
38 ReturnStatus
39 Lst_Move (ls, lns, ld, lnd, before)
40     Lst	    	    	ls; 	/* Source list */
41     register LstNode  	lns;	/* source list node */
42     Lst	    	    	ld; 	/* Destination list */
43     register LstNode  	lnd;	/* destination list node */
44     Boolean		before;	/* true if should use Lst_Insert */
45 {
46     ClientData	d;
47     ReturnStatus	rval;
48 
49     if (lns == NILLNODE || lnd == NILLNODE) {
50 	return (FAILURE);
51     }
52 
53     d = ((ListNode)lns)->datum;
54 
55     if (Lst_Remove (ls, lns) == FAILURE) {
56 	return (FAILURE);
57     }
58 
59     if (before == TRUE) {
60 	rval = Lst_Insert (ld, lnd, d);
61     } else {
62 	rval = Lst_Append (ld, lnd, d);
63     }
64 
65     return (rval);
66 }
67 
68