From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp-1.sys.kth.se (smtp-1.sys.kth.se [130.237.32.175]) by krisdoz.my.domain (8.14.3/8.14.3) with ESMTP id p37A2ZkQ028070 for ; Thu, 7 Apr 2011 06:02:36 -0400 (EDT) Received: from mailscan-1.sys.kth.se (mailscan-1.sys.kth.se [130.237.32.91]) by smtp-1.sys.kth.se (Postfix) with ESMTP id 5D381156B3E for ; Thu, 7 Apr 2011 12:02:29 +0200 (CEST) X-Virus-Scanned: by amavisd-new at kth.se Received: from smtp-1.sys.kth.se ([130.237.32.175]) by mailscan-1.sys.kth.se (mailscan-1.sys.kth.se [130.237.32.91]) (amavisd-new, port 10024) with LMTP id HlrkIQ9KdxvN for ; Thu, 7 Apr 2011 12:02:23 +0200 (CEST) X-KTH-Auth: kristaps [213.103.216.43] X-KTH-mail-from: kristaps@bsd.lv X-KTH-rcpt-to: tech@mdocml.bsd.lv Received: from macky.local (s213-103-216-43.cust.tele2.se [213.103.216.43]) by smtp-1.sys.kth.se (Postfix) with ESMTP id E9CE0154136 for ; Thu, 7 Apr 2011 12:02:21 +0200 (CEST) Message-ID: <4D9D8BAD.6010809@bsd.lv> Date: Thu, 07 Apr 2011 12:02:21 +0200 From: Kristaps Dzonsons User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 X-Mailinglist: mdocml-tech Reply-To: tech@mdocml.bsd.lv MIME-Version: 1.0 To: tech@mdocml.bsd.lv Subject: Re: roff conditional recursion References: <20110407003900.GA20175@britannica.bec.de> In-Reply-To: <20110407003900.GA20175@britannica.bec.de> Content-Type: multipart/mixed; boundary="------------070203000805050705040208" This is a multi-part message in MIME format. --------------070203000805050705040208 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit On 07/04/2011 02:39, Joerg Sonnenberger wrote: > Hi Ingo, > at the moment, as soon as ROFF_ie is seen, r->stackpos is incremented. > This happens in roff.c 1028. But the corresponding code for handling > ROFF_el in 995 doesn't decrement it again. Shouldn't it be > rule = r->rstack[r->rstackpos--]; > in line 998? > > Attached is a trivial example. Joerg, Enclosed is a patch that follows this logic, plus some clean-up and documentation (it works on test.1 and doesn't seem to cause problems anywhere else). The rstackpos, yes, can be safely "consumed" when the `el' is called, and need not wait until the nodes are popped. Ingo, any comments? Thanks, Kristaps --------------070203000805050705040208 Content-Type: text/plain; name="patch.roff.txt" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="patch.roff.txt" Index: roff.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/roff.c,v retrieving revision 1.131 diff -u -r1.131 roff.c --- roff.c 5 Apr 2011 22:22:33 -0000 1.131 +++ roff.c 7 Apr 2011 09:57:11 -0000 @@ -277,10 +277,6 @@ 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); @@ -976,29 +972,20 @@ int sv; enum roffrule rule; - /* Stack overflow! */ + /* + * 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. + */ - 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); + rule = ROFF_el == tok ? + (r->rstackpos < 0 ? + ROFFRULE_DENY : r->rstack[r->rstackpos--]) : + roff_evalcond(*bufp, &pos); sv = pos; - while (' ' == (*bufp)[pos]) pos++; @@ -1018,16 +1005,20 @@ 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) { - /* - * 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 (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; } /* If the parent has false as its rule, then so do we. */ --------------070203000805050705040208-- -- To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv