/**********************************************************************
 * ti library's routine for reordering nodes
 *
 * $Author: brlewis $
 * $Source: /afs/net.mit.edu/project/net_dev/brlewis/src/lib/RCS/reorder.c,v $
 * $Header: /afs/net.mit.edu/project/net_dev/brlewis/src/lib/RCS/reorder.c,v 0.2 92/04/01 16:18:35 brlewis Exp $
 *
 * Copyright 1991 by the Massachusetts Institute of Technology.
 *
 * For copying and distribution information, please see the file
 * <mit-copyright.h>.
 **********************************************************************/

#include <mit-copyright.h>

#ifndef lint
static char rcsid_ti_reorder_c[] = "$Header: /afs/net.mit.edu/project/net_dev/brlewis/src/lib/RCS/reorder.c,v 0.2 92/04/01 16:18:35 brlewis Exp $";
#endif /* lint */

#include <stdio.h>
#include <string.h>
#include <ti/ti.h>

/**********************************************************************
 * ti_reorder(TI_H hti, long pnid, long cnid1, cnid2, parity)
 *	caller supplies parent and child node id's.
 *
 * - reorders menu pnid by putting cnid2 in the current pos of cnid1
 * - parity determines whether cnid2 should be put above or below
 *   the current pos of cnid1
 * - returns error code
 **********************************************************************/

/* jms 7/9/92 -- windows-izing completed, pending approval */

/* NOTE -- there should probably a bit to select between 'g' and 'j' */

long
ti_reorder(hti, pnid, cnid1, cnid2, parity)
     TI_H hti;
     long pnid, cnid1, cnid2;
     int parity;
{
  long code;
  static char inbuf[BUFSIZ];
  char *format = " :%ld:%ld:%ld\n";

  format[0] = parity ? 'g' : 'j';

  /* send command and receive reply */
  if (code = _ti_talk(hti, inbuf, BUFSIZ-1,
                      format, pnid, cnid1, cnid2))
    return(code);

  /* success? */
  if (!atoi(inbuf)) return(0L);

  /* failure */
  sprintf(ti_context, "%ld/%ld,%ld", pnid, cnid1, cnid2);
  return(_ti_srverr(inbuf));
}



