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

Diff for /mandoc/term.c between version 1.98 and 1.104

version 1.98, 2009/09/15 08:16:20 version 1.104, 2009/10/10 11:05:23
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"
   
 extern  int               man_run(struct termp *,  /* FIXME: accomodate non-breaking, non-collapsing white-space. */
   /* FIXME: accomodate non-breaking, collapsing white-space. */
   
   extern  void              man_run(struct termp *,
                                 const struct man *);                                  const struct man *);
 extern  int               mdoc_run(struct termp *,  extern  void              mdoc_run(struct termp *,
                                 const struct mdoc *);                                  const struct mdoc *);
   
 static  struct termp     *term_alloc(enum termenc);  static  struct termp     *term_alloc(enum termenc);
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 51  ascii_alloc(void)
Line 53  ascii_alloc(void)
 }  }
   
   
 int  void
 terminal_man(void *arg, const struct man *man)  terminal_man(void *arg, const struct man *man)
 {  {
         struct termp    *p;          struct termp    *p;
   
         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);
   
         return(man_run(p, man));          man_run(p, man);
 }  }
   
   
 int  void
 terminal_mdoc(void *arg, const struct mdoc *mdoc)  terminal_mdoc(void *arg, const struct mdoc *mdoc)
 {  {
         struct termp    *p;          struct termp    *p;
   
         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);
   
         return(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 213  void
Line 159  void
 term_flushln(struct termp *p)  term_flushln(struct termp *p)
 {  {
         int              i, j;          int              i, j;
         size_t           vbl, vsz, vis, maxvis, mmax, bp;          size_t           vbl, vsz, vis, maxvis, mmax, bp, os;
         static int       overstep = 0;          static int       overstep = 0;
   
         /*          /*
Line 226  term_flushln(struct termp *p)
Line 172  term_flushln(struct termp *p)
         assert(p->offset < p->rmargin);          assert(p->offset < p->rmargin);
         assert((int)(p->rmargin - p->offset) - overstep > 0);          assert((int)(p->rmargin - p->offset) - overstep > 0);
   
           /* Save the overstep. */
           os = (size_t)overstep;
   
         maxvis = /* LINTED */          maxvis = /* LINTED */
                 p->rmargin - p->offset - overstep;                  p->rmargin - p->offset - overstep;
         mmax = /* LINTED */          mmax = /* LINTED */
Line 287  term_flushln(struct termp *p)
Line 236  term_flushln(struct termp *p)
                                         putchar(' ');                                          putchar(' ');
                                 vis = 0;                                  vis = 0;
                         }                          }
                           /* Remove the overstep width. */
                           bp += os;
                           os = 0;
                 } else {                  } else {
                         for (j = 0; j < (int)vbl; j++)                          for (j = 0; j < (int)vbl; j++)
                                 putchar(' ');                                  putchar(' ');
Line 389  do_special(struct termp *p, const char *word, size_t l
Line 341  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 364  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 494  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.98  
changed lines
  Added in v.1.104

CVSweb