/* file ttp_prep1.c */

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

char *ttp_prep1(char *out, char *in)
/*********************************************/
/* Pre-process input text:                   */
/* change <X>+s to <X>'s                     */
/* lower-case everything                     */
/* replace '-' with space                    */
/* remove punctuation except & and ' and \   */
/* make sure string begins & ends with space */
/*********************************************/
{char *p, *q;
 q = out;
 if (*in != ' ') *q++ = ' ';
 for (p = in; *p != '\0'; p++)
   {if (p > in)
      {if ((*p == '+') && isalpha((int)*(p-1)) && isalpha((int)*(p+1)))
         {*q++ = '\'';  /* "kiska+s" --> kiska's */
          continue;
      }  }
    if (*p == '-')
      {*q++ = ' ';
       continue;
      }
    if ( (!ispunct((int)*p)) ||
          (*p == '\'')  ||
          (*p == '\\')  ||
          (*p == '&'))
       *q++ = tolower(*p);

   }
 if (*(q-1) != ' ')  *q++ = ' ';
 *q = '\0';
 return out;
}
