diff options
author | Kristaps Dzonsons <kristaps@bsd.lv> | 2008-12-01 16:01:28 +0000 |
---|---|---|
committer | Kristaps Dzonsons <kristaps@bsd.lv> | 2008-12-01 16:01:28 +0000 |
commit | 184c23d8c4f64f7c9f1dacc99d76d0dd10303386 (patch) | |
tree | 5f1f72449b43ab185f0d0006899526e147ce5ec2 | |
parent | 78514c9d13534db5603803edfe8e818d9fe11597 (diff) | |
download | mandoc-184c23d8c4f64f7c9f1dacc99d76d0dd10303386.tar.gz |
Considerable scoping fixes.
-rw-r--r-- | Makefile | 5 | ||||
-rw-r--r-- | roff.c | 50 | ||||
-rw-r--r-- | xml.c | 8 |
3 files changed, 41 insertions, 22 deletions
@@ -21,10 +21,11 @@ CLEAN = mdocml mdocml.tgz $(LLNS) $(LNS) $(OBJS) $(LIBS) INSTALL = Makefile $(HEADS) $(SRCS) $(MANS) FAIL = test.0 test.1 test.2 test.3 test.4 test.5 test.6 \ - test.15 test.20 test.22 + test.15 test.20 test.22 test.24 test.26 test.27 test.30 SUCCEED = test.7 test.8 test.9 test.10 test.11 test.12 test.13 \ - test.14 test.16 test.17 test.18 test.19 test.21 test.23 + test.14 test.16 test.17 test.18 test.19 test.21 test.23 \ + test.25 test.28 test.29 all: mdocml @@ -236,7 +236,7 @@ static const struct rofftok tokens[ROFF_MAX] = { { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE | ROFF_LSCOPE }, /* Aq */ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, 0 }, /* At */ /* XXX at most 2 args */ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Bc */ - { NULL, NULL, NULL, NULL, 0, ROFF_TEXT, 0 }, /* Bf */ /* FIXME */ + { roff_layout, NULL, NULL, NULL, 0, ROFF_LAYOUT, 0 }, /* Bf */ /* FIXME */ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Bo */ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE | ROFF_LSCOPE }, /* Bq */ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED }, /* Bsx */ @@ -246,7 +246,7 @@ static const struct rofftok tokens[ROFF_MAX] = { { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Do */ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE | ROFF_LSCOPE }, /* Dq */ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Ec */ - { NULL, NULL, NULL, NULL, 0, ROFF_TEXT, 0 }, /* Ef */ /* FIXME */ + { roff_noop, NULL, NULL, NULL, ROFF_Bf, ROFF_LAYOUT, 0 }, /* Ef */ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Em */ /* XXX needs arg */ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Eo */ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED }, /* Fx */ @@ -257,7 +257,7 @@ static const struct rofftok tokens[ROFF_MAX] = { { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED }, /* Ox */ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Pc */ { NULL, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED }, /* Pf */ - { roff_text, NULL, NULL, NULL, 0, ROFF_LAYOUT, ROFF_PARSED | ROFF_CALLABLE }, /* Po */ + { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Po */ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE | ROFF_LSCOPE }, /* Pq */ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Qc */ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Ql */ @@ -380,14 +380,14 @@ roff_free(struct rofftree *tree, int flush) error = 1; if (ROFF_PRELUDE & tree->state) { - roff_warn(tree, NULL, "prelude never finished"); + roff_err(tree, NULL, "prelude never finished"); goto end; } - for (n = tree->last; n->parent; n = n->parent) { + for (n = tree->last; n; n = n->parent) { if (0 != tokens[n->tok].ctx) continue; - roff_warn(tree, NULL, "closing explicit scope `%s'", + roff_err(tree, NULL, "closing explicit scope `%s'", toknames[n->tok]); goto end; } @@ -554,8 +554,7 @@ roffparse(struct rofftree *tree, char *buf) if (ROFF_PRELUDE & tree->state) { assert(NULL == tree->last); return((*tokens[tok].cb)(tok, tree, argvp, ROFF_ENTER)); - } else - assert(tree->last); + } assert(ROFF_BODY & tree->state); @@ -564,14 +563,16 @@ roffparse(struct rofftree *tree, char *buf) * children are satisfied. */ - if ( ! roffscan(tree->last->tok, tokens[tok].parents)) { + if (tree->last && ! roffscan + (tree->last->tok, tokens[tok].parents)) { roff_err(tree, *argvp, "`%s' has invalid parent `%s'", toknames[tok], toknames[tree->last->tok]); return(0); } - if ( ! roffscan(tok, tokens[tree->last->tok].children)) { + if (tree->last && ! roffscan + (tok, tokens[tree->last->tok].children)) { roff_err(tree, *argvp, "`%s' is invalid child of `%s'", toknames[tok], toknames[tree->last->tok]); @@ -614,6 +615,11 @@ roffparse(struct rofftree *tree, char *buf) n = NULL; break; } + if (tokens[n->tok].ctx == n->tok) + continue; + roff_err(tree, *argv, "`%s' breaks `%s' scope", + toknames[tok], toknames[n->tok]); + return(0); } /* @@ -647,9 +653,26 @@ roffparse(struct rofftree *tree, char *buf) * In this, the `El' tag closes out the scope of `Bl'. */ - assert(tree->last); assert(tok != tokens[tok].ctx && 0 != tokens[tok].ctx); + for (n = tree->last; n; n = n->parent) + if (n->tok != tokens[tok].ctx) { + if (n->tok == tokens[n->tok].ctx) + continue; + roff_err(tree, *argv, "`%s' breaks `%s' scope", + toknames[tok], toknames[n->tok]); + return(0); + } else + break; + + + if (NULL == n) { + roff_err(tree, *argv, "`%s' has no starting tag `%s'", + toknames[tok], + toknames[tokens[tok].ctx]); + return(0); + } + /* LINTED */ do { t = tree->last->tok; @@ -657,7 +680,6 @@ roffparse(struct rofftree *tree, char *buf) return(0); } while (t != tokens[tok].ctx); - assert(tree->last); return(1); } @@ -940,7 +962,6 @@ roff_Os(ROFFCALL_ARGS) { if (ROFF_EXIT == type) { - roffnode_free(tree); return((*tree->cb.rofftail)(tree->arg)); } else if (ROFF_BODY & tree->state) { assert( ! (ROFF_PRELUDE & tree->state)); @@ -963,9 +984,6 @@ roff_Os(ROFFCALL_ARGS) assert(NULL == tree->last); - if (NULL == roffnode_new(tok, tree)) - return(0); - return((*tree->cb.roffhead)(tree->arg)); } @@ -28,7 +28,7 @@ #include "libmdocml.h" #include "private.h" -#define INDENT 4 +#define MAXINDENT 8 #define COLUMNS 60 #ifdef __linux__ /* FIXME */ @@ -141,11 +141,11 @@ mbuf_indent(struct md_xml *p) assert(p->pos == 0); /* LINTED */ - for (i = 0; i < MIN(p->indent, INDENT); i++) + for (i = 0; i < MIN(p->indent, MAXINDENT); i++) if ( ! md_buf_putstring(p->mbuf, " ")) return(0); - p->pos += i * INDENT; + p->pos += i * 4; return(1); } @@ -195,7 +195,7 @@ mbuf_data(struct md_xml *p, int space, char *buf) return(0); if ( ! mbuf_nputstring(p, bufp, sz)) return(0); - if (p->indent * INDENT + sz >= COLUMNS) { + if (p->indent * MAXINDENT + sz >= COLUMNS) { if ( ! mbuf_newline(p)) return(0); continue; |