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

Diff for /mandoc/term.c between version 1.183 and 1.184

version 1.183, 2011/04/04 21:14:12 version 1.184, 2011/04/09 15:29:40
Line 33 
Line 33 
 #include "term.h"  #include "term.h"
 #include "main.h"  #include "main.h"
   
 static  void              spec(struct termp *, enum roffdeco,  static  void              spec(struct termp *, const char *, size_t);
                                 const char *, size_t);  
 static  void              res(struct termp *, const char *, size_t);  static  void              res(struct termp *, const char *, size_t);
 static  void              bufferc(struct termp *, char);  static  void              bufferc(struct termp *, char);
 static  void              adjbuf(struct termp *p, size_t);  static  void              adjbuf(struct termp *p, size_t);
Line 358  numbered(struct termp *p, const char *word, size_t len
Line 357  numbered(struct termp *p, const char *word, size_t len
   
   
 static void  static void
 spec(struct termp *p, enum roffdeco d, const char *word, size_t len)  spec(struct termp *p, const char *word, size_t len)
 {  {
         const char      *rhs;          const char      *rhs;
         size_t           sz;          size_t           sz;
Line 366  spec(struct termp *p, enum roffdeco d, const char *wor
Line 365  spec(struct termp *p, enum roffdeco d, const char *wor
         rhs = chars_spec2str(p->symtab, word, len, &sz);          rhs = chars_spec2str(p->symtab, word, len, &sz);
         if (rhs)          if (rhs)
                 encode(p, rhs, sz);                  encode(p, rhs, sz);
         else if (DECO_SSPECIAL == d)          else if (1 == len)
                 encode(p, word, len);                  encode(p, word, len);
 }  }
   
Line 457  void
Line 456  void
 term_word(struct termp *p, const char *word)  term_word(struct termp *p, const char *word)
 {  {
         const char      *seq;          const char      *seq;
           int              sz;
         size_t           ssz;          size_t           ssz;
         enum roffdeco    deco;          enum mandoc_esc  esc;
   
         if ( ! (TERMP_NOSPACE & p->flags)) {          if ( ! (TERMP_NOSPACE & p->flags)) {
                 if ( ! (TERMP_KEEP & p->flags)) {                  if ( ! (TERMP_KEEP & p->flags)) {
Line 478  term_word(struct termp *p, const char *word)
Line 478  term_word(struct termp *p, const char *word)
   
         p->flags &= ~(TERMP_SENTENCE | TERMP_IGNDELIM);          p->flags &= ~(TERMP_SENTENCE | TERMP_IGNDELIM);
   
         while (*word) {          while ('\0' != *word) {
                 if ((ssz = strcspn(word, "\\")) > 0)                  if ((ssz = strcspn(word, "\\")) > 0)
                         encode(p, word, ssz);                          encode(p, word, ssz);
   
Line 486  term_word(struct termp *p, const char *word)
Line 486  term_word(struct termp *p, const char *word)
                 if ('\\' != *word)                  if ('\\' != *word)
                         continue;                          continue;
   
                 seq = ++word;                  word++;
                 word += a2roffdeco(&deco, &seq, &ssz);                  esc = mandoc_escape(&word, &seq, &sz);
                   if (ESCAPE_ERROR == esc)
                           break;
   
                 switch (deco) {                  switch (esc) {
                 case (DECO_NUMBERED):                  case (ESCAPE_NUMBERED):
                         numbered(p, seq, ssz);                          numbered(p, seq, sz);
                         break;                          break;
                 case (DECO_RESERVED):                  case (ESCAPE_PREDEF):
                         res(p, seq, ssz);                          res(p, seq, sz);
                         break;                          break;
                 case (DECO_SPECIAL):                  case (ESCAPE_SPECIAL):
                         /* FALLTHROUGH */                          spec(p, seq, sz);
                 case (DECO_SSPECIAL):  
                         spec(p, deco, seq, ssz);  
                         break;                          break;
                 case (DECO_BOLD):                  case (ESCAPE_FONTBOLD):
                         term_fontrepl(p, TERMFONT_BOLD);                          term_fontrepl(p, TERMFONT_BOLD);
                         break;                          break;
                 case (DECO_ITALIC):                  case (ESCAPE_FONTITALIC):
                         term_fontrepl(p, TERMFONT_UNDER);                          term_fontrepl(p, TERMFONT_UNDER);
                         break;                          break;
                 case (DECO_ROMAN):                  case (ESCAPE_FONTROMAN):
                         term_fontrepl(p, TERMFONT_NONE);                          term_fontrepl(p, TERMFONT_NONE);
                         break;                          break;
                 case (DECO_PREVIOUS):                  case (ESCAPE_FONTPREV):
                         term_fontlast(p);                          term_fontlast(p);
                         break;                          break;
                   case (ESCAPE_NOSPACE):
                           if ('\0' == *word)
                                   p->flags |= TERMP_NOSPACE;
                           break;
                 default:                  default:
                         break;                          break;
                 }                  }
   
                 if (DECO_NOSPACE == deco && '\0' == *word)  
                         p->flags |= TERMP_NOSPACE;  
         }          }
 }  }
   
Line 600  term_len(const struct termp *p, size_t sz)
Line 601  term_len(const struct termp *p, size_t sz)
 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, ssz, rsz, i;          size_t           sz, rsz, i;
         enum roffdeco    d;          int              ssz;
           enum mandoc_esc  esc;
         const char      *seq, *rhs;          const char      *seq, *rhs;
   
         for (sz = 0; '\0' != *cp; )          /*
                 /*           * Account for escaped sequences within string length
                  * Account for escaped sequences within string length           * calculations.  This follows the logic in term_word() as we
                  * calculations.  This follows the logic in term_word()           * must calculate the width of produced strings.
                  * as we must calculate the width of produced strings.           */
                  */  
                 if ('\\' == *cp) {  
                         seq = ++cp;  
                         cp += a2roffdeco(&d, &seq, &ssz);  
   
                         switch (d) {          sz = 0;
                         case (DECO_RESERVED):          while ('\0' != *cp)
                   switch (*cp) {
                   case ('\\'):
                           ++cp;
                           esc = mandoc_escape(&cp, &seq, &ssz);
                           if (ESCAPE_ERROR == esc)
                                   return(sz);
   
                           switch (esc) {
                           case (ESCAPE_PREDEF):
                                 rhs = chars_res2str                                  rhs = chars_res2str
                                         (p->symtab, seq, ssz, &rsz);                                          (p->symtab, seq, ssz, &rsz);
                                 break;                                  break;
                         case (DECO_SPECIAL):                          case (ESCAPE_SPECIAL):
                                 /* FALLTHROUGH */  
                         case (DECO_SSPECIAL):  
                                 rhs = chars_spec2str                                  rhs = chars_spec2str
                                         (p->symtab, seq, ssz, &rsz);                                          (p->symtab, seq, ssz, &rsz);
   
                                 /* Allow for one-char escapes. */                                  if (ssz != 1 || rhs)
                                 if (DECO_SSPECIAL != d || rhs)  
                                         break;                                          break;
   
                                 rhs = seq;                                  rhs = seq;
Line 637  term_strlen(const struct termp *p, const char *cp)
Line 641  term_strlen(const struct termp *p, const char *cp)
                                 break;                                  break;
                         }                          }
   
                         if (rhs)                          if (NULL == rhs)
                                 for (i = 0; i < rsz; i++)                                  break;
                                         sz += (*p->width)(p, *rhs++);  
                 } else if (ASCII_NBRSP == *cp) {                          for (i = 0; i < rsz; i++)
                                   sz += (*p->width)(p, *rhs++);
                           break;
                   case (ASCII_NBRSP):
                         sz += (*p->width)(p, ' ');                          sz += (*p->width)(p, ' ');
                         cp++;                          cp++;
                 } else if (ASCII_HYPH == *cp) {                          break;
                   case (ASCII_HYPH):
                         sz += (*p->width)(p, '-');                          sz += (*p->width)(p, '-');
                         cp++;                          cp++;
                 } else                          break;
                   default:
                         sz += (*p->width)(p, *cp++);                          sz += (*p->width)(p, *cp++);
                           break;
                   }
   
         return(sz);          return(sz);
 }  }

Legend:
Removed from v.1.183  
changed lines
  Added in v.1.184

CVSweb