From 0516216740b04a6adb890cc3d4639da26aee1f83 Mon Sep 17 00:00:00 2001 From: Kristaps Dzonsons Date: Wed, 25 Mar 2009 21:03:13 +0000 Subject: Added pflags to man_alloc. Abstract fflags -> pflags in main.c. --- libman.h | 1 + main.c | 27 +++++++++++++++++++++------ man.c | 30 +++++++++++++++++++++--------- man.h | 4 +++- 4 files changed, 46 insertions(+), 16 deletions(-) diff --git a/libman.h b/libman.h index eb75c322..5d32246e 100644 --- a/libman.h +++ b/libman.h @@ -30,6 +30,7 @@ struct man { void *data; struct man_cb cb; void *htab; + int pflags; int flags; #define MAN_HALT (1 << 0) enum man_next next; diff --git a/main.c b/main.c index 81b67b29..472a34c9 100644 --- a/main.c +++ b/main.c @@ -54,6 +54,10 @@ struct curparse { #define WARN_WERR (1 << 2) /* Warnings->errors. */ }; +#define IGN_SCOPE (1 << 0) /* Flag to ignore scope. */ +#define IGN_ESCAPE (1 << 1) /* Flag to ignore bad escapes. */ +#define IGN_MACRO (1 << 2) /* Flag to ignore unknown macros. */ + enum intt { INTT_MDOC = 0, INTT_MAN @@ -104,7 +108,7 @@ __dead static void usage(void); int main(int argc, char *argv[]) { - int c, rc, fflags; + int c, rc, fflags, pflags; struct mdoc_cb mdoccb; struct man_cb mancb; struct man *man; @@ -205,13 +209,24 @@ main(int argc, char *argv[]) man = NULL; mdoc = NULL; + pflags = 0; switch (inttype) { case (INTT_MAN): - man = man_alloc(&curp, &mancb); + if (fflags & IGN_MACRO) + pflags |= MAN_IGN_MACRO; + + man = man_alloc(&curp, pflags, &mancb); break; default: - mdoc = mdoc_alloc(&curp, fflags, &mdoccb); + if (fflags & IGN_SCOPE) + pflags |= MDOC_IGN_SCOPE; + if (fflags & IGN_ESCAPE) + pflags |= MDOC_IGN_ESCAPE; + if (fflags & IGN_MACRO) + pflags |= MDOC_IGN_MACRO; + + mdoc = mdoc_alloc(&curp, pflags, &mdoccb); break; } @@ -449,13 +464,13 @@ foptions(int *fflags, char *arg) while (*arg) switch (getsubopt(&arg, toks, &v)) { case (0): - *fflags |= MDOC_IGN_SCOPE; + *fflags |= IGN_SCOPE; break; case (1): - *fflags |= MDOC_IGN_ESCAPE; + *fflags |= IGN_ESCAPE; break; case (2): - *fflags |= MDOC_IGN_MACRO; + *fflags |= IGN_MACRO; break; default: warnx("bad argument: -f%s", arg); diff --git a/man.c b/man.c index 9165ad21..58db4f79 100644 --- a/man.c +++ b/man.c @@ -18,7 +18,6 @@ */ #include #include -#include #include #include #include @@ -83,7 +82,7 @@ man_free(struct man *man) struct man * -man_alloc(void *data, const struct man_cb *cb) +man_alloc(void *data, int pflags, const struct man_cb *cb) { struct man *p; @@ -98,6 +97,8 @@ man_alloc(void *data, const struct man_cb *cb) p->htab = man_hash_alloc(); p->data = data; + p->pflags = pflags; + return(p); } @@ -287,8 +288,7 @@ man_pmacro(struct man *m, int ln, char *buf) i++; if (0 == buf[i]) return(1); - warnx("invalid syntax"); - return(0); + return(man_vwarn(m, ln, 0, "invalid syntax")); } if (buf[1] && '\\' == buf[1]) @@ -307,13 +307,25 @@ man_pmacro(struct man *m, int ln, char *buf) mac[i - 1] = 0; if (i == 5 || i <= 1) { - warnx("unknown macro: %s", mac); - goto err; - } + if ( ! (MAN_IGN_MACRO & m->pflags)) { + (void)man_verr(m, ln, 1, + "ill-formed macro: %s", mac); + goto err; + } + if ( ! man_vwarn(m, ln, 1, "ill-formed macro: %s", mac)) + goto err; + return(1); + } if (MAN_MAX == (c = man_hash_find(m->htab, mac))) { - warnx("unknown macro: %s", mac); - goto err; + if ( ! (MAN_IGN_MACRO & m->pflags)) { + (void)man_verr(m, ln, 1, + "unknown macro: %s", mac); + goto err; + } + if ( ! man_vwarn(m, ln, 1, "unknown macro: %s", mac)) + goto err; + return(1); } /* The macro is sane. Jump to the next word. */ diff --git a/man.h b/man.h index 6e66a969..3e232c18 100644 --- a/man.h +++ b/man.h @@ -72,6 +72,8 @@ struct man_node { char *string; }; +#define MAN_IGN_MACRO (1 << 0) /* Ignore unknown macros. */ + extern const char *const *man_macronames; struct man_cb { @@ -84,7 +86,7 @@ __BEGIN_DECLS struct man; void man_free(struct man *); -struct man *man_alloc(void *, const struct man_cb *); +struct man *man_alloc(void *, int, const struct man_cb *); void man_reset(struct man *); int man_parseln(struct man *, int, char *buf); int man_endparse(struct man *); -- cgit