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

Diff for /mandoc/term.c between version 1.18 and 1.23

version 1.18, 2009/02/25 12:09:20 version 1.23, 2009/02/25 23:18:50
Line 17 
Line 17 
  * PERFORMANCE OF THIS SOFTWARE.   * PERFORMANCE OF THIS SOFTWARE.
  */   */
 #include <assert.h>  #include <assert.h>
   #include <err.h>
   #include <stdio.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
   
Line 30 
Line 32 
  */   */
   
 /* FIXME: indent/tab. */  /* FIXME: indent/tab. */
 /* FIXME: handle nested lists. */  /* FIXME: macro arguments can be escaped. */
   
 #define TTYPE_PROG        0  #define TTYPE_PROG        0
 #define TTYPE_CMD_FLAG    1  #define TTYPE_CMD_FLAG    1
Line 148  DECL_PRE(termp_ox);
Line 150  DECL_PRE(termp_ox);
 DECL_PRE(termp_pa);  DECL_PRE(termp_pa);
 DECL_PRE(termp_pp);  DECL_PRE(termp_pp);
 DECL_PRE(termp_rv);  DECL_PRE(termp_rv);
   DECL_PRE(termp_sm);
 DECL_PRE(termp_st);  DECL_PRE(termp_st);
 DECL_PRE(termp_sx);  DECL_PRE(termp_sx);
 DECL_PRE(termp_sy);  DECL_PRE(termp_sy);
Line 248  const struct termact __termacts[MDOC_MAX] = {
Line 251  const struct termact __termacts[MDOC_MAX] = {
         { NULL, NULL }, /* Sc */          { NULL, NULL }, /* Sc */
         { termp_sq_pre, termp_sq_post }, /* So */          { termp_sq_pre, termp_sq_post }, /* So */
         { termp_sq_pre, termp_sq_post }, /* Sq */          { termp_sq_pre, termp_sq_post }, /* Sq */
         { NULL, NULL }, /* Sm */          { termp_sm_pre, NULL }, /* Sm */
         { termp_sx_pre, NULL }, /* Sx */          { termp_sx_pre, NULL }, /* Sx */
         { termp_sy_pre, NULL }, /* Sy */          { termp_sy_pre, NULL }, /* Sy */
         { NULL, NULL }, /* Tn */          { NULL, NULL }, /* Tn */
Line 343  termp_dq_post(DECL_ARGS)
Line 346  termp_dq_post(DECL_ARGS)
   
   
 /* ARGSUSED */  /* ARGSUSED */
 static void  
 termp_it_post(DECL_ARGS)  
 {  
         const struct mdoc_node *n, *it;  
         const struct mdoc_block *bl;  
         int              i;  
         size_t           width, offset;  
   
         /*  
          * This (and termp_it_pre()) are the most complicated functions  
          * here.  They must account for a considerable number of  
          * switches that completely change the output behaviour, like  
          * -tag versus -column.  Yech.  
          */  
   
         switch (node->type) {  
         case (MDOC_BODY):  
                 /* FALLTHROUGH */  
         case (MDOC_HEAD):  
                 break;  
         default:  
                 return;  
         }  
   
         it = node->parent;  
         assert(MDOC_BLOCK == it->type);  
         assert(MDOC_It == it->tok);  
   
         n = it->parent;  
         assert(MDOC_BODY == n->type);  
         assert(MDOC_Bl == n->tok);  
         n = n->parent;  
         bl = &n->data.block;  
   
         /* If `-tag', adjust our margins accordingly. */  
   
         if (arg_hasattr(MDOC_Tag, bl->argc, bl->argv)) {  
                 flushln(p);  
   
                 /* FIXME: this should auto-size. */  
                 i = arg_getattr(MDOC_Width, bl->argc, bl->argv);  
                 width = i >= 0 ? arg_width(&bl->argv[i]) : 10;  
   
                 /* FIXME: nesting!  Should happen at block. */  
                 i = arg_getattr(MDOC_Offset, bl->argc, bl->argv);  
                 offset = i >= 0 ? arg_width(&bl->argv[i]) : 0;  
   
                 if (MDOC_HEAD == node->type) {  
                         p->rmargin = p->maxrmargin;  
                         p->offset -= offset;  
                         p->flags &= ~TERMP_NOBREAK;  
                 } else {  
                         p->offset -= width;  
                         p->flags &= ~TERMP_NOLPAD;  
                 }  
         }  
   
         if (arg_hasattr(MDOC_Ohang, bl->argc, bl->argv)) {  
                 i = arg_getattr(MDOC_Offset, bl->argc, bl->argv);  
                 offset = i >= 0 ? arg_offset(&bl->argv[i]) : 0;  
   
                 flushln(p);  
                 p->offset -= offset;  
                 return;  
         }  
 }  
   
   
 /* ARGSUSED */  
 static int  static int
 termp_it_pre(DECL_ARGS)  termp_it_pre(DECL_ARGS)
 {  {
         const struct mdoc_node *n, *it;          const struct mdoc_node *n, *it;
         const struct mdoc_block *bl;          const struct mdoc_block *bl;
         int              i;          char             buf[7], *tp;
           int              i, type;
         size_t           width, offset;          size_t           width, offset;
   
         /*  
          * Also see termp_it_post() for general comments.  
          */  
   
         switch (node->type) {          switch (node->type) {
         case (MDOC_BODY):          case (MDOC_BODY):
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
Line 437  termp_it_pre(DECL_ARGS)
Line 368  termp_it_pre(DECL_ARGS)
                 return(1);                  return(1);
         }          }
   
         assert(MDOC_BLOCK == it->type);          n = it->parent->parent;
         assert(MDOC_It == it->tok);  
   
         n = it->parent;  
         assert(MDOC_BODY == n->type);  
         assert(MDOC_Bl == n->tok);  
         n = n->parent;  
         bl = &n->data.block;          bl = &n->data.block;
   
         /* If `-compact', don't assert vertical space. */  
   
         if (MDOC_BLOCK == node->type) {          if (MDOC_BLOCK == node->type) {
                 if (arg_hasattr(MDOC_Compact, bl->argc, bl->argv))                  if (arg_hasattr(MDOC_Compact, bl->argc, bl->argv))
                         newln(p);                          newln(p);
Line 456  termp_it_pre(DECL_ARGS)
Line 379  termp_it_pre(DECL_ARGS)
                 return(1);                  return(1);
         }          }
   
         assert(MDOC_HEAD == node->type          /* Get our list type. */
                         || MDOC_BODY == node->type);  
   
         /* FIXME: see termp_it_post(). */          for (i = 0; i < (int)bl->argc; i++)
                   switch (bl->argv[i].arg) {
                   case (MDOC_Bullet):
                           /* FALLTHROUGH */
                   case (MDOC_Dash):
                           /* FALLTHROUGH */
                   case (MDOC_Enum):
                           /* FALLTHROUGH */
                   case (MDOC_Hyphen):
                           /* FALLTHROUGH */
                   case (MDOC_Item):
                           /* FALLTHROUGH */
                   case (MDOC_Tag):
                           /* FALLTHROUGH */
                   case (MDOC_Ohang):
                           type = bl->argv[i].arg;
                           i = (int)bl->argc;
                           break;
                   case (MDOC_Inset):
                           /* FALLTHROUGH */
                   case (MDOC_Hang):
                           /* FALLTHROUGH */
                   case (MDOC_Diag):
                           /* FALLTHROUGH */
                   case (MDOC_Column):
                           errx(1, "list type not supported");
                           /* NOTREACHED */
                   default:
                           break;
                   }
   
         /* If `-tag', adjust our margins accordingly. */          /* Save our existing (inherited) margin and offset. */
   
         if (arg_hasattr(MDOC_Tag, bl->argc, bl->argv)) {          pair->offset = p->offset;
                 p->flags |= TERMP_NOSPACE;          pair->rmargin = p->rmargin;
   
                 i = arg_getattr(MDOC_Width, bl->argc, bl->argv);          /* Get list width and offset. */
                 width = i >= 0 ? arg_width(&bl->argv[i]) : 10;  
   
                 i = arg_getattr(MDOC_Offset, bl->argc, bl->argv);          /* FIXME: auto-size. */
                 offset = i >= 0 ? arg_offset(&bl->argv[i]) : 0;          i = arg_getattr(MDOC_Width, bl->argc, bl->argv);
           width = i >= 0 ? arg_width(&bl->argv[i]) : 0;
   
                 if (MDOC_HEAD == node->type) {          i = arg_getattr(MDOC_Offset, bl->argc, bl->argv);
           offset = i >= 0 ? arg_offset(&bl->argv[i]) : 0;
   
           /* Override the width. */
   
           switch (type) {
           case (MDOC_Bullet):
                   /* FALLTHROUGH */
           case (MDOC_Dash):
                   /* FALLTHROUGH */
           case (MDOC_Enum):
                   /* FALLTHROUGH */
           case (MDOC_Hyphen):
                   width = width > 6 ? width : 6;
                   break;
           case (MDOC_Tag):
                   if (0 == width)
                           errx(1, "need non-zero -width");
                   break;
           default:
                   break;
           }
   
           /* Word-wrap control. */
   
           p->flags |= TERMP_NOSPACE;
   
           switch (type) {
           case (MDOC_Bullet):
                   /* FALLTHROUGH */
           case (MDOC_Dash):
                   /* FALLTHROUGH */
           case (MDOC_Enum):
                   /* FALLTHROUGH */
           case (MDOC_Hyphen):
                   /* FALLTHROUGH */
           case (MDOC_Tag):
                   if (MDOC_HEAD == node->type)
                         p->flags |= TERMP_NOBREAK;                          p->flags |= TERMP_NOBREAK;
                         p->offset += offset;                  else if (MDOC_BODY == node->type)
                         p->rmargin = p->offset + width;  
                 } else {  
                         p->flags |= TERMP_NOSPACE;  
                         p->flags |= TERMP_NOLPAD;                          p->flags |= TERMP_NOLPAD;
                         p->offset += width;                  break;
           case (MDOC_Ohang):
                   break;
           }
   
           /*
            * Get a token to use as the HEAD lead-in.  If NULL, we use the
            * HEAD child.
            */
   
           tp = NULL;
           if (MDOC_HEAD == node->type) {
                   if (arg_hasattr(MDOC_Bullet, bl->argc, bl->argv))
                           tp = "\\[bu]";
                   if (arg_hasattr(MDOC_Dash, bl->argc, bl->argv))
                           tp = "\\-";
                   if (arg_hasattr(MDOC_Enum, bl->argc, bl->argv)) {
                           (pair->ppair->ppair->count)++;
                           (void)snprintf(buf, sizeof(buf), "%d.",
                                           pair->ppair->ppair->count);
                           tp = buf;
                 }                  }
                 return(1);                  if (arg_hasattr(MDOC_Hyphen, bl->argc, bl->argv))
                           tp = "\\-";
                   if (arg_hasattr(MDOC_Item, bl->argc, bl->argv))
                           tp = "";
         }          }
   
         /* If `-ohang', adjust left-margin. */          /* Margin control. */
   
         if (arg_hasattr(MDOC_Ohang, bl->argc, bl->argv)) {          p->offset += offset;
                 i = arg_getattr(MDOC_Offset, bl->argc, bl->argv);  
                 offset = i >= 0 ? arg_offset(&bl->argv[i]) : 0;  
   
                 p->flags |= TERMP_NOSPACE;          switch (type) {
                 p->offset += offset;          case (MDOC_Bullet):
                 return(1);                  /* FALLTHROUGH */
           case (MDOC_Dash):
                   /* FALLTHROUGH */
           case (MDOC_Enum):
                   /* FALLTHROUGH */
           case (MDOC_Hyphen):
                   /* FALLTHROUGH */
           case (MDOC_Item):
                   /* FALLTHROUGH */
           case (MDOC_Tag):
                   if (MDOC_HEAD == node->type)
                           p->rmargin = p->offset + width;
                   else if (MDOC_BODY == node->type)
                           p->offset += width;
                   break;
           case (MDOC_Ohang):
                   break;
         }          }
   
         return(1);          if (NULL == tp)
                   return(1);
   
           /* XXX - ignoring children. */
   
           word(p, tp);
           return(0);
 }  }
   
   
 /* ARGSUSED */  /* ARGSUSED */
   static void
   termp_it_post(DECL_ARGS)
   {
   
           if (MDOC_BODY != node->type && MDOC_HEAD != node->type)
                   return;
   
           flushln(p);
   
           p->offset = pair->offset;
           p->rmargin = pair->rmargin;
   
           if (MDOC_HEAD == node->type) {
                   p->flags &= ~TERMP_NOBREAK;
                   p->flags &= ~TERMP_NORPAD;
           } else if (MDOC_BODY == node->type)
                   p->flags &= ~TERMP_NOLPAD;
   }
   
   
   /* ARGSUSED */
 static int  static int
 termp_nm_pre(DECL_ARGS)  termp_nm_pre(DECL_ARGS)
 {  {
Line 654  termp_op_post(DECL_ARGS)
Line 703  termp_op_post(DECL_ARGS)
   
   
 /* ARGSUSED */  /* ARGSUSED */
 static void  
 termp_sh_post(DECL_ARGS)  
 {  
   
         switch (node->type) {  
         case (MDOC_HEAD):  
                 newln(p);  
                 break;  
         case (MDOC_BODY):  
                 newln(p);  
                 p->offset = 0;  
                 break;  
         default:  
                 break;  
         }  
 }  
   
   
 /* ARGSUSED */  
 static int  static int
 termp_xr_pre(DECL_ARGS)  termp_xr_pre(DECL_ARGS)
 {  {
Line 765  termp_sh_pre(DECL_ARGS)
Line 795  termp_sh_pre(DECL_ARGS)
   
   
 /* ARGSUSED */  /* ARGSUSED */
   static void
   termp_sh_post(DECL_ARGS)
   {
   
           switch (node->type) {
           case (MDOC_HEAD):
                   newln(p);
                   break;
           case (MDOC_BODY):
                   newln(p);
                   p->offset = 0;
                   break;
           default:
                   break;
           }
   }
   
   
   /* ARGSUSED */
 static int  static int
 termp_op_pre(DECL_ARGS)  termp_op_pre(DECL_ARGS)
 {  {
Line 809  termp_d1_pre(DECL_ARGS)
Line 858  termp_d1_pre(DECL_ARGS)
         if (MDOC_BODY != node->type)          if (MDOC_BODY != node->type)
                 return(1);                  return(1);
         newln(p);          newln(p);
         p->offset += INDENT;          p->offset += (pair->offset = INDENT);
         return(1);          return(1);
 }  }
   
Line 822  termp_d1_post(DECL_ARGS)
Line 871  termp_d1_post(DECL_ARGS)
         if (MDOC_BODY != node->type)          if (MDOC_BODY != node->type)
                 return;                  return;
         newln(p);          newln(p);
         p->offset -= INDENT;          p->offset -= pair->offset;
 }  }
   
   
Line 982  termp_bd_pre(DECL_ARGS)
Line 1031  termp_bd_pre(DECL_ARGS)
                 return(1);                  return(1);
   
         assert(MDOC_BLOCK == node->parent->type);          assert(MDOC_BLOCK == node->parent->type);
           pair->offset = p->offset;
   
         bl = &node->parent->data.block;          bl = &node->parent->data.block;
   
   
         i = arg_getattr(MDOC_Offset, bl->argc, bl->argv);          i = arg_getattr(MDOC_Offset, bl->argc, bl->argv);
         if (-1 != i) {          if (-1 != i) {
                 assert(1 == bl->argv[i].sz);                  assert(1 == bl->argv[i].sz);
Line 1015  termp_bd_pre(DECL_ARGS)
Line 1066  termp_bd_pre(DECL_ARGS)
 static void  static void
 termp_bd_post(DECL_ARGS)  termp_bd_post(DECL_ARGS)
 {  {
         int              i;  
         const struct mdoc_block *bl;  
   
         if (MDOC_BODY != node->type)          if (MDOC_BODY != node->type)
                 return;                  return;
           newln(p);
         assert(MDOC_BLOCK == node->parent->type);          p->offset = pair->offset;
         bl = &node->parent->data.block;  
   
         i = arg_getattr(MDOC_Offset, bl->argc, bl->argv);  
         if (-1 != i) {  
                 assert(1 == bl->argv[i].sz);  
                 p->offset -= arg_offset(&bl->argv[i]);  
         }  
 }  }
   
   
Line 1416  termp_ms_pre(DECL_ARGS)
Line 1458  termp_ms_pre(DECL_ARGS)
         return(1);          return(1);
 }  }
   
   
   
   /* ARGSUSED */
   static int
   termp_sm_pre(DECL_ARGS)
   {
   
   #if notyet
           assert(node->child);
           if (0 == strcmp("off", node->child->data.text.string)) {
                   p->flags &= ~TERMP_NONOSPACE;
                   p->flags &= ~TERMP_NOSPACE;
           } else {
                   p->flags |= TERMP_NONOSPACE;
                   p->flags |= TERMP_NOSPACE;
           }
   #endif
   
           return(0);
   }

Legend:
Removed from v.1.18  
changed lines
  Added in v.1.23

CVSweb