=================================================================== RCS file: /cvs/mandoc/Attic/dummy.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -p -r1.5 -r1.6 --- mandoc/Attic/dummy.c 2008/11/25 12:14:02 1.5 +++ mandoc/Attic/dummy.c 2008/11/25 16:49:57 1.6 @@ -1,4 +1,4 @@ -/* $Id: dummy.c,v 1.5 2008/11/25 12:14:02 kristaps Exp $ */ +/* $Id: dummy.c,v 1.6 2008/11/25 16:49:57 kristaps Exp $ */ /* * Copyright (c) 2008 Kristaps Dzonsons * @@ -25,7 +25,7 @@ #include "libmdocml.h" #include "private.h" -#ifdef __Linux__ +#ifdef __linux__ #define strlcat strncat #endif @@ -34,31 +34,35 @@ 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 void dbg_prologue(const char *); +static void dbg_epilogue(void); static int dbg_lvl = 0; +static char dbg_line[72]; struct md_dummy { struct rofftree *tree; }; -static const char *const toknames[ROFF_MAX] = ROFF_NAMES; - - static void -dbg_indent(void) +dbg_prologue(const char *p) { - char buf[128]; - int i; + int i; - *buf = 0; - assert(dbg_lvl >= 0); - + (void)snprintf(dbg_line, sizeof(dbg_line) - 1, "%6s", p); + (void)strlcat(dbg_line, ": ", sizeof(dbg_line) - 1); /* LINTED */ for (i = 0; i < dbg_lvl; i++) - (void)strlcat(buf, " ", sizeof(buf) - 1); + (void)strlcat(dbg_line, " ", sizeof(dbg_line) - 1); +} - (void)printf("%s", buf); + +static void +dbg_epilogue(void) +{ + + assert(0 != dbg_line[0]); + (void)printf("%s\n", dbg_line); } @@ -66,8 +70,10 @@ static int md_dummy_blk_in(int tok) { - dbg_indent(); - (void)printf("%s\n", toknames[tok]); + dbg_prologue("blk"); + (void)strlcat(dbg_line, toknames[tok], sizeof(dbg_line) - 1); + dbg_epilogue(); + dbg_lvl++; return(1); } @@ -77,10 +83,7 @@ static int md_dummy_blk_out(int tok) { - assert(dbg_lvl > 0); dbg_lvl--; - dbg_indent(); - (void)printf("%s\n", toknames[tok]); return(1); } @@ -90,8 +93,26 @@ static int md_dummy_text_in(int tok, int *argcp, char **argvp) { - dbg_indent(); - (void)printf("%s\n", toknames[tok]); + dbg_prologue("text"); + (void)strlcat(dbg_line, toknames[tok], sizeof(dbg_line) - 1); + (void)strlcat(dbg_line, " ", sizeof(dbg_line) - 1); + while (ROFF_ARGMAX != *argcp) { + (void)strlcat(dbg_line, "[", sizeof(dbg_line) - 1); + (void)strlcat(dbg_line, tokargnames[*argcp], + sizeof(dbg_line) - 1); + if (*argvp) { + (void)strlcat(dbg_line, " [", + sizeof(dbg_line) - 1); + (void)strlcat(dbg_line, *argvp, + sizeof(dbg_line) - 1); + (void)strlcat(dbg_line, "]", + sizeof(dbg_line) - 1); + } + (void)strlcat(dbg_line, "]", sizeof(dbg_line) - 1); + argcp++; + argvp++; + } + dbg_epilogue(); return(1); } @@ -100,8 +121,6 @@ static int md_dummy_text_out(int tok) { - dbg_indent(); - (void)printf("%s\n", toknames[tok]); return(1); }