=================================================================== RCS file: /cvs/mandoc/roff.c,v retrieving revision 1.52 retrieving revision 1.54 diff -u -p -r1.52 -r1.54 --- mandoc/roff.c 2008/12/08 16:29:57 1.52 +++ mandoc/roff.c 2008/12/09 00:27:17 1.54 @@ -1,4 +1,4 @@ -/* $Id: roff.c,v 1.52 2008/12/08 16:29:57 kristaps Exp $ */ +/* $Id: roff.c,v 1.54 2008/12/09 00:27:17 kristaps Exp $ */ /* * Copyright (c) 2008 Kristaps Dzonsons * @@ -84,6 +84,7 @@ static int rofffindcallable(const char *); static int roffismsec(const char *); static int roffissec(const char **); static int roffispunct(const char *); +static int roffisatt(const char *); static int roffchecksec(struct rofftree *, const char *, int); static int roffargs(const struct rofftree *, @@ -126,10 +127,10 @@ roff_free(struct rofftree *tree, int flush) error = 1; if (ROFF_PRELUDE & tree->state) { - roff_err(tree, NULL, "prelude never finished"); + (void)roff_err(tree, NULL, "prelude never finished"); goto end; } else if ( ! (ROFFSec_NAME & tree->asec)) { - roff_err(tree, NULL, "missing `NAME' section"); + (void)roff_err(tree, NULL, "missing `NAME' section"); goto end; } else if ( ! (ROFFSec_NMASK & tree->asec)) roff_warn(tree, NULL, "missing suggested `NAME', " @@ -138,8 +139,8 @@ roff_free(struct rofftree *tree, int flush) for (n = tree->last; n; n = n->parent) { if (0 != tokens[n->tok].ctx) continue; - roff_err(tree, NULL, "closing explicit scope `%s'", - toknames[n->tok]); + (void)roff_err(tree, NULL, "closing explicit scope " + "`%s'", toknames[n->tok]); goto end; } @@ -193,10 +194,9 @@ roff_engine(struct rofftree *tree, char *buf) tree->cur = buf; assert(buf); - if (0 == *buf) { - roff_err(tree, buf, "blank line"); - return(0); - } else if ('.' != *buf) + if (0 == *buf) + return(roff_err(tree, buf, "blank line")); + else if ('.' != *buf) return(textparse(tree, buf)); return(roffparse(tree, buf)); @@ -210,10 +210,8 @@ textparse(struct rofftree *tree, char *buf) /* TODO: literal parsing. */ - if ( ! (ROFF_BODY & tree->state)) { - roff_err(tree, buf, "data not in body"); - return(0); - } + if ( ! (ROFF_BODY & tree->state)) + return(roff_err(tree, buf, "data not in body")); /* LINTED */ while (*buf) { @@ -269,13 +267,9 @@ roffargs(const struct rofftree *tree, argv[i] = ++buf; while (*buf && '\"' != *buf) buf++; - if (0 == *buf) { - roff_err(tree, argv[i], "unclosed " - "quote in argument " - "list for `%s'", - toknames[tok]); - return(0); - } + if (0 == *buf) + return(roff_err(tree, argv[i], + "unclosed quote in arg list")); } else { argv[i] = buf++; while (*buf) { @@ -298,11 +292,8 @@ roffargs(const struct rofftree *tree, } assert(i > 0); - if (ROFF_MAXLINEARG == i && *buf) { - roff_err(tree, p, "too many arguments for `%s'", toknames - [tok]); - return(0); - } + if (ROFF_MAXLINEARG == i && *buf) + return(roff_err(tree, p, "too many args")); argv[i] = NULL; return(1); @@ -336,11 +327,10 @@ roffparse(struct rofftree *tree, char *buf) if (0 == strncmp(buf, ".\\\"", 3)) return(1); - if (ROFF_MAX == (tok = rofffindtok(buf + 1))) { - roff_err(tree, buf, "bogus line macro"); + if (ROFF_MAX == (tok = rofffindtok(buf + 1))) + return(roff_err(tree, buf, "bogus line macro")); + else if ( ! roffargs(tree, tok, buf, argv)) return(0); - } else if ( ! roffargs(tree, tok, buf, argv)) - return(0); argvp = (char **)argv; @@ -361,20 +351,16 @@ roffparse(struct rofftree *tree, char *buf) */ 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); - } + (tree->last->tok, tokens[tok].parents)) + return(roff_err(tree, *argvp, "`%s' has invalid " + "parent `%s'", toknames[tok], + toknames[tree->last->tok])); 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]); - return(0); - } + (tok, tokens[tree->last->tok].children)) + return(roff_err(tree, *argvp, "`%s' has invalid " + "child `%s'", toknames[tok], + toknames[tree->last->tok])); /* * Branch if we're not a layout token. @@ -414,9 +400,10 @@ roffparse(struct rofftree *tree, char *buf) } if (tokens[n->tok].ctx == n->tok) continue; - roff_err(tree, *argv, "`%s' breaks `%s' scope", - toknames[tok], toknames[n->tok]); - return(0); + return(roff_err(tree, *argv, "`%s' breaks " + "scope of prior`%s'", + toknames[tok], + toknames[n->tok])); } /* @@ -457,20 +444,18 @@ roffparse(struct rofftree *tree, char *buf) 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); + return(roff_err(tree, *argv, "`%s' breaks " + "scope of prior `%s'", + toknames[tok], + toknames[n->tok])); } else break; + if (NULL == n) + return(roff_err(tree, *argv, "`%s' has no starting " + "tag `%s'", toknames[tok], + toknames[tokens[tok].ctx])); - 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; @@ -596,6 +581,7 @@ roffchecksec(struct rofftree *tree, const char *start, } +/* FIXME: move this into literals.c. */ static int roffissec(const char **p) { @@ -644,6 +630,7 @@ roffissec(const char **p) } +/* FIXME: move this into literals.c. */ static int roffismsec(const char *p) { @@ -679,7 +666,35 @@ roffismsec(const char *p) } +/* FIXME: move this into literals.c. */ static int +roffisatt(const char *p) +{ + + assert(p); + if (0 == strcmp(p, "v1")) + return(1); + else if (0 == strcmp(p, "v2")) + return(1); + else if (0 == strcmp(p, "v3")) + return(1); + else if (0 == strcmp(p, "v6")) + return(1); + else if (0 == strcmp(p, "v7")) + return(1); + else if (0 == strcmp(p, "32v")) + return(1); + else if (0 == strcmp(p, "V.1")) + return(1); + else if (0 == strcmp(p, "V.4")) + return(1); + + return(0); +} + + +/* FIXME: move this into literals.c (or similar). */ +static int roffispunct(const char *p) { @@ -788,24 +803,9 @@ roffspecial(struct rofftree *tree, int tok, const char case (ROFF_At): if (0 == sz) break; - if (0 == strcmp(*ordp, "v1")) + if (roffisatt(*ordp)) break; - else if (0 == strcmp(*ordp, "v2")) - break; - else if (0 == strcmp(*ordp, "v3")) - break; - else if (0 == strcmp(*ordp, "v6")) - break; - else if (0 == strcmp(*ordp, "v7")) - break; - else if (0 == strcmp(*ordp, "32v")) - break; - else if (0 == strcmp(*ordp, "V.1")) - break; - else if (0 == strcmp(*ordp, "V.4")) - break; - roff_err(tree, *ordp, "invalid `At' arg"); - return(0); + return(roff_err(tree, *ordp, "invalid `At' arg")); case (ROFF_Xr): if (2 == sz) { @@ -822,9 +822,8 @@ roffspecial(struct rofftree *tree, int tok, const char case (ROFF_Fn): if (0 != sz) break; - roff_err(tree, start, "`%s' expects at least " - "one arg", toknames[tok]); - return(0); + return(roff_err(tree, start, "`%s' expects at least " + "one arg", toknames[tok])); case (ROFF_Nm): if (0 == sz) { @@ -1047,7 +1046,7 @@ roff_Dd(ROFFCALL_ARGS) argv++; - if (0 == strcmp(*argv, "$Mdocdate: December 8 2008 $")) { + if (0 == strcmp(*argv, "$Mdocdate: December 9 2008 $")) { t = time(NULL); if (NULL == localtime_r(&t, &tree->tm)) err(1, "localtime_r"); @@ -1291,7 +1290,7 @@ static int roff_layout(ROFFCALL_ARGS) { int i, c, argcp[ROFF_MAXLINEARG]; - char *argvp[ROFF_MAXLINEARG]; + char *argvp[ROFF_MAXLINEARG], *p; /* * The roff_layout function is for multi-line macros. A layout @@ -1320,7 +1319,7 @@ roff_layout(ROFFCALL_ARGS) assert( ! (ROFF_CALLABLE & tokens[tok].flags)); - ++argv; + p = *argv++; if ( ! roffparseopts(tree, tok, &argv, argcp, argvp)) return(0);