/**********************************************************************
 * ti library's routine for replacing a node
 *
 * $Author: brlewis $
 * $Source: /afs/net.mit.edu/project/net_dev/brlewis/src/lib/RCS/replace.c,v $
 * $Header: /afs/net.mit.edu/project/net_dev/brlewis/src/lib/RCS/replace.c,v 0.2 92/04/01 16:19:37 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_replace_c[] = "$Header: /afs/net.mit.edu/project/net_dev/brlewis/src/lib/RCS/replace.c,v 0.2 92/04/01 16:19:37 brlewis Exp $";
#endif /* lint */

#include <stdio.h>
#include <string.h>
#include <ti/ti.h>

/**********************************************************************
 * ti_replace(TI *tp, ti_node *np)
 *	caller fills in appropriate fields of np
 *
 * - returns error code
 **********************************************************************/

long
ti_replace(tp, np)
     TI *tp;
     ti_node *np;
{
  long code;
  char inbuf[BUFSIZ], outbuf[BUFSIZ];

  /* construct techinfo command */
  sprintf(outbuf, "r:%d:%d:0:%s:%s:%s:%s:%s\n", ti_id(np),
	  ti_flags(np)|TI_NRESOLVED, ti_topic(np), ti_title(np),
	  ti_source(np), ti_locker(np), ti_file(np));

  /* send command and receive reply */
  if (code = _ti_talk(tp, outbuf, strlen(outbuf),
		      inbuf, BUFSIZ-1)) return(code);

  /* success? */
  if (!atoi(inbuf)) return(0L);

  /* failure */
  strcpy(ti_context, ti_title(np));
  return(_ti_srverr(inbuf));
}
