home *** CD-ROM | disk | FTP | other *** search
- /* strchr.c - functions for null-terminated strings */
- /* 1982/10/10 12:23
-
- Copyright 1982 William G. Hutchison, Jr.
- P.O. Box 278
- Exton, PA 19341-0278
- U.S.A.
-
- CompuServe 70665,1307
-
-
- These functions may be used freely for any non-commercial
- purpose, provided that the user does not remove or alter
- this notice or the copyright statement.
- Those who wish to sell or lease these functions, or to
- incorporate them into a product for sale or lease, should
- apply to the author (above) for licensing information.
- These functions are not covered by a warranty, either
- express or implied. The author shall not be responsible for
- any damages (including consequential) caused by reliance on
- the materials presented, including but not limited to
- typographical errors or arithmetic errors.
-
- NOTE: The names and functions of these sub-programs are
- the same as certain sub-programs provided with the UNIX
- system (tm Western Electric Co.), but these sub-programs are
- original work, not copies of the UNIX sub-programs.
-
- */
-
- /* definitions for Software Toolworks C/80 Version 2.0: */
- #ifdef MAINLY
- #else
- #include "c80def.h"
- #endif
-
- /* index - return pointer to c in s, or NULL if not found */
-
- #ifdef UNIX
- char *
- #endif
- index(s, c) char *s, c;
- {
- while(*s && *s != c) s++;
- return(*s? s : NULL);
- } /* end index */
-
- /* rindex - like index, but search s right-to-left */
-
- #ifdef UNIX
- char *
- #endif
- rindex(s, c) char *s, c;
- {
- register int i;
- for(i= strlen(s)-1; i >= 0 && c != s[i]; i--)
- ;
- return (i < 0? NULL : s+i);
- } /* end rindex */
-
- /* strcat - concatenate s2 onto end of s1, return s1 */
-
- #ifdef UNIX
- char *
- #endif
- strcat(s1, s2) char *s1, *s2;
- {
- return(strcpy(s1+strlen(s1), s2));
- } /* end strcat */
-
- /* strcmp - compare s1 vs. s2 in native code order. Return -1 if
- s1 < s2, +1 if s2 > s1, 0 otherwise. */
-
- #ifdef UNIX
- int
- #endif
- strcmp(s1, s2) char *s1, *s2;
- {
- for (; *s1 && *s1 == *s2; s1++, s2++)
- ;
- return(*s1 < *s2? -1 : (*s1 > *s2? 1 : 0));
- } /* end strcmp */
-
- /* strcpy - copy s2 to s1, return s1 */
-
- #ifdef UNIX
- char *
- #endif
- strcpy(s1, s2) char *s1, *s2;
- {
- char *s;
- s= s1;
- while(*s1++ = *s2++)
- ;
- return(s);
- } /* end strcpy */
-
- /* strlen - return length of string */
-
- #ifdef UNIX
- int
- #endif
- strlen(s) char *s;
- {
- register char *t;
- for(t=s; *t; t++)
- ;
- return(t-s);
- } /* end strlen */
-
- /* strncat - concatenate at most n characters from s2 onto end of s1;
- return s1 */
-
- #ifdef UNIX
- char *
- #endif
- strncat(s1, s2, n) char *s1, *s2;
- int n;
- {
- return(strncpy(s1+strlen(s1), s2, n));
- } /* end strncat */
-
- /* strncmp - compare at most n characters of s1 vs. s2 in native
- code order. Return -1 if s1 < s2, +1 if s2 > s1, 0 otherwise. */
-
- #ifdef UNIX
- int
- #endif
- strncmp(s1, s2, n) char *s1, *s2;
- int n;
- {
- for (; n-- > 0 && *s1 && *s1 == *s2; s1++, s2++)
- ;
- return(*s1 < *s2? -1 : (*s1 > *s2? 1 : 0));
- } /* end strncmp */
-
- /* strncpy - copy at most n characters from s2 to s1, return s1 */
-
- #ifdef UNIX
- char *
- #endif
- strncpy(s1, s2, n) char *s1, *s2;
- int n;
- {
- char *s;
- s= s1;
- while(n-- > 0 && (*s1++ = *s2++))
- ;
- return(s);
- } /* end strncpy */
-
- /* strpbrk - returns a pointer to the first occurrence in string s1
- of any character from string s2, or NULL if no character from s2
- exists in s1. */
-
- #ifdef UNIX
- char *
- #endif
- strpbrk(s1, s2) char *s1, *s2;
- {
- for(;*s1; s1++)
- if(index(s2, *s1) != NULL) return(s1);
- return(NULL);
- } /* end strpbrk */
-
- /* strspn - returns the length of the initial segment of string s1
- which consists entirely of characters from string s2. */
-
- #ifdef UNIX
- int
- #endif
- strspn(s1, s2) char *s1, *s2;
- {
- register char *t;
- for(t= s1; *t && strpbrk(t, s2) != NULL; t++)
- ;
- return(t-s1);
- } /* end strspn */
-
- /* strcspn - returns the length of the initial segment of string s1
- which consists entirely of characters not in string s2. */
-
- #ifdef UNIX
- int
- #endif
- strcspn(s1, s2) char *s1, *s2;
- {
- register char *t;
- for(t= s1; *t && strpbrk(t, s2) == NULL; t++)
- ;
- return(t-s1);
- } /* end strcspn */