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

Diff for /mandoc/term.c between version 1.161 and 1.168

version 1.161, 2010/07/16 22:33:30 version 1.168, 2010/08/20 23:22:09
Line 34 
Line 34 
 #include "term.h"  #include "term.h"
 #include "main.h"  #include "main.h"
   
 static  void              spec(struct termp *, const char *, size_t);  static  void              spec(struct termp *, enum roffdeco,
                                   const char *, size_t);
 static  void              res(struct termp *, const char *, size_t);  static  void              res(struct termp *, const char *, size_t);
 static  void              buffera(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);
 static  void              encode(struct termp *, const char *, size_t);  static  void              encode(struct termp *, const char *, size_t);
Line 83  term_alloc(enum termenc enc)
Line 83  term_alloc(enum termenc enc)
         p = calloc(1, sizeof(struct termp));          p = calloc(1, sizeof(struct termp));
         if (NULL == p) {          if (NULL == p) {
                 perror(NULL);                  perror(NULL);
                 exit(EXIT_FAILURE);                  exit(MANDOCLEVEL_SYSERR);
         }          }
   
         p->enc = enc;          p->enc = enc;
Line 241  term_flushln(struct termp *p)
Line 241  term_flushln(struct termp *p)
                         if ('\t' == p->buf[i])                          if ('\t' == p->buf[i])
                                 break;                                  break;
                         if (' ' == p->buf[i]) {                          if (' ' == p->buf[i]) {
                                 while (' ' == p->buf[i]) {                                  j = i;
                                         vbl += (*p->width)(p, p->buf[i]);                                  while (' ' == p->buf[i])
                                         i++;                                          i++;
                                 }                                  vbl += (i - j) * (*p->width)(p, ' ');
                                 break;                                  break;
                         }                          }
                         if (ASCII_NBRSP == p->buf[i]) {                          if (ASCII_NBRSP == p->buf[i]) {
Line 275  term_flushln(struct termp *p)
Line 275  term_flushln(struct termp *p)
                 vis = vend;                  vis = vend;
         }          }
   
           /*
            * If there was trailing white space, it was not printed;
            * so reset the cursor position accordingly.
            */
           vis -= vbl;
   
         p->col = 0;          p->col = 0;
         p->overstep = 0;          p->overstep = 0;
   
Line 360  term_vspace(struct termp *p)
Line 366  term_vspace(struct termp *p)
   
   
 static void  static void
 spec(struct termp *p, const char *word, size_t len)  spec(struct termp *p, enum roffdeco d, const char *word, size_t len)
 {  {
         const char      *rhs;          const char      *rhs;
         size_t           sz;          size_t           sz;
Line 368  spec(struct termp *p, const char *word, size_t len)
Line 374  spec(struct termp *p, const char *word, size_t len)
         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)
                   encode(p, word, len);
 }  }
   
   
Line 500  term_word(struct termp *p, const char *word)
Line 508  term_word(struct termp *p, const char *word)
   
         if ( ! (p->flags & TERMP_NONOSPACE))          if ( ! (p->flags & TERMP_NONOSPACE))
                 p->flags &= ~TERMP_NOSPACE;                  p->flags &= ~TERMP_NOSPACE;
           else
                   p->flags |= TERMP_NOSPACE;
   
         p->flags &= ~TERMP_SENTENCE;          p->flags &= ~TERMP_SENTENCE;
   
         /* FIXME: use strcspn. */  
   
         while (*word) {          while (*word) {
                 if ('\\' != *word) {                  if ((ssz = strcspn(word, "\\")) > 0)
                         encode(p, word, 1);                          encode(p, word, ssz);
                         word++;  
                   word += ssz;
                   if ('\\' != *word)
                         continue;                          continue;
                 }  
   
                 seq = ++word;                  seq = ++word;
                 sz = a2roffdeco(&deco, &seq, &ssz);                  sz = a2roffdeco(&deco, &seq, &ssz);
Line 520  term_word(struct termp *p, const char *word)
Line 529  term_word(struct termp *p, const char *word)
                         res(p, seq, ssz);                          res(p, seq, ssz);
                         break;                          break;
                 case (DECO_SPECIAL):                  case (DECO_SPECIAL):
                         spec(p, seq, ssz);                          /* FALLTHROUGH */
                   case (DECO_SSPECIAL):
                           spec(p, deco, seq, ssz);
                         break;                          break;
                 case (DECO_BOLD):                  case (DECO_BOLD):
                         term_fontrepl(p, TERMFONT_BOLD);                          term_fontrepl(p, TERMFONT_BOLD);
Line 547  term_word(struct termp *p, const char *word)
Line 558  term_word(struct termp *p, const char *word)
          * Note that we don't process the pipe: the parser sees it as           * Note that we don't process the pipe: the parser sees it as
          * punctuation, but we don't in terms of typography.           * punctuation, but we don't in terms of typography.
          */           */
         if (sv[0] && 0 == sv[1])          if (sv[0] && '\0' == sv[1])
                 switch (sv[0]) {                  switch (sv[0]) {
                 case('('):                  case('('):
                         /* FALLTHROUGH */                          /* FALLTHROUGH */
Line 572  adjbuf(struct termp *p, size_t sz)
Line 583  adjbuf(struct termp *p, size_t sz)
         p->buf = realloc(p->buf, p->maxcols);          p->buf = realloc(p->buf, p->maxcols);
         if (NULL == p->buf) {          if (NULL == p->buf) {
                 perror(NULL);                  perror(NULL);
                 exit(EXIT_FAILURE);                  exit(MANDOCLEVEL_SYSERR);
         }          }
 }  }
   
   
 static void  static void
 buffera(struct termp *p, const char *word, size_t sz)  
 {  
   
         if (p->col + sz >= p->maxcols)  
                 adjbuf(p, p->col + sz);  
   
         memcpy(&p->buf[(int)p->col], word, sz);  
         p->col += sz;  
 }  
   
   
 static void  
 bufferc(struct termp *p, char c)  bufferc(struct termp *p, char c)
 {  {
   
Line 613  encode(struct termp *p, const char *word, size_t sz)
Line 612  encode(struct termp *p, const char *word, size_t sz)
          */           */
   
         if (TERMFONT_NONE == (f = term_fonttop(p))) {          if (TERMFONT_NONE == (f = term_fonttop(p))) {
                 buffera(p, word, sz);                  if (p->col + sz >= p->maxcols)
                           adjbuf(p, p->col + sz);
                   memcpy(&p->buf[(int)p->col], word, sz);
                   p->col += sz;
                 return;                  return;
         }          }
   
           /* Pre-buffer, assuming worst-case. */
   
           if (p->col + 1 + (sz * 3) >= p->maxcols)
                   adjbuf(p, p->col + 1 + (sz * 3));
   
         for (i = 0; i < (int)sz; i++) {          for (i = 0; i < (int)sz; i++) {
                 if ( ! isgraph((u_char)word[i])) {                  if ( ! isgraph((u_char)word[i])) {
                         bufferc(p, word[i]);                          p->buf[(int)p->col++] = word[i];
                         continue;                          continue;
                 }                  }
   
                 if (TERMFONT_UNDER == f)                  if (TERMFONT_UNDER == f)
                         bufferc(p, '_');                          p->buf[(int)p->col++] = '_';
                 else                  else
                         bufferc(p, word[i]);                          p->buf[(int)p->col++] = word[i];
   
                 bufferc(p, 8);                  p->buf[(int)p->col++] = 8;
                 bufferc(p, word[i]);                  p->buf[(int)p->col++] = word[i];
         }          }
 }  }
   

Legend:
Removed from v.1.161  
changed lines
  Added in v.1.168

CVSweb