home *** CD-ROM | disk | FTP | other *** search
- /*
- * strfind.c
- * contains: strfind()
- *
- */
-
- #include <stdio.h>
- #include <string.h>
- #include "gfuncts.h"
-
- /*
- * int
- * strfind(ps,pt)
- *
- * ARGUMENT
- * (char *) ps - string to be searched
- * (char *) pt - string to search for
- *
- * DESCRIPTION
- * The string is searched for the substring. If it is found in its
- * entirety, the position in the specified string (ps) is returned.
- *
- * RETURNS
- * position of substring or -1 if not found.
- *
- * AUTHOR
- * Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
- */
- int GF_CONV strfind(ps,pt)
- char *ps, *pt;
- {
- int i,k,itemp,slen,tlen;
-
- if((!(tlen=strlen(pt))) || (tlen>(slen=strlen(ps))) )
- return (-1);
- i=k=itemp=0;
- while (1) {
- if (ps[i]==pt[0]) {
- itemp=i;
- while(1) {
- if((k+1)==tlen)
- return itemp;
- else if((i+k+1)==slen)
- return (-1);
- else {
- ++k;
- if(ps[i+k]!=pt[k]) {
- k=0;
- goto point1;
- }
- }
- }
- } else {
- if(!ps[i])
- return(-1);
- point1:
- ++i;
- }
- }
- }
-