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

Diff for /mandoc/out.c between version 1.82 and 1.84

version 1.82, 2021/09/07 17:07:58 version 1.84, 2021/10/17 20:48:28
Line 123  tblcalc(struct rofftbl *tbl, const struct tbl_span *sp
Line 123  tblcalc(struct rofftbl *tbl, const struct tbl_span *sp
         const struct tbl_dat    *dp;          const struct tbl_dat    *dp;
         struct roffcol          *col;          struct roffcol          *col;
         struct tbl_colgroup     *first_group, **gp, *g;          struct tbl_colgroup     *first_group, **gp, *g;
           size_t                  *colwidth;
         size_t                   ewidth, min1, min2, wanted, width, xwidth;          size_t                   ewidth, min1, min2, wanted, width, xwidth;
         int                      done, icol, maxcol, necol, nxcol, quirkcol;          int                      done, icol, maxcol, necol, nxcol, quirkcol;
   
Line 148  tblcalc(struct rofftbl *tbl, const struct tbl_span *sp
Line 149  tblcalc(struct rofftbl *tbl, const struct tbl_span *sp
                  * to data cells in the data section.                   * to data cells in the data section.
                  */                   */
   
                 gp = &first_group;  
                 for (dp = sp->first; dp != NULL; dp = dp->next) {                  for (dp = sp->first; dp != NULL; dp = dp->next) {
                         icol = dp->layout->col;                          icol = dp->layout->col;
                         while (maxcol < icol + dp->hspans)                          while (maxcol < icol + dp->hspans)
Line 189  tblcalc(struct rofftbl *tbl, const struct tbl_span *sp
Line 189  tblcalc(struct rofftbl *tbl, const struct tbl_span *sp
                                 continue;                                  continue;
   
                         /*                          /*
                          * Build an ordered, singly linked list                           * Build a singly linked list
                          * of all groups of columns joined by spans,                           * of all groups of columns joined by spans,
                          * recording the minimum width for each group.                           * recording the minimum width for each group.
                          */                           */
   
                         while (*gp != NULL && ((*gp)->startcol < icol ||                          gp = &first_group;
                             (*gp)->endcol < icol + dp->hspans))                          while (*gp != NULL && ((*gp)->startcol != icol ||
                               (*gp)->endcol != icol + dp->hspans))
                                 gp = &(*gp)->next;                                  gp = &(*gp)->next;
                         if (*gp == NULL || (*gp)->startcol > icol ||                          if (*gp == NULL) {
                             (*gp)->endcol > icol + dp->hspans) {  
                                 g = mandoc_malloc(sizeof(*g));                                  g = mandoc_malloc(sizeof(*g));
                                 g->next = *gp;                                  g->next = *gp;
                                 g->wanted = width;                                  g->wanted = width;
Line 256  tblcalc(struct rofftbl *tbl, const struct tbl_span *sp
Line 256  tblcalc(struct rofftbl *tbl, const struct tbl_span *sp
                         gp = &(*gp)->next;                          gp = &(*gp)->next;
         }          }
   
           colwidth = mandoc_reallocarray(NULL, maxcol + 1, sizeof(*colwidth));
         while (first_group != NULL) {          while (first_group != NULL) {
   
                 /*                  /*
                    * Rebuild the array of the widths of all columns
                    * participating in spans that require expansion.
                    */
   
                   for (icol = 0; icol <= maxcol; icol++)
                           colwidth[icol] = SIZE_MAX;
                   for (g = first_group; g != NULL; g = g->next)
                           for (icol = g->startcol; icol <= g->endcol; icol++)
                                   colwidth[icol] = tbl->cols[icol].width;
   
                   /*
                  * Find the smallest and second smallest column width                   * Find the smallest and second smallest column width
                  * among the columns which may need expamsion.                   * among the columns which may need expamsion.
                  */                   */
   
                 min1 = min2 = SIZE_MAX;                  min1 = min2 = SIZE_MAX;
                 for (icol = 0; icol <= maxcol; icol++) {                  for (icol = 0; icol <= maxcol; icol++) {
                         width = tbl->cols[icol].width;                          width = colwidth[icol];
                         if (min1 > width) {                          if (min1 > width) {
                                 min2 = min1;                                  min2 = min1;
                                 min1 = width;                                  min1 = width;
Line 283  tblcalc(struct rofftbl *tbl, const struct tbl_span *sp
Line 295  tblcalc(struct rofftbl *tbl, const struct tbl_span *sp
                 for (g = first_group; g != NULL; g = g->next) {                  for (g = first_group; g != NULL; g = g->next) {
                         necol = 0;                          necol = 0;
                         for (icol = g->startcol; icol <= g->endcol; icol++)                          for (icol = g->startcol; icol <= g->endcol; icol++)
                                 if (tbl->cols[icol].width == min1)                                  if (colwidth[icol] == min1)
                                         necol++;                                          necol++;
                         if (necol == 0)                          if (necol == 0)
                                 continue;                                  continue;
Line 300  tblcalc(struct rofftbl *tbl, const struct tbl_span *sp
Line 312  tblcalc(struct rofftbl *tbl, const struct tbl_span *sp
                 while ((g = *gp) != NULL) {                  while ((g = *gp) != NULL) {
                         done = 0;                          done = 0;
                         for (icol = g->startcol; icol <= g->endcol; icol++) {                          for (icol = g->startcol; icol <= g->endcol; icol++) {
                                 if (tbl->cols[icol].width != min1)                                  if (colwidth[icol] != min1)
                                         continue;                                          continue;
                                 if (g->wanted <= wanted - min1) {                                  if (g->wanted <= wanted - min1) {
                                         tbl->cols[icol].width += g->wanted;                                          tbl->cols[icol].width += g->wanted;
Line 317  tblcalc(struct rofftbl *tbl, const struct tbl_span *sp
Line 329  tblcalc(struct rofftbl *tbl, const struct tbl_span *sp
                                 gp = &(*gp)->next;                                  gp = &(*gp)->next;
                 }                  }
         }          }
           free(colwidth);
   
         /*          /*
          * Align numbers with text.           * Align numbers with text.
Line 540  tblcalc_number(struct rofftbl *tbl, struct roffcol *co
Line 553  tblcalc_number(struct rofftbl *tbl, struct roffcol *co
                 col->nwidth = totsz;                  col->nwidth = totsz;
         if (col->nwidth > col->width)          if (col->nwidth > col->width)
                 col->width = col->nwidth;                  col->width = col->nwidth;
           fprintf(stderr, "N=%zu D=%zu I=%zu T=%zu %s\n",
               col->nwidth, col->decimal, intsz, totsz, dp->string);
         return totsz;          return totsz;
 }  }

Legend:
Removed from v.1.82  
changed lines
  Added in v.1.84

CVSweb