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

Diff for /mandoc/term.c between version 1.99 and 1.103

version 1.99, 2009/09/16 09:41:24 version 1.103, 2009/09/23 11:02:21
Line 20 
Line 20 
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
   
   #include "chars.h"
 #include "term.h"  #include "term.h"
 #include "man.h"  #include "man.h"
 #include "mdoc.h"  #include "mdoc.h"
   
   /* FIXME: accomodate non-breaking, non-collapsing white-space. */
   /* FIXME: accomodate non-breaking, collapsing white-space. */
   
 extern  void              man_run(struct termp *,  extern  void              man_run(struct termp *,
                                 const struct man *);                                  const struct man *);
 extern  void              mdoc_run(struct termp *,  extern  void              mdoc_run(struct termp *,
Line 39  static void    do_reserved(struct termp *,
Line 43  static void    do_reserved(struct termp *,
                                 const char *, size_t);                                  const char *, size_t);
 static  void              buffer(struct termp *, char);  static  void              buffer(struct termp *, char);
 static  void              encode(struct termp *, char);  static  void              encode(struct termp *, char);
 static  int               isopendelim(const char *);  
 static  int               isclosedelim(const char *);  
   
   
 void *  void *
Line 58  terminal_man(void *arg, const struct man *man)
Line 60  terminal_man(void *arg, const struct man *man)
   
         p = (struct termp *)arg;          p = (struct termp *)arg;
         if (NULL == p->symtab)          if (NULL == p->symtab)
                 p->symtab = term_ascii2htab();                  p->symtab = chars_init(CHARS_ASCII);
   
         man_run(p, man);          man_run(p, man);
 }  }
Line 71  terminal_mdoc(void *arg, const struct mdoc *mdoc)
Line 73  terminal_mdoc(void *arg, const struct mdoc *mdoc)
   
         p = (struct termp *)arg;          p = (struct termp *)arg;
         if (NULL == p->symtab)          if (NULL == p->symtab)
                 p->symtab = term_ascii2htab();                  p->symtab = chars_init(CHARS_ASCII);
   
         mdoc_run(p, mdoc);          mdoc_run(p, mdoc);
 }  }
Line 91  term_free(struct termp *p)
Line 93  term_free(struct termp *p)
   
         if (p->buf)          if (p->buf)
                 free(p->buf);                  free(p->buf);
         if (TERMENC_ASCII == p->enc && p->symtab)          if (p->symtab)
                 term_asciifree(p->symtab);                  chars_free(p->symtab);
   
         free(p);          free(p);
 }  }
Line 112  term_alloc(enum termenc enc)
Line 114  term_alloc(enum termenc enc)
 }  }
   
   
 static int  
 isclosedelim(const char *p)  
 {  
   
         if ( ! (*p && 0 == *(p + 1)))  
                 return(0);  
   
         switch (*p) {  
         case('.'):  
                 /* FALLTHROUGH */  
         case(','):  
                 /* FALLTHROUGH */  
         case(';'):  
                 /* FALLTHROUGH */  
         case(':'):  
                 /* FALLTHROUGH */  
         case('?'):  
                 /* FALLTHROUGH */  
         case('!'):  
                 /* FALLTHROUGH */  
         case(')'):  
                 /* FALLTHROUGH */  
         case(']'):  
                 /* FALLTHROUGH */  
         case('}'):  
                 return(1);  
         default:  
                 break;  
         }  
   
         return(0);  
 }  
   
   
 static int  
 isopendelim(const char *p)  
 {  
   
         if ( ! (*p && 0 == *(p + 1)))  
                 return(0);  
   
         switch (*p) {  
         case('('):  
                 /* FALLTHROUGH */  
         case('['):  
                 /* FALLTHROUGH */  
         case('{'):  
                 return(1);  
         default:  
                 break;  
         }  
   
         return(0);  
 }  
   
   
 /*  /*
  * Flush a line of text.  A "line" is loosely defined as being something   * Flush a line of text.  A "line" is loosely defined as being something
  * that should be followed by a newline, regardless of whether it's   * that should be followed by a newline, regardless of whether it's
Line 389  do_special(struct termp *p, const char *word, size_t l
Line 335  do_special(struct termp *p, const char *word, size_t l
         size_t           sz;          size_t           sz;
         int              i;          int              i;
   
         rhs = term_a2ascii(p->symtab, word, len, &sz);          rhs = chars_a2ascii(p->symtab, word, len, &sz);
   
         if (NULL == rhs) {          if (NULL == rhs) {
 #if 0  #if 0
Line 412  do_reserved(struct termp *p, const char *word, size_t 
Line 358  do_reserved(struct termp *p, const char *word, size_t 
         size_t           sz;          size_t           sz;
         int              i;          int              i;
   
         rhs = term_a2res(p->symtab, word, len, &sz);          rhs = chars_a2res(p->symtab, word, len, &sz);
   
         if (NULL == rhs) {          if (NULL == rhs) {
 #if 0  #if 0
Line 542  term_word(struct termp *p, const char *word)
Line 488  term_word(struct termp *p, const char *word)
 {  {
         const char       *sv;          const char       *sv;
   
         if (isclosedelim(word))          sv = word;
                 if ( ! (TERMP_IGNDELIM & p->flags))  
                         p->flags |= TERMP_NOSPACE;  
   
           if (word[0] && 0 == word[1])
                   switch (word[0]) {
                   case('.'):
                           /* FALLTHROUGH */
                   case(','):
                           /* FALLTHROUGH */
                   case(';'):
                           /* FALLTHROUGH */
                   case(':'):
                           /* FALLTHROUGH */
                   case('?'):
                           /* FALLTHROUGH */
                   case('!'):
                           /* FALLTHROUGH */
                   case(')'):
                           /* FALLTHROUGH */
                   case(']'):
                           /* FALLTHROUGH */
                   case('}'):
                           if ( ! (TERMP_IGNDELIM & p->flags))
                                   p->flags |= TERMP_NOSPACE;
                           break;
                   default:
                           break;
                   }
   
         if ( ! (TERMP_NOSPACE & p->flags))          if ( ! (TERMP_NOSPACE & p->flags))
                 buffer(p, ' ');                  buffer(p, ' ');
   
         if ( ! (p->flags & TERMP_NONOSPACE))          if ( ! (p->flags & TERMP_NONOSPACE))
                 p->flags &= ~TERMP_NOSPACE;                  p->flags &= ~TERMP_NOSPACE;
   
         for (sv = word; *word; word++)          for ( ; *word; word++)
                 if ('\\' != *word)                  if ('\\' != *word)
                         encode(p, *word);                          encode(p, *word);
                 else                  else
                         do_escaped(p, &word);                          do_escaped(p, &word);
   
         if (isopendelim(sv))          if (sv[0] && 0 == sv[1])
                 p->flags |= TERMP_NOSPACE;                  switch (sv[0]) {
                   case('('):
                           /* FALLTHROUGH */
                   case('['):
                           /* FALLTHROUGH */
                   case('{'):
                           p->flags |= TERMP_NOSPACE;
                           break;
                   default:
                           break;
                   }
 }  }
   
   

Legend:
Removed from v.1.99  
changed lines
  Added in v.1.103

CVSweb