/*
 *          s t r f n d
 *
 * Routine to find the position of string1 in string2,
 *
 * Returns:
 *      -1  if not found
 *      position in string on success
 *
 * AMENDMENT HISTORY
 * ~~~~~~~~~~~~~~~~~
 *  03 Oct 93   DJW   - Changed to use pointer arithmetic in place of array
 *                      arithmetic for improved performance/size.
 *
 *  21 Jun 94   DJW   - Casts added to correctly handle characters with
 *                      internal values above 127.
 *
 *  25 Jan 95   DJW   - Added 'const' keywords to parameter definitions
 */

#include <string.h>
#include <ctype.h>

int strfnd ( s1, s2, lusig)
const char *s1;
const char *s2;
int lusig;                      /* If TRUE - case is significant */
{
    const char    *p;
    const char    *p1;
    const char    *p2;

    for( p = s2; *p; p++) {
        for (p1=s1, p2=p ; *p1 && *p2 ; p1++, p2++) {
            if (lusig != 0 && *p1 != *p2) {
                break;
            } else {
                if (tolower((unsigned char)*p1) != tolower((unsigned char)*p2)) {
                    break;
                }
            }
        }
        /*
         *  If end of string1 reached - we have a match
         */
        if( *p1 == '\0') {
            return (int)(p - s2);
        }
    }           
    return -1;
}

