[BACK]Return to tree.c CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / mandoc

Diff for /mandoc/tree.c between version 1.7 and 1.8

version 1.7, 2009/02/23 07:09:13 version 1.8, 2009/03/19 16:17:27
Line 1 
Line 1 
 /* $Id$ */  /* $Id$ */
 /*  /*
  * Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>   * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@openbsd.org>
  *   *
  * Permission to use, copy, modify, and distribute this software for any   * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the   * purpose with or without fee is hereby granted, provided that the
Line 16 
Line 16 
  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR   * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  * PERFORMANCE OF THIS SOFTWARE.   * PERFORMANCE OF THIS SOFTWARE.
  */   */
 #include <stdlib.h>  #include <assert.h>
   #include <err.h>
 #include <stdio.h>  #include <stdio.h>
   #include <stdlib.h>
   
 #include "mdoc.h"  #include "mdoc.h"
   
 #define xprintf         (void)printf  static  void    tree_body(const struct mdoc_node *, int);
   
 static  void     treeprint_r(const struct mdoc_node *, int);  
   
   int
   tree_run(void *arg, const struct mdoc *mdoc)
   {
   
           tree_body(mdoc_node(mdoc), 0);
           return(1);
   }
   
   
 static void  static void
 treeprint_r(const struct mdoc_node *n, int indent)  tree_body(const struct mdoc_node *n, int indent)
 {  {
         const char       *p, *t;          const char       *p, *t;
         int               i, j;          int               i, j;
         size_t            argc, sz;          size_t            argc, sz;
         char            **params;          char            **params;
         struct mdoc_arg  *argv;          struct mdoc_argv *argv;
   
         argv = NULL;          argv = NULL;
         argc = sz = 0;          argc = sz = 0;
Line 67  treeprint_r(const struct mdoc_node *n, int indent)
Line 77  treeprint_r(const struct mdoc_node *n, int indent)
   
         switch (n->type) {          switch (n->type) {
         case (MDOC_TEXT):          case (MDOC_TEXT):
                 p = n->data.text.string;                  p = n->string;
                 break;                  break;
         case (MDOC_BODY):          case (MDOC_BODY):
                 p = mdoc_macronames[n->tok];                  p = mdoc_macronames[n->tok];
Line 80  treeprint_r(const struct mdoc_node *n, int indent)
Line 90  treeprint_r(const struct mdoc_node *n, int indent)
                 break;                  break;
         case (MDOC_ELEM):          case (MDOC_ELEM):
                 p = mdoc_macronames[n->tok];                  p = mdoc_macronames[n->tok];
                 argv = n->data.elem.argv;                  if (n->args) {
                 argc = n->data.elem.argc;                          argv = n->args->argv;
                           argc = n->args->argc;
                   }
                 break;                  break;
         case (MDOC_BLOCK):          case (MDOC_BLOCK):
                 p = mdoc_macronames[n->tok];                  p = mdoc_macronames[n->tok];
                 argv = n->data.block.argv;                  if (n->args) {
                 argc = n->data.block.argc;                          argv = n->args->argv;
                           argc = n->args->argc;
                   }
                 break;                  break;
         case (MDOC_ROOT):          case (MDOC_ROOT):
                 p = "root";                  p = "root";
Line 97  treeprint_r(const struct mdoc_node *n, int indent)
Line 111  treeprint_r(const struct mdoc_node *n, int indent)
         }          }
   
         for (i = 0; i < indent; i++)          for (i = 0; i < indent; i++)
                 xprintf("    ");                  (void)printf("    ");
         xprintf("%s (%s)", p, t);          (void)printf("%s (%s)", p, t);
   
         for (i = 0; i < (int)argc; i++) {          for (i = 0; i < (int)argc; i++) {
                 xprintf(" -%s", mdoc_argnames[argv[i].arg]);                  (void)printf(" -%s", mdoc_argnames[argv[i].arg]);
                 if (argv[i].sz > 0)                  if (argv[i].sz > 0)
                         xprintf(" [");                          (void)printf(" [");
                 for (j = 0; j < (int)argv[i].sz; j++)                  for (j = 0; j < (int)argv[i].sz; j++)
                         xprintf(" [%s]", argv[i].value[j]);                          (void)printf(" [%s]", argv[i].value[j]);
                 if (argv[i].sz > 0)                  if (argv[i].sz > 0)
                         xprintf(" ]");                          (void)printf(" ]");
         }          }
   
         for (i = 0; i < (int)sz; i++)          for (i = 0; i < (int)sz; i++)
                 xprintf(" [%s]", params[i]);                  (void)printf(" [%s]", params[i]);
   
         xprintf(" %d:%d\n", n->line, n->pos);          (void)printf(" %d:%d\n", n->line, n->pos);
   
         if (n->child)          if (n->child)
                 treeprint_r(n->child, indent + 1);                  tree_body(n->child, indent + 1);
         if (n->next)          if (n->next)
                 treeprint_r(n->next, indent);                  tree_body(n->next, indent);
 }  }
   
   
 /* ARGSUSED */  
 void  
 treeprint(const struct mdoc_node *node,  
                 const struct mdoc_meta *meta)  
 {  
   
         treeprint_r(node, 0);  
 }  

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8

CVSweb