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

Diff for /mandoc/term.c between version 1.265 and 1.266

version 1.265, 2017/06/07 02:14:09 version 1.266, 2017/06/07 17:38:26
Line 32 
Line 32 
 #include "main.h"  #include "main.h"
   
 static  size_t           cond_width(const struct termp *, int, int *);  static  size_t           cond_width(const struct termp *, int, int *);
 static  void             adjbuf(struct termp *p, size_t);  static  void             adjbuf(struct termp_col *, size_t);
 static  void             bufferc(struct termp *, char);  static  void             bufferc(struct termp *, char);
 static  void             encode(struct termp *, const char *, size_t);  static  void             encode(struct termp *, const char *, size_t);
 static  void             encode1(struct termp *, int);  static  void             encode1(struct termp *, int);
Line 42  static void   endline(struct termp *);
Line 42  static void   endline(struct termp *);
 void  void
 term_free(struct termp *p)  term_free(struct termp *p)
 {  {
           for (p->tcol = p->tcols; p->tcol < p->tcols + p->maxtcol; p->tcol++)
         free(p->buf);                  free(p->tcol->buf);
           free(p->tcols);
         free(p->fontq);          free(p->fontq);
         free(p);          free(p);
 }  }
Line 94  term_end(struct termp *p)
Line 95  term_end(struct termp *p)
 void  void
 term_flushln(struct termp *p)  term_flushln(struct termp *p)
 {  {
         size_t           i;     /* current input position in p->buf */          size_t           i;     /* current input position in p->tcol->buf */
         int              ntab;  /* number of tabs to prepend */  
         size_t           vis;   /* current visual position on output */          size_t           vis;   /* current visual position on output */
         size_t           vbl;   /* number of blanks to prepend to output */          size_t           vbl;   /* number of blanks to prepend to output */
         size_t           vend;  /* end of word visual position on output */          size_t           vend;  /* end of word visual position on output */
         size_t           bp;    /* visual right border position */          size_t           bp;    /* visual right border position */
         size_t           dv;    /* temporary for visual pos calculations */          size_t           dv;    /* temporary for visual pos calculations */
         size_t           j;     /* temporary loop index for p->buf */          size_t           j;     /* temporary loop index for p->tcol->buf */
         size_t           jhy;   /* last hyph before overflow w/r/t j */          size_t           jhy;   /* last hyph before overflow w/r/t j */
         size_t           maxvis; /* output position of visible boundary */          size_t           maxvis; /* output position of visible boundary */
           int              ntab;  /* number of tabs to prepend */
   
         vbl = (p->flags & TERMP_NOPAD) || p->offset < p->viscol ? 0 :          vbl = (p->flags & TERMP_NOPAD) || p->tcol->offset < p->viscol ?
             p->offset - p->viscol;              0 : p->tcol->offset - p->viscol;
         if (p->minbl && vbl < p->minbl)          if (p->minbl && vbl < p->minbl)
                 vbl = p->minbl;                  vbl = p->minbl;
         maxvis = p->rmargin > p->viscol + vbl ?          maxvis = p->tcol->rmargin > p->viscol + vbl ?
             p->rmargin - p->viscol - vbl : 0;              p->tcol->rmargin - p->viscol - vbl : 0;
         bp = !(p->flags & TERMP_NOBREAK) ? maxvis :          bp = !(p->flags & TERMP_NOBREAK) ? maxvis :
             p->maxrmargin > p->viscol + vbl ?              p->maxrmargin > p->viscol + vbl ?
             p->maxrmargin - p->viscol - vbl : 0;              p->maxrmargin - p->viscol - vbl : 0;
Line 123  term_flushln(struct termp *p)
Line 124  term_flushln(struct termp *p)
                  * subsequent tabs into a single huge set of spaces.                   * subsequent tabs into a single huge set of spaces.
                  */                   */
                 ntab = 0;                  ntab = 0;
                 while (i < p->lastcol && p->buf[i] == '\t') {                  while (i < p->lastcol && p->tcol->buf[i] == '\t') {
                         vend = term_tab_next(vis);                          vend = term_tab_next(vis);
                         vbl += vend - vis;                          vbl += vend - vis;
                         vis = vend;                          vis = vend;
Line 139  term_flushln(struct termp *p)
Line 140  term_flushln(struct termp *p)
                  */                   */
   
                 for (j = i, jhy = 0; j < p->lastcol; j++) {                  for (j = i, jhy = 0; j < p->lastcol; j++) {
                         if (' ' == p->buf[j] || '\t' == p->buf[j])                          if (p->tcol->buf[j] == ' ' || p->tcol->buf[j] == '\t')
                                 break;                                  break;
   
                         /* Back over the last printed character. */                          /* Back over the last printed character. */
                         if (8 == p->buf[j]) {                          if (p->tcol->buf[j] == '\b') {
                                 assert(j);                                  assert(j);
                                 vend -= (*p->width)(p, p->buf[j - 1]);                                  vend -= (*p->width)(p, p->tcol->buf[j - 1]);
                                 continue;                                  continue;
                         }                          }
   
                         /* Regular word. */                          /* Regular word. */
                         /* Break at the hyphen point if we overrun. */                          /* Break at the hyphen point if we overrun. */
                         if (vend > vis && vend < bp &&                          if (vend > vis && vend < bp &&
                             (ASCII_HYPH == p->buf[j] ||                              (p->tcol->buf[j] == ASCII_HYPH||
                              ASCII_BREAK == p->buf[j]))                               p->tcol->buf[j] == ASCII_BREAK))
                                 jhy = j;                                  jhy = j;
   
                         /*                          /*
                          * Hyphenation now decided, put back a real                           * Hyphenation now decided, put back a real
                          * hyphen such that we get the correct width.                           * hyphen such that we get the correct width.
                          */                           */
                         if (ASCII_HYPH == p->buf[j])                          if (p->tcol->buf[j] == ASCII_HYPH)
                                 p->buf[j] = '-';                                  p->tcol->buf[j] = '-';
   
                         vend += (*p->width)(p, p->buf[j]);                          vend += (*p->width)(p, p->tcol->buf[j]);
                 }                  }
   
                 /*                  /*
Line 184  term_flushln(struct termp *p)
Line 185  term_flushln(struct termp *p)
                         /* Re-establish indentation. */                          /* Re-establish indentation. */
   
                         if (p->flags & TERMP_BRIND)                          if (p->flags & TERMP_BRIND)
                                 vbl += p->rmargin;                                  vbl += p->tcol->rmargin;
                         else                          else
                                 vbl += p->offset;                                  vbl += p->tcol->offset;
                         maxvis = p->rmargin > vbl ? p->rmargin - vbl : 0;                          maxvis = p->tcol->rmargin > vbl ?
                               p->tcol->rmargin - vbl : 0;
                         bp = !(p->flags & TERMP_NOBREAK) ? maxvis :                          bp = !(p->flags & TERMP_NOBREAK) ? maxvis :
                             p->maxrmargin > vbl ?  p->maxrmargin - vbl : 0;                              p->maxrmargin > vbl ?  p->maxrmargin - vbl : 0;
                 }                  }
Line 196  term_flushln(struct termp *p)
Line 198  term_flushln(struct termp *p)
                 for ( ; i < p->lastcol; i++) {                  for ( ; i < p->lastcol; i++) {
                         if (vend > bp && jhy > 0 && i > jhy)                          if (vend > bp && jhy > 0 && i > jhy)
                                 break;                                  break;
                         if ('\t' == p->buf[i])                          if (p->tcol->buf[i] == '\t')
                                 break;                                  break;
                         if (' ' == p->buf[i]) {                          if (p->tcol->buf[i] == ' ') {
                                 j = i;                                  j = i;
                                 while (i < p->lastcol && ' ' == p->buf[i])                                  while (i < p->lastcol &&
                                       p->tcol->buf[i] == ' ')
                                         i++;                                          i++;
                                 dv = (i - j) * (*p->width)(p, ' ');                                  dv = (i - j) * (*p->width)(p, ' ');
                                 vbl += dv;                                  vbl += dv;
                                 vend += dv;                                  vend += dv;
                                 break;                                  break;
                         }                          }
                         if (ASCII_NBRSP == p->buf[i]) {                          if (p->tcol->buf[i] == ASCII_NBRSP) {
                                 vbl += (*p->width)(p, ' ');                                  vbl += (*p->width)(p, ' ');
                                 continue;                                  continue;
                         }                          }
                         if (ASCII_BREAK == p->buf[i])                          if (p->tcol->buf[i] == ASCII_BREAK)
                                 continue;                                  continue;
   
                         /*                          /*
Line 225  term_flushln(struct termp *p)
Line 228  term_flushln(struct termp *p)
                                 vbl = 0;                                  vbl = 0;
                         }                          }
   
                         (*p->letter)(p, p->buf[i]);                          (*p->letter)(p, p->tcol->buf[i]);
                         if (8 == p->buf[i])                          if (p->tcol->buf[i] == '\b')
                                 p->viscol -= (*p->width)(p, p->buf[i-1]);                                  p->viscol -= (*p->width)(p, p->tcol->buf[i-1]);
                         else                          else
                                 p->viscol += (*p->width)(p, p->buf[i]);                                  p->viscol += (*p->width)(p, p->tcol->buf[i]);
                 }                  }
                 vis = vend;                  vis = vend;
         }          }
Line 472  term_word(struct termp *p, const char *word)
Line 475  term_word(struct termp *p, const char *word)
                         else {                          else {
                                 uc += p->col;                                  uc += p->col;
                                 p->col = 0;                                  p->col = 0;
                                 if (p->offset > (size_t)(-uc)) {                                  if (p->tcol->offset > (size_t)(-uc)) {
                                         p->ti += uc;                                          p->ti += uc;
                                         p->offset += uc;                                          p->tcol->offset += uc;
                                 } else {                                  } else {
                                         p->ti -= p->offset;                                          p->ti -= p->tcol->offset;
                                         p->offset = 0;                                          p->tcol->offset = 0;
                                 }                                  }
                         }                          }
                         continue;                          continue;
Line 486  term_word(struct termp *p, const char *word)
Line 489  term_word(struct termp *p, const char *word)
                                 continue;                                  continue;
                         uc = term_hspan(p, &su) / 24;                          uc = term_hspan(p, &su) / 24;
                         if (uc <= 0) {                          if (uc <= 0) {
                                 if (p->rmargin <= p->offset)                                  if (p->tcol->rmargin <= p->tcol->offset)
                                         continue;                                          continue;
                                 lsz = p->rmargin - p->offset;                                  lsz = p->tcol->rmargin - p->tcol->offset;
                         } else                          } else
                                 lsz = uc;                                  lsz = uc;
                         while (sz &&                          while (sz &&
Line 557  term_word(struct termp *p, const char *word)
Line 560  term_word(struct termp *p, const char *word)
                         }                          }
                         /* Trim trailing backspace/blank pair. */                          /* Trim trailing backspace/blank pair. */
                         if (p->lastcol > 2 &&                          if (p->lastcol > 2 &&
                             (p->buf[p->lastcol - 1] == ' ' ||                              (p->tcol->buf[p->lastcol - 1] == ' ' ||
                              p->buf[p->lastcol - 1] == '\t'))                               p->tcol->buf[p->lastcol - 1] == '\t'))
                                 p->lastcol -= 2;                                  p->lastcol -= 2;
                         if (p->col > p->lastcol)                          if (p->col > p->lastcol)
                                 p->col = p->lastcol;                                  p->col = p->lastcol;
Line 586  term_word(struct termp *p, const char *word)
Line 589  term_word(struct termp *p, const char *word)
 }  }
   
 static void  static void
 adjbuf(struct termp *p, size_t sz)  adjbuf(struct termp_col *c, size_t sz)
 {  {
           if (c->maxcols == 0)
         if (0 == p->maxcols)                  c->maxcols = 1024;
                 p->maxcols = 1024;          while (c->maxcols <= sz)
         while (sz >= p->maxcols)                  c->maxcols <<= 2;
                 p->maxcols <<= 2;          c->buf = mandoc_reallocarray(c->buf, c->maxcols, sizeof(*c->buf));
   
         p->buf = mandoc_reallocarray(p->buf, p->maxcols, sizeof(int));  
 }  }
   
 static void  static void
Line 604  bufferc(struct termp *p, char c)
Line 605  bufferc(struct termp *p, char c)
                 (*p->letter)(p, c);                  (*p->letter)(p, c);
                 return;                  return;
         }          }
         if (p->col + 1 >= p->maxcols)          if (p->col + 1 >= p->tcol->maxcols)
                 adjbuf(p, p->col + 1);                  adjbuf(p->tcol, p->col + 1);
         if (p->lastcol <= p->col || (c != ' ' && c != ASCII_NBRSP))          if (p->lastcol <= p->col || (c != ' ' && c != ASCII_NBRSP))
                 p->buf[p->col] = c;                  p->tcol->buf[p->col] = c;
         if (p->lastcol < ++p->col)          if (p->lastcol < ++p->col)
                 p->lastcol = p->col;                  p->lastcol = p->col;
 }  }
Line 627  encode1(struct termp *p, int c)
Line 628  encode1(struct termp *p, int c)
                 return;                  return;
         }          }
   
         if (p->col + 7 >= p->maxcols)          if (p->col + 7 >= p->tcol->maxcols)
                 adjbuf(p, p->col + 7);                  adjbuf(p->tcol, p->col + 7);
   
         f = (c == ASCII_HYPH || c > 127 || isgraph(c)) ?          f = (c == ASCII_HYPH || c > 127 || isgraph(c)) ?
             p->fontq[p->fonti] : TERMFONT_NONE;              p->fontq[p->fonti] : TERMFONT_NONE;
   
         if (p->flags & TERMP_BACKBEFORE) {          if (p->flags & TERMP_BACKBEFORE) {
                 if (p->buf[p->col - 1] == ' ' || p->buf[p->col - 1] == '\t')                  if (p->tcol->buf[p->col - 1] == ' ' ||
                       p->tcol->buf[p->col - 1] == '\t')
                         p->col--;                          p->col--;
                 else                  else
                         p->buf[p->col++] = 8;                          p->tcol->buf[p->col++] = '\b';
                 p->flags &= ~TERMP_BACKBEFORE;                  p->flags &= ~TERMP_BACKBEFORE;
         }          }
         if (TERMFONT_UNDER == f || TERMFONT_BI == f) {          if (f == TERMFONT_UNDER || f == TERMFONT_BI) {
                 p->buf[p->col++] = '_';                  p->tcol->buf[p->col++] = '_';
                 p->buf[p->col++] = 8;                  p->tcol->buf[p->col++] = '\b';
         }          }
         if (TERMFONT_BOLD == f || TERMFONT_BI == f) {          if (f == TERMFONT_BOLD || f == TERMFONT_BI) {
                 if (ASCII_HYPH == c)                  if (c == ASCII_HYPH)
                         p->buf[p->col++] = '-';                          p->tcol->buf[p->col++] = '-';
                 else                  else
                         p->buf[p->col++] = c;                          p->tcol->buf[p->col++] = c;
                 p->buf[p->col++] = 8;                  p->tcol->buf[p->col++] = '\b';
         }          }
         if (p->lastcol <= p->col || (c != ' ' && c != ASCII_NBRSP))          if (p->lastcol <= p->col || (c != ' ' && c != ASCII_NBRSP))
                 p->buf[p->col] = c;                  p->tcol->buf[p->col] = c;
         if (p->lastcol < ++p->col)          if (p->lastcol < ++p->col)
                 p->lastcol = p->col;                  p->lastcol = p->col;
         if (p->flags & TERMP_BACKAFTER) {          if (p->flags & TERMP_BACKAFTER) {
Line 672  encode(struct termp *p, const char *word, size_t sz)
Line 674  encode(struct termp *p, const char *word, size_t sz)
                 return;                  return;
         }          }
   
         if (p->col + 2 + (sz * 5) >= p->maxcols)          if (p->col + 2 + (sz * 5) >= p->tcol->maxcols)
                 adjbuf(p, p->col + 2 + (sz * 5));                  adjbuf(p->tcol, p->col + 2 + (sz * 5));
   
         for (i = 0; i < sz; i++) {          for (i = 0; i < sz; i++) {
                 if (ASCII_HYPH == word[i] ||                  if (ASCII_HYPH == word[i] ||
Line 682  encode(struct termp *p, const char *word, size_t sz)
Line 684  encode(struct termp *p, const char *word, size_t sz)
                 else {                  else {
                         if (p->lastcol <= p->col ||                          if (p->lastcol <= p->col ||
                             (word[i] != ' ' && word[i] != ASCII_NBRSP))                              (word[i] != ' ' && word[i] != ASCII_NBRSP))
                                 p->buf[p->col] = word[i];                                  p->tcol->buf[p->col] = word[i];
                         p->col++;                          p->col++;
   
                         /*                          /*

Legend:
Removed from v.1.265  
changed lines
  Added in v.1.266

CVSweb