home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / elm / elm2.4 / src / string2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-03  |  2.1 KB  |  90 lines

  1.  
  2. static char rcsid[] = "@(#)$Id: string2.c,v 5.1 1992/10/03 22:58:40 syd Exp $";
  3.  
  4. /*******************************************************************************
  5.  *  The Elm Mail System  -  $Revision: 5.1 $   $State: Exp $
  6.  *
  7.  *             Copyright (c) 1988-1992 USENET Community Trust
  8.  *             Copyright (c) 1986,1987 Dave Taylor
  9.  *******************************************************************************
  10.  * Bug reports, patches, comments, suggestions should be sent to:
  11.  *
  12.  *    Syd Weinstein, Elm Coordinator
  13.  *    elm@DSI.COM            dsinc!elm
  14.  *
  15.  *******************************************************************************
  16.  * $Log: string2.c,v $
  17.  * Revision 5.1  1992/10/03  22:58:40  syd
  18.  * Initial checkin as of 2.4 Release at PL0
  19.  *
  20.  *
  21.  ******************************************************************************/
  22.  
  23. /** This file contains string functions that are shared throughout the
  24.     various ELM utilities...
  25.  
  26. **/
  27.  
  28. #include "headers.h"
  29. #include <ctype.h>
  30.  
  31. #ifdef BSD
  32. #undef tolower
  33. #undef toupper
  34. #endif
  35.  
  36.  
  37. int
  38. occurances_of(ch, string)
  39. char ch, *string;
  40. {
  41.     /** returns the number of occurances of 'ch' in string 'string' **/
  42.  
  43.     register int count = 0;
  44.  
  45.     for (; *string; string++)
  46.       if (*string == ch) count++;
  47.  
  48.     return(count);
  49. }
  50.  
  51. int
  52. qoccurances_of(ch, string)
  53. char ch, *string;
  54. {
  55.     /** returns the number of occurances of 'ch' in string 'string' **/
  56.  
  57.     register int count = 0, len;
  58.  
  59.     while(*string) {
  60.       len = len_next_part(string);
  61.       if (len == 1 && *string == ch) count++;
  62.       string += len;
  63.     }
  64.  
  65.     return(count);
  66. }
  67.  
  68. remove_possible_trailing_spaces(string)
  69. char *string;
  70. {
  71.     /** an incredibly simple routine that will read backwards through
  72.         a string and remove all trailing whitespace.
  73.     **/
  74.  
  75.     register int i, j;
  76.  
  77.     for ( j = i = strlen(string); --i >= 0 && whitespace(string[i]); )
  78.         /** spin backwards, semicolon intented **/ ;
  79.  
  80.     if (string[i-1] == '\\') /* allow for line to end with \blank  */
  81.         i++;
  82.  
  83.     if (i < j)
  84.       string[i+1] = '\0';    /* note that even in the worst case when there
  85.                    are no trailing spaces at all, we'll simply
  86.                    end up replacing the existing '\0' with
  87.                    another one!  No worries, as M.G. would say
  88.                 */
  89. }
  90.