[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.172 and 1.183

version 1.172, 2015/04/02 22:48:17 version 1.183, 2015/04/19 19:44:21
Line 49  struct mtermp {
Line 49  struct mtermp {
 #define DECL_ARGS         struct termp *p, \  #define DECL_ARGS         struct termp *p, \
                           struct mtermp *mt, \                            struct mtermp *mt, \
                           struct roff_node *n, \                            struct roff_node *n, \
                           const struct man_meta *meta                            const struct roff_meta *meta
   
 struct  termact {  struct  termact {
         int             (*pre)(DECL_ARGS);          int             (*pre)(DECL_ARGS);
Line 60  struct termact {
Line 60  struct termact {
   
 static  void              print_man_nodelist(DECL_ARGS);  static  void              print_man_nodelist(DECL_ARGS);
 static  void              print_man_node(DECL_ARGS);  static  void              print_man_node(DECL_ARGS);
 static  void              print_man_head(struct termp *, const void *);  static  void              print_man_head(struct termp *,
 static  void              print_man_foot(struct termp *, const void *);                                  const struct roff_meta *);
   static  void              print_man_foot(struct termp *,
                                   const struct roff_meta *);
 static  void              print_bvspace(struct termp *,  static  void              print_bvspace(struct termp *,
                                 const struct roff_node *, int);                                  const struct roff_node *, int);
   
Line 136  static const struct termact termacts[MAN_MAX] = {
Line 138  static const struct termact termacts[MAN_MAX] = {
   
   
 void  void
 terminal_man(void *arg, const struct man *man)  terminal_man(void *arg, const struct roff_man *man)
 {  {
         struct termp            *p;          struct termp            *p;
         const struct man_meta   *meta;  
         struct roff_node        *n;          struct roff_node        *n;
         struct mtermp            mt;          struct mtermp            mt;
   
         p = (struct termp *)arg;          p = (struct termp *)arg;
   
         p->overstep = 0;          p->overstep = 0;
         p->rmargin = p->maxrmargin = p->defrmargin;          p->rmargin = p->maxrmargin = p->defrmargin;
         p->tabwidth = term_len(p, 5);          p->tabwidth = term_len(p, 5);
   
         n = man_node(man)->child;  
         meta = man_meta(man);  
   
         memset(&mt, 0, sizeof(struct mtermp));          memset(&mt, 0, sizeof(struct mtermp));
   
         mt.lmargin[mt.lmargincur] = term_len(p, p->defindent);          mt.lmargin[mt.lmargincur] = term_len(p, p->defindent);
         mt.offset = term_len(p, p->defindent);          mt.offset = term_len(p, p->defindent);
         mt.pardist = 1;          mt.pardist = 1;
   
           n = man->first->child;
         if (p->synopsisonly) {          if (p->synopsisonly) {
                 while (n != NULL) {                  while (n != NULL) {
                         if (n->tok == MAN_SH &&                          if (n->tok == MAN_SH &&
Line 165  terminal_man(void *arg, const struct man *man)
Line 162  terminal_man(void *arg, const struct man *man)
                             !strcmp(n->child->child->string, "SYNOPSIS")) {                              !strcmp(n->child->child->string, "SYNOPSIS")) {
                                 if (n->child->next->child != NULL)                                  if (n->child->next->child != NULL)
                                         print_man_nodelist(p, &mt,                                          print_man_nodelist(p, &mt,
                                             n->child->next->child, meta);                                              n->child->next->child,
                                               &man->meta);
                                 term_newln(p);                                  term_newln(p);
                                 break;                                  break;
                         }                          }
Line 174  terminal_man(void *arg, const struct man *man)
Line 172  terminal_man(void *arg, const struct man *man)
         } else {          } else {
                 if (p->defindent == 0)                  if (p->defindent == 0)
                         p->defindent = 7;                          p->defindent = 7;
                 term_begin(p, print_man_head, print_man_foot, meta);                  term_begin(p, print_man_head, print_man_foot, &man->meta);
                 p->flags |= TERMP_NOSPACE;                  p->flags |= TERMP_NOSPACE;
                 if (n != NULL)                  if (n != NULL)
                         print_man_nodelist(p, &mt, n, meta);                          print_man_nodelist(p, &mt, n, &man->meta);
                 term_end(p);                  term_end(p);
         }          }
 }  }
Line 319  pre_alternate(DECL_ARGS)
Line 317  pre_alternate(DECL_ARGS)
                 term_fontrepl(p, font[i]);                  term_fontrepl(p, font[i]);
                 if (savelit && NULL == nn->next)                  if (savelit && NULL == nn->next)
                         mt->fl |= MANT_LITERAL;                          mt->fl |= MANT_LITERAL;
                 print_man_node(p, mt, nn, meta);                  assert(nn->type == ROFFT_TEXT);
                   term_word(p, nn->string);
                   if (nn->flags & MAN_EOS)
                           p->flags |= TERMP_SENTENCE;
                 if (nn->next)                  if (nn->next)
                         p->flags |= TERMP_NOSPACE;                          p->flags |= TERMP_NOSPACE;
         }          }
Line 425  pre_in(DECL_ARGS)
Line 426  pre_in(DECL_ARGS)
         if ( ! a2roffsu(++cp, &su, SCALE_EN))          if ( ! a2roffsu(++cp, &su, SCALE_EN))
                 return(0);                  return(0);
   
         v = term_hspan(p, &su);          v = (term_hspan(p, &su) + 11) / 24;
   
         if (less < 0)          if (less < 0)
                 p->offset -= p->offset > v ? v : p->offset;                  p->offset -= p->offset > v ? v : p->offset;
Line 481  pre_sp(DECL_ARGS)
Line 482  pre_sp(DECL_ARGS)
                 for (i = 0; i < len; i++)                  for (i = 0; i < len; i++)
                         term_vspace(p);                          term_vspace(p);
   
           /*
            * Handle an explicit break request in the same way
            * as an overflowing line.
            */
   
           if (p->flags & TERMP_BRIND) {
                   p->offset = p->rmargin;
                   p->rmargin = p->maxrmargin;
                   p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND);
           }
   
         return(0);          return(0);
 }  }
   
Line 510  pre_HP(DECL_ARGS)
Line 522  pre_HP(DECL_ARGS)
   
         if ((nn = n->parent->head->child) != NULL &&          if ((nn = n->parent->head->child) != NULL &&
             a2roffsu(nn->string, &su, SCALE_EN)) {              a2roffsu(nn->string, &su, SCALE_EN)) {
                 len = term_hspan(p, &su);                  len = term_hspan(p, &su) / 24;
                 if (len < 0 && (size_t)(-len) > mt->offset)                  if (len < 0 && (size_t)(-len) > mt->offset)
                         len = -mt->offset;                          len = -mt->offset;
                 else if (len > SHRT_MAX)                  else if (len > SHRT_MAX)
Line 531  post_HP(DECL_ARGS)
Line 543  post_HP(DECL_ARGS)
         switch (n->type) {          switch (n->type) {
         case ROFFT_BODY:          case ROFFT_BODY:
                 term_newln(p);                  term_newln(p);
   
                   /*
                    * Compatibility with a groff bug.
                    * The .HP macro uses the undocumented .tag request
                    * which causes a line break and cancels no-space
                    * mode even if there isn't any output.
                    */
   
                   if (n->child == NULL)
                           term_vspace(p);
   
                 p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND);                  p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND);
                 p->trailspace = 0;                  p->trailspace = 0;
                 p->offset = mt->offset;                  p->offset = mt->offset;
Line 584  pre_IP(DECL_ARGS)
Line 607  pre_IP(DECL_ARGS)
         if ((nn = n->parent->head->child) != NULL &&          if ((nn = n->parent->head->child) != NULL &&
             (nn = nn->next) != NULL &&              (nn = nn->next) != NULL &&
             a2roffsu(nn->string, &su, SCALE_EN)) {              a2roffsu(nn->string, &su, SCALE_EN)) {
                 len = term_hspan(p, &su);                  len = term_hspan(p, &su) / 24;
                 if (len < 0 && (size_t)(-len) > mt->offset)                  if (len < 0 && (size_t)(-len) > mt->offset)
                         len = -mt->offset;                          len = -mt->offset;
                 else if (len > SHRT_MAX)                  else if (len > SHRT_MAX)
Line 666  pre_TP(DECL_ARGS)
Line 689  pre_TP(DECL_ARGS)
         if ((nn = n->parent->head->child) != NULL &&          if ((nn = n->parent->head->child) != NULL &&
             nn->string != NULL && ! (MAN_LINE & nn->flags) &&              nn->string != NULL && ! (MAN_LINE & nn->flags) &&
             a2roffsu(nn->string, &su, SCALE_EN)) {              a2roffsu(nn->string, &su, SCALE_EN)) {
                 len = term_hspan(p, &su);                  len = term_hspan(p, &su) / 24;
                 if (len < 0 && (size_t)(-len) > mt->offset)                  if (len < 0 && (size_t)(-len) > mt->offset)
                         len = -mt->offset;                          len = -mt->offset;
                 else if (len > SHRT_MAX)                  else if (len > SHRT_MAX)
Line 744  pre_SS(DECL_ARGS)
Line 767  pre_SS(DECL_ARGS)
   
                 do {                  do {
                         n = n->prev;                          n = n->prev;
                 } while (n != NULL && n->tok != MAN_MAX &&                  } while (n != NULL && n->tok != TOKEN_NONE &&
                     termacts[n->tok].flags & MAN_NOTEXT);                      termacts[n->tok].flags & MAN_NOTEXT);
                 if (n == NULL || (n->tok == MAN_SS && n->body->child == NULL))                  if (n == NULL || (n->tok == MAN_SS && n->body->child == NULL))
                         break;                          break;
Line 755  pre_SS(DECL_ARGS)
Line 778  pre_SS(DECL_ARGS)
         case ROFFT_HEAD:          case ROFFT_HEAD:
                 term_fontrepl(p, TERMFONT_BOLD);                  term_fontrepl(p, TERMFONT_BOLD);
                 p->offset = term_len(p, 3);                  p->offset = term_len(p, 3);
                   p->rmargin = mt->offset;
                   p->trailspace = mt->offset;
                   p->flags |= TERMP_NOBREAK | TERMP_BRIND;
                 break;                  break;
         case ROFFT_BODY:          case ROFFT_BODY:
                 p->offset = mt->offset;                  p->offset = mt->offset;
                   p->rmargin = p->maxrmargin;
                   p->trailspace = 0;
                   p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND);
                 break;                  break;
         default:          default:
                 break;                  break;
Line 810  pre_SH(DECL_ARGS)
Line 839  pre_SH(DECL_ARGS)
         case ROFFT_HEAD:          case ROFFT_HEAD:
                 term_fontrepl(p, TERMFONT_BOLD);                  term_fontrepl(p, TERMFONT_BOLD);
                 p->offset = 0;                  p->offset = 0;
                   p->rmargin = mt->offset;
                   p->trailspace = mt->offset;
                   p->flags |= TERMP_NOBREAK | TERMP_BRIND;
                 break;                  break;
         case ROFFT_BODY:          case ROFFT_BODY:
                 p->offset = mt->offset;                  p->offset = mt->offset;
                   p->rmargin = p->maxrmargin;
                   p->trailspace = 0;
                   p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND);
                 break;                  break;
         default:          default:
                 break;                  break;
Line 854  pre_RS(DECL_ARGS)
Line 889  pre_RS(DECL_ARGS)
   
         n = n->parent->head;          n = n->parent->head;
         n->aux = SHRT_MAX + 1;          n->aux = SHRT_MAX + 1;
         if (n->child != NULL && a2roffsu(n->child->string, &su, SCALE_EN))          if (n->child == NULL)
                 n->aux = term_hspan(p, &su);                  n->aux = mt->lmargin[mt->lmargincur];
           else if (a2roffsu(n->child->string, &su, SCALE_EN))
                   n->aux = term_hspan(p, &su) / 24;
         if (n->aux < 0 && (size_t)(-n->aux) > mt->offset)          if (n->aux < 0 && (size_t)(-n->aux) > mt->offset)
                 n->aux = -mt->offset;                  n->aux = -mt->offset;
         else if (n->aux > SHRT_MAX)          else if (n->aux > SHRT_MAX)
Line 868  pre_RS(DECL_ARGS)
Line 905  pre_RS(DECL_ARGS)
         if (++mt->lmarginsz < MAXMARGINS)          if (++mt->lmarginsz < MAXMARGINS)
                 mt->lmargincur = mt->lmarginsz;                  mt->lmargincur = mt->lmarginsz;
   
         mt->lmargin[mt->lmargincur] = mt->lmargin[mt->lmargincur - 1];          mt->lmargin[mt->lmargincur] = term_len(p, p->defindent);
         return(1);          return(1);
 }  }
   
Line 1012  print_man_nodelist(DECL_ARGS)
Line 1049  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 struct roff_meta *meta)
 {  {
         const struct man_meta   *meta;  
         char                    *title;          char                    *title;
         size_t                   datelen, titlen;          size_t                   datelen, titlen;
   
         meta = (const struct man_meta *)arg;  
         assert(meta->title);          assert(meta->title);
         assert(meta->msec);          assert(meta->msec);
         assert(meta->date);          assert(meta->date);
Line 1030  print_man_foot(struct termp *p, const void *arg)
Line 1065  print_man_foot(struct termp *p, const void *arg)
   
         /*          /*
          * Temporary, undocumented option to imitate mdoc(7) output.           * Temporary, undocumented option to imitate mdoc(7) output.
          * In the bottom right corner, use the source instead of           * In the bottom right corner, use the operating system
          * the title.           * instead of the title.
          */           */
   
         if ( ! p->mdocstyle) {          if ( ! p->mdocstyle) {
Line 1041  print_man_foot(struct termp *p, const void *arg)
Line 1076  print_man_foot(struct termp *p, const void *arg)
                 }                  }
                 mandoc_asprintf(&title, "%s(%s)",                  mandoc_asprintf(&title, "%s(%s)",
                     meta->title, meta->msec);                      meta->title, meta->msec);
         } else if (meta->source) {          } else if (meta->os) {
                 title = mandoc_strdup(meta->source);                  title = mandoc_strdup(meta->os);
         } else {          } else {
                 title = mandoc_strdup("");                  title = mandoc_strdup("");
         }          }
         datelen = term_strlen(p, meta->date);          datelen = term_strlen(p, meta->date);
   
         /* Bottom left corner: manual source. */          /* Bottom left corner: operating system. */
   
         p->flags |= TERMP_NOSPACE | TERMP_NOBREAK;          p->flags |= TERMP_NOSPACE | TERMP_NOBREAK;
         p->trailspace = 1;          p->trailspace = 1;
Line 1056  print_man_foot(struct termp *p, const void *arg)
Line 1091  print_man_foot(struct termp *p, const void *arg)
         p->rmargin = p->maxrmargin > datelen ?          p->rmargin = p->maxrmargin > datelen ?
             (p->maxrmargin + term_len(p, 1) - datelen) / 2 : 0;              (p->maxrmargin + term_len(p, 1) - datelen) / 2 : 0;
   
         if (meta->source)          if (meta->os)
                 term_word(p, meta->source);                  term_word(p, meta->os);
         term_flushln(p);          term_flushln(p);
   
         /* At the bottom in the middle: manual date. */          /* At the bottom in the middle: manual date. */
Line 1084  print_man_foot(struct termp *p, const void *arg)
Line 1119  print_man_foot(struct termp *p, const void *arg)
 }  }
   
 static void  static void
 print_man_head(struct termp *p, const void *arg)  print_man_head(struct termp *p, const struct roff_meta *meta)
 {  {
         const struct man_meta   *meta;  
         const char              *volume;          const char              *volume;
         char                    *title;          char                    *title;
         size_t                   vollen, titlen;          size_t                   vollen, titlen;
   
         meta = (const struct man_meta *)arg;  
         assert(meta->title);          assert(meta->title);
         assert(meta->msec);          assert(meta->msec);
   

Legend:
Removed from v.1.172  
changed lines
  Added in v.1.183

CVSweb