1 /*
2 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Adam de Boor.
7 *
8 * Redistribution and use in source and binary forms are permitted
9 * provided that the above copyright notice and this paragraph are
10 * duplicated in all such forms and that any documentation,
11 * advertising materials, and other materials related to such
12 * distribution and use acknowledge that the software was developed
13 * by the University of California, Berkeley. The name of the
14 * University may not be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 */
20
21 #ifndef lint
22 static char sccsid[] = "@(#)lstMove.c 5.2 (Berkeley) 03/11/90";
23 #endif /* not lint */
24
25 /*-
26 * LstMove.c --
27 * Move an existing node after or before one in the same or different
28 * list.
29 */
30
31 #include "lstInt.h"
32
33 /*-
34 *-----------------------------------------------------------------------
35 * Lst_Move --
36 * Move a node after or before a destination node. The nodes do not
37 * need to be in the same list, of course.
38 *
39 * Results:
40 * SUCCESS or FAILURE.
41 *
42 * Side Effects:
43 * The firstPtr and lastPtr fields of either or both of the involved
44 * lists may be altered to reflect reality.
45 *
46 *-----------------------------------------------------------------------
47 */
48 ReturnStatus
Lst_Move(ls,lns,ld,lnd,before)49 Lst_Move (ls, lns, ld, lnd, before)
50 Lst ls; /* Source list */
51 register LstNode lns; /* source list node */
52 Lst ld; /* Destination list */
53 register LstNode lnd; /* destination list node */
54 Boolean before; /* true if should use Lst_Insert */
55 {
56 ClientData d;
57 ReturnStatus rval;
58
59 if (lns == NILLNODE || lnd == NILLNODE) {
60 return (FAILURE);
61 }
62
63 d = ((ListNode)lns)->datum;
64
65 if (Lst_Remove (ls, lns) == FAILURE) {
66 return (FAILURE);
67 }
68
69 if (before == TRUE) {
70 rval = Lst_Insert (ld, lnd, d);
71 } else {
72 rval = Lst_Append (ld, lnd, d);
73 }
74
75 return (rval);
76 }
77
78