xref: /plan9-contrib/sys/src/cmd/rc/utfutf.c (revision c6df144405f586b73992827d584728dc975dff14)
1*c6df1444SDavid du Colombier #include "rc.h"
2*c6df1444SDavid du Colombier 
3*c6df1444SDavid du Colombier /*
4*c6df1444SDavid du Colombier  * Return pointer to first occurrence of s2 in s1,
5*c6df1444SDavid du Colombier  * 0 if none
6*c6df1444SDavid du Colombier  */
7*c6df1444SDavid du Colombier char*
utfutf(char * s1,char * s2)8*c6df1444SDavid du Colombier utfutf(char *s1, char *s2)
9*c6df1444SDavid du Colombier {
10*c6df1444SDavid du Colombier 	char *p;
11*c6df1444SDavid du Colombier 	long f, n1, n2;
12*c6df1444SDavid du Colombier 	Rune r;
13*c6df1444SDavid du Colombier 
14*c6df1444SDavid du Colombier 	n1 = chartorune(&r, s2);
15*c6df1444SDavid du Colombier 	f = r;
16*c6df1444SDavid du Colombier 	if(f <= Runesync)		/* represents self */
17*c6df1444SDavid du Colombier 		return strstr(s1, s2);
18*c6df1444SDavid du Colombier 
19*c6df1444SDavid du Colombier 	n2 = strlen(s2);
20*c6df1444SDavid du Colombier 	for(p=s1; p=utfrune(p, f); p+=n1)
21*c6df1444SDavid du Colombier 		if(strncmp(p, s2, n2) == 0)
22*c6df1444SDavid du Colombier 			return p;
23*c6df1444SDavid du Colombier 	return 0;
24*c6df1444SDavid du Colombier }
25