aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/roff.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2010-05-24 23:54:18 +0000
committerIngo Schwarze <schwarze@openbsd.org>2010-05-24 23:54:18 +0000
commit2aefdbffeeeeda1b600266dae034d7133292ad46 (patch)
tree6f3de305c81786d101b59487b38fec286bda3558 /roff.c
parentf33e9bc8a5b75be1fa9e13e0040f67f086caf19d (diff)
downloadmandoc-2aefdbffeeeeda1b600266dae034d7133292ad46.tar.gz
mandoc-2aefdbffeeeeda1b600266dae034d7133292ad46.tar.zst
mandoc-2aefdbffeeeeda1b600266dae034d7133292ad46.zip
recognize ".if n" as true;
nothing fancy yet, no negation, no grammer, just that one letter; from OpenBSD; "looks fine" kristaps@
Diffstat (limited to 'roff.c')
-rw-r--r--roff.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/roff.c b/roff.c
index 3057cb8c..d57d2457 100644
--- a/roff.c
+++ b/roff.c
@@ -1,4 +1,4 @@
-/* $Id: roff.c,v 1.83 2010/05/24 22:25:58 schwarze Exp $ */
+/* $Id: roff.c,v 1.84 2010/05/24 23:54:18 schwarze Exp $ */
/*
* Copyright (c) 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -575,7 +575,7 @@ roff_cond_sub(ROFF_ARGS)
ppos = pos;
rr = r->last->rule;
- roffnode_cleanscope(r);
+ roff_cond_text(r, tok, bufp, szp, ln, ppos, pos, offs);
if (ROFF_MAX == (t = roff_parse(*bufp, &pos)))
return(ROFFRULE_DENY == rr ? ROFF_IGN : ROFF_CONT);
@@ -616,8 +616,10 @@ roff_cond_text(ROFF_ARGS)
return(ROFFRULE_DENY == rr ? ROFF_IGN : ROFF_CONT);
}
- if (ep > st && '\\' != *(ep - 1))
+ if (ep > st && '\\' != *(ep - 1)) {
+ ep = '\0';
roffnode_pop(r);
+ }
roffnode_cleanscope(r);
return(ROFFRULE_DENY == rr ? ROFF_IGN : ROFF_CONT);
@@ -628,6 +630,7 @@ roff_cond_text(ROFF_ARGS)
static enum rofferr
roff_cond(ROFF_ARGS)
{
+ int cpos; /* position of the condition */
int sv;
/* Stack overflow! */
@@ -637,6 +640,8 @@ roff_cond(ROFF_ARGS)
return(ROFF_ERR);
}
+ cpos = pos;
+
if (ROFF_if == tok || ROFF_ie == tok) {
/*
* Read ahead past the conditional. FIXME: this does
@@ -667,9 +672,12 @@ roff_cond(ROFF_ARGS)
if ( ! roffnode_push(r, tok, ln, ppos))
return(ROFF_ERR);
- /* TODO: here we would evaluate the conditional. */
+ /* XXX: Implement more conditionals. */
- if (ROFF_el == tok) {
+ if (ROFF_if == tok || ROFF_ie == tok)
+ r->last->rule = 'n' == (*bufp)[cpos] ?
+ ROFFRULE_ALLOW : ROFFRULE_DENY;
+ else if (ROFF_el == tok) {
/*
* An `.el' will get the value of the current rstack
* entry set in prior `ie' calls or defaults to DENY.
@@ -678,7 +686,8 @@ roff_cond(ROFF_ARGS)
r->last->rule = ROFFRULE_DENY;
else
r->last->rule = r->rstack[r->rstackpos];
- } else if (ROFF_ie == tok) {
+ }
+ if (ROFF_ie == tok) {
/*
* An if-else will put the NEGATION of the current
* evaluated conditional into the stack.
@@ -689,6 +698,8 @@ roff_cond(ROFF_ARGS)
else
r->rstack[r->rstackpos] = ROFFRULE_DENY;
}
+ if (r->last->parent && ROFFRULE_DENY == r->last->parent->rule)
+ r->last->rule = ROFFRULE_DENY;
r->last->endspan = 1;