FreeBSD/contrib/mdocml/roff.c
/*
 * Evaluate an optionally negated single character, numerical,
 * or string condition.
 */
Evaluate an optionally negated single character, numerical,
or string condition.
Evaluate an optionally negated single character numerical or string condition .
static int
roff_evalcond(struct roff *r, int ln, char *v, int *pos)
{
	char	*cp, *name;
	size_t	 sz;
	int	 number, savepos, wanttrue;
	if ('!' == v[*pos]) {
		wanttrue = 0;
		(*pos)++;
	} else
		wanttrue = 1;
	switch (v[*pos]) {
	case '\0':
		return 0;
	case 'n':
	case 'o':
		(*pos)++;
		return wanttrue;
	case 'c':
	case 'd':
	case 'e':
	case 't':
	case 'v':
		(*pos)++;
		return !wanttrue;
	case 'r':
		cp = name = v + ++*pos;
		sz = roff_getname(r, &cp, ln, *pos);
		*pos = cp - v;
		return (sz && roff_hasregn(r, name, sz)) == wanttrue;
	default:
		break;
	}
	savepos = *pos;
	if (roff_evalnum(r, ln, v, pos, &number, ROFFNUM_SCALE))
		return (number > 0) == wanttrue;
	else if (*pos == savepos)
		return roff_evalstrcond(v, pos) == wanttrue;
	else
		return 0;
}
static int roff_evalcond ( struct roff * r , int ln , char * v , int * pos ) { char * cp , * name ; size_t sz ; int number , savepos , wanttrue ; if ( ' ' == v [ * pos ] ) { wanttrue = 0 ; ( * pos ) ++ ; } else wanttrue = 1 ; switch ( v [ * pos ] ) { case ' \0 ' : return 0 ; case ' ' : case ' ' : ( * pos ) ++ ; return wanttrue ; case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : ( * pos ) ++ ; return ! wanttrue ; case ' ' : cp = name = v + ++ * pos ; sz = roff_getname ( r , & cp , ln , * pos ) ; * pos = cp - v ; return ( sz && roff_hasregn ( r , name , sz ) ) == wanttrue ; default : break ; } savepos = * pos ; if ( roff_evalnum ( r , ln , v , pos , & number , ROFFNUM_SCALE ) ) return ( number > 0 ) == wanttrue ; else if ( * pos == savepos ) return roff_evalstrcond ( v , pos ) == wanttrue ; else return 0 ; }
Evaluate an optionally negated single character, numerical,
 or string condition.
Evaluate an optionally negated single character numerical or string condition .