version 1.31, 2009/01/01 20:40:16 |
version 1.38, 2009/01/09 14:45:44 |
Line 57 static int buf_leave(struct md_parse *, int); |
|
Line 57 static int buf_leave(struct md_parse *, int); |
|
|
|
static int msg_err(void *, int, int, enum mdoc_err); |
static int msg_err(void *, int, int, enum mdoc_err); |
static int msg_warn(void *, int, int, enum mdoc_warn); |
static int msg_warn(void *, int, int, enum mdoc_warn); |
static void msg_msg(void *, int, const char *); |
static void msg_msg(void *, int, int, const char *); |
|
|
#ifdef __linux__ |
#ifdef __linux__ |
extern int getsubopt(char **, char *const *, char **); |
extern int getsubopt(char **, char *const *, char **); |
Line 206 print_node(const struct mdoc_node *n, int indent) |
|
Line 206 print_node(const struct mdoc_node *n, int indent) |
|
p = mdoc_macronames[n->data.head.tok]; |
p = mdoc_macronames[n->data.head.tok]; |
t = "block-head"; |
t = "block-head"; |
break; |
break; |
|
case (MDOC_TAIL): |
|
p = mdoc_macronames[n->data.tail.tok]; |
|
t = "block-tail"; |
|
break; |
case (MDOC_ELEM): |
case (MDOC_ELEM): |
assert(NULL == n->child); |
|
p = mdoc_macronames[n->data.elem.tok]; |
p = mdoc_macronames[n->data.elem.tok]; |
t = "element"; |
t = "element"; |
argv = n->data.elem.argv; |
argv = n->data.elem.argv; |
argc = n->data.elem.argc; |
argc = n->data.elem.argc; |
params = n->data.elem.args; |
|
sz = n->data.elem.sz; |
|
break; |
break; |
case (MDOC_BLOCK): |
case (MDOC_BLOCK): |
p = mdoc_macronames[n->data.block.tok]; |
p = mdoc_macronames[n->data.block.tok]; |
Line 221 print_node(const struct mdoc_node *n, int indent) |
|
Line 222 print_node(const struct mdoc_node *n, int indent) |
|
argv = n->data.block.argv; |
argv = n->data.block.argv; |
argc = n->data.block.argc; |
argc = n->data.block.argc; |
break; |
break; |
|
case (MDOC_ROOT): |
|
p = "root"; |
|
t = "root"; |
|
break; |
default: |
default: |
abort(); |
abort(); |
/* NOTREACHED */ |
/* NOTREACHED */ |
Line 253 parse_leave(struct md_parse *p, int code) |
|
Line 258 parse_leave(struct md_parse *p, int code) |
|
{ |
{ |
const struct mdoc_node *n; |
const struct mdoc_node *n; |
|
|
if (p->mdoc) { |
if (NULL == p->mdoc) |
if ((n = mdoc_result(p->mdoc))) |
return(code); |
print_node(n, 0); |
|
mdoc_free(p->mdoc); |
if ( ! mdoc_endparse(p->mdoc)) |
} |
code = 0; |
|
if ((n = mdoc_result(p->mdoc))) |
|
print_node(n, 0); |
|
|
|
mdoc_free(p->mdoc); |
|
|
return(code); |
return(code); |
} |
} |
|
|
Line 301 parse_begin(struct md_parse *p) |
|
Line 311 parse_begin(struct md_parse *p) |
|
} |
} |
|
|
line[(int)pos] = sv[(int)pos] = 0; |
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)); |
return(parse_leave(p, 0)); |
|
|
p->lnn++; |
p->lnn++; |
Line 314 parse_begin(struct md_parse *p) |
|
Line 324 parse_begin(struct md_parse *p) |
|
|
|
|
|
static int |
static int |
msg_err(void *arg, int tok, int col, enum mdoc_err type) |
msg_err(void *arg, int line, int col, enum mdoc_err type) |
{ |
{ |
char *fmt, *lit; |
char *lit; |
struct md_parse *p; |
struct md_parse *p; |
int i; |
int i; |
|
|
p = (struct md_parse *)arg; |
p = (struct md_parse *)arg; |
|
|
fmt = lit = NULL; |
lit = NULL; |
|
|
switch (type) { |
switch (type) { |
|
case (ERR_SYNTAX_NOTEXT): |
|
lit = "syntax: context-free text disallowed"; |
|
break; |
case (ERR_SYNTAX_QUOTE): |
case (ERR_SYNTAX_QUOTE): |
lit = "syntax: disallowed argument quotation"; |
lit = "syntax: disallowed argument quotation"; |
break; |
break; |
Line 335 msg_err(void *arg, int tok, int col, enum mdoc_err typ |
|
Line 348 msg_err(void *arg, int tok, int col, enum mdoc_err typ |
|
lit = "syntax: whitespace in argument"; |
lit = "syntax: whitespace in argument"; |
break; |
break; |
case (ERR_SYNTAX_ARGFORM): |
case (ERR_SYNTAX_ARGFORM): |
fmt = "syntax: macro `%s' arguments malformed"; |
lit = "syntax: macro arguments malformed"; |
break; |
break; |
case (ERR_SYNTAX_NOPUNCT): |
case (ERR_SYNTAX_NOPUNCT): |
fmt = "syntax: macro `%s' doesn't understand punctuation"; |
lit = "syntax: macro doesn't understand punctuation"; |
break; |
break; |
case (ERR_SYNTAX_ARG): |
case (ERR_SYNTAX_ARG): |
fmt = "syntax: unknown argument for macro `%s'"; |
lit = "syntax: unknown argument for macro"; |
break; |
break; |
case (ERR_SCOPE_BREAK): |
case (ERR_SCOPE_BREAK): |
/* Which scope is broken? */ |
/* Which scope is broken? */ |
fmt = "scope: macro `%s' breaks prior explicit scope"; |
lit = "scope: macro breaks prior explicit scope"; |
break; |
break; |
case (ERR_SCOPE_NOCTX): |
case (ERR_SCOPE_NOCTX): |
fmt = "scope: closure macro `%s' has no context"; |
lit = "scope: closure macro has no context"; |
break; |
break; |
case (ERR_SCOPE_NONEST): |
case (ERR_SCOPE_NONEST): |
fmt = "scope: macro `%s' may not be nested in the current context"; |
lit = "scope: macro may not be nested in the current context"; |
break; |
break; |
case (ERR_MACRO_NOTSUP): |
case (ERR_MACRO_NOTSUP): |
fmt = "macro `%s' not supported"; |
lit = "macro not supported"; |
break; |
break; |
case (ERR_MACRO_NOTCALL): |
case (ERR_MACRO_NOTCALL): |
fmt = "macro `%s' not callable"; |
lit = "macro not callable"; |
break; |
break; |
case (ERR_SEC_PROLOGUE): |
case (ERR_SEC_PROLOGUE): |
fmt = "macro `%s' cannot be called in the prologue"; |
lit = "macro cannot be called in the prologue"; |
break; |
break; |
case (ERR_SEC_NPROLOGUE): |
case (ERR_SEC_NPROLOGUE): |
fmt = "macro `%s' called outside of prologue"; |
lit = "macro called outside of prologue"; |
break; |
break; |
case (ERR_ARGS_EQ0): |
case (ERR_ARGS_EQ0): |
fmt = "macro `%s' expects zero arguments"; |
lit = "macro expects zero arguments"; |
break; |
break; |
case (ERR_ARGS_EQ1): |
case (ERR_ARGS_EQ1): |
fmt = "macro `%s' expects one argument"; |
lit = "macro expects one argument"; |
break; |
break; |
case (ERR_ARGS_GE1): |
case (ERR_ARGS_GE1): |
fmt = "macro `%s' expects one or more arguments"; |
lit = "macro expects one or more arguments"; |
break; |
break; |
case (ERR_ARGS_LE2): |
case (ERR_ARGS_LE2): |
fmt = "macro `%s' expects two or fewer arguments"; |
lit = "macro expects two or fewer arguments"; |
break; |
break; |
|
case (ERR_ARGS_LE8): |
|
lit = "macro expects eight or fewer arguments"; |
|
break; |
case (ERR_ARGS_MANY): |
case (ERR_ARGS_MANY): |
fmt = "macro `%s' has too many arguments"; |
lit = "macro has too many arguments"; |
break; |
break; |
case (ERR_SEC_PROLOGUE_OO): |
case (ERR_SEC_PROLOGUE_OO): |
fmt = "prologue macro `%s' is out-of-order"; |
lit = "prologue macro is out-of-order"; |
break; |
break; |
case (ERR_SEC_PROLOGUE_REP): |
case (ERR_SEC_PROLOGUE_REP): |
fmt = "prologue macro `%s' repeated"; |
lit = "prologue macro repeated"; |
break; |
break; |
case (ERR_SEC_NAME): |
case (ERR_SEC_NAME): |
lit = "`NAME' section must be first"; |
lit = "`NAME' section must be first"; |
Line 398 msg_err(void *arg, int tok, int col, enum mdoc_err typ |
|
Line 414 msg_err(void *arg, int tok, int col, enum mdoc_err typ |
|
case (ERR_SYNTAX_ARGMANY): |
case (ERR_SYNTAX_ARGMANY): |
lit = "syntax: too many values for macro argument"; |
lit = "syntax: too many values for macro argument"; |
break; |
break; |
case (ERR_CHILD_HEAD): |
case (ERR_SYNTAX_CHILDHEAD): |
lit = "scope context expects block-header child"; |
lit = "syntax: expected only block-header section"; |
break; |
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: |
default: |
abort(); |
abort(); |
/* NOTREACHED */ |
/* NOTREACHED */ |
} |
} |
|
|
if (fmt) { |
(void)fprintf(stderr, "%s:%d: error: %s", p->name, p->lnn, lit); |
(void)fprintf(stderr, "%s:%d: error: ", |
|
p->name, p->lnn); |
|
(void)fprintf(stderr, fmt, mdoc_macronames[tok]); |
|
} else |
|
(void)fprintf(stderr, "%s:%d: error: %s", |
|
p->name, p->lnn, lit); |
|
|
|
if (p->dbg < 1) { |
if (p->dbg < 1) { |
if (-1 != col) |
(void)fprintf(stderr, " (column %d)\n", col); |
(void)fprintf(stderr, " (column %d)\n", col); |
|
return(0); |
return(0); |
} else if (-1 == col) { |
} |
(void)fprintf(stderr, "\nFrom: %s", p->line); |
|
return(0); |
|
} |
|
|
|
(void)fprintf(stderr, "\nFrom: %s\n ", p->line); |
(void)fprintf(stderr, "\nFrom: %s\n ", p->line); |
for (i = 0; i < col; i++) |
for (i = 0; i < col; i++) |
Line 433 msg_err(void *arg, int tok, int col, enum mdoc_err typ |
|
Line 448 msg_err(void *arg, int tok, int col, enum mdoc_err typ |
|
|
|
|
|
static void |
static void |
msg_msg(void *arg, int col, const char *msg) |
msg_msg(void *arg, int line, int col, const char *msg) |
{ |
{ |
struct md_parse *p; |
struct md_parse *p; |
int i; |
int i; |
Line 443 msg_msg(void *arg, int col, const char *msg) |
|
Line 458 msg_msg(void *arg, int col, const char *msg) |
|
if (p->dbg < 2) |
if (p->dbg < 2) |
return; |
return; |
|
|
(void)printf("%s:%d: %s", p->name, p->lnn, msg); |
(void)printf("%s:%d: %s", p->name, line, msg); |
|
|
if (p->dbg < 3) { |
if (p->dbg < 3) { |
if (-1 != col) |
(void)printf(" (column %d)\n", col); |
(void)printf(" (column %d)\n", col); |
|
return; |
return; |
} else if (-1 == col) { |
|
(void)printf("\nFrom %s\n", p->line); |
|
return; |
|
} |
} |
|
|
(void)printf("\nFrom: %s\n ", p->line); |
(void)printf("\nFrom: %s\n ", p->line); |
Line 462 msg_msg(void *arg, int col, const char *msg) |
|
Line 473 msg_msg(void *arg, int col, const char *msg) |
|
|
|
|
|
static int |
static int |
msg_warn(void *arg, int tok, int col, enum mdoc_warn type) |
msg_warn(void *arg, int line, int col, enum mdoc_warn type) |
{ |
{ |
char *fmt, *lit; |
char *lit; |
struct md_parse *p; |
struct md_parse *p; |
int i; |
int i; |
extern char *__progname; |
extern char *__progname; |
Line 474 msg_warn(void *arg, int tok, int col, enum mdoc_warn t |
|
Line 485 msg_warn(void *arg, int tok, int col, enum mdoc_warn t |
|
if ( ! (p->warn & MD_WARN_ALL)) |
if ( ! (p->warn & MD_WARN_ALL)) |
return(1); |
return(1); |
|
|
fmt = lit = NULL; |
lit = NULL; |
|
|
switch (type) { |
switch (type) { |
case (WARN_SYNTAX_WS_EOLN): |
case (WARN_SYNTAX_WS_EOLN): |
Line 489 msg_warn(void *arg, int tok, int col, enum mdoc_warn t |
|
Line 500 msg_warn(void *arg, int tok, int col, enum mdoc_warn t |
|
case (WARN_SYNTAX_ARGLIKE): |
case (WARN_SYNTAX_ARGLIKE): |
lit = "syntax: argument-like value"; |
lit = "syntax: argument-like value"; |
break; |
break; |
|
case (WARN_SYNTAX_EMPTYBODY): |
|
lit = "syntax: empty block-body section"; |
|
break; |
case (WARN_SEC_OO): |
case (WARN_SEC_OO): |
lit = "section is out of conventional order"; |
lit = "section is out of conventional order"; |
break; |
break; |
|
case (WARN_SEC_REP): |
|
lit = "section repeated"; |
|
break; |
case (WARN_ARGS_GE1): |
case (WARN_ARGS_GE1): |
fmt = "macro `%s' suggests one or more arguments"; |
lit = "macro suggests one or more arguments"; |
break; |
break; |
case (WARN_ARGS_EQ0): |
case (WARN_ARGS_EQ0): |
fmt = "macro `%s' suggests zero arguments"; |
lit = "macro suggests zero arguments"; |
break; |
break; |
case (WARN_IGN_AFTER_BLK): |
case (WARN_IGN_AFTER_BLK): |
fmt = "ignore: macro `%s' ignored after block macro"; |
lit = "ignore: macro ignored after block macro"; |
break; |
break; |
case (WARN_IGN_OBSOLETE): |
case (WARN_IGN_OBSOLETE): |
fmt = "ignore: macro `%s' is obsolete"; |
lit = "ignore: macro is obsolete"; |
break; |
break; |
case (WARN_IGN_BEFORE_BLK): |
case (WARN_IGN_BEFORE_BLK): |
fmt = "ignore: macro before block macro `%s' ignored"; |
lit = "ignore: macro before block macro ignored"; |
break; |
break; |
case (WARN_COMPAT_TROFF): |
case (WARN_COMPAT_TROFF): |
fmt = "compat: macro `%s' behaves differently in troff and nroff"; |
lit = "compat: macro behaves differently in troff and nroff"; |
break; |
break; |
default: |
default: |
abort(); |
abort(); |
/* NOTREACHED */ |
/* NOTREACHED */ |
} |
} |
|
|
if (fmt) { |
|
(void)fprintf(stderr, "%s:%d: warning: ", |
|
p->name, p->lnn); |
|
(void)fprintf(stderr, fmt, mdoc_macronames[tok]); |
|
} else |
|
(void)fprintf(stderr, "%s:%d: warning: %s", |
|
p->name, p->lnn, lit); |
|
|
|
|
(void)fprintf(stderr, "%s:%d: warning: %s", p->name, line, lit); |
|
|
if (p->dbg >= 1) { |
if (p->dbg >= 1) { |
(void)fprintf(stderr, "\nFrom: %s\n ", p->line); |
(void)fprintf(stderr, "\nFrom: %s\n ", p->line); |
for (i = 0; i < col; i++) |
for (i = 0; i < col; i++) |
(void)fprintf(stderr, " "); |
(void)fprintf(stderr, " "); |
(void)fprintf(stderr, "^\n"); |
(void)fprintf(stderr, "^\n"); |
} else |
} else |
(void)fprintf(stderr, " (column %d)\n", col); |
(void)fprintf(stderr, " (column %d)\n", col); |
|
|
if (p->warn & MD_WARN_ERR) { |
if (p->warn & MD_WARN_ERR) { |