home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume9 / elm2 / part01 / src / string2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-03-08  |  993 b   |  57 lines

  1. /**            string2.c        **/
  2.  
  3. /** This file contains string functions that are shared throughout the
  4.     various ELM utilities...
  5.  
  6.     (C) Copyright 1986 Dave Taylor
  7. **/
  8.  
  9. #ifndef TRUE
  10. #define TRUE        1
  11. #define FALSE        0
  12. #endif
  13.  
  14. int 
  15. in_string(buffer, pattern)
  16. char *buffer, *pattern;
  17. {
  18.     /** Returns TRUE iff pattern occurs IN IT'S ENTIRETY in buffer. **/ 
  19.  
  20.     register int i = 0, j = 0;
  21.     
  22.     while (buffer[i] != '\0') {
  23.       while (buffer[i++] == pattern[j++]) 
  24.         if (pattern[j] == '\0') 
  25.           return(TRUE);
  26.       i = i - j + 1;
  27.       j = 0;
  28.     }
  29.     return(FALSE);
  30. }
  31.  
  32. int
  33. chloc(string, ch)
  34. char *string, ch;
  35. {
  36.     /** returns the index of ch in string, or -1 if not in string **/
  37.     register int i;
  38.  
  39.     for (i=0; i<strlen(string); i++)
  40.       if (string[i] == ch) return(i);
  41.     return(-1);
  42. }
  43.  
  44. int
  45. occurances_of(ch, string)
  46. char ch, *string;
  47. {
  48.     /** returns the number of occurances of 'ch' in string 'string' **/
  49.  
  50.     register int count = 0, i;
  51.  
  52.     for (i=0; i<strlen(string); i++)
  53.       if (string[i] == ch) count++;
  54.  
  55.     return(count);
  56. }
  57.