diff options
author | 2009-06-15 02:19:32 +0000 | |
---|---|---|
committer | 2009-06-15 02:19:32 +0000 | |
commit | 160546161c85eef9b48d12f4a9aa663caecac57f (patch) | |
tree | 809a1f75ee94eeb661e048c373f5873b278c0d34 | |
parent | sync to 1.7.16: implement \~ and \^ escapes, and repair \(ss (diff) | |
download | wireguard-openbsd-160546161c85eef9b48d12f4a9aa663caecac57f.tar.xz wireguard-openbsd-160546161c85eef9b48d12f4a9aa663caecac57f.zip |
sync to 1.7.16:
reduce code duplication in warning and error reporting functions
while here, garbage collect three unused function prototypes
-rw-r--r-- | usr.bin/mandoc/libmdoc.h | 49 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc.c | 143 |
2 files changed, 40 insertions, 152 deletions
diff --git a/usr.bin/mandoc/libmdoc.h b/usr.bin/mandoc/libmdoc.h index 0f8ce114e87..061f5719320 100644 --- a/usr.bin/mandoc/libmdoc.h +++ b/usr.bin/mandoc/libmdoc.h @@ -1,4 +1,4 @@ -/* $Id: libmdoc.h,v 1.3 2009/06/14 23:00:57 schwarze Exp $ */ +/* $Id: libmdoc.h,v 1.4 2009/06/15 02:19:32 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -55,6 +55,38 @@ struct mdoc_macro { /* Reserved words in arguments treated as text. */ }; +#define mdoc_nwarn(mdoc, node, type, fmt, ...) \ + mdoc_vwarn((mdoc), (node)->line, \ + (node)->pos, (type), (fmt), ##__VA_ARGS__) + +#define mdoc_nerr(mdoc, node, fmt, ...) \ + mdoc_verr((mdoc), (node)->line, \ + (node)->pos, (fmt), ##__VA_ARGS__) + +#define mdoc_warn(mdoc, type, fmt, ...) \ + mdoc_vwarn((mdoc), (mdoc)->last->line, \ + (mdoc)->last->pos, (type), (fmt), ##__VA_ARGS__) + +#define mdoc_err(mdoc, fmt, ...) \ + mdoc_verr((mdoc), (mdoc)->last->line, \ + (mdoc)->last->pos, (fmt), ##__VA_ARGS__) + +#define mdoc_msg(mdoc, fmt, ...) \ + mdoc_vmsg((mdoc), (mdoc)->last->line, \ + (mdoc)->last->pos, (fmt), ##__VA_ARGS__) + +#define mdoc_pmsg(mdoc, line, pos, fmt, ...) \ + mdoc_vmsg((mdoc), (line), \ + (pos), (fmt), ##__VA_ARGS__) + +#define mdoc_pwarn(mdoc, line, pos, type, fmt, ...) \ + mdoc_vwarn((mdoc), (line), \ + (pos), (type), (fmt), ##__VA_ARGS__) + +#define mdoc_perr(mdoc, line, pos, fmt, ...) \ + mdoc_verr((mdoc), (line), \ + (pos), (fmt), ##__VA_ARGS__) + extern const struct mdoc_macro *const mdoc_macros; __BEGIN_DECLS @@ -65,17 +97,6 @@ void mdoc_vmsg(struct mdoc *, int, int, const char *, ...); int mdoc_verr(struct mdoc *, int, int, const char *, ...); -int mdoc_nwarn(struct mdoc *, const struct mdoc_node *, - enum mdoc_warn, const char *, ...); -int mdoc_nerr(struct mdoc *, const struct mdoc_node *, - const char *, ...); -int mdoc_warn(struct mdoc *, enum mdoc_warn, const char *, ...); -int mdoc_err(struct mdoc *, const char *, ...); -void mdoc_msg(struct mdoc *, const char *, ...); -void mdoc_pmsg(struct mdoc *, int, int, const char *, ...); -int mdoc_pwarn(struct mdoc *, int, int, - enum mdoc_warn,const char *, ...); -int mdoc_perr(struct mdoc *, int, int, const char *, ...); int mdoc_macro(MACRO_PROT_ARGS); int mdoc_word_alloc(struct mdoc *, int, int, const char *); @@ -123,10 +144,6 @@ int mdoc_args(struct mdoc *, int, #define ARGS_QWORD (3) #define ARGS_PHRASE (4) -/* FIXME: get rid of these. */ -int xstrlcpys(char *, const struct mdoc_node *, size_t); -void *xrealloc(void *, size_t); -char *xstrdup(const char *); int mdoc_macroend(struct mdoc *); __END_DECLS diff --git a/usr.bin/mandoc/mdoc.c b/usr.bin/mandoc/mdoc.c index c7a3841900c..946835592d9 100644 --- a/usr.bin/mandoc/mdoc.c +++ b/usr.bin/mandoc/mdoc.c @@ -1,4 +1,4 @@ -/* $Id: mdoc.c,v 1.3 2009/06/14 23:00:57 schwarze Exp $ */ +/* $Id: mdoc.c,v 1.4 2009/06/15 02:19:32 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -259,7 +259,8 @@ mdoc_vmsg(struct mdoc *mdoc, int ln, int pos, const char *fmt, ...) int -mdoc_verr(struct mdoc *mdoc, int ln, int pos, const char *fmt, ...) +mdoc_verr(struct mdoc *mdoc, int ln, int pos, + const char *fmt, ...) { char buf[256]; va_list ap; @@ -292,138 +293,6 @@ mdoc_vwarn(struct mdoc *mdoc, int ln, int pos, int -mdoc_nwarn(struct mdoc *mdoc, const struct mdoc_node *node, enum mdoc_warn type, - const char *fmt, ...) -{ - char buf[256]; - va_list ap; - - if (NULL == mdoc->cb.mdoc_warn) - return(0); - - va_start(ap, fmt); - (void)vsnprintf(buf, sizeof(buf) - 1, fmt, ap); - va_end(ap); - return((*mdoc->cb.mdoc_warn)(mdoc->data, node->line, node->pos, type, - buf)); -} - -int -mdoc_nerr(struct mdoc *mdoc, const struct mdoc_node *node, const char *fmt, ...) -{ - char buf[256]; - va_list ap; - - if (NULL == mdoc->cb.mdoc_err) - return(0); - - va_start(ap, fmt); - (void)vsnprintf(buf, sizeof(buf) - 1, fmt, ap); - va_end(ap); - return((*mdoc->cb.mdoc_err)(mdoc->data, node->line, node->pos, buf)); -} - - -int -mdoc_warn(struct mdoc *mdoc, enum mdoc_warn type, const char *fmt, ...) -{ - char buf[256]; - va_list ap; - - if (NULL == mdoc->cb.mdoc_warn) - return(0); - - va_start(ap, fmt); - (void)vsnprintf(buf, sizeof(buf) - 1, fmt, ap); - va_end(ap); - return((*mdoc->cb.mdoc_warn)(mdoc->data, mdoc->last->line, - mdoc->last->pos, type, buf)); -} - - -int -mdoc_err(struct mdoc *mdoc, const char *fmt, ...) -{ - char buf[256]; - va_list ap; - - if (NULL == mdoc->cb.mdoc_err) - return(0); - - va_start(ap, fmt); - (void)vsnprintf(buf, sizeof(buf) - 1, fmt, ap); - va_end(ap); - return((*mdoc->cb.mdoc_err)(mdoc->data, mdoc->last->line, - mdoc->last->pos, buf)); -} - - -void -mdoc_msg(struct mdoc *mdoc, const char *fmt, ...) -{ - char buf[256]; - va_list ap; - - if (NULL == mdoc->cb.mdoc_msg) - return; - - va_start(ap, fmt); - (void)vsnprintf(buf, sizeof(buf) - 1, fmt, ap); - va_end(ap); - (*mdoc->cb.mdoc_msg)(mdoc->data, mdoc->last->line, mdoc->last->pos, - buf); -} - - -void -mdoc_pmsg(struct mdoc *mdoc, int line, int pos, const char *fmt, ...) -{ - char buf[256]; - va_list ap; - - if (NULL == mdoc->cb.mdoc_msg) - return; - - va_start(ap, fmt); - (void)vsnprintf(buf, sizeof(buf) - 1, fmt, ap); - va_end(ap); - (*mdoc->cb.mdoc_msg)(mdoc->data, line, pos, buf); -} - - -int -mdoc_pwarn(struct mdoc *mdoc, int line, int pos, enum mdoc_warn type, - const char *fmt, ...) -{ - char buf[256]; - va_list ap; - - if (NULL == mdoc->cb.mdoc_warn) - return(0); - - va_start(ap, fmt); - (void)vsnprintf(buf, sizeof(buf) - 1, fmt, ap); - va_end(ap); - return((*mdoc->cb.mdoc_warn)(mdoc->data, line, pos, type, buf)); -} - -int -mdoc_perr(struct mdoc *mdoc, int line, int pos, const char *fmt, ...) -{ - char buf[256]; - va_list ap; - - if (NULL == mdoc->cb.mdoc_err) - return(0); - - va_start(ap, fmt); - (void)vsnprintf(buf, sizeof(buf) - 1, fmt, ap); - va_end(ap); - return((*mdoc->cb.mdoc_err)(mdoc->data, line, pos, buf)); -} - - -int mdoc_macro(struct mdoc *m, int tok, int ln, int pp, int *pos, char *buf) { @@ -611,7 +480,8 @@ mdoc_block_alloc(struct mdoc *mdoc, int line, int pos, p = node_alloc(mdoc, line, pos, tok, MDOC_BLOCK); if (NULL == p) return(0); - if ((p->args = args)) + p->args = args; + if (p->args) (args->refcnt)++; return(node_append(mdoc, p)); } @@ -626,7 +496,8 @@ mdoc_elem_alloc(struct mdoc *mdoc, int line, int pos, p = node_alloc(mdoc, line, pos, tok, MDOC_ELEM); if (NULL == p) return(0); - if ((p->args = args)) + p->args = args; + if (p->args) (args->refcnt)++; return(node_append(mdoc, p)); } |