diff options
author | Kristaps Dzonsons <kristaps@bsd.lv> | 2009-01-17 14:04:25 +0000 |
---|---|---|
committer | Kristaps Dzonsons <kristaps@bsd.lv> | 2009-01-17 14:04:25 +0000 |
commit | 56f0b4a0fb2fb74f3bf1c6f8ed87ce2b716bcf52 (patch) | |
tree | 336c6f8871c8ab7b939a25b3e18e651fabbaf704 /mdocml.c | |
parent | 50c7e68a675c2b7d573e94e93564b37785d2cad6 (diff) | |
download | mandoc-56f0b4a0fb2fb74f3bf1c6f8ed87ce2b716bcf52.tar.gz |
Separating output filters.
Diffstat (limited to 'mdocml.c')
-rw-r--r-- | mdocml.c | 42 |
1 files changed, 29 insertions, 13 deletions
@@ -31,11 +31,25 @@ #include "mdoc.h" #define xfprintf (void)fprintf -#define xprintf (void)printf -#define xvfprintf (void)fvprintf #define MD_LINE_SZ (256) /* Max input line size. */ +/* + * Put this into a mdoctrans.h, which has: + * + * struct mdoc_trans; (opaque) + * + * struct mdoc_trans *mdoc_trans_alloc(const char *filter); + * + * mdoc_trans_free(struct mdoc_trans *); + * + * int mdoc_trans_getopt(struct mdoc_trans *, char *); + * + * int mdoc_trans_print(struct mdoc_trans *, const struct mdoc_node *); + */ + +typedef int (*mdocprint)(const struct mdoc_node *); + struct md_parse { int warn; /* Warning flags. */ @@ -49,12 +63,12 @@ struct md_parse { u_long bufsz; /* Input buffer size. */ char *name; /* Input file name. */ int fd; /* Input file desc. */ - int (*fp)(const struct mdoc_node *, const char *); + mdocprint print; /* Node-print function. */ }; extern char *__progname; -extern int +extern int treeprint(const struct mdoc_node *); static void usage(void); @@ -79,7 +93,7 @@ main(int argc, char *argv[]) { int c; struct md_parse parser; - char *opts, *v, *filter, *output; + char *opts, *v, *filter; #define ALL 0 #define COMPAT 1 #define SYNTAX 2 @@ -90,18 +104,15 @@ main(int argc, char *argv[]) extern char *optarg; extern int optind; - output = filter = NULL; + filter = NULL; (void)memset(&parser, 0, sizeof(struct md_parse)); - while (-1 != (c = getopt(argc, argv, "f:vW:o:"))) + while (-1 != (c = getopt(argc, argv, "f:vW:"))) switch (c) { case ('f'): filter = optarg; break; - case ('o'): - output = optarg; - break; case ('v'): parser.dbg++; break; @@ -138,6 +149,11 @@ main(int argc, char *argv[]) if (1 == argc) parser.name = *argv++; + if (filter) { + if (0 == strcmp(filter, "tree")) + parser.print = treeprint; + } + if ( ! io_begin(&parser)) return(EXIT_FAILURE); @@ -216,8 +232,8 @@ parse_leave(struct md_parse *p, int code) if ( ! mdoc_endparse(p->mdoc)) code = 0; - if (p->fp && (n = mdoc_result(p->mdoc))) - (*p->fp)(n, NULL); + if (p->print && (n = mdoc_result(p->mdoc))) + (*p->print)(n); mdoc_free(p->mdoc); @@ -336,6 +352,6 @@ usage(void) { xfprintf(stderr, "usage: %s [-v] [-Wwarn...] [-ffilter] " - "[-o outfile] [infile]\n", __progname); + "[infile]\n", __progname); } |