=================================================================== RCS file: /cvs/mandoc/Attic/dummy.c,v retrieving revision 1.2 retrieving revision 1.5 diff -u -p -r1.2 -r1.5 --- mandoc/Attic/dummy.c 2008/11/24 08:50:33 1.2 +++ mandoc/Attic/dummy.c 2008/11/25 12:14:02 1.5 @@ -1,4 +1,4 @@ -/* $Id: dummy.c,v 1.2 2008/11/24 08:50:33 kristaps Exp $ */ +/* $Id: dummy.c,v 1.5 2008/11/25 12:14:02 kristaps Exp $ */ /* * Copyright (c) 2008 Kristaps Dzonsons * @@ -17,28 +17,138 @@ * PERFORMANCE OF THIS SOFTWARE. */ #include +#include +#include #include +#include #include "libmdocml.h" #include "private.h" +#ifdef __Linux__ +#define strlcat strncat +#endif -int -md_line_dummy(const struct md_args *args, - struct md_mbuf *out, const struct md_rbuf *in, - char *buf, size_t sz, void *data) +static int md_dummy_blk_in(int); +static int md_dummy_blk_out(int); +static int md_dummy_text_in(int, int *, char **); +static int md_dummy_text_out(int); + +static void dbg_indent(void); + +static int dbg_lvl = 0; + +struct md_dummy { + struct rofftree *tree; +}; + +static const char *const toknames[ROFF_MAX] = ROFF_NAMES; + + +static void +dbg_indent(void) { + char buf[128]; + int i; - assert(buf); - assert(out); - assert(in); - assert(args); - assert(NULL == data); + *buf = 0; + assert(dbg_lvl >= 0); - if ( ! md_buf_puts(out, buf, sz)) - return(0); - if ( ! md_buf_putchar(out, '\n')) - return(0); + /* LINTED */ + for (i = 0; i < dbg_lvl; i++) + (void)strlcat(buf, " ", sizeof(buf) - 1); + (void)printf("%s", buf); +} + + +static int +md_dummy_blk_in(int tok) +{ + + dbg_indent(); + (void)printf("%s\n", toknames[tok]); + dbg_lvl++; return(1); +} + + +static int +md_dummy_blk_out(int tok) +{ + + assert(dbg_lvl > 0); + dbg_lvl--; + dbg_indent(); + (void)printf("%s\n", toknames[tok]); + return(1); +} + + +/* ARGSUSED */ +static int +md_dummy_text_in(int tok, int *argcp, char **argvp) +{ + + dbg_indent(); + (void)printf("%s\n", toknames[tok]); + return(1); +} + + +static int +md_dummy_text_out(int tok) +{ + + dbg_indent(); + (void)printf("%s\n", toknames[tok]); + return(1); +} + + +int +md_line_dummy(void *arg, char *buf, size_t sz) +{ + struct md_dummy *p; + + p = (struct md_dummy *)arg; + return(roff_engine(p->tree, buf, sz)); +} + + +int +md_exit_dummy(void *data, int flush) +{ + int c; + struct md_dummy *p; + + p = (struct md_dummy *)data; + c = roff_free(p->tree, flush); + free(p); + + return(c); +} + + +void * +md_init_dummy(const struct md_args *args, + struct md_mbuf *mbuf, const struct md_rbuf *rbuf) +{ + struct md_dummy *p; + + if (NULL == (p = malloc(sizeof(struct md_dummy)))) { + warn("malloc"); + return(NULL); + } + + p->tree = roff_alloc(args, mbuf, rbuf, + md_dummy_text_in, md_dummy_text_out, + md_dummy_blk_in, md_dummy_blk_out); + + if (NULL == p->tree) { + free(p); + return(NULL); + } + + return(p); }