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

Diff for /mandoc/tbl_term.c between version 1.11 and 1.17

version 1.11, 2011/01/05 15:37:23 version 1.17, 2011/01/10 14:56:06
Line 27 
Line 27 
 #include "out.h"  #include "out.h"
 #include "term.h"  #include "term.h"
   
 /* FIXME: `n' modifier doesn't always do the right thing. */  
 /* FIXME: `n' modifier doesn't use the cell-spacing buffer. */  
   
 static  size_t  term_tbl_len(size_t, void *);  static  size_t  term_tbl_len(size_t, void *);
 static  size_t  term_tbl_strlen(const char *, void *);  static  size_t  term_tbl_strlen(const char *, void *);
 static  void    tbl_char(struct termp *, char, int);  static  void    tbl_char(struct termp *, char, size_t);
 static  void    tbl_data(struct termp *, const struct tbl *,  static  void    tbl_data(struct termp *, const struct tbl *,
                         const struct tbl_dat *,                          const struct tbl_dat *,
                         const struct roffcol *);                          const struct roffcol *);
Line 67  term_tbl(struct termp *tp, const struct tbl_span *sp)
Line 64  term_tbl(struct termp *tp, const struct tbl_span *sp)
         const struct tbl_head   *hp;          const struct tbl_head   *hp;
         const struct tbl_dat    *dp;          const struct tbl_dat    *dp;
         struct roffcol          *col;          struct roffcol          *col;
         int                      rmargin, maxrmargin;          int                      spans;
           size_t                   rmargin, maxrmargin;
   
         rmargin = tp->rmargin;          rmargin = tp->rmargin;
         maxrmargin = tp->maxrmargin;          maxrmargin = tp->maxrmargin;
Line 118  term_tbl(struct termp *tp, const struct tbl_span *sp)
Line 116  term_tbl(struct termp *tp, const struct tbl_span *sp)
         case (TBL_SPAN_DATA):          case (TBL_SPAN_DATA):
                 /* Iterate over template headers. */                  /* Iterate over template headers. */
                 dp = sp->first;                  dp = sp->first;
                   spans = 0;
                 for (hp = sp->head; hp; hp = hp->next) {                  for (hp = sp->head; hp; hp = hp->next) {
                           /*
                            * If the current data header is invoked during
                            * a spanner ("spans" > 0), don't emit anything
                            * at all.
                            */
                         switch (hp->pos) {                          switch (hp->pos) {
                         case (TBL_HEAD_VERT):                          case (TBL_HEAD_VERT):
                                 /* FALLTHROUGH */                                  /* FALLTHROUGH */
                         case (TBL_HEAD_DVERT):                          case (TBL_HEAD_DVERT):
                                 tbl_vrule(tp, hp);                                  if (spans <= 0)
                                           tbl_vrule(tp, hp);
                                 continue;                                  continue;
                         case (TBL_HEAD_DATA):                          case (TBL_HEAD_DATA):
                                 break;                                  break;
                         }                          }
   
                           if (--spans >= 0)
                                   continue;
   
                         col = &tp->tbl.cols[hp->ident];                          col = &tp->tbl.cols[hp->ident];
                         tbl_data(tp, sp->tbl, dp, col);                          tbl_data(tp, sp->tbl, dp, col);
   
                         /* Go to the next data cell. */                          /*
                         if (dp)                           * Go to the next data cell and assign the
                            * number of subsequent spans, if applicable.
                            */
   
                           if (dp) {
                                   spans = dp->spans;
                                 dp = dp->next;                                  dp = dp->next;
                           }
                 }                  }
                 break;                  break;
         }          }
Line 165  tbl_hrule(struct termp *tp, const struct tbl_span *sp)
Line 179  tbl_hrule(struct termp *tp, const struct tbl_span *sp)
 {  {
         const struct tbl_head *hp;          const struct tbl_head *hp;
         char             c;          char             c;
         int              width;          size_t           width;
   
         /*          /*
          * An hrule extends across the entire table and is demarked by a           * An hrule extends across the entire table and is demarked by a
Line 202  static void
Line 216  static void
 tbl_hframe(struct termp *tp, const struct tbl_span *sp)  tbl_hframe(struct termp *tp, const struct tbl_span *sp)
 {  {
         const struct tbl_head *hp;          const struct tbl_head *hp;
         int              width;          size_t           width;
   
         if ( ! (TBL_OPT_BOX & sp->tbl->opts ||          if ( ! (TBL_OPT_BOX & sp->tbl->opts ||
                         TBL_OPT_DBOX & sp->tbl->opts))                          TBL_OPT_DBOX & sp->tbl->opts))
Line 247  tbl_data(struct termp *tp, const struct tbl *tbl,
Line 261  tbl_data(struct termp *tp, const struct tbl *tbl,
                 const struct tbl_dat *dp,                  const struct tbl_dat *dp,
                 const struct roffcol *col)                  const struct roffcol *col)
 {  {
         enum tbl_cellt   pos;  
   
         if (NULL == dp) {          if (NULL == dp) {
                 tbl_char(tp, ASCII_NBRSP, col->width);                  tbl_char(tp, ASCII_NBRSP, col->width);
                 return;                  return;
         }          }
           assert(dp->layout);
   
         switch (dp->pos) {          switch (dp->pos) {
         case (TBL_DATA_NONE):          case (TBL_DATA_NONE):
Line 272  tbl_data(struct termp *tp, const struct tbl *tbl,
Line 286  tbl_data(struct termp *tp, const struct tbl *tbl,
                 break;                  break;
         }          }
   
         pos = dp->layout ? dp->layout->pos : TBL_CELL_LEFT;          switch (dp->layout->pos) {
   
         switch (pos) {  
         case (TBL_CELL_HORIZ):          case (TBL_CELL_HORIZ):
                 tbl_char(tp, '-', col->width);                  tbl_char(tp, '-', col->width);
                 break;                  break;
Line 324  tbl_vframe(struct termp *tp, const struct tbl *tbl)
Line 336  tbl_vframe(struct termp *tp, const struct tbl *tbl)
 }  }
   
 static void  static void
 tbl_char(struct termp *tp, char c, int len)  tbl_char(struct termp *tp, char c, size_t len)
 {  {
         int             i, sz;          size_t          i, sz;
         const char      cp[2] = {c, '\0'};          char            cp[2];
   
           cp[0] = c;
           cp[1] = '\0';
   
         sz = term_strlen(tp, cp);          sz = term_strlen(tp, cp);
   
         for (i = 0; i < len; i += sz)          for (i = 0; i < len; i += sz)
Line 339  static void
Line 354  static void
 tbl_literal(struct termp *tp, const struct tbl_dat *dp,  tbl_literal(struct termp *tp, const struct tbl_dat *dp,
                 const struct roffcol *col)                  const struct roffcol *col)
 {  {
         int              padl, padr, ssz;          size_t           padl, padr, ssz;
         enum tbl_cellt   pos;  
   
         padl = padr = 0;          padl = padr = 0;
   
         pos = dp->layout ? dp->layout->pos : TBL_CELL_LEFT;          assert(dp->string);
   
         ssz = term_len(tp, 1);          ssz = term_len(tp, 1);
   
         switch (pos) {          switch (dp->layout->pos) {
         case (TBL_CELL_LONG):          case (TBL_CELL_LONG):
                 padl = ssz;                  padl = ssz;
                 padr = col->width - term_strlen(tp, dp->string) - ssz;                  padr = col->width - term_strlen(tp, dp->string) - ssz;
Line 379  tbl_number(struct termp *tp, const struct tbl *tbl,
Line 394  tbl_number(struct termp *tp, const struct tbl *tbl,
 {  {
         char            *cp;          char            *cp;
         char             buf[2];          char             buf[2];
         const char      *str;  
         size_t           sz, psz, ssz, d, padl;          size_t           sz, psz, ssz, d, padl;
         int              i;          int              i;
   
Line 388  tbl_number(struct termp *tp, const struct tbl *tbl,
Line 402  tbl_number(struct termp *tp, const struct tbl *tbl,
          * and the maximum decimal; right-pad by the remaining amount.           * and the maximum decimal; right-pad by the remaining amount.
          */           */
   
         str = "";          assert(dp->string);
         if (dp->string)  
                 str = dp->string;  
   
         sz = term_strlen(tp, str);          sz = term_strlen(tp, dp->string);
   
         buf[0] = tbl->decimal;          buf[0] = tbl->decimal;
         buf[1] = '\0';          buf[1] = '\0';
   
         psz = term_strlen(tp, buf);          psz = term_strlen(tp, buf);
   
         if (NULL != (cp = strchr(str, tbl->decimal))) {          if (NULL != (cp = strrchr(dp->string, tbl->decimal))) {
                 buf[1] = '\0';                  buf[1] = '\0';
                 for (ssz = 0, i = 0; cp != &str[i]; i++) {                  for (ssz = 0, i = 0; cp != &dp->string[i]; i++) {
                         buf[0] = str[i];                          buf[0] = dp->string[i];
                         ssz += term_strlen(tp, buf);                          ssz += term_strlen(tp, buf);
                 }                  }
                 d = ssz + psz;                  d = ssz + psz;

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.17

CVSweb