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

Diff for /mandoc/man_term.c between version 1.116 and 1.123

version 1.116, 2011/09/18 21:08:34 version 1.123, 2011/11/13 15:33:41
Line 33 
Line 33 
 #include "term.h"  #include "term.h"
 #include "main.h"  #include "main.h"
   
 #define INDENT            7 /* fixed-width char full-indent */  
 #define HALFINDENT        3 /* fixed-width char half-indent */  
 #define MAXMARGINS        64 /* maximum number of indented scopes */  #define MAXMARGINS        64 /* maximum number of indented scopes */
   
 /* FIXME: have PD set the default vspace width. */  /* FIXME: have PD set the default vspace width. */
Line 141  terminal_man(void *arg, const struct man *man)
Line 139  terminal_man(void *arg, const struct man *man)
   
         p = (struct termp *)arg;          p = (struct termp *)arg;
   
           if (0 == p->defindent)
                   p->defindent = 7;
   
         p->overstep = 0;          p->overstep = 0;
         p->maxrmargin = p->defrmargin;          p->maxrmargin = p->defrmargin;
         p->tabwidth = term_len(p, 5);          p->tabwidth = term_len(p, 5);
Line 156  terminal_man(void *arg, const struct man *man)
Line 157  terminal_man(void *arg, const struct man *man)
   
         memset(&mt, 0, sizeof(struct mtermp));          memset(&mt, 0, sizeof(struct mtermp));
   
         mt.lmargin[mt.lmargincur] = term_len(p, INDENT);          mt.lmargin[mt.lmargincur] = term_len(p, p->defindent);
         mt.offset = term_len(p, INDENT);          mt.offset = term_len(p, p->defindent);
   
         if (n->child)          if (n->child)
                 print_man_nodelist(p, &mt, n->child, m);                  print_man_nodelist(p, &mt, n->child, m);
Line 245  pre_literal(DECL_ARGS)
Line 246  pre_literal(DECL_ARGS)
         else          else
                 mt->fl &= ~MANT_LITERAL;                  mt->fl &= ~MANT_LITERAL;
   
           /*
            * Unlike .IP and .TP, .HP does not have a HEAD.
            * So in case a second call to term_flushln() is needed,
            * indentation has to be set up explicitly.
            */
           if (MAN_HP == n->parent->tok && p->rmargin < p->maxrmargin) {
                   p->offset = p->rmargin;
                   p->rmargin = p->maxrmargin;
                   p->flags &= ~(TERMP_NOBREAK | TERMP_TWOSPACE);
                   p->flags |= TERMP_NOSPACE;
           }
   
         return(0);          return(0);
 }  }
   
Line 431  pre_sp(DECL_ARGS)
Line 444  pre_sp(DECL_ARGS)
 static int  static int
 pre_HP(DECL_ARGS)  pre_HP(DECL_ARGS)
 {  {
         size_t                   len;          size_t                   len, one;
         int                      ival;          int                      ival;
         const struct man_node   *nn;          const struct man_node   *nn;
   
Line 456  pre_HP(DECL_ARGS)
Line 469  pre_HP(DECL_ARGS)
                 if ((ival = a2width(p, nn->string)) >= 0)                  if ((ival = a2width(p, nn->string)) >= 0)
                         len = (size_t)ival;                          len = (size_t)ival;
   
         if (0 == len)          one = term_len(p, 1);
                 len = term_len(p, 1);          if (len < one)
                   len = one;
   
         p->offset = mt->offset;          p->offset = mt->offset;
         p->rmargin = mt->offset + len;          p->rmargin = mt->offset + len;
Line 498  pre_PP(DECL_ARGS)
Line 512  pre_PP(DECL_ARGS)
   
         switch (n->type) {          switch (n->type) {
         case (MAN_BLOCK):          case (MAN_BLOCK):
                 mt->lmargin[mt->lmargincur] = term_len(p, INDENT);                  mt->lmargin[mt->lmargincur] = term_len(p, p->defindent);
                 print_bvspace(p, n);                  print_bvspace(p, n);
                 break;                  break;
         default:          default:
Line 520  pre_IP(DECL_ARGS)
Line 534  pre_IP(DECL_ARGS)
   
         switch (n->type) {          switch (n->type) {
         case (MAN_BODY):          case (MAN_BODY):
                 p->flags |= TERMP_NOLPAD;  
                 p->flags |= TERMP_NOSPACE;                  p->flags |= TERMP_NOSPACE;
                 break;                  break;
         case (MAN_HEAD):          case (MAN_HEAD):
Line 591  post_IP(DECL_ARGS)
Line 604  post_IP(DECL_ARGS)
                 break;                  break;
         case (MAN_BODY):          case (MAN_BODY):
                 term_newln(p);                  term_newln(p);
                 p->flags &= ~TERMP_NOLPAD;  
                 break;                  break;
         default:          default:
                 break;                  break;
Line 612  pre_TP(DECL_ARGS)
Line 624  pre_TP(DECL_ARGS)
                 p->flags |= TERMP_NOBREAK;                  p->flags |= TERMP_NOBREAK;
                 break;                  break;
         case (MAN_BODY):          case (MAN_BODY):
                 p->flags |= TERMP_NOLPAD;  
                 p->flags |= TERMP_NOSPACE;                  p->flags |= TERMP_NOSPACE;
                 break;                  break;
         case (MAN_BLOCK):          case (MAN_BLOCK):
Line 628  pre_TP(DECL_ARGS)
Line 639  pre_TP(DECL_ARGS)
         /* Calculate offset. */          /* Calculate offset. */
   
         if (NULL != (nn = n->parent->head->child))          if (NULL != (nn = n->parent->head->child))
                 if (nn->parent->line == nn->line)                  if (nn->string && nn->parent->line == nn->line)
                         if ((ival = a2width(p, nn->string)) >= 0)                          if ((ival = a2width(p, nn->string)) >= 0)
                                 len = (size_t)ival;                                  len = (size_t)ival;
   
Line 681  post_TP(DECL_ARGS)
Line 692  post_TP(DECL_ARGS)
                 break;                  break;
         case (MAN_BODY):          case (MAN_BODY):
                 term_newln(p);                  term_newln(p);
                 p->flags &= ~TERMP_NOLPAD;  
                 break;                  break;
         default:          default:
                 break;                  break;
Line 697  pre_SS(DECL_ARGS)
Line 707  pre_SS(DECL_ARGS)
         switch (n->type) {          switch (n->type) {
         case (MAN_BLOCK):          case (MAN_BLOCK):
                 mt->fl &= ~MANT_LITERAL;                  mt->fl &= ~MANT_LITERAL;
                 mt->lmargin[mt->lmargincur] = term_len(p, INDENT);                  mt->lmargin[mt->lmargincur] = term_len(p, p->defindent);
                 mt->offset = term_len(p, INDENT);                  mt->offset = term_len(p, p->defindent);
                 /* If following a prior empty `SS', no vspace. */                  /* If following a prior empty `SS', no vspace. */
                 if (n->prev && MAN_SS == n->prev->tok)                  if (n->prev && MAN_SS == n->prev->tok)
                         if (NULL == n->prev->body->child)                          if (NULL == n->prev->body->child)
Line 709  pre_SS(DECL_ARGS)
Line 719  pre_SS(DECL_ARGS)
                 break;                  break;
         case (MAN_HEAD):          case (MAN_HEAD):
                 term_fontrepl(p, TERMFONT_BOLD);                  term_fontrepl(p, TERMFONT_BOLD);
                 p->offset = term_len(p, HALFINDENT);                  p->offset = term_len(p, p->defindent/2);
                 break;                  break;
         case (MAN_BODY):          case (MAN_BODY):
                 p->offset = mt->offset;                  p->offset = mt->offset;
Line 748  pre_SH(DECL_ARGS)
Line 758  pre_SH(DECL_ARGS)
         switch (n->type) {          switch (n->type) {
         case (MAN_BLOCK):          case (MAN_BLOCK):
                 mt->fl &= ~MANT_LITERAL;                  mt->fl &= ~MANT_LITERAL;
                 mt->lmargin[mt->lmargincur] = term_len(p, INDENT);                  mt->lmargin[mt->lmargincur] = term_len(p, p->defindent);
                 mt->offset = term_len(p, INDENT);                  mt->offset = term_len(p, p->defindent);
                 /* If following a prior empty `SH', no vspace. */                  /* If following a prior empty `SH', no vspace. */
                 if (n->prev && MAN_SH == n->prev->tok)                  if (n->prev && MAN_SH == n->prev->tok)
                         if (NULL == n->prev->body->child)                          if (NULL == n->prev->body->child)
Line 808  pre_RS(DECL_ARGS)
Line 818  pre_RS(DECL_ARGS)
                 break;                  break;
         }          }
   
         sz = term_len(p, INDENT);          sz = term_len(p, p->defindent);
   
         if (NULL != (n = n->parent->head->child))          if (NULL != (n = n->parent->head->child))
                 if ((ival = a2width(p, n->string)) >= 0)                  if ((ival = a2width(p, n->string)) >= 0)
                         sz = (size_t)ival;                          sz = (size_t)ival;
   
         mt->offset += sz;          mt->offset += sz;
         p->offset = mt->offset;          p->rmargin = p->maxrmargin;
           p->offset = mt->offset < p->rmargin ? mt->offset : p->rmargin;
   
         if (++mt->lmarginsz < MAXMARGINS)          if (++mt->lmarginsz < MAXMARGINS)
                 mt->lmargincur = mt->lmarginsz;                  mt->lmargincur = mt->lmarginsz;
Line 841  post_RS(DECL_ARGS)
Line 852  post_RS(DECL_ARGS)
                 break;                  break;
         }          }
   
         sz = term_len(p, INDENT);          sz = term_len(p, p->defindent);
   
         if (NULL != (n = n->parent->head->child))          if (NULL != (n = n->parent->head->child))
                 if ((ival = a2width(p, n->string)) >= 0)                  if ((ival = a2width(p, n->string)) >= 0)
Line 882  print_man_node(DECL_ARGS)
Line 893  print_man_node(DECL_ARGS)
                  * -man doesn't have nested macros, we don't need to be                   * -man doesn't have nested macros, we don't need to be
                  * more specific than this.                   * more specific than this.
                  */                   */
                 if (MANT_LITERAL & mt->fl &&                  if (MANT_LITERAL & mt->fl && ! (TERMP_NOBREAK & p->flags) &&
                                 (NULL == n->next ||                                  (NULL == n->next ||
                                  n->next->line > n->line)) {                                   n->next->line > n->line)) {
                         rm = p->rmargin;                          rm = p->rmargin;
Line 890  print_man_node(DECL_ARGS)
Line 901  print_man_node(DECL_ARGS)
                         p->rmargin = p->maxrmargin = TERM_MAXMARGIN;                          p->rmargin = p->maxrmargin = TERM_MAXMARGIN;
                         p->flags |= TERMP_NOSPACE;                          p->flags |= TERMP_NOSPACE;
                         term_flushln(p);                          term_flushln(p);
                         p->flags &= ~TERMP_NOLPAD;  
                         p->rmargin = rm;                          p->rmargin = rm;
                         p->maxrmargin = rmax;                          p->maxrmargin = rmax;
                 }                  }
Line 948  print_man_nodelist(DECL_ARGS)
Line 958  print_man_nodelist(DECL_ARGS)
 static void  static void
 print_man_foot(struct termp *p, const void *arg)  print_man_foot(struct termp *p, const void *arg)
 {  {
           char            title[BUFSIZ];
           size_t          datelen;
         const struct man_meta *meta;          const struct man_meta *meta;
   
         meta = (const struct man_meta *)arg;          meta = (const struct man_meta *)arg;
Line 957  print_man_foot(struct termp *p, const void *arg)
Line 969  print_man_foot(struct termp *p, const void *arg)
         term_vspace(p);          term_vspace(p);
         term_vspace(p);          term_vspace(p);
         term_vspace(p);          term_vspace(p);
           snprintf(title, BUFSIZ, "%s(%s)", meta->title, meta->msec);
           datelen = term_strlen(p, meta->date);
   
         p->flags |= TERMP_NOSPACE | TERMP_NOBREAK;          p->flags |= TERMP_NOSPACE | TERMP_NOBREAK;
         p->rmargin = p->maxrmargin - term_strlen(p, meta->date);  
         p->offset = 0;          p->offset = 0;
           p->rmargin = (p->maxrmargin - datelen + term_len(p, 1)) / 2;
   
         /* term_strlen() can return zero. */  
         if (p->rmargin == p->maxrmargin)  
                 p->rmargin--;  
   
         if (meta->source)          if (meta->source)
                 term_word(p, meta->source);                  term_word(p, meta->source);
         if (meta->source)  
                 term_word(p, "");  
         term_flushln(p);          term_flushln(p);
   
         p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;          p->flags |= TERMP_NOSPACE;
         p->offset = p->rmargin;          p->offset = p->rmargin;
         p->rmargin = p->maxrmargin;          p->rmargin = p->maxrmargin - term_strlen(p, title);
         p->flags &= ~TERMP_NOBREAK;          if (p->offset + datelen >= p->rmargin)
                   p->rmargin = p->offset + datelen;
   
         term_word(p, meta->date);          term_word(p, meta->date);
         term_flushln(p);          term_flushln(p);
   
           p->flags &= ~TERMP_NOBREAK;
           p->flags |= TERMP_NOSPACE;
           p->offset = p->rmargin;
           p->rmargin = p->maxrmargin;
   
           term_word(p, title);
           term_flushln(p);
 }  }
   
   
Line 997  print_man_head(struct termp *p, const void *arg)
Line 1014  print_man_head(struct termp *p, const void *arg)
          * point we did so here.           * point we did so here.
          */           */
   
           p->offset = 0;
         p->rmargin = p->maxrmargin;          p->rmargin = p->maxrmargin;
   
         p->offset = 0;  
         buf[0] = title[0] = '\0';          buf[0] = title[0] = '\0';
   
         if (m->vol)          if (m->vol)
Line 1009  print_man_head(struct termp *p, const void *arg)
Line 1026  print_man_head(struct termp *p, const void *arg)
         snprintf(title, BUFSIZ, "%s(%s)", m->title, m->msec);          snprintf(title, BUFSIZ, "%s(%s)", m->title, m->msec);
         titlen = term_strlen(p, title);          titlen = term_strlen(p, title);
   
           p->flags |= TERMP_NOBREAK | TERMP_NOSPACE;
         p->offset = 0;          p->offset = 0;
         p->rmargin = 2 * (titlen+1) + buflen < p->maxrmargin ?          p->rmargin = 2 * (titlen+1) + buflen < p->maxrmargin ?
             (p->maxrmargin -              (p->maxrmargin -
              term_strlen(p, buf) + term_len(p, 1)) / 2 :               term_strlen(p, buf) + term_len(p, 1)) / 2 :
             p->maxrmargin - buflen;              p->maxrmargin - buflen;
         p->flags |= TERMP_NOBREAK | TERMP_NOSPACE;  
   
         term_word(p, title);          term_word(p, title);
         term_flushln(p);          term_flushln(p);
   
         p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;          p->flags |= TERMP_NOSPACE;
         p->offset = p->rmargin;          p->offset = p->rmargin;
         p->rmargin = p->offset + buflen + titlen < p->maxrmargin ?          p->rmargin = p->offset + buflen + titlen < p->maxrmargin ?
             p->maxrmargin - titlen : p->maxrmargin;              p->maxrmargin - titlen : p->maxrmargin;
Line 1029  print_man_head(struct termp *p, const void *arg)
Line 1046  print_man_head(struct termp *p, const void *arg)
   
         p->flags &= ~TERMP_NOBREAK;          p->flags &= ~TERMP_NOBREAK;
         if (p->rmargin + titlen <= p->maxrmargin) {          if (p->rmargin + titlen <= p->maxrmargin) {
                 p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;                  p->flags |= TERMP_NOSPACE;
                 p->offset = p->rmargin;                  p->offset = p->rmargin;
                 p->rmargin = p->maxrmargin;                  p->rmargin = p->maxrmargin;
                 term_word(p, title);                  term_word(p, title);
                 term_flushln(p);                  term_flushln(p);
         }          }
   
         p->rmargin = p->maxrmargin;  
         p->offset = 0;  
         p->flags &= ~TERMP_NOSPACE;          p->flags &= ~TERMP_NOSPACE;
           p->offset = 0;
           p->rmargin = p->maxrmargin;
   
         /*          /*
          * Groff likes to have some leading spaces before content.  Well           * Groff likes to have some leading spaces before content.  Well

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

CVSweb