From: Kristaps Dzonsons Date: Mon, 15 Jun 2009 09:55:43 +0000 (+0000) Subject: mdoc error/warn macros replaced with real functions for GCC2 support (miod@openbsd... X-Git-Tag: VERSION_1_7_17~4 X-Git-Url: https://git.cameronkatri.com/mandoc.git/commitdiff_plain/0eabacb3a7d215c5457b1a90099650131ad91c64?hp=b955ea9093c1ade9ae232421ae55b82809cf9e4a mdoc error/warn macros replaced with real functions for GCC2 support (miod@openbsd.org). --- diff --git a/libmdoc.h b/libmdoc.h index 880d7ea5..1461fdf7 100644 --- a/libmdoc.h +++ b/libmdoc.h @@ -1,4 +1,4 @@ -/* $Id: libmdoc.h,v 1.7 2009/06/10 20:18:43 kristaps Exp $ */ +/* $Id: libmdoc.h,v 1.8 2009/06/15 09:55:43 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -55,48 +55,31 @@ 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 +/* + * When GCC2 is deprecated, most of these can be reverted to #define + * as mdoc_vmsg using __VA_ARGS__. Until then, use real functions. + */ int mdoc_vwarn(struct mdoc *, int, int, enum mdoc_warn, const char *, ...); 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 *); diff --git a/mdoc.c b/mdoc.c index b3ad3f9e..580809ac 100644 --- a/mdoc.c +++ b/mdoc.c @@ -1,4 +1,4 @@ -/* $Id: mdoc.c,v 1.77 2009/06/12 12:52:51 kristaps Exp $ */ +/* $Id: mdoc.c,v 1.78 2009/06/15 09:55:43 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -292,6 +292,138 @@ 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)