/***************************************************************************
 *                                                                         *
 *   STRSREP.C                                                             *
 *                                                                         *
 *   Copyright (c) 1996-1997 Galacticomm, Inc.    All Rights Reserved.     *
 *                                                                         *
 *   Replaces a string in a string with a new string                       *
 *   Pulled from galfilut.c                                                *
 *                                                                         *
 *                                        - D. Pitchford  9/28/93          *
 *                                        - Craig Yap 01/17/96             *
 *                                                                         *
 ***************************************************************************/

#include "gcomm.h"

#define FILREV "$Revision: 2 $"

GBOOL                              /*   returns TRUE if string was found   */
strsrep(                           /* replace a stg in a stg w/ a stg      */
CHAR *stg,                         /*   the string to search               */
CHAR *from,                        /*   the string to be replaced          */
CHAR *to)                          /*   the string to replace with         */
{
     static CHAR rs[400];
     INT loop,len;
     CHAR *o;

     setmem(rs,400,0);
     len=strlen(o=stg);
     if (len >= 200) {
          return(FALSE);
     }
     for (loop=0 ; loop < len ; loop++) {
          if (sameto(from,o)) {
               strcat(rs,to);
               strcat(rs,&o[strlen(from)]);
               strcpy(stg,rs);
               return(TRUE);
          }
          rs[loop]=*o++;
     }
     return(FALSE);
}
