-/* Replace the occurrences of PAT with REP in COMMAND.
- This returns a new string; the caller should free it. */
-static char *
-fc_replace (pat, rep, command)
- char *pat, *rep, *command;
-{
- register int i;
- int patlen, replen, templen;
- char *new, *temp;
-
- patlen = strlen (pat);
- replen = strlen (rep);
-
- temp = savestring (command);
- templen = strlen (temp);
- i = 0;
-
- for (; (i + patlen) <= templen; i++)
- {
- if (STREQN (temp + i, pat, patlen))
- {
- new = (char *) xmalloc (1 + (replen - patlen) + templen);
-
- strncpy (new, temp, i);
- strncpy (new + i, rep, replen);
- strncpy (new + i + replen,
- temp + i + patlen, templen - (i + patlen));
- new[templen + (replen - patlen)] = '\0'; /* just in case */
-
- free (temp);
- temp = new;
- i += replen;
- templen = strlen (temp);
- }
- }
- return (temp);
-}
-