aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/roff.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2008-11-29 14:14:21 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2008-11-29 14:14:21 +0000
commit344abfe1dd84dad326b359cadfbb4094a60e74d7 (patch)
tree792423cf38d6cecebbd7655abed67aacc4958090 /roff.c
parent24ab2f2f835520af37cfd66dd0ff850d758a3d71 (diff)
downloadmandoc-344abfe1dd84dad326b359cadfbb4094a60e74d7.tar.gz
mandoc-344abfe1dd84dad326b359cadfbb4094a60e74d7.tar.zst
mandoc-344abfe1dd84dad326b359cadfbb4094a60e74d7.zip
Inclusion of "real" validation code.
Diffstat (limited to 'roff.c')
-rw-r--r--roff.c40
1 files changed, 22 insertions, 18 deletions
diff --git a/roff.c b/roff.c
index c4bcb3d7..a873a435 100644
--- a/roff.c
+++ b/roff.c
@@ -1,4 +1,4 @@
-/* $Id: roff.c,v 1.16 2008/11/28 18:15:29 kristaps Exp $ */
+/* $Id: roff.c,v 1.17 2008/11/29 14:14:21 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -130,9 +130,8 @@ static int roffargs(const struct rofftree *,
static int roffargok(int, int);
static int roffnextopt(const struct rofftree *,
int, const char ***, char **);
-static int roffparse(struct rofftree *, char *, size_t);
-static int textparse(const struct rofftree *,
- const char *, size_t);
+static int roffparse(struct rofftree *, char *);
+static int textparse(const struct rofftree *, char *);
static const int roffarg_An[] = { ROFF_Split, ROFF_Nosplit,
@@ -360,6 +359,8 @@ roff_free(struct rofftree *tree, int flush)
int error, t;
struct roffnode *n;
+ error = 0;
+
if ( ! flush)
goto end;
@@ -372,7 +373,7 @@ roff_free(struct rofftree *tree, int flush)
for (n = tree->last; n->parent; n = n->parent) {
if (0 != tokens[n->tok].ctx)
- break;
+ continue;
roff_warn(tree, NULL, "closing explicit scope `%s'",
toknames[n->tok]);
goto end;
@@ -384,7 +385,7 @@ roff_free(struct rofftree *tree, int flush)
goto end;
}
- if ( ! (*tree->cb.roffhead)(tree->arg))
+ if ( ! (*tree->cb.rofftail)(tree->arg))
goto end;
error = 0;
@@ -395,6 +396,7 @@ end:
roffnode_free(tree);
free(tree);
+
return(error ? 0 : 1);
}
@@ -404,6 +406,9 @@ roff_alloc(const struct roffcb *cb, void *args)
{
struct rofftree *tree;
+ assert(args);
+ assert(cb);
+
if (NULL == (tree = calloc(1, sizeof(struct rofftree))))
err(1, "calloc");
@@ -422,27 +427,27 @@ roff_alloc(const struct roffcb *cb, void *args)
int
-roff_engine(struct rofftree *tree, char *buf, size_t sz)
+roff_engine(struct rofftree *tree, char *buf)
{
- tree->cur = NULL;
+ tree->cur = buf;
+ assert(buf);
- if (0 == sz) {
+ if (0 == *buf) {
roff_warn(tree, buf, "blank line");
return(0);
} else if ('.' != *buf)
- return(textparse(tree, buf, sz));
+ return(textparse(tree, buf));
- return(roffparse(tree, buf, sz));
+ return(roffparse(tree, buf));
}
static int
-textparse(const struct rofftree *tree, const char *buf, size_t sz)
+textparse(const struct rofftree *tree, char *buf)
{
-
- /* Print text. */
- return(1);
+
+ return((*tree->cb.roffdata)(tree->arg, buf));
}
@@ -512,15 +517,13 @@ roffscan(int tok, const int *tokv)
static int
-roffparse(struct rofftree *tree, char *buf, size_t sz)
+roffparse(struct rofftree *tree, char *buf)
{
int tok, t;
struct roffnode *n;
char *argv[ROFF_MAXARG];
const char **argvp;
- assert(sz > 0);
-
if (ROFF_MAX == (tok = rofffindtok(buf + 1))) {
roff_err(tree, buf + 1, "bogus line macro");
return(0);
@@ -959,6 +962,7 @@ roff_layout(ROFFCALL_ARGS)
break;
}
+ assert(tree->arg);
if ( ! (*tree->cb.roffdata)(tree->arg, *argv++))
return(0);
}