]> git.cameronkatri.com Git - mandoc.git/blobdiff - tbl_term.c
When finding a bogus database entry,
[mandoc.git] / tbl_term.c
index 40342d2f2327344df808e594ff8fe463bd671da1..c154a0e9b967cb5668b99753c439b67c405881cb 100644 (file)
@@ -1,4 +1,4 @@
-/*     $Id: tbl_term.c,v 1.54 2017/06/17 14:55:30 schwarze Exp $ */
+/*     $Id: tbl_term.c,v 1.57 2017/07/31 16:14:10 schwarze Exp $ */
 /*
  * Copyright (c) 2009, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2011,2012,2014,2015,2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -51,7 +51,10 @@ static       void    tbl_word(struct termp *, const struct tbl_dat *);
 static size_t
 term_tbl_sulen(const struct roffsu *su, void *arg)
 {
-       return term_hen((const struct termp *)arg, su);
+       int      i;
+
+       i = term_hen((const struct termp *)arg, su);
+       return i > 0 ? i : 0;
 }
 
 static size_t
@@ -101,7 +104,7 @@ term_tbl(struct termp *tp, const struct tbl_span *sp)
                for (ic = 0; ic < sp->opts->cols; ic++) {
                        coloff += tp->tbl.cols[ic].width;
                        term_tab_iset(coloff);
-                       coloff += 3;
+                       coloff += tp->tbl.cols[ic].spacing;
                }
 
                /* Center the table as a whole. */
@@ -110,9 +113,11 @@ term_tbl(struct termp *tp, const struct tbl_span *sp)
                if (sp->opts->opts & TBL_OPT_CENTRE) {
                        tsz = sp->opts->opts & (TBL_OPT_BOX | TBL_OPT_DBOX)
                            ? 2 : !!sp->opts->lvert + !!sp->opts->rvert;
-                       for (ic = 0; ic < sp->opts->cols; ic++)
-                               tsz += tp->tbl.cols[ic].width + 3;
-                       tsz -= 3;
+                       for (ic = 0; ic + 1 < sp->opts->cols; ic++)
+                               tsz += tp->tbl.cols[ic].width +
+                                   tp->tbl.cols[ic].spacing;
+                       if (sp->opts->cols)
+                               tsz += tp->tbl.cols[sp->opts->cols - 1].width;
                        if (offset + tsz > tp->tcol->rmargin)
                                tsz -= 1;
                        tp->tcol->offset = offset + tp->tcol->rmargin > tsz ?
@@ -159,9 +164,8 @@ term_tbl(struct termp *tp, const struct tbl_span *sp)
                        }
                        coloff += tp->tbl.cols[ic].width;
                        tp->tcol->rmargin = coloff;
-                       coloff++;
                        if (ic + 1 < sp->opts->cols)
-                               coloff += 2;
+                               coloff += tp->tbl.cols[ic].spacing;
                        if (spans) {
                                spans--;
                                continue;
@@ -169,13 +173,14 @@ term_tbl(struct termp *tp, const struct tbl_span *sp)
                        if (dp == NULL)
                                continue;
                        spans = dp->spans;
-                       dp = dp->next;
+                       if (ic || sp->layout->first->pos != TBL_CELL_SPAN)
+                               dp = dp->next;
                }
 
                /* Set up a column for a right vertical frame. */
 
                tp->tcol++;
-               tp->tcol->offset = coloff;
+               tp->tcol->offset = coloff + 1;
                tp->tcol->rmargin = tp->maxrmargin;
 
                /* Spans may have reduced the number of columns. */
@@ -203,7 +208,8 @@ term_tbl(struct termp *tp, const struct tbl_span *sp)
                        if (dp == NULL)
                                continue;
                        spans = dp->spans;
-                       dp = dp->next;
+                       if (cp->pos != TBL_CELL_SPAN)
+                               dp = dp->next;
                }
                break;
        }
@@ -303,7 +309,9 @@ term_tbl(struct termp *tp, const struct tbl_span *sp)
                                }
                                if (dp != NULL) {
                                        spans = dp->spans;
-                                       dp = dp->next;
+                                       if (ic || sp->layout->first->pos
+                                           != TBL_CELL_SPAN)
+                                               dp = dp->next;
                                }
 
                                /*
@@ -327,13 +335,13 @@ term_tbl(struct termp *tp, const struct tbl_span *sp)
                                    tp->tcol + 1 == tp->tcols + tp->lasttcol))
                                        continue;
 
-                               if (tp->tcol->rmargin > tp->viscol) {
+                               if (tp->viscol < tp->tcol->rmargin) {
                                        (*tp->advance)(tp, tp->tcol->rmargin
                                           - tp->viscol);
                                        tp->viscol = tp->tcol->rmargin;
                                }
-
-                               if (tp->tcol->rmargin + 1 > tp->viscol) {
+                               while (tp->viscol < tp->tcol->rmargin +
+                                   tp->tbl.cols[ic].spacing / 2) {
                                        (*tp->letter)(tp, fc);
                                        tp->viscol++;
                                }
@@ -353,10 +361,11 @@ term_tbl(struct termp *tp, const struct tbl_span *sp)
                                                break;
                                        }
                                }
-
-                               (*tp->letter)(tp,
-                                   fc == ' ' ? '|' : vert ? '+' : fc);
-                               tp->viscol++;
+                               if (tp->tbl.cols[ic].spacing) {
+                                       (*tp->letter)(tp, fc == ' ' ? '|' :
+                                           vert ? '+' : fc);
+                                       tp->viscol++;
+                               }
 
                                if (fc != ' ') {
                                        if (cp != NULL &&
@@ -368,7 +377,8 @@ term_tbl(struct termp *tp, const struct tbl_span *sp)
                                        else
                                                fc = ' ';
                                }
-                               if (vert > 1 || fc != ' ') {
+                               if (tp->tbl.cols[ic].spacing > 2 &&
+                                   (vert > 1 || fc != ' ')) {
                                        (*tp->letter)(tp, fc == ' ' ? '|' :
                                            vert > 1 ? '+' : fc);
                                        tp->viscol++;
@@ -448,6 +458,7 @@ static void
 tbl_hrule(struct termp *tp, const struct tbl_span *sp, int kind)
 {
        const struct tbl_cell *cp, *cpn, *cpp;
+       const struct roffcol *col;
        int      vert;
        char     line, cross;
 
@@ -464,7 +475,8 @@ tbl_hrule(struct termp *tp, const struct tbl_span *sp, int kind)
        if (cpn == cp)
                cpn = NULL;
        for (;;) {
-               tbl_char(tp, line, tp->tbl.cols[cp->col].width + 1);
+               col = tp->tbl.cols + cp->col;
+               tbl_char(tp, line, col->width + col->spacing / 2);
                vert = cp->vert;
                if ((cp = cp->next) == NULL)
                         break;
@@ -480,10 +492,12 @@ tbl_hrule(struct termp *tp, const struct tbl_span *sp, int kind)
                }
                if (sp->opts->opts & TBL_OPT_ALLBOX && !vert)
                        vert = 1;
-               if (vert)
-                       tbl_char(tp, cross, vert);
-               if (vert < 2)
-                       tbl_char(tp, line, 2 - vert);
+               if (col->spacing)
+                       tbl_char(tp, vert ? cross : line, 1);
+               if (col->spacing > 2)
+                       tbl_char(tp, vert > 1 ? cross : line, 1);
+               if (col->spacing > 4)
+                       tbl_char(tp, line, (col->spacing - 3) / 2);
        }
        if (kind) {
                term_word(tp, "+");
@@ -507,14 +521,11 @@ tbl_data(struct termp *tp, const struct tbl_opts *opts,
                break;
        }
 
-       if (dp == NULL) {
-               tbl_char(tp, ASCII_NBRSP, col->width);
+       if (dp == NULL)
                return;
-       }
 
        switch (dp->pos) {
        case TBL_DATA_NONE:
-               tbl_char(tp, ASCII_NBRSP, col->width);
                return;
        case TBL_DATA_HORIZ:
        case TBL_DATA_NHORIZ:
@@ -539,7 +550,7 @@ tbl_data(struct termp *tp, const struct tbl_opts *opts,
                tbl_number(tp, opts, dp, col);
                break;
        case TBL_CELL_DOWN:
-               tbl_char(tp, ASCII_NBRSP, col->width);
+       case TBL_CELL_SPAN:
                break;
        default:
                abort();