version 1.9, 2009/03/19 16:20:37 |
version 1.11, 2009/04/03 11:08:39 |
|
|
#include <stdlib.h> |
#include <stdlib.h> |
|
|
#include "mdoc.h" |
#include "mdoc.h" |
|
#include "man.h" |
|
|
static void tree_body(const struct mdoc_node *, int); |
static void print_mdoc(const struct mdoc_node *, int); |
|
static void print_man(const struct man_node *, int); |
|
|
|
|
/* ARGSUSED */ |
/* ARGSUSED */ |
int |
int |
tree_run(void *arg, const struct mdoc *mdoc) |
tree_mdoc(void *arg, const struct mdoc *mdoc) |
{ |
{ |
|
|
tree_body(mdoc_node(mdoc), 0); |
print_mdoc(mdoc_node(mdoc), 0); |
return(1); |
return(1); |
} |
} |
|
|
|
|
|
/* ARGSUSED */ |
|
int |
|
tree_man(void *arg, const struct man *man) |
|
{ |
|
|
|
print_man(man_node(man), 0); |
|
return(1); |
|
} |
|
|
|
|
static void |
static void |
tree_body(const struct mdoc_node *n, int indent) |
print_mdoc(const struct mdoc_node *n, int indent) |
{ |
{ |
const char *p, *t; |
const char *p, *t; |
int i, j; |
int i, j; |
Line 131 tree_body(const struct mdoc_node *n, int indent) |
|
Line 143 tree_body(const struct mdoc_node *n, int indent) |
|
(void)printf(" %d:%d\n", n->line, n->pos); |
(void)printf(" %d:%d\n", n->line, n->pos); |
|
|
if (n->child) |
if (n->child) |
tree_body(n->child, indent + 1); |
print_mdoc(n->child, indent + 1); |
if (n->next) |
if (n->next) |
tree_body(n->next, indent); |
print_mdoc(n->next, indent); |
} |
} |
|
|
|
|
|
static void |
|
print_man(const struct man_node *n, int indent) |
|
{ |
|
const char *p, *t; |
|
int i; |
|
|
|
switch (n->type) { |
|
case (MAN_ROOT): |
|
t = "root"; |
|
break; |
|
case (MAN_ELEM): |
|
t = "elem"; |
|
break; |
|
case (MAN_TEXT): |
|
t = "text"; |
|
break; |
|
default: |
|
abort(); |
|
/* NOTREACHED */ |
|
} |
|
|
|
switch (n->type) { |
|
case (MAN_TEXT): |
|
p = n->string; |
|
break; |
|
case (MAN_ELEM): |
|
p = man_macronames[n->tok]; |
|
break; |
|
case (MAN_ROOT): |
|
p = "root"; |
|
break; |
|
default: |
|
abort(); |
|
/* NOTREACHED */ |
|
} |
|
|
|
for (i = 0; i < indent; i++) |
|
(void)printf(" "); |
|
(void)printf("%s (%s) %d:%d\n", p, t, n->line, n->pos); |
|
|
|
if (n->child) |
|
print_man(n->child, indent + 1); |
|
if (n->next) |
|
print_man(n->next, indent); |
|
} |