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

Diff for /mandoc/out.c between version 1.71 and 1.73

version 1.71, 2018/08/18 16:44:55 version 1.73, 2018/08/19 23:10:28
Line 20 
Line 20 
 #include <sys/types.h>  #include <sys/types.h>
   
 #include <assert.h>  #include <assert.h>
   #include <ctype.h>
 #include <stdint.h>  #include <stdint.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
Line 168  tblcalc(struct rofftbl *tbl, const struct tbl_span *sp
Line 169  tblcalc(struct rofftbl *tbl, const struct tbl_span *sp
         }          }
   
         /*          /*
            * Align numbers with text.
          * Count columns to equalize and columns to maximize.           * Count columns to equalize and columns to maximize.
          * Find maximum width of the columns to equalize.           * Find maximum width of the columns to equalize.
          * Find total width of the columns *not* to maximize.           * Find total width of the columns *not* to maximize.
Line 177  tblcalc(struct rofftbl *tbl, const struct tbl_span *sp
Line 179  tblcalc(struct rofftbl *tbl, const struct tbl_span *sp
         ewidth = xwidth = 0;          ewidth = xwidth = 0;
         for (icol = 0; icol <= maxcol; icol++) {          for (icol = 0; icol <= maxcol; icol++) {
                 col = tbl->cols + icol;                  col = tbl->cols + icol;
                   if (col->width > col->nwidth)
                           col->decimal += (col->width - col->nwidth) / 2;
                   else
                           col->width = col->nwidth;
                 if (col->spacing == SIZE_MAX || icol == maxcol)                  if (col->spacing == SIZE_MAX || icol == maxcol)
                         col->spacing = 3;                          col->spacing = 3;
                 if (col->flags & TBL_CELL_EQUAL) {                  if (col->flags & TBL_CELL_EQUAL) {
Line 319  static void
Line 325  static void
 tblcalc_number(struct rofftbl *tbl, struct roffcol *col,  tblcalc_number(struct rofftbl *tbl, struct roffcol *col,
                 const struct tbl_opts *opts, const struct tbl_dat *dp)                  const struct tbl_opts *opts, const struct tbl_dat *dp)
 {  {
         int              i;          const char      *cp, *lastdigit, *lastpoint;
         size_t           sz, ssz, d;          size_t           intsz, totsz;
         const char      *str;  
         char            *cp;  
         char             buf[2];          char             buf[2];
   
           if (dp->string == NULL || *dp->string == '\0')
                   return;
   
         /*          /*
          * First calculate number width and decimal place (last + 1 for           * Find the last digit and
          * non-decimal numbers).  If the stored decimal is subsequent to           * the last decimal point that is adjacent to a digit.
          * ours, make our size longer by that difference           * The alignment indicator "\&" overrides everything.
          * (right-"shifting"); similarly, if ours is subsequent the  
          * stored, then extend the stored size by the difference.  
          * Finally, re-assign the stored values.  
          */           */
   
         str = dp->string ? dp->string : "";          lastdigit = lastpoint = NULL;
         sz = (*tbl->slen)(str, tbl->arg);          for (cp = dp->string; cp[0] != '\0'; cp++) {
                   if (cp[0] == '\\' && cp[1] == '&') {
                           lastdigit = lastpoint = cp;
                           break;
                   } else if (cp[0] == opts->decimal &&
                       (isdigit((unsigned char)cp[1]) ||
                        (cp > dp->string && isdigit((unsigned char)cp[-1]))))
                           lastpoint = cp;
                   else if (isdigit((unsigned char)cp[0]))
                           lastdigit = cp;
           }
   
         /* FIXME: TBL_DATA_HORIZ et al.? */          /* Not a number, treat as a literal string. */
   
         buf[0] = opts->decimal;          totsz = (*tbl->slen)(dp->string, tbl->arg);
         buf[1] = '\0';          if (lastdigit == NULL) {
                   if (col->width < totsz)
                           col->width = totsz;
                   return;
           }
   
         if (NULL != (cp = strrchr(str, opts->decimal))) {          /* Measure the width of the integer part. */
                 buf[1] = '\0';  
                 for (ssz = 0, i = 0; cp != &str[i]; i++) {  
                         buf[0] = str[i];  
                         ssz += (*tbl->slen)(buf, tbl->arg);  
                 }  
                 d = ssz;  
         } else  
                 d = sz;  
   
         /* Adjust the settings for this column. */          if (lastpoint == NULL)
                   lastpoint = lastdigit + 1;
           intsz = 0;
           buf[1] = '\0';
           for (cp = dp->string; cp < lastpoint; cp++) {
                   buf[0] = cp[0];
                   intsz += (*tbl->slen)(buf, tbl->arg);
           }
   
         if (col->decimal > d) {          /*
                 sz += col->decimal - d;           * If this number has more integer digits than all numbers
                 d = col->decimal;           * seen on earlier lines, shift them all to the right.
            * If it has fewer, shift this number to the right.
            */
   
           if (intsz > col->decimal) {
                   col->nwidth += intsz - col->decimal;
                   col->decimal = intsz;
         } else          } else
                 col->width += d - col->decimal;                  totsz += col->decimal - intsz;
   
         if (sz > col->width)          /* Update the maximum total width seen so far. */
                 col->width = sz;  
         if (d > col->decimal)          if (totsz > col->nwidth)
                 col->decimal = d;                  col->nwidth = totsz;
 }  }

Legend:
Removed from v.1.71  
changed lines
  Added in v.1.73

CVSweb