home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name stsindex -- Returns the position of the first occurrence
- * of one string within another.
- *
- * Synopsis index = stsindex(pcheck,psearch);
- *
- * int index The position of pcheck within psearch
- * char *pcheck Pointer to the string to searched for
- * char *psearch Pointer to the string to be searched
- *
- * Description STSINDEX searches the string psearch for the string
- * pcheck, returning the position of first occurrence. If
- * the string does not occur, -1 is returned. If the
- * length of pcheck is zero, 0 is returned.
- *
- * See also STSCHIND.
- *
- * Returns index The position of pcheck in psearch
- *
- * Version 3.0 (C)Copyright Blaise Computing Inc. 1983, 1984, 1986
- *
- **/
-
- #include <string.h>
-
- #include <bstring.h>
-
- int stsindex(pcheck,psearch)
- register char *pcheck;
- char *psearch;
- {
- int lenc,pos,fpos;
- register int j;
- register char *ptemp;
-
- if ((lenc = (int) strlen(pcheck)) == 0)
- return(0); /* pcheck has length zero */
-
- /* Search psearch, starting where the first character of pcheck is */
- /* found. If the string is not found, find the next possible */
- /* position for a match. If a match is found, return the position */
- /* where the string starts; otherwise -1. */
-
- fpos = 0;
- while (((int) strlen(psearch)) >= lenc)
- {
- if ((pos = stschind(*pcheck,psearch)) < 0)
- break; /* First character not found */
- fpos += pos;
- ptemp = psearch + pos; /* String to search */
- for (j = 0; (j < lenc) && (*pcheck++ == *ptemp++); j++);
- if (j == lenc)
- return(fpos); /* String found */
- pcheck -= j + 1; /* Restore pointer to string to check*/
- psearch += pos + 1; /* Look for first character of pcheck*/
- fpos++; /* at the next position. */
- }
-
- return(-1); /* String not found */
- }