[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.91 and 1.97

version 1.91, 2009/10/18 13:34:17 version 1.97, 2009/10/27 08:26:12
Line 23 
Line 23 
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
   
   #include "out.h"
 #include "term.h"  #include "term.h"
 #include "mdoc.h"  #include "mdoc.h"
 #include "chars.h"  #include "chars.h"
Line 47  struct termact {
Line 48  struct termact {
         void    (*post)(DECL_ARGS);          void    (*post)(DECL_ARGS);
 };  };
   
   static  size_t    a2width(const struct mdoc_argv *, int);
   static  size_t    a2height(const struct mdoc_node *);
   static  size_t    a2offs(const struct mdoc_argv *);
   
   static  int       arg_hasattr(int, const struct mdoc_node *);
   static  int       arg_getattrs(const int *, int *, size_t,
                           const struct mdoc_node *);
   static  int       arg_getattr(int, const struct mdoc_node *);
   static  int       arg_listtype(const struct mdoc_node *);
   static  void      print_bvspace(struct termp *,
                           const struct mdoc_node *,
                           const struct mdoc_node *);
   static  void      print_node(DECL_ARGS);
   static  void      print_head(DECL_ARGS);
   static  void      print_body(DECL_ARGS);
   static  void      print_foot(DECL_ARGS);
   
   #ifdef __linux__
   extern  size_t    strlcpy(char *, const char *, size_t);
   extern  size_t    strlcat(char *, const char *, size_t);
   #endif
   
 static  void      termp____post(DECL_ARGS);  static  void      termp____post(DECL_ARGS);
 static  void      termp_an_post(DECL_ARGS);  static  void      termp_an_post(DECL_ARGS);
 static  void      termp_aq_post(DECL_ARGS);  static  void      termp_aq_post(DECL_ARGS);
Line 235  static const struct termact termacts[MDOC_MAX] = {
Line 258  static const struct termact termacts[MDOC_MAX] = {
         { NULL, termp____post }, /* %Q */          { NULL, termp____post }, /* %Q */
         { termp_sp_pre, NULL }, /* br */          { termp_sp_pre, NULL }, /* br */
         { termp_sp_pre, NULL }, /* sp */          { termp_sp_pre, NULL }, /* sp */
           { termp_under_pre, termp____post }, /* %U */
 };  };
   
 #ifdef __linux__  
 extern  size_t    strlcpy(char *, const char *, size_t);  
 extern  size_t    strlcat(char *, const char *, size_t);  
 #endif  
   
 static  size_t    arg2width(const struct mdoc_argv *, int);  
 static  size_t    arg2height(const struct mdoc_node *);  
 static  size_t    arg2offs(const struct mdoc_argv *);  
   
 static  int       arg_hasattr(int, const struct mdoc_node *);  
 static  int       arg_getattrs(const int *, int *, size_t,  
                         const struct mdoc_node *);  
 static  int       arg_getattr(int, const struct mdoc_node *);  
 static  int       arg_listtype(const struct mdoc_node *);  
 static  void      print_bvspace(struct termp *,  
                         const struct mdoc_node *,  
                         const struct mdoc_node *);  
 static  void      print_node(DECL_ARGS);  
 static  void      print_head(DECL_ARGS);  
 static  void      print_body(DECL_ARGS);  
 static  void      print_foot(DECL_ARGS);  
   
   
 void  void
 terminal_mdoc(void *arg, const struct mdoc *mdoc)  terminal_mdoc(void *arg, const struct mdoc *mdoc)
 {  {
Line 313  print_node(DECL_ARGS)
Line 315  print_node(DECL_ARGS)
         bold = p->bold;          bold = p->bold;
         under = p->under;          under = p->under;
   
         bzero(&npair, sizeof(struct termpair));          memset(&npair, 0, sizeof(struct termpair));
         npair.ppair = pair;          npair.ppair = pair;
   
         if (MDOC_TEXT != n->type) {          if (MDOC_TEXT != n->type) {
Line 346  print_node(DECL_ARGS)
Line 348  print_node(DECL_ARGS)
 static void  static void
 print_foot(DECL_ARGS)  print_foot(DECL_ARGS)
 {  {
         struct tm       *tm;          char             buf[DATESIZ];
         char            *buf, *os;          char            *os;
   
         /*          /*
          * Output the footer in new-groff style, that is, three columns           * Output the footer in new-groff style, that is, three columns
Line 357  print_foot(DECL_ARGS)
Line 359  print_foot(DECL_ARGS)
          * SYSTEM                  DATE                    SYSTEM           * SYSTEM                  DATE                    SYSTEM
          */           */
   
         if (NULL == (buf = malloc(p->rmargin)))  
                 err(EXIT_FAILURE, "malloc");  
         if (NULL == (os = malloc(p->rmargin)))          if (NULL == (os = malloc(p->rmargin)))
                 err(EXIT_FAILURE, "malloc");                  err(EXIT_FAILURE, "malloc");
   
         tm = localtime(&m->date);          time2a(m->date, buf, DATESIZ);
   
         if (0 == strftime(buf, p->rmargin, "%B %e, %Y", tm))  
                 err(EXIT_FAILURE, "strftime");  
   
         (void)strlcpy(os, m->os, p->rmargin);          (void)strlcpy(os, m->os, p->rmargin);
   
         term_vspace(p);          term_vspace(p);
Line 397  print_foot(DECL_ARGS)
Line 394  print_foot(DECL_ARGS)
         p->rmargin = p->maxrmargin;          p->rmargin = p->maxrmargin;
         p->flags = 0;          p->flags = 0;
   
         free(buf);  
         free(os);          free(os);
 }  }
   
Line 473  print_head(DECL_ARGS)
Line 469  print_head(DECL_ARGS)
   
   
 static size_t  static size_t
 arg2height(const struct mdoc_node *n)  a2height(const struct mdoc_node *n)
 {  {
         int              r;          struct roffsu    su;
   
         assert(MDOC_TEXT == n->type);          assert(MDOC_TEXT == n->type);
         assert(n->string);          assert(n->string);
           if ( ! a2roffsu(n->string, &su, SCALE_VS))
                   SCALE_VS_INIT(&su, strlen(n->string));
   
         if ((r = a2height(n->string)) < 0)          return(term_vspan(&su));
                 return(1);  
   
         return((size_t)r);  
 }  }
   
   
 static size_t  static size_t
 arg2width(const struct mdoc_argv *arg, int pos)  a2width(const struct mdoc_argv *arg, int pos)
 {  {
         int              r;          struct roffsu    su;
   
         assert(arg->value[pos]);          assert(arg->value[pos]);
         if ('\0' == arg->value[pos][0])          if ( ! a2roffsu(arg->value[pos], &su, SCALE_MAX))
                 return(2);                  SCALE_HS_INIT(&su, strlen(arg->value[pos]));
   
         if ((r = a2width(arg->value[pos])) >= 0)          /* XXX: pachemu? */
                 return((size_t)r);          return(term_hspan(&su) + 2);
   
         return(strlen(arg->value[pos]) + 2);  
 }  }
   
   
 /* FIXME: put in utility file for front-ends. */  
 static int  static int
 arg_listtype(const struct mdoc_node *n)  arg_listtype(const struct mdoc_node *n)
 {  {
Line 546  arg_listtype(const struct mdoc_node *n)
Line 538  arg_listtype(const struct mdoc_node *n)
   
   
 static size_t  static size_t
 arg2offs(const struct mdoc_argv *arg)  a2offs(const struct mdoc_argv *arg)
 {  {
         int              r;          struct roffsu    su;
   
         if ('\0' == arg->value[0][0])          if ('\0' == arg->value[0][0])
                 return(0);                  return(0);
Line 558  arg2offs(const struct mdoc_argv *arg)
Line 550  arg2offs(const struct mdoc_argv *arg)
                 return(INDENT + 1);                  return(INDENT + 1);
         else if (0 == strcmp(arg->value[0], "indent-two"))          else if (0 == strcmp(arg->value[0], "indent-two"))
                 return((INDENT + 1) * 2);                  return((INDENT + 1) * 2);
         else if ((r = a2width(arg->value[0])) >= 0)          else if ( ! a2roffsu(arg->value[0], &su, SCALE_MAX))
                 return((size_t)r);                  SCALE_HS_INIT(&su, strlen(arg->value[0]));
   
         return(strlen(arg->value[0]));          return(term_hspan(&su));
 }  }
   
   
Line 725  termp_it_pre(DECL_ARGS)
Line 717  termp_it_pre(DECL_ARGS)
                 for (i = 0, nn = n->prev; nn &&                  for (i = 0, nn = n->prev; nn &&
                                 i < (int)bl->args->argv[vals[2]].sz;                                  i < (int)bl->args->argv[vals[2]].sz;
                                 nn = nn->prev, i++)                                  nn = nn->prev, i++)
                         offset += arg2width                          offset += a2width
                                 (&bl->args->argv[vals[2]], i);                                  (&bl->args->argv[vals[2]], i);
   
                 /* Whether exceeds maximum column. */                  /* Whether exceeds maximum column. */
                 if (i < (int)bl->args->argv[vals[2]].sz)                  if (i < (int)bl->args->argv[vals[2]].sz)
                         width = arg2width(&bl->args->argv[vals[2]], i);                          width = a2width(&bl->args->argv[vals[2]], i);
                 else                  else
                         width = 0;                          width = 0;
   
                 if (vals[1] >= 0)                  if (vals[1] >= 0)
                         offset += arg2offs(&bl->args->argv[vals[1]]);                          offset += a2offs(&bl->args->argv[vals[1]]);
                 break;                  break;
         default:          default:
                 if (vals[0] >= 0)                  if (vals[0] >= 0)
                         width = arg2width(&bl->args->argv[vals[0]], 0);                          width = a2width(&bl->args->argv[vals[0]], 0);
                 if (vals[1] >= 0)                  if (vals[1] >= 0)
                         offset += arg2offs(&bl->args->argv[vals[1]]);                          offset += a2offs(&bl->args->argv[vals[1]]);
                 break;                  break;
         }          }
   
Line 1564  termp_bd_pre(DECL_ARGS)
Line 1556  termp_bd_pre(DECL_ARGS)
                         type = nn->args->argv[i].arg;                          type = nn->args->argv[i].arg;
                         break;                          break;
                 case (MDOC_Offset):                  case (MDOC_Offset):
                         p->offset += arg2offs(&nn->args->argv[i]);                          p->offset += a2offs(&nn->args->argv[i]);
                         break;                          break;
                 default:                  default:
                         break;                          break;
Line 1819  termp_sp_pre(DECL_ARGS)
Line 1811  termp_sp_pre(DECL_ARGS)
   
         switch (n->tok) {          switch (n->tok) {
         case (MDOC_sp):          case (MDOC_sp):
                 len = n->child ? arg2height(n->child) : 1;                  len = n->child ? a2height(n->child) : 1;
                 break;                  break;
         case (MDOC_br):          case (MDOC_br):
                 len = 0;                  len = 0;
Line 2015  static void
Line 2007  static void
 termp____post(DECL_ARGS)  termp____post(DECL_ARGS)
 {  {
   
           /* TODO: %U. */
   
         p->flags |= TERMP_NOSPACE;          p->flags |= TERMP_NOSPACE;
         switch (n->tok) {          switch (n->tok) {
         case (MDOC__T):          case (MDOC__T):
Line 2034  termp_lk_pre(DECL_ARGS)
Line 2028  termp_lk_pre(DECL_ARGS)
 {  {
         const struct mdoc_node *nn;          const struct mdoc_node *nn;
   
         if (NULL == (nn = n->child->next)) {          p->under++;
                 p->under++;          nn = n->child;
   
           if (NULL == nn->next)
                 return(1);                  return(1);
         }  
   
         p->under++;  
         term_word(p, nn->string);          term_word(p, nn->string);
           p->under--;
   
         p->flags |= TERMP_NOSPACE;          p->flags |= TERMP_NOSPACE;
         term_word(p, ":");          term_word(p, ":");
         p->under--;  
   
         p->bold++;          p->bold++;
         for (nn = nn->next; nn; nn = nn->next)          for (nn = nn->next; nn; nn = nn->next)

Legend:
Removed from v.1.91  
changed lines
  Added in v.1.97

CVSweb