From f71c769f3131a98555b338bfb3f462d3bb674108 Mon Sep 17 00:00:00 2001 From: Kristaps Dzonsons Date: Tue, 9 Dec 2008 00:27:17 +0000 Subject: *** empty log message *** --- libmdocml.h | 3 +- literals.c | 4 ++- mdocml.c | 28 ++++++++++++---- roff.c | 106 ++++++++++++++++++++++++++---------------------------------- 4 files changed, 73 insertions(+), 68 deletions(-) diff --git a/libmdocml.h b/libmdocml.h index 8788467d..12839fb6 100644 --- a/libmdocml.h +++ b/libmdocml.h @@ -1,4 +1,4 @@ -/* $Id: libmdocml.h,v 1.12 2008/12/04 11:25:29 kristaps Exp $ */ +/* $Id: libmdocml.h,v 1.13 2008/12/09 00:27:17 kristaps Exp $ */ /* * Copyright (c) 2008 Kristaps Dzonsons * @@ -47,6 +47,7 @@ struct md_args { int warnings; #define MD_WARN_ALL (1 << 0) +#define MD_WARN_ERROR (1 << 1) int verbosity; }; diff --git a/literals.c b/literals.c index 45b3f0d8..64e37bf1 100644 --- a/literals.c +++ b/literals.c @@ -1,4 +1,4 @@ -/* $Id: literals.c,v 1.3 2008/12/08 16:29:57 kristaps Exp $ */ +/* $Id: literals.c,v 1.4 2008/12/09 00:27:17 kristaps Exp $ */ /* * Copyright (c) 2008 Kristaps Dzonsons * @@ -24,6 +24,8 @@ #include "private.h" #include "ml.h" +/* FIXME: make this roff_section and so on. */ + char * ml_section(enum roffmsec sec) diff --git a/mdocml.c b/mdocml.c index de52dac3..ed1572fb 100644 --- a/mdocml.c +++ b/mdocml.c @@ -1,4 +1,4 @@ -/* $Id: mdocml.c,v 1.17 2008/12/04 11:25:29 kristaps Exp $ */ +/* $Id: mdocml.c,v 1.18 2008/12/09 00:27:17 kristaps Exp $ */ /* * Copyright (c) 2008 Kristaps Dzonsons * @@ -54,8 +54,11 @@ int main(int argc, char *argv[]) { int c; - char *out, *in; + char *out, *in, *opts, *v; struct md_args args; +#define ALL 0 +#define ERROR 1 + char *toks[] = { "all", "error", NULL }; extern char *optarg; extern int optind; @@ -66,7 +69,7 @@ main(int argc, char *argv[]) args.type = MD_XML; - while (-1 != (c = getopt(argc, argv, "c:ef:o:vW"))) + while (-1 != (c = getopt(argc, argv, "c:ef:o:vW:"))) switch (c) { case ('c'): if (args.type != MD_HTML) @@ -93,7 +96,19 @@ main(int argc, char *argv[]) args.verbosity++; break; case ('W'): - args.warnings |= MD_WARN_ALL; + opts = optarg; + while (*opts) + switch (getsubopt(&opts, toks, &v)) { + case (ALL): + args.warnings |= MD_WARN_ALL; + break; + case (ERROR): + args.warnings |= MD_WARN_ERROR; + break; + default: + usage(); + return(1); + } break; default: usage(); @@ -250,6 +265,7 @@ usage(void) { extern char *__progname; - (void)printf("usage: %s [-vW] [-f filter] [-o outfile] " - "[infile]\n", __progname); + (void)printf("usage: %s [-v] [-Wwarn...] [-f filter] " + "[-o outfile] [infile]\n", __progname); } + diff --git a/roff.c b/roff.c index d13e07eb..b737c569 100644 --- a/roff.c +++ b/roff.c @@ -1,4 +1,4 @@ -/* $Id: roff.c,v 1.53 2008/12/08 20:32:49 kristaps Exp $ */ +/* $Id: roff.c,v 1.54 2008/12/09 00:27:17 kristaps Exp $ */ /* * Copyright (c) 2008 Kristaps Dzonsons * @@ -127,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', " @@ -139,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; } @@ -194,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)); @@ -211,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) { @@ -270,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) { @@ -299,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); @@ -337,10 +327,9 @@ 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"); - return(0); - } else if ( ! roffargs(tree, tok, buf, argv)) + if (ROFF_MAX == (tok = rofffindtok(buf + 1))) + return(roff_err(tree, buf, "bogus line macro")); + else if ( ! roffargs(tree, tok, buf, argv)) return(0); argvp = (char **)argv; @@ -362,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. @@ -415,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])); } /* @@ -458,19 +444,17 @@ 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) { - roff_err(tree, *argv, "`%s' has no starting tag `%s'", - toknames[tok], - toknames[tokens[tok].ctx]); - return(0); - } + if (NULL == n) + return(roff_err(tree, *argv, "`%s' has no starting " + "tag `%s'", toknames[tok], + toknames[tokens[tok].ctx])); /* LINTED */ do { @@ -597,6 +581,7 @@ roffchecksec(struct rofftree *tree, const char *start, int sec) } +/* FIXME: move this into literals.c. */ static int roffissec(const char **p) { @@ -645,6 +630,7 @@ roffissec(const char **p) } +/* FIXME: move this into literals.c. */ static int roffismsec(const char *p) { @@ -680,6 +666,7 @@ roffismsec(const char *p) } +/* FIXME: move this into literals.c. */ static int roffisatt(const char *p) { @@ -706,6 +693,7 @@ roffisatt(const char *p) } +/* FIXME: move this into literals.c (or similar). */ static int roffispunct(const char *p) { @@ -817,8 +805,7 @@ roffspecial(struct rofftree *tree, int tok, const char *start, break; if (roffisatt(*ordp)) break; - roff_err(tree, *ordp, "invalid `At' arg"); - return(0); + return(roff_err(tree, *ordp, "invalid `At' arg")); case (ROFF_Xr): if (2 == sz) { @@ -835,9 +822,8 @@ roffspecial(struct rofftree *tree, int tok, const char *start, 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) { @@ -1060,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"); -- cgit v1.2.3-56-ge451