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

Diff for /mandoc/mdoc_term.c between version 1.116 and 1.125

version 1.116, 2010/04/06 16:27:53 version 1.125, 2010/05/17 22:11:42
Line 22 
Line 22 
   
 #include <assert.h>  #include <assert.h>
 #include <ctype.h>  #include <ctype.h>
   #include <stdint.h>
 #include <stdio.h>  #include <stdio.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
   
   #include "mandoc.h"
 #include "out.h"  #include "out.h"
 #include "term.h"  #include "term.h"
 #include "mdoc.h"  #include "mdoc.h"
Line 58  static int   arg_hasattr(int, const struct mdoc_node *
Line 60  static int   arg_hasattr(int, const struct mdoc_node *
 static  int       arg_getattrs(const int *, int *, size_t,  static  int       arg_getattrs(const int *, int *, size_t,
                         const struct mdoc_node *);                          const struct mdoc_node *);
 static  int       arg_getattr(int, const struct mdoc_node *);  static  int       arg_getattr(int, const struct mdoc_node *);
   static  int       arg_disptype(const struct mdoc_node *);
 static  int       arg_listtype(const struct mdoc_node *);  static  int       arg_listtype(const struct mdoc_node *);
 static  void      print_bvspace(struct termp *,  static  void      print_bvspace(struct termp *,
                         const struct mdoc_node *,                          const struct mdoc_node *,
Line 93  static void   termp_sq_post(DECL_ARGS);
Line 96  static void   termp_sq_post(DECL_ARGS);
 static  void      termp_ss_post(DECL_ARGS);  static  void      termp_ss_post(DECL_ARGS);
 static  void      termp_vt_post(DECL_ARGS);  static  void      termp_vt_post(DECL_ARGS);
   
 static  int       termp__t_pre(DECL_ARGS);  
 static  int       termp_an_pre(DECL_ARGS);  static  int       termp_an_pre(DECL_ARGS);
 static  int       termp_ap_pre(DECL_ARGS);  static  int       termp_ap_pre(DECL_ARGS);
 static  int       termp_aq_pre(DECL_ARGS);  static  int       termp_aq_pre(DECL_ARGS);
Line 188  static const struct termact termacts[MDOC_MAX] = {
Line 190  static const struct termact termacts[MDOC_MAX] = {
         { NULL, termp____post }, /* %O */          { NULL, termp____post }, /* %O */
         { NULL, termp____post }, /* %P */          { NULL, termp____post }, /* %P */
         { NULL, termp____post }, /* %R */          { NULL, termp____post }, /* %R */
         { termp__t_pre, termp____post }, /* %T */          { termp_under_pre, termp____post }, /* %T */
         { NULL, termp____post }, /* %V */          { NULL, termp____post }, /* %V */
         { NULL, NULL }, /* Ac */          { NULL, NULL }, /* Ac */
         { termp_aq_pre, termp_aq_post }, /* Ao */          { termp_aq_pre, termp_aq_post }, /* Ao */
Line 272  terminal_mdoc(void *arg, const struct mdoc *mdoc)
Line 274  terminal_mdoc(void *arg, const struct mdoc *mdoc)
         p = (struct termp *)arg;          p = (struct termp *)arg;
   
         p->overstep = 0;          p->overstep = 0;
         p->maxrmargin = 78;          p->maxrmargin = p->defrmargin;
   
         if (NULL == p->symtab)          if (NULL == p->symtab)
                 switch (p->enc) {                  switch (p->enc) {
Line 336  print_mdoc_node(DECL_ARGS)
Line 338  print_mdoc_node(DECL_ARGS)
                 if (termacts[n->tok].post)                  if (termacts[n->tok].post)
                         (*termacts[n->tok].post)(p, &npair, m, n);                          (*termacts[n->tok].post)(p, &npair, m, n);
   
           if (MDOC_EOS & n->flags)
                   p->flags |= TERMP_SENTENCE;
   
         p->offset = offset;          p->offset = offset;
         p->rmargin = rmargin;          p->rmargin = rmargin;
 }  }
Line 421  print_mdoc_head(DECL_ARGS)
Line 426  print_mdoc_head(DECL_ARGS)
                 strlcat(buf, ")", BUFSIZ);                  strlcat(buf, ")", BUFSIZ);
         }          }
   
         snprintf(title, BUFSIZ, "%s(%d)", m->title, m->msec);          snprintf(title, BUFSIZ, "%s(%s)", m->title, m->msec);
   
         p->offset = 0;          p->offset = 0;
         p->rmargin = (p->maxrmargin - strlen(buf) + 1) / 2;          p->rmargin = (p->maxrmargin - strlen(buf) + 1) / 2;
Line 479  a2width(const struct mdoc_argv *arg, int pos)
Line 484  a2width(const struct mdoc_argv *arg, int pos)
   
   
 static int  static int
   arg_disptype(const struct mdoc_node *n)
   {
           int              i, len;
   
           assert(MDOC_BLOCK == n->type);
   
           len = (int)(n->args ? n->args->argc : 0);
   
           for (i = 0; i < len; i++)
                   switch (n->args->argv[i].arg) {
                   case (MDOC_Centred):
                           /* FALLTHROUGH */
                   case (MDOC_Ragged):
                           /* FALLTHROUGH */
                   case (MDOC_Filled):
                           /* FALLTHROUGH */
                   case (MDOC_Unfilled):
                           /* FALLTHROUGH */
                   case (MDOC_Literal):
                           return(n->args->argv[i].arg);
                   default:
                           break;
                   }
   
           return(-1);
   }
   
   
   static int
 arg_listtype(const struct mdoc_node *n)  arg_listtype(const struct mdoc_node *n)
 {  {
         int              i, len;          int              i, len;
Line 1052  static int
Line 1086  static int
 termp_nm_pre(DECL_ARGS)  termp_nm_pre(DECL_ARGS)
 {  {
   
         if (SEC_SYNOPSIS == n->sec)          if (NULL == n->child && NULL == m->name)
   
           if (SEC_SYNOPSIS == n->sec && MDOC_LINE & n->flags)
                 term_newln(p);                  term_newln(p);
   
         term_fontpush(p, TERMFONT_BOLD);          term_fontpush(p, TERMFONT_BOLD);
   
         if (NULL == n->child)          if (NULL == n->child)
                 term_word(p, m->name);                  term_word(p, m->name);
   
         return(1);          return(1);
 }  }
   
Line 1127  termp_an_post(DECL_ARGS)
Line 1164  termp_an_post(DECL_ARGS)
                 return;                  return;
         }          }
   
         if (arg_getattr(MDOC_Split, n) > -1) {          if (arg_hasattr(MDOC_Split, n)) {
                 p->flags &= ~TERMP_NOSPLIT;                  p->flags &= ~TERMP_NOSPLIT;
                 p->flags |= TERMP_SPLIT;                  p->flags |= TERMP_SPLIT;
         } else {          } else {
Line 1183  termp_rv_pre(DECL_ARGS)
Line 1220  termp_rv_pre(DECL_ARGS)
                         term_word(p, "()");                          term_word(p, "()");
         }          }
   
         if (n->child->next)          if (n->child && n->child->next)
                 term_word(p, "functions return");                  term_word(p, "functions return");
         else          else
                 term_word(p, "function returns");                  term_word(p, "function returns");
Line 1222  termp_ex_pre(DECL_ARGS)
Line 1259  termp_ex_pre(DECL_ARGS)
                         p->flags &= ~TERMP_NOSPACE;                          p->flags &= ~TERMP_NOSPACE;
         }          }
   
         if (n->child->next)          if (n->child && n->child->next)
                 term_word(p, "utilities exit");                  term_word(p, "utilities exit");
         else          else
                 term_word(p, "utility exits");                  term_word(p, "utility exits");
Line 1351  static void
Line 1388  static void
 termp_fd_post(DECL_ARGS)  termp_fd_post(DECL_ARGS)
 {  {
   
         if (n->sec != SEC_SYNOPSIS)          if (n->sec != SEC_SYNOPSIS || ! (MDOC_LINE & n->flags))
                 return;                  return;
   
         term_newln(p);          term_newln(p);
Line 1438  static void
Line 1475  static void
 termp_lb_post(DECL_ARGS)  termp_lb_post(DECL_ARGS)
 {  {
   
         if (SEC_LIBRARY == n->sec)          if (SEC_LIBRARY == n->sec && MDOC_LINE & n->flags)
                 term_newln(p);                  term_newln(p);
 }  }
   
Line 1507  static int
Line 1544  static int
 termp_ft_pre(DECL_ARGS)  termp_ft_pre(DECL_ARGS)
 {  {
   
         if (SEC_SYNOPSIS == n->sec)          if (SEC_SYNOPSIS == n->sec && MDOC_LINE & n->flags)
                 if (n->prev && MDOC_Fo == n->prev->tok)                  if (n->prev && MDOC_Fo == n->prev->tok)
                         term_vspace(p);                          term_vspace(p);
   
Line 1521  static void
Line 1558  static void
 termp_ft_post(DECL_ARGS)  termp_ft_post(DECL_ARGS)
 {  {
   
         if (SEC_SYNOPSIS == n->sec)          if (SEC_SYNOPSIS == n->sec && MDOC_LINE & n->flags)
                 term_newln(p);                  term_newln(p);
 }  }
   
Line 1562  static void
Line 1599  static void
 termp_fn_post(DECL_ARGS)  termp_fn_post(DECL_ARGS)
 {  {
   
         if (n->sec == SEC_SYNOPSIS && n->next)          if (n->sec == SEC_SYNOPSIS && n->next && MDOC_LINE & n->flags)
                 term_vspace(p);                  term_vspace(p);
 }  }
   
Line 1599  static int
Line 1636  static int
 termp_bd_pre(DECL_ARGS)  termp_bd_pre(DECL_ARGS)
 {  {
         int                      i, type;          int                      i, type;
           size_t                   rm, rmax;
         const struct mdoc_node  *nn;          const struct mdoc_node  *nn;
   
         if (MDOC_BLOCK == n->type) {          if (MDOC_BLOCK == n->type) {
Line 1609  termp_bd_pre(DECL_ARGS)
Line 1647  termp_bd_pre(DECL_ARGS)
   
         nn = n->parent;          nn = n->parent;
   
         for (type = -1, i = 0; i < (int)nn->args->argc; i++) {          type = arg_disptype(nn);
                 switch (nn->args->argv[i].arg) {          assert(-1 != type);
                 case (MDOC_Centred):  
                         /* FALLTHROUGH */  
                 case (MDOC_Ragged):  
                         /* FALLTHROUGH */  
                 case (MDOC_Filled):  
                         /* FALLTHROUGH */  
                 case (MDOC_Unfilled):  
                         /* FALLTHROUGH */  
                 case (MDOC_Literal):  
                         type = nn->args->argv[i].arg;  
                         break;  
                 case (MDOC_Offset):  
                         p->offset += a2offs(&nn->args->argv[i]);  
                         break;  
                 default:  
                         break;  
                 }  
         }  
   
           if (-1 != (i = arg_getattr(MDOC_Offset, nn)))
                   p->offset += a2offs(&nn->args->argv[i]);
   
         /*          /*
          * If -ragged or -filled are specified, the block does nothing           * If -ragged or -filled are specified, the block does nothing
          * but change the indentation.  If -unfilled or -literal are           * but change the indentation.  If -unfilled or -literal are
Line 1638  termp_bd_pre(DECL_ARGS)
Line 1661  termp_bd_pre(DECL_ARGS)
          * lines are allowed.           * lines are allowed.
          */           */
   
         assert(type > -1);  
         if (MDOC_Literal != type && MDOC_Unfilled != type)          if (MDOC_Literal != type && MDOC_Unfilled != type)
                 return(1);                  return(1);
   
           rm = p->rmargin;
           rmax = p->maxrmargin;
           p->rmargin = p->maxrmargin = TERM_MAXMARGIN;
   
         for (nn = n->child; nn; nn = nn->next) {          for (nn = n->child; nn; nn = nn->next) {
                 p->flags |= TERMP_NOSPACE;                  p->flags |= TERMP_NOSPACE;
                 print_mdoc_node(p, pair, m, nn);                  print_mdoc_node(p, pair, m, nn);
Line 1653  termp_bd_pre(DECL_ARGS)
Line 1679  termp_bd_pre(DECL_ARGS)
                         term_flushln(p);                          term_flushln(p);
         }          }
   
           p->rmargin = rm;
           p->maxrmargin = rmax;
         return(0);          return(0);
 }  }
   
Line 1661  termp_bd_pre(DECL_ARGS)
Line 1689  termp_bd_pre(DECL_ARGS)
 static void  static void
 termp_bd_post(DECL_ARGS)  termp_bd_post(DECL_ARGS)
 {  {
           int              type;
           size_t           rm, rmax;
   
         if (MDOC_BODY != n->type)          if (MDOC_BODY != n->type)
                 return;                  return;
   
           type = arg_disptype(n->parent);
           assert(-1 != type);
   
           rm = p->rmargin;
           rmax = p->maxrmargin;
   
           if (MDOC_Literal == type || MDOC_Unfilled == type)
                   p->rmargin = p->maxrmargin = TERM_MAXMARGIN;
   
         p->flags |= TERMP_NOSPACE;          p->flags |= TERMP_NOSPACE;
         term_flushln(p);          term_flushln(p);
   
           p->rmargin = rm;
           p->maxrmargin = rmax;
 }  }
   
   
Line 1855  termp_in_post(DECL_ARGS)
Line 1898  termp_in_post(DECL_ARGS)
         term_word(p, ">");          term_word(p, ">");
         term_fontpop(p);          term_fontpop(p);
   
         if (SEC_SYNOPSIS != n->sec)          if (SEC_SYNOPSIS != n->sec && ! (MDOC_LINE & n->flags))
                 return;                  return;
   
         term_newln(p);          term_newln(p);
Line 2080  termp____post(DECL_ARGS)
Line 2123  termp____post(DECL_ARGS)
         /* TODO: %U. */          /* TODO: %U. */
   
         p->flags |= TERMP_NOSPACE;          p->flags |= TERMP_NOSPACE;
         switch (n->tok) {  
         case (MDOC__T):  
                 term_word(p, "\\(rq");  
                 p->flags |= TERMP_NOSPACE;  
                 break;  
         default:  
                 break;  
         }  
         term_word(p, n->next ? "," : ".");          term_word(p, n->next ? "," : ".");
 }  }
   
Line 2135  termp_under_pre(DECL_ARGS)
Line 2170  termp_under_pre(DECL_ARGS)
 {  {
   
         term_fontpush(p, TERMFONT_UNDER);          term_fontpush(p, TERMFONT_UNDER);
         return(1);  
 }  
   
   
 /* ARGSUSED */  
 static int  
 termp__t_pre(DECL_ARGS)  
 {  
   
         term_word(p, "\\(lq");  
         p->flags |= TERMP_NOSPACE;  
         return(1);          return(1);
 }  }

Legend:
Removed from v.1.116  
changed lines
  Added in v.1.125

CVSweb