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

Diff for /mandoc/term.c between version 1.202 and 1.203

version 1.202, 2012/05/27 18:02:49 version 1.203, 2012/05/31 22:29:13
Line 33 
Line 33 
 #include "term.h"  #include "term.h"
 #include "main.h"  #include "main.h"
   
   static  size_t           cond_width(const struct termp *, int, int *);
 static  void             adjbuf(struct termp *p, int);  static  void             adjbuf(struct termp *p, int);
 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);
Line 419  term_word(struct termp *p, const char *word)
Line 420  term_word(struct termp *p, const char *word)
         p->flags &= ~(TERMP_SENTENCE | TERMP_IGNDELIM);          p->flags &= ~(TERMP_SENTENCE | TERMP_IGNDELIM);
   
         while ('\0' != *word) {          while ('\0' != *word) {
                 if ((ssz = strcspn(word, "\\")) > 0)                  if ('\\' != *word) {
                           if (TERMP_SKIPCHAR & p->flags) {
                                   p->flags &= ~TERMP_SKIPCHAR;
                                   word++;
                                   continue;
                           }
                           ssz = strcspn(word, "\\");
                         encode(p, word, ssz);                          encode(p, word, ssz);
                           word += (int)ssz;
                 word += (int)ssz;  
                 if ('\\' != *word)  
                         continue;                          continue;
                   }
   
                 word++;                  word++;
                 esc = mandoc_escape(&word, &seq, &sz);                  esc = mandoc_escape(&word, &seq, &sz);
Line 480  term_word(struct termp *p, const char *word)
Line 486  term_word(struct termp *p, const char *word)
                         term_fontlast(p);                          term_fontlast(p);
                         break;                          break;
                 case (ESCAPE_NOSPACE):                  case (ESCAPE_NOSPACE):
                         if ('\0' == *word)                          if (TERMP_SKIPCHAR & p->flags)
                                   p->flags &= ~TERMP_SKIPCHAR;
                           else if ('\0' == *word)
                                 p->flags |= TERMP_NOSPACE;                                  p->flags |= TERMP_NOSPACE;
                         break;                          break;
                   case (ESCAPE_SKIPCHAR):
                           p->flags |= TERMP_SKIPCHAR;
                           break;
                 default:                  default:
                         break;                          break;
                 }                  }
Line 522  encode1(struct termp *p, int c)
Line 533  encode1(struct termp *p, int c)
 {  {
         enum termfont     f;          enum termfont     f;
   
           if (TERMP_SKIPCHAR & p->flags) {
                   p->flags &= ~TERMP_SKIPCHAR;
                   return;
           }
   
         if (p->col + 4 >= p->maxcols)          if (p->col + 4 >= p->maxcols)
                 adjbuf(p, p->col + 4);                  adjbuf(p, p->col + 4);
   
Line 545  encode(struct termp *p, const char *word, size_t sz)
Line 561  encode(struct termp *p, const char *word, size_t sz)
         enum termfont     f;          enum termfont     f;
         int               i, len;          int               i, len;
   
           if (TERMP_SKIPCHAR & p->flags) {
                   p->flags &= ~TERMP_SKIPCHAR;
                   return;
           }
   
         /* LINTED */          /* LINTED */
         len = sz;          len = sz;
   
Line 593  term_len(const struct termp *p, size_t sz)
Line 614  term_len(const struct termp *p, size_t sz)
         return((*p->width)(p, ' ') * sz);          return((*p->width)(p, ' ') * sz);
 }  }
   
   static size_t
   cond_width(const struct termp *p, int c, int *skip)
   {
   
           if (*skip) {
                   (*skip) = 0;
                   return(0);
           } else
                   return((*p->width)(p, c));
   }
   
 size_t  size_t
 term_strlen(const struct termp *p, const char *cp)  term_strlen(const struct termp *p, const char *cp)
 {  {
         size_t           sz, rsz, i;          size_t           sz, rsz, i;
         int              ssz, c;          int              ssz, skip, c;
         const char      *seq, *rhs;          const char      *seq, *rhs;
         enum mandoc_esc  esc;          enum mandoc_esc  esc;
         static const char rej[] = { '\\', ASCII_HYPH, ASCII_NBRSP, '\0' };          static const char rej[] = { '\\', ASCII_HYPH, ASCII_NBRSP, '\0' };
Line 610  term_strlen(const struct termp *p, const char *cp)
Line 641  term_strlen(const struct termp *p, const char *cp)
          */           */
   
         sz = 0;          sz = 0;
           skip = 0;
         while ('\0' != *cp) {          while ('\0' != *cp) {
                 rsz = strcspn(cp, rej);                  rsz = strcspn(cp, rej);
                 for (i = 0; i < rsz; i++)                  for (i = 0; i < rsz; i++)
                         sz += (*p->width)(p, *cp++);                          sz += cond_width(p, *cp++, &skip);
   
                 c = 0;                  c = 0;
                 switch (*cp) {                  switch (*cp) {
Line 630  term_strlen(const struct termp *p, const char *cp)
Line 662  term_strlen(const struct termp *p, const char *cp)
                                                 (seq + 1, ssz - 1);                                                  (seq + 1, ssz - 1);
                                         if ('\0' == c)                                          if ('\0' == c)
                                                 break;                                                  break;
                                         sz += (*p->width)(p, c);                                          sz += cond_width(p, c, &skip);
                                         continue;                                          continue;
                                 case (ESCAPE_SPECIAL):                                  case (ESCAPE_SPECIAL):
                                         c = mchars_spec2cp                                          c = mchars_spec2cp
                                                 (p->symtab, seq, ssz);                                                  (p->symtab, seq, ssz);
                                         if (c <= 0)                                          if (c <= 0)
                                                 break;                                                  break;
                                         sz += (*p->width)(p, c);                                          sz += cond_width(p, c, &skip);
                                         continue;                                          continue;
                                 default:                                  default:
                                         break;                                          break;
Line 647  term_strlen(const struct termp *p, const char *cp)
Line 679  term_strlen(const struct termp *p, const char *cp)
   
                         switch (esc) {                          switch (esc) {
                         case (ESCAPE_UNICODE):                          case (ESCAPE_UNICODE):
                                 sz += (*p->width)(p, '?');                                  sz += cond_width(p, '?', &skip);
                                 break;                                  break;
                         case (ESCAPE_NUMBERED):                          case (ESCAPE_NUMBERED):
                                 c = mchars_num2char(seq, ssz);                                  c = mchars_num2char(seq, ssz);
                                 if ('\0' != c)                                  if ('\0' != c)
                                         sz += (*p->width)(p, c);                                          sz += cond_width(p, c, &skip);
                                 break;                                  break;
                         case (ESCAPE_SPECIAL):                          case (ESCAPE_SPECIAL):
                                 rhs = mchars_spec2str                                  rhs = mchars_spec2str
Line 664  term_strlen(const struct termp *p, const char *cp)
Line 696  term_strlen(const struct termp *p, const char *cp)
                                 rhs = seq;                                  rhs = seq;
                                 rsz = ssz;                                  rsz = ssz;
                                 break;                                  break;
                           case (ESCAPE_SKIPCHAR):
                                   skip = 1;
                                   break;
                         default:                          default:
                                 break;                                  break;
                         }                          }
Line 671  term_strlen(const struct termp *p, const char *cp)
Line 706  term_strlen(const struct termp *p, const char *cp)
                         if (NULL == rhs)                          if (NULL == rhs)
                                 break;                                  break;
   
                           if (skip) {
                                   skip = 0;
                                   break;
                           }
   
                         for (i = 0; i < rsz; i++)                          for (i = 0; i < rsz; i++)
                                 sz += (*p->width)(p, *rhs++);                                  sz += (*p->width)(p, *rhs++);
                         break;                          break;
                 case (ASCII_NBRSP):                  case (ASCII_NBRSP):
                         sz += (*p->width)(p, ' ');                          sz += cond_width(p, ' ', &skip);
                         cp++;                          cp++;
                         break;                          break;
                 case (ASCII_HYPH):                  case (ASCII_HYPH):
                         sz += (*p->width)(p, '-');                          sz += cond_width(p, '-', &skip);
                         cp++;                          cp++;
                         break;                          break;
                 default:                  default:

Legend:
Removed from v.1.202  
changed lines
  Added in v.1.203

CVSweb