/*static char *SCCSID = "@(#)mkfirst.c	6.2 92/01/31";*/
#include <os2.h>
#include "const.h"
#include "misc.h"
#include "chain.h"
#include "buf.h"
#include "dir.h"
#include "storage.h"
#include "volume.h"
#include "frame.h"
#include "tables.h"
#include "pr_MISC.h"


/*
 ***	MakeFirst - moves the node in question to the beginning of the
 *		sibling chain.  The actual result is that the node to
 *		move is inserted in the chain before the head pointer.
 *		Thus, before calling this function, you should check to
 *		see if the node you're trying to move is last.  In this
 *		case you should just reassign where head is rather than
 *		calling this routine.
 *
 *	ENTRY	psbdHead - pointer to 1st node.
 *		psbdToMove - pointer to the sibling that is in the chain.
 *
 *	EXIT	None
 */

void
MakeFirst (pdcpHead, pdcpToMove)
PDOUBLYCHAINEDNEARPTRS pdcpHead;    /* parent subdir struct */
PDOUBLYCHAINEDNEARPTRS pdcpToMove;  /* kid to move to front of chain */
{
	/*
	 * If the kid is not last then do the big move, otherwise we
	 * can simply adjust the parent's pointer to point to the kid.
	 */
	if (pdcpToMove -> pFwd != pdcpHead) {

		/* take tomove node out of chain */
		((PDOUBLYCHAINEDNEARPTRS) (pdcpToMove -> pFwd)) -> pBak =
			pdcpToMove -> pBak;
		((PDOUBLYCHAINEDNEARPTRS) (pdcpToMove -> pBak)) -> pFwd =
			pdcpToMove -> pFwd;

		/* put node before head */
		((PDOUBLYCHAINEDNEARPTRS) (pdcpHead -> pBak)) -> pFwd = pdcpToMove;
		pdcpToMove -> pBak = pdcpHead -> pBak;
		pdcpToMove -> pFwd = pdcpHead;
		pdcpHead -> pBak = pdcpToMove;
	}
}
