Beispiel #1
0
static Nlm_CharPtr Nlm_FindSubString (const char FAR *str, const char FAR *sub,
                                      Nlm_Boolean caseCounts)

{
  int      ch;
  int      d [256];
  int      i;
  int      j;
  int      k;
  size_t   strLen;
  size_t   subLen;

  if (sub != NULL && sub [0] != '\0' && str != NULL && str [0] != '\0') {
    strLen = Nlm_StringLen (str);
    subLen = Nlm_StringLen (sub);
    if (subLen <= strLen) {
      for (ch = 0; ch < 256; ch++) {
        d [ch] = subLen;
      }
      for (j = 0; j < (int)(subLen - 1); j++) {
        ch = (int) (caseCounts ? sub [j] : TO_UPPER (sub [j]));
        if (ch >= 0 && ch <= 255) {
          d [ch] = subLen - j - 1;
        }
      }
      i = subLen;
      do {
        j = subLen;
        k = i;
        do {
          k--;
          j--;
        } while (j >= 0 &&
                 (caseCounts ? sub [j] : TO_UPPER (sub [j])) ==
                 (caseCounts ? str [k] : TO_UPPER (str [k])));
        if (j >= 0) {
          ch = (int) (caseCounts ? str [i - 1] : TO_UPPER (str [i - 1]));
          if (ch >= 0 && ch <= 255) {
            i += d [ch];
          } else {
            i++;
          }
        }
      } while (j >= 0 && i <= (int) strLen);
      if (j < 0) {
        i -= subLen;
        return (Nlm_CharPtr) (str + i);
      }
    }
  }
  return NULL;
}
Beispiel #2
0
NLM_EXTERN Nlm_Boolean Nlm_SetupSubString (
  const char FAR *sub,
  Nlm_Boolean caseCounts,
  Nlm_SubStringData PNTR data
)

{
  int     ch;
  int     j;
  size_t  subLen;

  if (data == NULL) return FALSE;
  MemSet ((Nlm_VoidPtr) data, 0, sizeof (Nlm_SubStringData));
  if (sub == NULL || sub [0] == '\0') return FALSE;

  subLen = Nlm_StringLen (sub);

  for (ch = 0; ch < 256; ch++) {
    data->d [ch] = subLen;
  }
  for (j = 0; j < (int)(subLen - 1); j++) {
    ch = (int) (caseCounts ? sub [j] : TO_UPPER (sub [j]));
    if (ch >= 0 && ch <= 255) {
      data->d [ch] = subLen - j - 1;
    }
  }

  data->subLen = subLen;
  data->caseCounts = caseCounts;
  data->initialized = TRUE;
  data->sub = sub;

  return TRUE;
}
Beispiel #3
0
NLM_EXTERN Nlm_CharPtr LIBCALL Nlm_text2stream(const Nlm_Char FAR PNTR str)
{
  int on_space = 0;
  Nlm_CharPtr line, s;

  if ( !str )
    return NULL;

  while (*str  &&  IS_WHITESP( *str ))
    str++;
  if ( !*str )
    return NULL;

  s = line = (Nlm_CharPtr) Nlm_MemNew(Nlm_StringLen(str) + 1);

  for (  ;  *str;  str++)
    {
      if ( IS_WHITESP(*str) )
        {
          if (*str == '\n')
            *s = '\n';
          on_space = 1;
        }
      else
        {
          if ( on_space ) {
            if (*s == '\n'  &&
                s - line > 1  &&  *(s-1) == '-'  &&  IS_ALPHA(*(s-2)))
              {
                *s = '\0';
                s--;  /* eat dash before end-of-line, merge the broken word */
              }
            else
              *s++ = SPACE;

            *s++ = *str;
            on_space = 0;
          }
          else
            *s++ = *str;
        }
    }
  *s = '\0';

  return (Nlm_CharPtr) realloc(line, Nlm_StringLen(line) + 1);
}
Beispiel #4
0
NLM_EXTERN Nlm_Boolean LIBCALL  Nlm_CreateDir (Nlm_CharPtr pathname)
{
#ifndef OS_VMS
  size_t          len;
  Nlm_Char        path[PATH_MAX];
#endif
#ifdef OS_UNIX
  mode_t          oldmask;
#endif
  Nlm_Boolean     rsult = FALSE;

  if (pathname != NULL && pathname [0] != '\0') {
#if defined(OS_MSWIN) || defined(OS_NT)
    Nlm_StringNCpy_0(path, pathname, sizeof(path));
    len = Nlm_StringLen (path);
    if (len > 0 && path [len - 1] == DIRDELIMCHR) {
        path [len - 1] = '\0';
    }
    rsult = (Nlm_Boolean) (mkdir ((char *) path) == 0);
    if (errno == EACCES) { /* it's O.K. if it was already there */
	rsult = TRUE;
    }
#endif
#ifdef OS_UNIX
    oldmask = umask (0000);
    Nlm_StringNCpy_0(path, pathname, sizeof(path));
    len = Nlm_StringLen (path);
    if (len > 0 && path [len - 1] == DIRDELIMCHR) {
        path [len - 1] = '\0';
    }
    rsult = (Nlm_Boolean) (mkdir ((char *) path, 0755) == 0);
    if (errno == EEXIST) { /* it's O.K. if it was already there */
	rsult = TRUE;
    }
    umask (oldmask);
#endif
#ifdef OS_VMS
    rsult = (Nlm_Boolean) (mkdir ((char *) pathname, 0755) == 0);
#endif
  }
  return rsult;
}
Beispiel #5
0
NLM_EXTERN Nlm_CharPtr LIBCALL  Nlm_StrSave (const char FAR *from)
{
	size_t len;
	Nlm_CharPtr to;

	len = Nlm_StringLen(from);
	if ((to = (Nlm_CharPtr) Nlm_MemGet(len +1, FALSE)) != NULL) {
    	Nlm_MemCpy (to, from, len +1);
	}
	return to;
}
Beispiel #6
0
NLM_EXTERN Nlm_CharPtr LIBCALL SkipPastString(char FAR *theString,char FAR *Find)
/* returns a pointer to the next character after the leftmost
   instance of Find in theString, or to the trailing NULL if none found. */
{
  Nlm_CharPtr Ptr = SkipToString(theString,Find);

  if (*Ptr == '\0')
    return (Ptr);

  return (Ptr + Nlm_StringLen(Find));
}
Beispiel #7
0
NLM_EXTERN size_t Nlm_stream2text(const Nlm_Char FAR PNTR str, size_t max_col,
                                  int PNTR dash)
{
  const Nlm_Char FAR PNTR s;
  const Nlm_Char FAR PNTR sb; /* the nearest breakable position */
  size_t n_lead = 0;
  size_t n_tail = 0;

  size_t len = Nlm_StringLen( str );
  len = max_col < len ? max_col : len;

  *dash = 0;
  if (len == 0  ||  can_break(str[len-1], str[len]))
    return len;

  /* go to the beginning of the last completely fit word */
  for (sb = &str[len-1];
       sb != str  &&  !IS_WHITESP(*sb)  &&  !can_break(*sb, *(sb+1));
       sb--) continue;
  while (sb != str  &&  IS_WHITESP(*sb))
    sb--;

  if (sb == str)
    { /* the first word is longer than "max_col" */
      if (len > MAX_NO_DASH  &&  IS_ALPHA(str[len-1])  &&  IS_ALPHA(str[len]))
        *dash = 1;  /* recommend use dash in the place of last symbol */

      return len;
    }

  /* decide of whether and how to break the last alphabet word */

  /*  count the lead and the tail of the last non-fit word */
  for (s = &str[len];  *s != '\0'  &&  IS_ALPHA(*s);  s++, n_tail++) continue;
  for (s = &str[len-1];  IS_ALPHA(*s);  s--, n_lead++) continue;
  ASSERT ( s > str );

  /* try to "move" symbols from lead in the sake of tail */
  while (n_lead > MIN_LEAD  &&  n_tail < MIN_TAIL)  {
    n_lead--;
    n_tail++;
  }

  if (n_lead < MIN_LEAD  ||  n_tail < MIN_TAIL)
    { /* no luck this time -- move the whole non-fit word to the next line */
      return (sb - str + 1);
    }
  else
    {
      *dash = 1;
      return (s - str + n_lead + 1);
    }
}
Beispiel #8
0
NLM_EXTERN Nlm_CharPtr Nlm_SearchSubString (
  const char FAR *str,
  Nlm_SubStringData PNTR data
)

{
  Nlm_Boolean     caseCounts;
  int             ch;
  int             i;
  int             j;
  int             k;
  size_t          strLen;
  size_t          subLen;
  const char FAR  *sub;

  if (str == NULL || str [0] == '\0') return NULL;
  if (data == NULL || ! data->initialized) return NULL;

  strLen = Nlm_StringLen (str);
  subLen = data->subLen;
  if (strLen < subLen) return NULL;

  caseCounts = data->caseCounts;
  sub = data->sub;
  if (sub == NULL || sub [0] == '\0') return NULL;

  i = subLen;
  do {
	j = subLen;
	k = i;
	do {
	  k--;
	  j--;
	} while (j >= 0 &&
			 (caseCounts ? sub [j] : TO_UPPER (sub [j])) ==
			 (caseCounts ? str [k] : TO_UPPER (str [k])));
	if (j >= 0) {
	  ch = (int) (caseCounts ? str [i - 1] : TO_UPPER (str [i - 1]));
	  if (ch >= 0 && ch <= 255) {
		i += data->d [ch];
	  } else {
		i++;
	  }
	}
  } while (j >= 0 && i <= (int) strLen);
  if (j < 0) {
	i -= subLen;
	return (Nlm_CharPtr) (str + i);
  }

  return NULL;
}
Beispiel #9
0
/*****************************************************************************
*
*   FilePathFind()
*
*****************************************************************************/
NLM_EXTERN Nlm_CharPtr LIBCALL Nlm_FilePathFind(const Nlm_Char* fullname)
{
  Nlm_CharPtr str;
  size_t	     len = Nlm_StringLen(fullname);
  if ( !len )
    return 0;

  while (len  &&  fullname[len] != DIRDELIMCHR)
    len--;

  str = (Nlm_Char*)Nlm_MemGet(len + 1, MGET_ERRPOST);
  Nlm_MemCpy(str, fullname, len);
  str[len] = '\0';
  return str;
}
Beispiel #10
0
/*****************************************************************************
*
*   FileNameFind()
*
*****************************************************************************/
NLM_EXTERN Nlm_CharPtr LIBCALL Nlm_FileNameFind (Nlm_CharPtr pathname)

{
  Nlm_CharPtr  filename;
  Nlm_Int2     len;

  if (pathname != NULL) {
    len = Nlm_StringLen (pathname);
    filename = &(pathname [len]);
    while (len > 0 && pathname [len - 1] != DIRDELIMCHR) {
      len--;
      filename--;
    }
    return filename;
  } else {
    return NULL;
  }
}
Beispiel #11
0
extern Nlm_Boolean Nlm_StrToDouble (Nlm_CharPtr str, Nlm_FloatHiPtr doubleval)

{
  Nlm_Char     ch;
  Nlm_Int2     i;
  Nlm_Int2     len;
  Nlm_Char     local [64];
  Nlm_Boolean  nodigits;
  Nlm_Boolean  rsult;
  double       val;

  rsult = FALSE;
  if (doubleval != NULL) {
    *doubleval = (Nlm_FloatHi) 0;
  }
  len = (Nlm_Int2) Nlm_StringLen (str);
  if (len != 0) {
    rsult = TRUE;
    nodigits = TRUE;
    for (i = 0; i < len; i++) {
      ch = str [i];
      if (ch == '+' || ch == '-' || ch == '.' || ch == 'E' || ch == 'e') {
      } else if (ch < '0' || ch > '9') {
        rsult = FALSE;
      } else {
        nodigits = FALSE;
      }
    }
    if (nodigits) {
      rsult = FALSE;
    }
    if (rsult && doubleval != NULL) {
      Nlm_StringNCpy_0 (local, str, sizeof (local));
      for (i = 0; i < len; i++) {
        local [i] = TO_UPPER (local [i]);
      }
      if (sscanf (local, "%lf", &val) == 1) {
        *doubleval = val;
      }
    }
  }
  return rsult;
}
Beispiel #12
0
NLM_EXTERN Nlm_Int4 LIBCALL CountStrings(char FAR *theString, char FAR *Find)
/*  This returns the number of non-overlapping instances of Find
    in theString. */
{
  Nlm_Int4 count = 0;
  Nlm_Int4 Len = Nlm_StringLen(Find);
  Nlm_CharPtr Ptr = theString;

  for(;;)
    {
      Ptr = SkipToString(Ptr,Find);
      if (*Ptr == NULLB)
        break;

      count++;
      Ptr += Len;
    }

  return count;
}
Beispiel #13
0
extern Nlm_Boolean Nlm_StrToPtr (Nlm_CharPtr str, Nlm_VoidPtr PNTR ptrval)

{
  Nlm_Char     ch;
  Nlm_Int2     i;
  Nlm_Int2     len;
  Nlm_Char     local [64];
  Nlm_Boolean  nodigits;
  Nlm_Boolean  rsult;
  long         val;

  rsult = FALSE;
  if (ptrval != NULL) {
    *ptrval = NULL;
  }
  len = (Nlm_Int2) Nlm_StringLen (str);
  if (len != 0) {
    rsult = TRUE;
    nodigits = TRUE;
    for (i = 0; i < len; i++) {
      ch = str [i];
      if (ch == ' ') {
      } else if (ch < '0' || ch > '9') {
        rsult = FALSE;
      } else {
        nodigits = FALSE;
      }
    }
    if (nodigits) {
      rsult = FALSE;
    }
    if (rsult && ptrval != NULL) {
      Nlm_StringNCpy_0 (local, str, sizeof (local));
      if (sscanf (local, "%ld", &val) == 1) {
        *ptrval = (Nlm_VoidPtr) val;
      }
    }
  }
  return rsult;
}
Beispiel #14
0
extern Nlm_Boolean Nlm_StrToInt (Nlm_CharPtr str, Nlm_Int2Ptr intval)

{
  Nlm_Char     ch;
  Nlm_Int2     i;
  Nlm_Int2     len;
  Nlm_Char     local [64];
  Nlm_Boolean  nodigits;
  Nlm_Boolean  rsult;
  int          val;

  rsult = FALSE;
  if (intval != NULL) {
    *intval = (Nlm_Int2) 0;
  }
  len = (Nlm_Int2) Nlm_StringLen (str);
  if (len != 0) {
    rsult = TRUE;
    nodigits = TRUE;
    for (i = 0; i < len; i++) {
      ch = str [i];
      if (ch == ' ' || ch == '+' || ch == '-') {
      } else if (ch < '0' || ch > '9') {
        rsult = FALSE;
      } else {
        nodigits = FALSE;
      }
    }
    if (nodigits) {
      rsult = FALSE;
    }
    if (rsult && intval != NULL) {
      Nlm_StringNCpy_0 (local, str, sizeof (local));
      if (sscanf (local, "%d", &val) == 1) {
        *intval = (Nlm_Int2) val;
      }
    }
  }
  return rsult;
}
Beispiel #15
0
Boolean LIBCALL StrToInt4 (CharPtr str, Int4Ptr longval)
{
  Nlm_Char     ch;
  Nlm_Int2     i;
  Nlm_Int2     len;
  Nlm_Char     local [64];
  Nlm_Boolean  nodigits;
  Nlm_Boolean  rsult;
  long int     val;

  rsult = FALSE;
  if (longval != NULL) {
    *longval = (Nlm_Int4) 0;
  }
  len = (Nlm_Int2) Nlm_StringLen (str);
  if (len != 0) {
    rsult = TRUE;
    nodigits = TRUE;
    for (i = 0; i < len; i++) {
      ch = str [i];
      if (ch == ' ' || ch == '+' || ch == '-') {
      } else if (ch < '0' || ch > '9') {
        rsult = FALSE;
      } else {
        nodigits = FALSE;
      }
    }
    if (nodigits) {
      rsult = FALSE;
    }
    if (rsult && longval != NULL) {
      Nlm_StringNCpy (local, str, sizeof (local));
      if (sscanf (local, "%ld", &val) == 1) {
        *longval = val;
      }
    }
  }
  return rsult;
}
Beispiel #16
0
static void Nlm_FileCacheReadBlock (
  Nlm_FileCache PNTR fcp
)

{
  int  total;

  if (fcp == NULL || fcp->fp == NULL) return;

  if (fcp->ctr >= fcp->total) {
    fcp->offset += (Nlm_Int4) fcp->total;
    fcp->ctr = 0;
    fcp->total = 0;

    fcp->buf [0] = '\0';
    total = (int) Nlm_FileRead ((Nlm_VoidPtr) fcp->buf, sizeof (Nlm_Char), (size_t) 512, fcp->fp);
    if (total < 0 || total > 512) {
      total = 512;
    }

    fcp->buf [total] = '\0';
    fcp->total = Nlm_StringLen (fcp->buf);
  }
}
Beispiel #17
0
NLM_EXTERN Nlm_CharPtr LIBCALL Nlm_rule_line(const Nlm_Char FAR PNTR str,
                                             size_t len,
                                             enumRuleLine method)
{
  size_t str_len;
  size_t n_space;

  /* allocate and initialize the resulting string */
  Nlm_CharPtr s = (Nlm_CharPtr) Nlm_MemNew(len + 1);
  Nlm_MemSet(s, SPACE, len);
  s[len] = '\0';

  /* skip leading and trailing spaces */
  while ( IS_WHITESP(*str) )
    str++;
  if ( !*str )
    return s;
  for (str_len = Nlm_StringLen( str );  IS_WHITESP(str[str_len-1]); str_len--) continue;


  /* truncate the original string if doesn't fit */
  if (len <= str_len) {
    x_memcpy(s, str, len);
    return s;
  }

  n_space = len - str_len;
  switch ( method )
    {
    case RL_Left:
      {
        x_memcpy(s, str, str_len);
        break;
      }
    case RL_Right:
      {
        x_memcpy(s + n_space, str, str_len);
        break;
      }
    case RL_Spread:
      {
        size_t n_gap = 0;

        int prev_space = 0;
        const Nlm_Char FAR PNTR _str = str;
        size_t i = str_len;
        for ( ;  i--;  _str++)
          {
            ASSERT ( *_str );
            if ( IS_WHITESP(*_str) )
              {
                if ( !prev_space ) {
                  n_gap++;
                  prev_space = 1;
                }
                n_space++;
              }
            else
              prev_space = 0;
          }
        ASSERT ( !prev_space );

        if ( n_gap )
          {
            size_t n_div = n_space / n_gap;
            size_t n_mod = n_space % n_gap;

            Nlm_CharPtr _s = s;
            for (_str = str;  *_str; )
              {
                if ( !IS_WHITESP( *_str ) )
                  *_s++ = *_str++;
                else if ( n_space )
                  {
                    size_t n_add = n_div;
                    if (n_mod > 0) {
                      n_add++;
                      n_mod--;
                    }
                    n_space -= n_add;
                    while ( n_add-- )
                      *_s++ = SPACE;

                    for (_str++;  IS_WHITESP(*_str);  _str++) continue;
                  }
                else
                  break;
              }
            ASSERT ( _s == s + len );
            break;
          }  /* else -- use RL_Center */
      }

    case RL_Center:
      {
        x_memcpy(s + n_space/2, str, str_len);
        break;
      }

    default:
      ASSERT ( 0 );
      Nlm_MemFree( s );
      return 0;
    }

  return s;
}
Beispiel #18
0
static Boolean
LoadMMDBIdx(CharPtr db,  CharPtr idx)
{
  FILE *f;
  Char fullpath [PATH_MAX];
  CharPtr ptr;
  Char pcBuf[100];
  CharPtr pcTest;
  Char  pcMmdb[20];
  Char  pcPdb[20];
  Uint4Ptr     pU4Pdb;
  Int4Ptr      pI4Mmdb;
  long count = 0;
  long mmdbid = 0;
  /* StrToLong stuff */
  Nlm_Char     ch;
  Nlm_Int2     i;
  Nlm_Int2     len;
  Nlm_Char     local [64];
  Nlm_Boolean  nodigits;
  Nlm_Boolean  rsult;
  long int     val;
 

  StringCpy(fullpath, db);
  StringCat(fullpath, idx);
  if ((f = FileOpen (fullpath, "r")) == NULL) 
    {
      ErrPostEx(SEV_FATAL,0,0, "MMDBInit - Failed to load MMDB index - check config file.");
      return FALSE;
    } 
   
  pcTest = fgets(pcBuf, (size_t)100, f);
  if (pcTest)
    {
      sscanf(pcBuf, "%ld", &iMMDBSize);
    }
  if ((iMMDBSize == 0) || (iMMDBSize > 100000))
    {
      ErrPostEx(SEV_FATAL,0,0, "Internal - LoadMMDBIdx() Failure 2;");
      return FALSE;
    } 
  pI4Mmdbidx = (Int4Ptr) MemNew((size_t) ((iMMDBSize)*sizeof(Int4)));
  pU4Pdbidx = (Uint4Ptr) MemNew((size_t) ((iMMDBSize)*sizeof(Uint4)));

  if ((!pI4Mmdbidx) || (!pU4Pdbidx))
    {
      ErrPostEx(SEV_FATAL,0,0, "Internal - LoadMMDBIdx() Out of Memory;");
      return FALSE;
    }
   
  pI4Mmdb = pI4Mmdbidx;
  pU4Pdb = pU4Pdbidx;
   
  do 
    {
      pcBuf[0] = '\0';
      pcTest = fgets(pcBuf,  (size_t)100,  f);
      if (pcTest)
        {
          sscanf(pcBuf, "%s%s",  pcMmdb ,  pcPdb);
          StrUpper(pcPdb);	 
          mmdbid = 0;
 	    
          /* this is code from Nlm StrToLong */
          rsult = FALSE;
          len = (Nlm_Int2) Nlm_StringLen (pcMmdb);
          if (len != 0) {
            rsult = TRUE;
            nodigits = TRUE;
            for (i = 0; i < len; i++) {
              ch = pcMmdb [i];
              if (ch == ' ' || ch == '+' || ch == '-') {
              } else if (ch < '0' || ch > '9') {
                rsult = FALSE;
              } else {
                nodigits = FALSE;
              }
            }
            if (nodigits) {
              rsult = FALSE;
            }
            if (rsult) {
              Nlm_StringNCpy (local, pcMmdb, sizeof (local));
              if (sscanf (local, "%ld", &val) == 1) {
                mmdbid = val;
              }
            }
          }

          /* printf("%ld %s %ld %ld\n", mmdbid, pcPdb, (long) count, (long) iMMDBSize-1);  */
          if ((mmdbid == 0) ||  (StringLen(pcPdb) > 4))
            {
              MMDBFini();
              ErrPostEx(SEV_FATAL,0,0, "Internal - LoadMMDBIdx() Bad Index Values");
              return FALSE;
            }
    
          *pI4Mmdb = mmdbid;
          *pU4Pdb =  HashPDBCode(pcPdb);
          pI4Mmdb++;
          pU4Pdb++;
          count++;
	}   
      if (count > (iMMDBSize))
        {
          MMDBFini();
          ErrPostEx(SEV_FATAL,0,0, "Internal - LoadMMDBIdx() Index count is wrong at top of file;");
          return FALSE;
        }
    } while (pcTest);   
  FileClose(f);
  return TRUE;
}
Beispiel #19
0
NLM_EXTERN Nlm_Boolean LIBCALL StringSubString(char FAR *theString, char FAR *Find, char FAR *Replace, Nlm_Int4 MaxLength)
/* replaces all non-overlapping instances of the string Find in the
   string theString with the string Replace. The strings do not have to be the 
   same size. The new string is truncated at MaxLength characters
   Including the final NULL). If MaxLength is zero, the string's current
   length is presumed to be the maximum.
   It returns TRUE if any strings were replaced, else FALSE.
   */
{
  Nlm_CharPtr FindPtr,ComparePtr,StringPtr,NewString, NewStringPtr;
  Nlm_Int4 SpaceNeeded,Len;
  Nlm_Boolean Replaced = FALSE;

  if (*Find == NULLB)
    return(FALSE);

  Len = Nlm_StringLen(theString);
  SpaceNeeded = MAX( (Nlm_Int4)((Len * Nlm_StringLen(Replace) 
				 * sizeof(Nlm_Char) )
				/ Nlm_StringLen(Find) + 1),Len) + 1;

  NewStringPtr = NewString = (Nlm_CharPtr)
    Nlm_MemGet((size_t)SpaceNeeded, MGET_ERRPOST);

  StringPtr = theString;
  while (*StringPtr != NULLB)
    {
      FindPtr = Find;
      ComparePtr = StringPtr;
      while ( (*FindPtr != NULLB) && (*FindPtr == *ComparePtr) )
	{
	  FindPtr++;
	  ComparePtr++;
	}
      
      /* if we found the entire string, replace it. */
      if (*FindPtr == NULLB)
	{
	  NewStringPtr = StringMove(NewStringPtr,Replace);
	  StringPtr = ComparePtr;
	  Replaced = TRUE;
	}
      else
	/* otherwise, move on to the next character. */
	*NewStringPtr++ = *StringPtr++;
    }
  *NewStringPtr = NULLB;

  if (MaxLength <= 0)
    MaxLength = strlen(theString) + 1;

  /* Truncate the string, if necessary.*/
  if ((Nlm_Int4)strlen(NewString) >= MaxLength - 1)
    {
      NewString[MaxLength-1] = NULLB;
    }
    
  Nlm_StringCpy(theString,NewString);
  Nlm_MemFree(NewString);

  return(Replaced);
}