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

Diff for /mandoc/term.c between version 1.5 and 1.6

version 1.5, 2009/02/21 19:05:28 version 1.6, 2009/02/21 21:00:06
Line 25 
Line 25 
 #include <unistd.h>  #include <unistd.h>
   
 #include "term.h"  #include "term.h"
 #include "private.h" /* XXX */  
   
 enum    termstyle {  enum    termstyle {
         STYLE_CLEAR,          STYLE_CLEAR,
Line 42  static void    termprint_footer(struct termp *,
Line 41  static void    termprint_footer(struct termp *,
                                 const struct mdoc_meta *);                                  const struct mdoc_meta *);
   
 static  void              pword(struct termp *, const char *, size_t);  static  void              pword(struct termp *, const char *, size_t);
   static  void              pescape(struct termp *,
                                   const char *, size_t *, size_t);
 static  void              chara(struct termp *, char);  static  void              chara(struct termp *, char);
 static  void              escape(struct termp *, enum termstyle);  static  void              style(struct termp *, enum termstyle);
   
   
 void  void
Line 185  chara(struct termp *p, char c)
Line 186  chara(struct termp *p, char c)
   
   
 static void  static void
 escape(struct termp *p, enum termstyle esc)  style(struct termp *p, enum termstyle esc)
 {  {
   
         if (p->col + 4 >= p->maxcols)          if (p->col + 4 >= p->maxcols)
Line 212  escape(struct termp *p, enum termstyle esc)
Line 213  escape(struct termp *p, enum termstyle esc)
   
   
 static void  static void
   pescape(struct termp *p, const char *word, size_t *i, size_t len)
   {
   
           (*i)++;
           assert(*i < len);
   
           if ('(' == word[*i]) {
                   /* Two-character escapes. */
                   (*i)++;
                   assert(*i + 1 < len);
   
                   if ('r' == word[*i] && 'B' == word[*i + 1])
                           chara(p, ']');
                   else if ('l' == word[*i] && 'B' == word[*i + 1])
                           chara(p, '[');
   
                   (*i)++;
                   return;
   
           } else if ('[' != word[*i]) {
                   /* One-character escapes. */
                   switch (word[*i]) {
                   case ('\\'):
                           /* FALLTHROUGH */
                   case ('\''):
                           /* FALLTHROUGH */
                   case ('`'):
                           /* FALLTHROUGH */
                   case ('-'):
                           /* FALLTHROUGH */
                   case ('.'):
                           chara(p, word[*i]);
                   default:
                           break;
                   }
                   return;
           }
           /* n-character escapes. */
   }
   
   
   static void
 pword(struct termp *p, const char *word, size_t len)  pword(struct termp *p, const char *word, size_t len)
 {  {
         size_t           i;          size_t           i;
Line 224  pword(struct termp *p, const char *word, size_t len)
Line 267  pword(struct termp *p, const char *word, size_t len)
         p->flags &= ~TERMP_NOSPACE;          p->flags &= ~TERMP_NOSPACE;
   
         if (p->flags & TERMP_BOLD)          if (p->flags & TERMP_BOLD)
                 escape(p, STYLE_BOLD);                  style(p, STYLE_BOLD);
         if (p->flags & TERMP_UNDERLINE)          if (p->flags & TERMP_UNDERLINE)
                 escape(p, STYLE_UNDERLINE);                  style(p, STYLE_UNDERLINE);
   
         /* TODO: escape patterns. */          for (i = 0; i < len; i++) {
                   if ('\\' == word[i]) {
         for (i = 0; i < len; i++)                          pescape(p, word, &i, len);
                           continue;
                   }
                 chara(p, word[i]);                  chara(p, word[i]);
           }
   
         if (p->flags & TERMP_BOLD ||          if (p->flags & TERMP_BOLD ||
                         p->flags & TERMP_UNDERLINE)                          p->flags & TERMP_UNDERLINE)
                 escape(p, STYLE_CLEAR);                  style(p, STYLE_CLEAR);
 }  }
   
   
Line 293  termprint_r(struct termp *p, const struct mdoc_meta *m
Line 339  termprint_r(struct termp *p, const struct mdoc_meta *m
   
         /* Post-processing. */          /* Post-processing. */
   
         if (MDOC_TEXT != node->type) {          if (MDOC_TEXT != node->type)
                 if (termacts[node->tok].post)                  if (termacts[node->tok].post)
                         if ( ! (*termacts[node->tok].post)(p, meta, node))                          (*termacts[node->tok].post)(p, meta, node);
                                 return;  
         }  
   
         /* Siblings. */          /* Siblings. */
   
Line 351  termprint_footer(struct termp *p, const struct mdoc_me
Line 395  termprint_footer(struct termp *p, const struct mdoc_me
 static void  static void
 termprint_header(struct termp *p, const struct mdoc_meta *meta)  termprint_header(struct termp *p, const struct mdoc_meta *meta)
 {  {
         char            *msec, *buf, *title, *pp;          char            *buf, *title;
           const char      *pp, *msec;
         size_t           ssz, tsz, ttsz, i;;          size_t           ssz, tsz, ttsz, i;;
   
         if (NULL == (buf = malloc(p->rmargin)))          if (NULL == (buf = malloc(p->rmargin)))
Line 439  termprint_header(struct termp *p, const struct mdoc_me
Line 484  termprint_header(struct termp *p, const struct mdoc_me
 }  }
   
   
 int  void
 termprint(const struct mdoc_node *node,  termprint(const struct mdoc_node *node,
                 const struct mdoc_meta *meta)                  const struct mdoc_meta *meta)
 {  {
Line 459  termprint(const struct mdoc_node *node,
Line 504  termprint(const struct mdoc_node *node,
         termprint_footer(&p, meta);          termprint_footer(&p, meta);
   
         free(p.buf);          free(p.buf);
   
         return(1);  
 }  }
   
   

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

CVSweb