Exemplo n.º 1
0
/*
 * Wordch tells whether character at *wc is a word character
 * i.e. an alfa, digit, or underscore.
 */
int 
wordch(char *wc)
{
	int c;

#ifdef	MB
	if (mb_cur_max > 0 && *wc & 0200) {
		mbtowi(&c, wc, mb_cur_max);
		if (c & INVBIT)
			return 1;
	} else
#endif
		c = wc[0]&0377;
	return (xisalnum(c) || c == '_'
#ifdef	BIT8
#ifdef	ISO8859_1
	/*
	 * We consider all ISO 8859-1 characters except for
	 * no-break-space as word characters.
	 */
			|| c&0200 && (!(c&QUOTE) && (c&TRIM) != 0240)
#endif
#endif
			);
}
Exemplo n.º 2
0
static int
cblank(char *cp)
{
	if (mb_cur_max > 1 && *cp & 0200) {
		int	c;
		return mbtowi(&c, cp, mb_cur_max) > 0 && iswspace(c);
	} else
		return isspace(*cp&0377);
}
Exemplo n.º 3
0
int
wsamechar(char *cp, int d)
{
	int	c;

	if (mbtowi(&c, cp, mb_cur_max) >= 0 && c == d)
		return 1;
	return 0;
}
Exemplo n.º 4
0
/*
 * Range search for multibyte locales using the modified UNIX(R) Regular
 * Expression Library DFA.
 */
static int
rc_rangew(struct iblok *ip, char *last)
{
	char	*p;
	int	n, cstat, nstat;
	wint_t	wc;
	Dfa	*dp = e0->e_exp->re_dfa;

	p = ip->ib_cur;
	lineno++;
	cstat = dp->anybol;
	if (dp->acc[cstat])
		goto found;
	for (;;) {
		if (*p & 0200) {
			if ((n = mbtowi(&wc, p, last + 1 - p)) < 0) {
				n = 1;
				wc = WEOF;
			}
		} else {
			wc = *p;
			n = 1;
		}
		if ((wc & ~(wchar_t)(NCHAR-1)) != 0 ||
				(nstat = dp->trans[cstat][wc]) == 0) {
			/*
			 * '\0' is used to indicate end-of-line. If a '\0'
			 * character appears in input, it matches '$' but
			 * the DFA remains in dead state afterwards; there
			 * is thus no need to handle this condition
			 * specially to get the same behavior as in plain
			 * regexec().
			 */
			if (wc == '\n')
				wc = '\0';
			if ((nstat = regtrans(dp, cstat, wc, mb_cur_max)) == 0)
				goto fail;
			dp->trans[cstat]['\n'] = dp->trans[cstat]['\0'];
		}
		if (dp->acc[cstat = nstat - 1]) {
		found:	for (;;) {
				if (vflag == 0) {
		succeed:		outline(ip, last, p - ip->ib_cur);
					if (qflag || lflag)
						return 1;
				} else {
		fail:			ip->ib_cur = p;
					while (*ip->ib_cur++ != '\n');
				}
				if ((p = ip->ib_cur) > last)
					return 0;
				lineno++;
				if (dp->acc[cstat = dp->anybol] == 0)
					goto brk2;
			}
		}
		p += n;
		if (p[-n] == '\n') {
			if (vflag) {
				p--;
				goto succeed;
			}
			if ((ip->ib_cur = p) > last)
				return 0;
			lineno++;
			if (dp->acc[cstat = dp->anybol])
				goto found;
		}
		brk2:;
	}
}