]> git.cameronkatri.com Git - mandoc.git/blobdiff - tree.c
Finally, represent the man(7) .PP and .HP macros by the natural
[mandoc.git] / tree.c
diff --git a/tree.c b/tree.c
index 989a2c3cf817401f7e046709403e012c0a94291d..649c0804c8b932b546a22cd22ca089f7af73d42c 100644 (file)
--- a/tree.c
+++ b/tree.c
@@ -1,7 +1,7 @@
-/*     $Id: tree.c,v 1.74 2017/04/24 23:06:18 schwarze Exp $ */
+/*     $Id: tree.c,v 1.84 2019/01/01 05:56:34 schwarze Exp $ */
 /*
  * Copyright (c) 2008, 2009, 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2013, 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2013-2015, 2017-2019 Ingo Schwarze <schwarze@openbsd.org>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -29,6 +29,8 @@
 #include "roff.h"
 #include "mdoc.h"
 #include "man.h"
+#include "tbl.h"
+#include "eqn.h"
 #include "main.h"
 
 static void    print_box(const struct eqn_box *, int);
@@ -39,18 +41,18 @@ static      void    print_span(const struct tbl_span *, int);
 
 
 void
-tree_mdoc(void *arg, const struct roff_man *mdoc)
+tree_mdoc(void *arg, const struct roff_meta *mdoc)
 {
-       print_meta(&mdoc->meta);
+       print_meta(mdoc);
        putchar('\n');
        print_mdoc(mdoc->first->child, 0);
 }
 
 void
-tree_man(void *arg, const struct roff_man *man)
+tree_man(void *arg, const struct roff_meta *man)
 {
-       print_meta(&man->meta);
-       if (man->meta.hasbody == 0)
+       print_meta(man);
+       if (man->hasbody == 0)
                puts("body  = empty");
        putchar('\n');
        print_man(man->first->child, 0);
@@ -115,6 +117,9 @@ print_mdoc(const struct roff_node *n, int indent)
        case ROFFT_TEXT:
                t = "text";
                break;
+       case ROFFT_COMMENT:
+               t = "comment";
+               break;
        case ROFFT_TBL:
                break;
        case ROFFT_EQN:
@@ -126,6 +131,7 @@ print_mdoc(const struct roff_node *n, int indent)
 
        switch (n->type) {
        case ROFFT_TEXT:
+       case ROFFT_COMMENT:
                p = n->string;
                break;
        case ROFFT_BODY:
@@ -183,26 +189,28 @@ print_mdoc(const struct roff_node *n, int indent)
                }
 
                putchar(' ');
-               if (NODE_DELIMO & n->flags)
+               if (n->flags & NODE_DELIMO)
                        putchar('(');
-               if (NODE_LINE & n->flags)
+               if (n->flags & NODE_LINE)
                        putchar('*');
                printf("%d:%d", n->line, n->pos + 1);
-               if (NODE_DELIMC & n->flags)
+               if (n->flags & NODE_DELIMC)
                        putchar(')');
-               if (NODE_EOS & n->flags)
+               if (n->flags & NODE_EOS)
                        putchar('.');
-               if (NODE_BROKEN & n->flags)
+               if (n->flags & NODE_BROKEN)
                        printf(" BROKEN");
-               if (NODE_NOSRC & n->flags)
+               if (n->flags & NODE_NOFILL)
+                       printf(" NOFILL");
+               if (n->flags & NODE_NOSRC)
                        printf(" NOSRC");
-               if (NODE_NOPRT & n->flags)
+               if (n->flags & NODE_NOPRT)
                        printf(" NOPRT");
                putchar('\n');
        }
 
        if (n->eqn)
-               print_box(n->eqn->root->first, indent + 4);
+               print_box(n->eqn->first, indent + 4);
        if (n->child)
                print_mdoc(n->child, indent +
                    (n->type == ROFFT_BLOCK ? 2 : 4));
@@ -231,6 +239,9 @@ print_man(const struct roff_node *n, int indent)
        case ROFFT_TEXT:
                t = "text";
                break;
+       case ROFFT_COMMENT:
+               t = "comment";
+               break;
        case ROFFT_BLOCK:
                t = "block";
                break;
@@ -251,6 +262,7 @@ print_man(const struct roff_node *n, int indent)
 
        switch (n->type) {
        case ROFFT_TEXT:
+       case ROFFT_COMMENT:
                p = n->string;
                break;
        case ROFFT_ELEM:
@@ -278,16 +290,20 @@ print_man(const struct roff_node *n, int indent)
                for (i = 0; i < indent; i++)
                        putchar(' ');
                printf("%s (%s) ", p, t);
-               if (NODE_LINE & n->flags)
+               if (n->flags & NODE_LINE)
                        putchar('*');
                printf("%d:%d", n->line, n->pos + 1);
-               if (NODE_EOS & n->flags)
+               if (n->flags & NODE_DELIMC)
+                       putchar(')');
+               if (n->flags & NODE_EOS)
                        putchar('.');
+               if (n->flags & NODE_NOFILL)
+                       printf(" NOFILL");
                putchar('\n');
        }
 
        if (n->eqn)
-               print_box(n->eqn->root->first, indent + 4);
+               print_box(n->eqn->first, indent + 4);
        if (n->child)
                print_man(n->child, indent +
                    (n->type == ROFFT_BLOCK ? 2 : 4));
@@ -313,10 +329,6 @@ print_box(const struct eqn_box *ep, int indent)
 
        t = NULL;
        switch (ep->type) {
-       case EQN_ROOT:
-               t = "eqn-root";
-               break;
-       case EQN_LISTONE:
        case EQN_LIST:
                t = "eqn-list";
                break;
@@ -373,35 +385,41 @@ print_span(const struct tbl_span *sp, int indent)
        switch (sp->pos) {
        case TBL_SPAN_HORIZ:
                putchar('-');
-               return;
+               putchar(' ');
+               break;
        case TBL_SPAN_DHORIZ:
                putchar('=');
-               return;
-       default:
+               putchar(' ');
                break;
-       }
-
-       for (dp = sp->first; dp; dp = dp->next) {
-               switch (dp->pos) {
-               case TBL_DATA_HORIZ:
-               case TBL_DATA_NHORIZ:
-                       putchar('-');
-                       continue;
-               case TBL_DATA_DHORIZ:
-               case TBL_DATA_NDHORIZ:
-                       putchar('=');
-                       continue;
-               default:
-                       break;
+       default:
+               for (dp = sp->first; dp; dp = dp->next) {
+                       switch (dp->pos) {
+                       case TBL_DATA_HORIZ:
+                       case TBL_DATA_NHORIZ:
+                               putchar('-');
+                               putchar(' ');
+                               continue;
+                       case TBL_DATA_DHORIZ:
+                       case TBL_DATA_NDHORIZ:
+                               putchar('=');
+                               putchar(' ');
+                               continue;
+                       default:
+                               break;
+                       }
+                       printf("[\"%s\"", dp->string ? dp->string : "");
+                       if (dp->hspans)
+                               printf(">%d", dp->hspans);
+                       if (dp->vspans)
+                               printf("v%d", dp->vspans);
+                       if (dp->layout == NULL)
+                               putchar('*');
+                       else if (dp->layout->pos == TBL_CELL_DOWN)
+                               putchar('^');
+                       putchar(']');
+                       putchar(' ');
                }
-               printf("[\"%s\"", dp->string ? dp->string : "");
-               if (dp->spans)
-                       printf("(%d)", dp->spans);
-               if (NULL == dp->layout)
-                       putchar('*');
-               putchar(']');
-               putchar(' ');
+               break;
        }
-
        printf("(tbl) %d:1\n", sp->line);
 }