/* file cocoon1.c */

#if !defined(COMPILE_ENVIRONMENT)
#include <gp/stdcenvf.h> /* std compile environment for functions */
#endif


char *cocoon(char *sx, char *token)
/*************************************************/
/* Puts *token in a cocoon of quotes if need be  */
/* to protect internal characters that might     */
/* otherwise be mistaken for token boundaries;   */
/* puts result in *sx and returns sx.            */
/*************************************************/
  {
/* if it starts with ", bound it with '  */
   if (*token == '\"')
     {sx = strcpy(sx,"\'");
      sx = strcat(sx,token);
      sx = strcat(sx,"\'");
      goto RETURN;
     }
/* if it starts with ', bound it with "  */
   if (*token == '\'')
     {sx = strcpy(sx,"\"");
      sx = strcat(sx,token);
      sx = strcat(sx,"\"");
      goto RETURN;
     }
/* if it contains a space, bound it with "  */
   if (contains_whitespace(token))
     {sx = strcpy(sx,"\"");
      sx = strcat(sx,token);
      sx = strcat(sx,"\"");
      goto RETURN;
     }
/* otherwise just use as is  */
   sx = strcpy(sx,token);

RETURN:
   return sx;
  }
