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

Diff for /mandoc/term.c between version 1.20 and 1.24

version 1.20, 2009/02/25 13:30:53 version 1.24, 2009/02/26 14:56:27
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 348  termp_it_pre(DECL_ARGS)
Line 351  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;
   
         switch (node->type) {          switch (node->type) {
Line 364  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 383  termp_it_pre(DECL_ARGS)
Line 379  termp_it_pre(DECL_ARGS)
                 return(1);                  return(1);
         }          }
   
           /* Get our list type. */
   
           for (type = -1, 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_Tag):
                           /* FALLTHROUGH */
                   case (MDOC_Ohang):
                           type = bl->argv[i].arg;
                           i = (int)bl->argc;
                           break;
                   default:
                           errx(1, "list type not supported");
                           /* NOTREACHED */
                   }
   
           assert(-1 != type);
   
           /* Save our existing (inherited) margin and offset. */
   
         pair->offset = p->offset;          pair->offset = p->offset;
         pair->rmargin = p->rmargin;          pair->rmargin = p->rmargin;
   
         /* FIXME: auto-size. */          /* Get list width and offset. */
   
         i = arg_getattr(MDOC_Width, bl->argc, bl->argv);          i = arg_getattr(MDOC_Width, bl->argc, bl->argv);
         width = i >= 0 ? arg_width(&bl->argv[i]) : 10;          width = i >= 0 ? arg_width(&bl->argv[i]) : 0;
   
         i = arg_getattr(MDOC_Offset, bl->argc, bl->argv);          i = arg_getattr(MDOC_Offset, bl->argc, bl->argv);
         offset = i >= 0 ? arg_offset(&bl->argv[i]) : 0;          offset = i >= 0 ? arg_offset(&bl->argv[i]) : 0;
   
         assert(MDOC_HEAD == node->type ||          /* Override the width. */
                         MDOC_BODY == node->type);  
   
         if (arg_hasattr(MDOC_Tag, bl->argc, bl->argv)) {          switch (type) {
                 p->flags |= TERMP_NOSPACE;          case (MDOC_Bullet):
                   /* FALLTHROUGH */
           case (MDOC_Dash):
                   /* FALLTHROUGH */
           case (MDOC_Enum):
                   /* FALLTHROUGH */
           case (MDOC_Hyphen):
                   width = width > 6 ? width : 6;
                   break;
           case (MDOC_Tag):
                   /* FIXME: auto-size. */
                   if (0 == width)
                           errx(1, "need non-zero -width");
                   break;
           default:
                   break;
           }
   
                 if (MDOC_HEAD == node->type) {          /* 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_NOLPAD;                          p->flags |= TERMP_NOLPAD;
                         p->offset += width;                  break;
           default:
                   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;
                 }                  }
                   if (arg_hasattr(MDOC_Hyphen, bl->argc, bl->argv))
                           tp = "\\-";
           }
   
         } else if (arg_hasattr(MDOC_Ohang, bl->argc, bl->argv)) {          /* Margin control. */
                 p->flags |= TERMP_NOSPACE;  
                 p->offset += offset;          p->offset += offset;
   
           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->rmargin = p->offset + width;
                   else if (MDOC_BODY == node->type)
                           p->offset += width;
                   break;
           default:
                   break;
         }          }
   
         return(1);          if (NULL == tp)
                   return(1);
   
           word(p, tp);
           return(0);
 }  }
   
   
Line 421  termp_it_pre(DECL_ARGS)
Line 518  termp_it_pre(DECL_ARGS)
 static void  static void
 termp_it_post(DECL_ARGS)  termp_it_post(DECL_ARGS)
 {  {
         const struct mdoc_node *n, *it;  
         const struct mdoc_block *bl;  
   
         switch (node->type) {          if (MDOC_BODY != node->type && MDOC_HEAD != node->type)
         case (MDOC_BODY):  
                 /* FALLTHROUGH */  
         case (MDOC_HEAD):  
                 break;  
         default:  
                 return;                  return;
         }  
   
         it = node->parent;          flushln(p);
         assert(MDOC_BLOCK == it->type);  
         assert(MDOC_It == it->tok);  
   
         n = it->parent;          p->offset = pair->offset;
         assert(MDOC_BODY == n->type);          p->rmargin = pair->rmargin;
         assert(MDOC_Bl == n->tok);  
         n = n->parent;  
         bl = &n->data.block;  
   
         /* If `-tag', adjust our margins accordingly. */          if (MDOC_HEAD == node->type) {
                   p->flags &= ~TERMP_NOBREAK;
         if (arg_hasattr(MDOC_Tag, bl->argc, bl->argv)) {                  p->flags &= ~TERMP_NORPAD;
                 flushln(p);          } else if (MDOC_BODY == node->type)
                   p->flags &= ~TERMP_NOLPAD;
                 if (MDOC_HEAD == node->type) {  
                         p->rmargin = pair->rmargin;  
                         p->offset = pair->offset;  
                         p->flags &= ~TERMP_NOBREAK;  
                 } else {  
                         p->offset = pair->offset;  
                         p->flags &= ~TERMP_NOLPAD;  
                 }  
   
         } else if (arg_hasattr(MDOC_Ohang, bl->argc, bl->argv)) {  
                 flushln(p);  
                 p->offset = pair->offset;  
         }  
 }  }
   
   
Line 1374  termp_ms_pre(DECL_ARGS)
Line 1445  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.20  
changed lines
  Added in v.1.24

CVSweb