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