/**********************************************************************
 * ti library's routine for cleaning up keyword field
 *
 * $Author: brlewis $
 * $Source: /afs/net.mit.edu/project/net_dev/brlewis/src/lib/RCS/ti_kwfix.c,v $
 * $Header: /afs/net.mit.edu/project/net_dev/brlewis/src/lib/RCS/ti_kwfix.c,v 0.1 92/03/12 15:27: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_kwfix_c[] = "$Header: /afs/net.mit.edu/project/net_dev/brlewis/src/lib/RCS/ti_kwfix.c,v 0.1 92/03/12 15:27:35 brlewis Exp $";
#endif /* lint */

#include <ctype.h>
#include <ti/ti.h>

/**********************************************************************
 * ti_kwfix(ti_node *np)
 *	ti_topic(np) should be filled in by user
 *
 * - changes ':' to ','
 * - removes white space around ','
 * - returns error code
 **********************************************************************/

long
ti_kwfix(np)
     ti_node *np;
{
  register char *ptr1, *ptr2;
  char newtopic[256];

  for (ptr1 = ti_topic(np), ptr2 = newtopic;
       *ptr1;
       ptr1++, ptr2++)
    {
      if (isspace(*ptr1))
	{
	  /* skip whitespace before other whitespace or separator */
	  if (isspace(*(ptr1+1)) || *(ptr1+1) == ',' || *(ptr1+1) == ':')
	    {
	      ptr2--;
	      continue;
	    }
	}
      if (*ptr1 == ',' || *ptr1 == ':')
	{
	  *ptr2 = ',';		/* correct separator */
	  if (isspace(*(ptr1+1))) ptr1++;
	  continue;
	}
      *ptr2 = *ptr1;
    }
  *ptr2 = '\0';
  return(ti_settopic(np, newtopic));
}
