From 218935b0c729218c96bc720361b113d7b0afd03e Mon Sep 17 00:00:00 2001 From: Kristaps Dzonsons Date: Wed, 13 Apr 2011 10:01:27 +0000 Subject: Back out commit to roff.c that needs to go in on its own. --- roff.c | 59 ++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/roff.c b/roff.c index 11ed7435..02018389 100644 --- a/roff.c +++ b/roff.c @@ -1,4 +1,4 @@ -/* $Id: roff.c,v 1.132 2011/04/13 09:57:41 kristaps Exp $ */ +/* $Id: roff.c,v 1.133 2011/04/13 10:01:27 kristaps Exp $ */ /* * Copyright (c) 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010, 2011 Ingo Schwarze @@ -277,6 +277,10 @@ roffnode_pop(struct roff *r) assert(r->last); p = r->last; + if (ROFF_el == p->tok) + if (r->rstackpos > -1) + r->rstackpos--; + r->last = r->last->parent; free(p->name); free(p->end); @@ -972,20 +976,29 @@ roff_cond(ROFF_ARGS) int sv; enum roffrule rule; - /* - * An `.el' has no conditional body: it will consume the value - * of the current rstack entry set in prior `ie' calls or - * defaults to DENY. - * - * If we're not an `el', however, then evaluate the conditional. - */ + /* Stack overflow! */ - rule = ROFF_el == tok ? - (r->rstackpos < 0 ? - ROFFRULE_DENY : r->rstack[r->rstackpos--]) : - roff_evalcond(*bufp, &pos); + if (ROFF_ie == tok && r->rstackpos == RSTACK_MAX - 1) { + mandoc_msg(MANDOCERR_MEM, r->parse, ln, ppos, NULL); + return(ROFF_ERR); + } + + /* First, evaluate the conditional. */ + + if (ROFF_el == tok) { + /* + * An `.el' will get the value of the current rstack + * entry set in prior `ie' calls or defaults to DENY. + */ + if (r->rstackpos < 0) + rule = ROFFRULE_DENY; + else + rule = r->rstack[r->rstackpos]; + } else + rule = roff_evalcond(*bufp, &pos); sv = pos; + while (' ' == (*bufp)[pos]) pos++; @@ -1005,20 +1018,16 @@ roff_cond(ROFF_ARGS) r->last->rule = rule; - /* - * An if-else will put the NEGATION of the current evaluated - * conditional into the stack of rules. - */ - if (ROFF_ie == tok) { - if (r->rstackpos == RSTACK_MAX - 1) { - mandoc_msg(MANDOCERR_MEM, - r->parse, ln, ppos, NULL); - return(ROFF_ERR); - } - r->rstack[++r->rstackpos] = - ROFFRULE_DENY == r->last->rule ? - ROFFRULE_ALLOW : ROFFRULE_DENY; + /* + * An if-else will put the NEGATION of the current + * evaluated conditional into the stack. + */ + r->rstackpos++; + if (ROFFRULE_DENY == r->last->rule) + r->rstack[r->rstackpos] = ROFFRULE_ALLOW; + else + r->rstack[r->rstackpos] = ROFFRULE_DENY; } /* If the parent has false as its rule, then so do we. */ -- cgit v1.2.3-56-ge451