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

Diff for /mandoc/tree.c between version 1.53 and 1.62

version 1.53, 2014/07/02 07:10:38 version 1.62, 2015/02/05 00:14:13
Line 1 
Line 1 
 /*      $Id$ */  /*      $Id$ */
 /*  /*
  * Copyright (c) 2008, 2009, 2011 Kristaps Dzonsons <kristaps@bsd.lv>   * Copyright (c) 2008, 2009, 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>   * Copyright (c) 2013, 2014, 2015 Ingo Schwarze <schwarze@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 above   * purpose with or without fee is hereby granted, provided that the above
Line 15 
Line 15 
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF   * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.   * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */   */
 #ifdef HAVE_CONFIG_H  
 #include "config.h"  #include "config.h"
 #endif  
   
   #include <sys/types.h>
   
 #include <assert.h>  #include <assert.h>
 #include <limits.h>  #include <limits.h>
 #include <stdio.h>  #include <stdio.h>
Line 40  void
Line 40  void
 tree_mdoc(void *arg, const struct mdoc *mdoc)  tree_mdoc(void *arg, const struct mdoc *mdoc)
 {  {
   
         print_mdoc(mdoc_node(mdoc), 0);          print_mdoc(mdoc_node(mdoc)->child, 0);
 }  }
   
 void  void
 tree_man(void *arg, const struct man *man)  tree_man(void *arg, const struct man *man)
 {  {
   
         print_man(man_node(man), 0);          print_man(man_node(man)->child, 0);
 }  }
   
 static void  static void
Line 58  print_mdoc(const struct mdoc_node *n, int indent)
Line 58  print_mdoc(const struct mdoc_node *n, int indent)
         size_t            argc;          size_t            argc;
         struct mdoc_argv *argv;          struct mdoc_argv *argv;
   
           if (n == NULL)
                   return;
   
         argv = NULL;          argv = NULL;
         argc = 0;          argc = 0;
         t = p = NULL;          t = p = NULL;
Line 88  print_mdoc(const struct mdoc_node *n, int indent)
Line 91  print_mdoc(const struct mdoc_node *n, int indent)
                 t = "text";                  t = "text";
                 break;                  break;
         case MDOC_TBL:          case MDOC_TBL:
                 /* FALLTHROUGH */                  break;
         case MDOC_EQN:          case MDOC_EQN:
                   t = "eqn";
                 break;                  break;
         default:          default:
                 abort();                  abort();
Line 124  print_mdoc(const struct mdoc_node *n, int indent)
Line 128  print_mdoc(const struct mdoc_node *n, int indent)
                 }                  }
                 break;                  break;
         case MDOC_TBL:          case MDOC_TBL:
                 /* FALLTHROUGH */                  break;
         case MDOC_EQN:          case MDOC_EQN:
                   p = "EQ";
                 break;                  break;
         case MDOC_ROOT:          case MDOC_ROOT:
                 p = "root";                  p = "root";
Line 138  print_mdoc(const struct mdoc_node *n, int indent)
Line 143  print_mdoc(const struct mdoc_node *n, int indent)
         if (n->span) {          if (n->span) {
                 assert(NULL == p && NULL == t);                  assert(NULL == p && NULL == t);
                 print_span(n->span, indent);                  print_span(n->span, indent);
         } else if (n->eqn) {  
                 assert(NULL == p && NULL == t);  
                 print_box(n->eqn->root, indent);  
         } else {          } else {
                 for (i = 0; i < indent; i++)                  for (i = 0; i < indent; i++)
                         putchar('\t');                          putchar(' ');
   
                 printf("%s (%s)", p, t);                  printf("%s (%s)", p, t);
   
Line 160  print_mdoc(const struct mdoc_node *n, int indent)
Line 162  print_mdoc(const struct mdoc_node *n, int indent)
                 putchar(' ');                  putchar(' ');
                 if (MDOC_LINE & n->flags)                  if (MDOC_LINE & n->flags)
                         putchar('*');                          putchar('*');
                 printf("%d:%d", n->line, n->pos + 1);                  printf("%d:%d\n", n->line, n->pos + 1);
                 if (n->lastline != n->line)  
                         printf("-%d", n->lastline);  
                 putchar('\n');  
         }          }
   
           if (n->eqn)
                   print_box(n->eqn->root->first, indent + 4);
         if (n->child)          if (n->child)
                 print_mdoc(n->child, indent + 1);                  print_mdoc(n->child, indent +
                       (n->type == MDOC_BLOCK ? 2 : 4));
         if (n->next)          if (n->next)
                 print_mdoc(n->next, indent);                  print_mdoc(n->next, indent);
 }  }
Line 178  print_man(const struct man_node *n, int indent)
Line 180  print_man(const struct man_node *n, int indent)
         const char       *p, *t;          const char       *p, *t;
         int               i;          int               i;
   
           if (n == NULL)
                   return;
   
         t = p = NULL;          t = p = NULL;
   
         switch (n->type) {          switch (n->type) {
Line 199  print_man(const struct man_node *n, int indent)
Line 204  print_man(const struct man_node *n, int indent)
         case MAN_BODY:          case MAN_BODY:
                 t = "block-body";                  t = "block-body";
                 break;                  break;
         case MAN_TAIL:  
                 t = "block-tail";  
                 break;  
         case MAN_TBL:          case MAN_TBL:
                 /* FALLTHROUGH */                  break;
         case MAN_EQN:          case MAN_EQN:
                   t = "eqn";
                 break;                  break;
         default:          default:
                 abort();                  abort();
Line 221  print_man(const struct man_node *n, int indent)
Line 224  print_man(const struct man_node *n, int indent)
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case MAN_HEAD:          case MAN_HEAD:
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case MAN_TAIL:  
                 /* FALLTHROUGH */  
         case MAN_BODY:          case MAN_BODY:
                 p = man_macronames[n->tok];                  p = man_macronames[n->tok];
                 break;                  break;
Line 230  print_man(const struct man_node *n, int indent)
Line 231  print_man(const struct man_node *n, int indent)
                 p = "root";                  p = "root";
                 break;                  break;
         case MAN_TBL:          case MAN_TBL:
                 /* FALLTHROUGH */                  break;
         case MAN_EQN:          case MAN_EQN:
                   p = "EQ";
                 break;                  break;
         default:          default:
                 abort();                  abort();
Line 241  print_man(const struct man_node *n, int indent)
Line 243  print_man(const struct man_node *n, int indent)
         if (n->span) {          if (n->span) {
                 assert(NULL == p && NULL == t);                  assert(NULL == p && NULL == t);
                 print_span(n->span, indent);                  print_span(n->span, indent);
         } else if (n->eqn) {  
                 assert(NULL == p && NULL == t);  
                 print_box(n->eqn->root, indent);  
         } else {          } else {
                 for (i = 0; i < indent; i++)                  for (i = 0; i < indent; i++)
                         putchar('\t');                          putchar(' ');
                 printf("%s (%s) ", p, t);                  printf("%s (%s) ", p, t);
                 if (MAN_LINE & n->flags)                  if (MAN_LINE & n->flags)
                         putchar('*');                          putchar('*');
                 printf("%d:%d\n", n->line, n->pos + 1);                  printf("%d:%d\n", n->line, n->pos + 1);
         }          }
   
           if (n->eqn)
                   print_box(n->eqn->root->first, indent + 4);
         if (n->child)          if (n->child)
                 print_man(n->child, indent + 1);                  print_man(n->child, indent +
                       (n->type == MAN_BLOCK ? 2 : 4));
         if (n->next)          if (n->next)
                 print_man(n->next, indent);                  print_man(n->next, indent);
 }  }
Line 265  print_box(const struct eqn_box *ep, int indent)
Line 267  print_box(const struct eqn_box *ep, int indent)
         int              i;          int              i;
         const char      *t;          const char      *t;
   
           static const char *posnames[] = {
               NULL, "sup", "subsup", "sub",
               "to", "from", "fromto",
               "over", "sqrt", NULL };
   
         if (NULL == ep)          if (NULL == ep)
                 return;                  return;
         for (i = 0; i < indent; i++)          for (i = 0; i < indent; i++)
                 putchar('\t');                  putchar(' ');
   
         t = NULL;          t = NULL;
         switch (ep->type) {          switch (ep->type) {
         case EQN_ROOT:          case EQN_ROOT:
                 t = "eqn-root";                  t = "eqn-root";
                 break;                  break;
           case EQN_LISTONE:
         case EQN_LIST:          case EQN_LIST:
                 t = "eqn-list";                  t = "eqn-list";
                 break;                  break;
Line 284  print_box(const struct eqn_box *ep, int indent)
Line 292  print_box(const struct eqn_box *ep, int indent)
         case EQN_TEXT:          case EQN_TEXT:
                 t = "eqn-text";                  t = "eqn-text";
                 break;                  break;
           case EQN_PILE:
                   t = "eqn-pile";
                   break;
         case EQN_MATRIX:          case EQN_MATRIX:
                 t = "eqn-matrix";                  t = "eqn-matrix";
                 break;                  break;
         }          }
   
         assert(t);          fputs(t, stdout);
         printf("%s(%d, %d, %d, %d, %d, \"%s\", \"%s\") %s\n",          if (ep->pos)
             t, EQN_DEFSIZE == ep->size ? 0 : ep->size,                  printf(" pos=%s", posnames[ep->pos]);
             ep->pos + 1, ep->font, ep->mark, ep->pile,          if (ep->left)
             ep->left ? ep->left : "",                  printf(" left=\"%s\"", ep->left);
             ep->right ? ep->right : "",          if (ep->right)
             ep->text ? ep->text : "");                  printf(" right=\"%s\"", ep->right);
           if (ep->top)
                   printf(" top=\"%s\"", ep->top);
           if (ep->bottom)
                   printf(" bottom=\"%s\"", ep->bottom);
           if (ep->text)
                   printf(" text=\"%s\"", ep->text);
           if (ep->font)
                   printf(" font=%d", ep->font);
           if (ep->size != EQN_DEFSIZE)
                   printf(" size=%d", ep->size);
           if (ep->expectargs != UINT_MAX && ep->expectargs != ep->args)
                   printf(" badargs=%zu(%zu)", ep->args, ep->expectargs);
           else if (ep->args)
                   printf(" args=%zu", ep->args);
           putchar('\n');
   
         print_box(ep->first, indent + 1);          print_box(ep->first, indent + 4);
         print_box(ep->next, indent);          print_box(ep->next, indent);
 }  }
   
Line 308  print_span(const struct tbl_span *sp, int indent)
Line 334  print_span(const struct tbl_span *sp, int indent)
         int              i;          int              i;
   
         for (i = 0; i < indent; i++)          for (i = 0; i < indent; i++)
                 putchar('\t');                  putchar(' ');
   
         switch (sp->pos) {          switch (sp->pos) {
         case TBL_SPAN_HORIZ:          case TBL_SPAN_HORIZ:

Legend:
Removed from v.1.53  
changed lines
  Added in v.1.62

CVSweb