[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.3 and 1.7

version 1.3, 2011/01/03 14:45:59 version 1.7, 2011/01/04 12:06:21
Line 40  static void   tbl_data_number(struct termp *, 
Line 40  static void   tbl_data_number(struct termp *, 
 static  void             tbl_data_literal(struct termp *,  static  void             tbl_data_literal(struct termp *,
                                 const struct tbl_dat *,                                  const struct tbl_dat *,
                                 const struct termp_tbl *);                                  const struct termp_tbl *);
 static  void             tbl_data_spanner(struct termp *,  
                                 const struct tbl_dat *,  
                                 const struct termp_tbl *);  
 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 termp_tbl *);                                  const struct termp_tbl *);
Line 72  term_tbl(struct termp *tp, const struct tbl_span *sp)
Line 69  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;
   
           /* Inhibit printing of spaces: we do padding ourselves. */
   
           tp->flags |= TERMP_NONOSPACE;
           tp->flags |= TERMP_NOSPACE;
   
           /*
            * The first time we're invoked for a given table block, create
            * the termp_tbl structure.  This contains the column
            * configuration for the entire table, e.g., table-wide column
            * width, decimal point, etc.
            */
   
         if (TBL_SPAN_FIRST & sp->flags) {          if (TBL_SPAN_FIRST & sp->flags) {
                 assert(NULL == tp->tbl);                  assert(NULL == tp->tbl);
                 tp->tbl = calloc                  tp->tbl = calloc
Line 81  term_tbl(struct termp *tp, const struct tbl_span *sp)
Line 90  term_tbl(struct termp *tp, const struct tbl_span *sp)
                         exit(EXIT_FAILURE);                          exit(EXIT_FAILURE);
                 }                  }
                 tbl_calc(tp, sp);                  tbl_calc(tp, sp);
   
                   /* Flush out any preceding data. */
                 term_flushln(tp);                  term_flushln(tp);
         }          }
   
           /* Horizontal frame at the start of boxed tables. */
   
         if (TBL_SPAN_FIRST & sp->flags)          if (TBL_SPAN_FIRST & sp->flags)
                 tbl_hframe(tp, sp);                  tbl_hframe(tp, sp);
   
         tp->flags |= TERMP_NONOSPACE;          /* Vertical frame at the start of each row. */
         tp->flags |= TERMP_NOSPACE;  
   
         tbl_vframe(tp, sp->tbl);          tbl_vframe(tp, sp->tbl);
   
           /*
            * Now print the actual data itself depending on the span type.
            * Spanner spans get a horizontal rule; data spanners have their
            * data printed by matching data to header.
            */
   
         switch (sp->pos) {          switch (sp->pos) {
         case (TBL_SPAN_HORIZ):          case (TBL_SPAN_HORIZ):
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case (TBL_SPAN_DHORIZ):          case (TBL_SPAN_DHORIZ):
                 tbl_hrule(tp, sp);                  tbl_hrule(tp, sp);
                 tbl_vframe(tp, sp->tbl);  
                 term_newln(tp);  
                 goto end;  
         default:  
                 break;                  break;
         }          case (TBL_SPAN_DATA):
                   /* Iterate over template headers. */
                   dp = sp->first;
                   for (hp = sp->head; hp; hp = hp->next) {
                           switch (hp->pos) {
                           case (TBL_HEAD_VERT):
                                   /* FALLTHROUGH */
                           case (TBL_HEAD_DVERT):
                                   tbl_spanner(tp, hp);
                                   continue;
                           case (TBL_HEAD_DATA):
                                   break;
                           }
                           tbl_data(tp, sp->tbl, dp,
                                   &tp->tbl[hp->ident]);
   
         dp = sp->first;                          /* Go to the next data cell. */
         for (hp = sp->head; hp; hp = hp->next) {  
                 switch (hp->pos) {  
                 case (TBL_HEAD_VERT):  
                         /* FALLTHROUGH */  
                 case (TBL_HEAD_DVERT):  
                         tbl_spanner(tp, hp);  
                         break;  
                 case (TBL_HEAD_DATA):  
                         tbl_data(tp, sp->tbl, dp, &tp->tbl[hp->ident]);  
                         if (dp)                          if (dp)
                                 dp = dp->next;                                  dp = dp->next;
                         break;  
                 default:  
                         abort();  
                         /* NOTREACHED */  
                 }                  }
                   break;
         }          }
   
         tbl_vframe(tp, sp->tbl);          tbl_vframe(tp, sp->tbl);
         term_flushln(tp);          term_flushln(tp);
   
 end:          /*
            * If we're the last row, clean up after ourselves: clear the
            * existing table configuration and set it to NULL.
            */
   
         if (TBL_SPAN_LAST & sp->flags) {          if (TBL_SPAN_LAST & sp->flags) {
                 tbl_hframe(tp, sp);                  tbl_hframe(tp, sp);
                 assert(tp->tbl);                  assert(tp->tbl);
Line 238  tbl_data(struct termp *tp, const struct tbl *tbl,
Line 258  tbl_data(struct termp *tp, const struct tbl *tbl,
         switch (dp->pos) {          switch (dp->pos) {
         case (TBL_DATA_HORIZ):          case (TBL_DATA_HORIZ):
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
           case (TBL_DATA_NHORIZ):
                   tbl_char(tp, '-', tbp->width);
                   return;
           case (TBL_DATA_NDHORIZ):
                   /* FALLTHROUGH */
         case (TBL_DATA_DHORIZ):          case (TBL_DATA_DHORIZ):
                 tbl_data_spanner(tp, dp, tbp);                  tbl_char(tp, '=', tbp->width);
                 return;                  return;
         default:          default:
                 break;                  break;
Line 249  tbl_data(struct termp *tp, const struct tbl *tbl,
Line 274  tbl_data(struct termp *tp, const struct tbl *tbl,
   
         switch (pos) {          switch (pos) {
         case (TBL_CELL_HORIZ):          case (TBL_CELL_HORIZ):
                 /* FALLTHROUGH */                  tbl_char(tp, '-', tbp->width);
                   break;
         case (TBL_CELL_DHORIZ):          case (TBL_CELL_DHORIZ):
                 tbl_data_spanner(tp, dp, tbp);                  tbl_char(tp, '=', tbp->width);
                 break;                  break;
         case (TBL_CELL_LONG):          case (TBL_CELL_LONG):
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
Line 295  tbl_vframe(struct termp *tp, const struct tbl *tbl)
Line 321  tbl_vframe(struct termp *tp, const struct tbl *tbl)
                 term_word(tp, "|");                  term_word(tp, "|");
 }  }
   
   
 static inline void  static inline void
 tbl_char(struct termp *tp, char c, int len)  tbl_char(struct termp *tp, char c, int len)
 {  {
Line 312  tbl_char(struct termp *tp, char c, int len)
Line 337  tbl_char(struct termp *tp, char c, int len)
 }  }
   
 static void  static void
 tbl_data_spanner(struct termp *tp,  
                 const struct tbl_dat *dp,  
                 const struct termp_tbl *tblp)  
 {  
   
         switch (dp->pos) {  
         case (TBL_DATA_HORIZ):  
         case (TBL_DATA_NHORIZ):  
                 tbl_char(tp, '-', tblp->width);  
                 break;  
         case (TBL_DATA_DHORIZ):  
         case (TBL_DATA_NDHORIZ):  
                 tbl_char(tp, '=', tblp->width);  
                 break;  
         default:  
                 break;  
         }  
 }  
   
 static void  
 tbl_data_literal(struct termp *tp,  tbl_data_literal(struct termp *tp,
                 const struct tbl_dat *dp,                  const struct tbl_dat *dp,
                 const struct termp_tbl *tblp)                  const struct termp_tbl *tblp)
Line 374  tbl_data_number(struct termp *tp, const struct tbl *tb
Line 379  tbl_data_number(struct termp *tp, const struct tbl *tb
                 const struct tbl_dat *dp,                  const struct tbl_dat *dp,
                 const struct termp_tbl *tblp)                  const struct termp_tbl *tblp)
 {  {
         char            *decp;          char            *decp, buf[2];
         int              d, padl, sz;          int              d, padl, sz, psz, ssz, i;
   
         /*          /*
          * See calc_data_number().  Left-pad by taking the offset of our           * See calc_data_number().  Left-pad by taking the offset of our
          * and the maximum decimal; right-pad by the remaining amount.           * and the maximum decimal; right-pad by the remaining amount.
          */           */
   
         sz = (int)strlen(dp->string);          sz = term_strlen(tp, dp->string);
           psz = term_strlen(tp, ".");
   
         if (NULL == (decp = strchr(dp->string, tbl->decimal))) {          if (NULL != (decp = strchr(dp->string, tbl->decimal))) {
                 d = sz + 1;                  buf[1] = '\0';
         } else {                  for (ssz = i = 0; decp != &dp->string[i]; i++) {
                 d = (int)(decp - dp->string) + 1;                          buf[0] = dp->string[i];
         }                          ssz += term_strlen(tp, buf);
                   }
                   d = ssz + psz;
           } else
                   d = sz + psz;
   
         assert(d <= tblp->decimal);          assert(d <= tblp->decimal);
         assert(sz - d <= tblp->width - tblp->decimal);          assert(sz - d <= tblp->width - tblp->decimal);
   
         padl = tblp->decimal - d + 1;          padl = tblp->decimal - d + term_len(tp, 1);
         assert(tblp->width - sz - padl);          assert(tblp->width - sz - padl);
   
         tbl_char(tp, ASCII_NBRSP, padl);          tbl_char(tp, ASCII_NBRSP, padl);
Line 479  static void
Line 489  static void
 tbl_calc_data_number(struct termp *tp, const struct tbl *tbl,  tbl_calc_data_number(struct termp *tp, const struct tbl *tbl,
                 const struct tbl_dat *dp, struct termp_tbl *tblp)                  const struct tbl_dat *dp, struct termp_tbl *tblp)
 {  {
         int              sz, d;          int              sz, d, psz, i, ssz;
         char            *cp;          char            *cp, buf[2];
   
         /*          /*
          * First calculate number width and decimal place (last + 1 for           * First calculate number width and decimal place (last + 1 for
Line 494  tbl_calc_data_number(struct termp *tp, const struct tb
Line 504  tbl_calc_data_number(struct termp *tp, const struct tb
         /* TODO: use spacing modifier. */          /* TODO: use spacing modifier. */
   
         assert(dp->string);          assert(dp->string);
         sz = (int)strlen(dp->string);          sz = term_strlen(tp, dp->string);
           psz = term_strlen(tp, ".");
   
         if (NULL == (cp = strchr(dp->string, tbl->decimal)))          if (NULL != (cp = strchr(dp->string, tbl->decimal))) {
                 d = sz + 1;                  buf[1] = '\0';
         else                  for (ssz = i = 0; cp != &dp->string[i]; i++) {
                 d = (int)(cp - dp->string) + 1;                          buf[0] = dp->string[i];
                           ssz += term_strlen(tp, buf);
                   }
                   d = ssz + psz;
           } else
                   d = sz + psz;
   
         sz += 2;          sz += term_len(tp, 2);
   
         if (tblp->decimal > d) {          if (tblp->decimal > d) {
                 sz += tblp->decimal - d;                  sz += tblp->decimal - d;

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.7

CVSweb