=================================================================== RCS file: /cvs/mandoc/Attic/mdocml.c,v retrieving revision 1.24 retrieving revision 1.36 diff -u -p -r1.24 -r1.36 --- mandoc/Attic/mdocml.c 2008/12/23 05:30:49 1.24 +++ mandoc/Attic/mdocml.c 2009/01/07 15:53:00 1.36 @@ -1,4 +1,4 @@ -/* $Id: mdocml.c,v 1.24 2008/12/23 05:30:49 kristaps Exp $ */ +/* $Id: mdocml.c,v 1.36 2009/01/07 15:53:00 kristaps Exp $ */ /* * Copyright (c) 2008 Kristaps Dzonsons * @@ -181,18 +181,21 @@ buf_begin(struct md_parse *p) static void print_node(const struct mdoc_node *n, int indent) { - const char *p, *t; - int i, j; - size_t argc; - struct mdoc_arg *argv; + const char *p, *t; + int i, j; + size_t argc, sz; + char **params; + struct mdoc_arg *argv; argv = NULL; argc = 0; + params = NULL; + sz = 0; switch (n->type) { case (MDOC_TEXT): assert(NULL == n->child); - p = ""; + p = n->data.text.string; t = "text"; break; case (MDOC_BODY): @@ -203,8 +206,11 @@ print_node(const struct mdoc_node *n, int indent) p = mdoc_macronames[n->data.head.tok]; t = "block-head"; break; + case (MDOC_TAIL): + p = mdoc_macronames[n->data.tail.tok]; + t = "block-tail"; + break; case (MDOC_ELEM): - assert(NULL == n->child); p = mdoc_macronames[n->data.elem.tok]; t = "element"; argv = n->data.elem.argv; @@ -231,6 +237,9 @@ print_node(const struct mdoc_node *n, int indent) (void)printf(" \"%s\"", argv[i].value[j]); } + for (i = 0; i < (int)sz; i++) + (void)printf(" \"%s\"", params[i]); + (void)printf("\n"); if (n->child) @@ -245,11 +254,14 @@ parse_leave(struct md_parse *p, int code) { const struct mdoc_node *n; - if (p->mdoc) { - if ((n = mdoc_result(p->mdoc))) - print_node(n, 0); - mdoc_free(p->mdoc); - } + if (NULL == p->mdoc) + return(code); + + if ( ! mdoc_endparse(p->mdoc)) + code = 0; + if ((n = mdoc_result(p->mdoc))) + print_node(n, 0); + return(code); } @@ -293,7 +305,7 @@ parse_begin(struct md_parse *p) } line[(int)pos] = sv[(int)pos] = 0; - if ( ! mdoc_parseln(p->mdoc, line)) + if ( ! mdoc_parseln(p->mdoc, p->lnn, line)) return(parse_leave(p, 0)); p->lnn++; @@ -317,6 +329,9 @@ msg_err(void *arg, int tok, int col, enum mdoc_err typ fmt = lit = NULL; switch (type) { + case (ERR_SYNTAX_NOTEXT): + lit = "syntax: context-free text disallowed"; + break; case (ERR_SYNTAX_QUOTE): lit = "syntax: disallowed argument quotation"; break; @@ -326,10 +341,13 @@ msg_err(void *arg, int tok, int col, enum mdoc_err typ case (ERR_SYNTAX_WS): lit = "syntax: whitespace in argument"; break; - case (ERR_SYNTAX_ARGS): + case (ERR_SYNTAX_ARGFORM): fmt = "syntax: macro `%s' arguments malformed"; break; - case (ERR_SYNTAX_BADARG): + case (ERR_SYNTAX_NOPUNCT): + fmt = "syntax: macro `%s' doesn't understand punctuation"; + break; + case (ERR_SYNTAX_ARG): fmt = "syntax: unknown argument for macro `%s'"; break; case (ERR_SCOPE_BREAK): @@ -339,8 +357,11 @@ msg_err(void *arg, int tok, int col, enum mdoc_err typ case (ERR_SCOPE_NOCTX): fmt = "scope: closure macro `%s' has no context"; break; + case (ERR_SCOPE_NONEST): + fmt = "scope: macro `%s' may not be nested in the current context"; + break; case (ERR_MACRO_NOTSUP): - fmt = "macro `%s' not supported"; + lit = "macro not supported"; break; case (ERR_MACRO_NOTCALL): fmt = "macro `%s' not callable"; @@ -351,9 +372,21 @@ msg_err(void *arg, int tok, int col, enum mdoc_err typ case (ERR_SEC_NPROLOGUE): fmt = "macro `%s' called outside of prologue"; break; + case (ERR_ARGS_EQ0): + fmt = "macro `%s' expects zero arguments"; + break; + case (ERR_ARGS_EQ1): + fmt = "macro `%s' expects one argument"; + break; case (ERR_ARGS_GE1): fmt = "macro `%s' expects one or more arguments"; break; + case (ERR_ARGS_LE2): + fmt = "macro `%s' expects two or fewer arguments"; + break; + case (ERR_ARGS_LE8): + fmt = "macro `%s' expects eight or fewer arguments"; + break; case (ERR_ARGS_MANY): fmt = "macro `%s' has too many arguments"; break; @@ -369,9 +402,24 @@ msg_err(void *arg, int tok, int col, enum mdoc_err typ case (ERR_SYNTAX_ARGVAL): lit = "syntax: expected value for macro argument"; break; + case (ERR_SYNTAX_ARGBAD): + lit = "syntax: invalid value for macro argument"; + break; case (ERR_SYNTAX_ARGMANY): lit = "syntax: too many values for macro argument"; break; + case (ERR_SYNTAX_CHILDHEAD): + lit = "syntax: expected only block-header section"; + break; + case (ERR_SYNTAX_CHILDBODY): + lit = "syntax: expected only a block-body section"; + break; + case (ERR_SYNTAX_EMPTYHEAD): + lit = "syntax: block-header section may not be empty"; + break; + case (ERR_SYNTAX_EMPTYBODY): + lit = "syntax: block-body section may not be empty"; + break; default: abort(); /* NOTREACHED */ @@ -390,7 +438,7 @@ msg_err(void *arg, int tok, int col, enum mdoc_err typ (void)fprintf(stderr, " (column %d)\n", col); return(0); } else if (-1 == col) { - (void)fprintf(stderr, "\nFrom: %s", p->line); + (void)fprintf(stderr, "\nFrom: %s\n", p->line); return(0); } @@ -451,18 +499,39 @@ msg_warn(void *arg, int tok, int col, enum mdoc_warn t case (WARN_SYNTAX_WS_EOLN): lit = "syntax: whitespace at end-of-line"; break; + case (WARN_SYNTAX_QUOTED): + lit = "syntax: quotation mark starting string"; + break; case (WARN_SYNTAX_MACLIKE): lit = "syntax: macro-like argument"; break; case (WARN_SYNTAX_ARGLIKE): lit = "syntax: argument-like value"; break; + case (WARN_SYNTAX_EMPTYBODY): + lit = "syntax: empty block-body section"; + break; case (WARN_SEC_OO): lit = "section is out of conventional order"; break; case (WARN_ARGS_GE1): fmt = "macro `%s' suggests one or more arguments"; break; + case (WARN_ARGS_EQ0): + fmt = "macro `%s' suggests zero arguments"; + break; + case (WARN_IGN_AFTER_BLK): + fmt = "ignore: macro `%s' ignored after block macro"; + break; + case (WARN_IGN_OBSOLETE): + fmt = "ignore: macro `%s' is obsolete"; + break; + case (WARN_IGN_BEFORE_BLK): + fmt = "ignore: macro before block macro `%s' ignored"; + break; + case (WARN_COMPAT_TROFF): + fmt = "compat: macro `%s' behaves differently in troff and nroff"; + break; default: abort(); /* NOTREACHED */ @@ -476,13 +545,15 @@ msg_warn(void *arg, int tok, int col, enum mdoc_warn t (void)fprintf(stderr, "%s:%d: warning: %s", p->name, p->lnn, lit); - if (p->dbg >= 1) { + if (col >= 0 && p->dbg >= 1) { (void)fprintf(stderr, "\nFrom: %s\n ", p->line); for (i = 0; i < col; i++) (void)fprintf(stderr, " "); (void)fprintf(stderr, "^\n"); - } else + } else if (col >= 0) (void)fprintf(stderr, " (column %d)\n", col); + else + (void)fprintf(stderr, "\n"); if (p->warn & MD_WARN_ERR) { (void)fprintf(stderr, "%s: considering warnings as "