/* TERMLIB: Terminal independant database.
 *
 * Module: tutil.c
 *
 * Purpose: Utility routines for TERMLIB functions.
 *
 */

/* tutil.c (libtermlib.a)
 * Utility routines for termlib
 *
 */

_match(s1, s2)                 /* returns length of text common to s1 and s2 */
char *s1, *s2;
{
	int i = 0;

	while(s1[i] && s1[i] == s2[i])
		i++;

	return i;
}

char *
_find(s, set)   /* finds next c in s that's a member of set, returns pointer */
char *s, *set;
{
	for(; *s; s++) {
		char    *ptr = set;

		while(*ptr && *s != *ptr)
			ptr++;

		if(*ptr)
			return s;
	}

	return s;
}

char *
_addfmt(buf, fmt, val)             /* add val to buf according to format fmt */
char *buf, *fmt;
int val;
{
	sprintf(buf, fmt, val);
	while(*buf)
		buf++;
	return buf;
}
