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

Diff for /mandoc/term_ascii.c between version 1.37 and 1.43

version 1.37, 2014/10/28 02:43:59 version 1.43, 2015/02/16 14:11:41
Line 19 
Line 19 
   
 #include <sys/types.h>  #include <sys/types.h>
   
   #include <assert.h>
 #if HAVE_WCHAR  #if HAVE_WCHAR
 #include <locale.h>  #include <locale.h>
 #endif  #endif
Line 36 
Line 37 
 #include "term.h"  #include "term.h"
 #include "main.h"  #include "main.h"
   
 static  struct termp     *ascii_init(enum termenc, char *);  static  struct termp     *ascii_init(enum termenc,
                                   const struct mchars *, char *);
 static  double            ascii_hspan(const struct termp *,  static  double            ascii_hspan(const struct termp *,
                                 const struct roffsu *);                                  const struct roffsu *);
 static  size_t            ascii_width(const struct termp *, int);  static  size_t            ascii_width(const struct termp *, int);
Line 56  static size_t    locale_width(const struct termp *, in
Line 58  static size_t    locale_width(const struct termp *, in
   
   
 static struct termp *  static struct termp *
 ascii_init(enum termenc enc, char *outopts)  ascii_init(enum termenc enc, const struct mchars *mchars, char *outopts)
 {  {
         const char      *toks[5];          const char      *toks[5];
         char            *v;          char            *v;
         struct termp    *p;          struct termp    *p;
           const char      *errstr;
           int             num;
   
         p = mandoc_calloc(1, sizeof(struct termp));          p = mandoc_calloc(1, sizeof(struct termp));
   
           p->symtab = mchars;
         p->tabwidth = 5;          p->tabwidth = 5;
         p->defrmargin = p->lastrmargin = 78;          p->defrmargin = p->lastrmargin = 78;
           p->fontq = mandoc_reallocarray(NULL,
                (p->fontsz = 8), sizeof(enum termfont));
           p->fontq[0] = p->fontl = TERMFONT_NONE;
   
         p->begin = ascii_begin;          p->begin = ascii_begin;
         p->end = ascii_end;          p->end = ascii_end;
Line 103  ascii_init(enum termenc enc, char *outopts)
Line 111  ascii_init(enum termenc enc, char *outopts)
         while (outopts && *outopts)          while (outopts && *outopts)
                 switch (getsubopt(&outopts, UNCONST(toks), &v)) {                  switch (getsubopt(&outopts, UNCONST(toks), &v)) {
                 case 0:                  case 0:
                         p->defindent = (size_t)atoi(v);                          num = strtonum(v, 0, 1000, &errstr);
                           if (!errstr)
                                   p->defindent = num;
                         break;                          break;
                 case 1:                  case 1:
                         p->defrmargin = (size_t)atoi(v);                          num = strtonum(v, 0, 1000, &errstr);
                           if (!errstr)
                                   p->defrmargin = num;
                         break;                          break;
                 case 2:                  case 2:
                         /*                          /*
Line 131  ascii_init(enum termenc enc, char *outopts)
Line 143  ascii_init(enum termenc enc, char *outopts)
 }  }
   
 void *  void *
 ascii_alloc(char *outopts)  ascii_alloc(const struct mchars *mchars, char *outopts)
 {  {
   
         return(ascii_init(TERMENC_ASCII, outopts));          return(ascii_init(TERMENC_ASCII, mchars, outopts));
 }  }
   
 void *  void *
 utf8_alloc(char *outopts)  utf8_alloc(const struct mchars *mchars, char *outopts)
 {  {
   
         return(ascii_init(TERMENC_UTF8, outopts));          return(ascii_init(TERMENC_UTF8, mchars, outopts));
 }  }
   
 void *  void *
 locale_alloc(char *outopts)  locale_alloc(const struct mchars *mchars, char *outopts)
 {  {
   
         return(ascii_init(TERMENC_LOCALE, outopts));          return(ascii_init(TERMENC_LOCALE, mchars, outopts));
 }  }
   
 static void  static void
Line 156  ascii_setwidth(struct termp *p, int iop, size_t width)
Line 168  ascii_setwidth(struct termp *p, int iop, size_t width)
 {  {
   
         p->rmargin = p->defrmargin;          p->rmargin = p->defrmargin;
         if (0 < iop)          if (iop > 0)
                 p->defrmargin += width;                  p->defrmargin += width;
         else if (0 > iop)          else if (iop == 0)
                   p->defrmargin = width ? width : p->lastrmargin;
           else if (p->defrmargin > width)
                 p->defrmargin -= width;                  p->defrmargin -= width;
         else          else
                 p->defrmargin = width ? width : p->lastrmargin;                  p->defrmargin = 0;
         p->lastrmargin = p->rmargin;          p->lastrmargin = p->rmargin;
         p->rmargin = p->maxrmargin = p->defrmargin;          p->rmargin = p->maxrmargin = p->defrmargin;
 }  }
   
   void
   ascii_sepline(void *arg)
   {
           struct termp    *p;
           size_t           i;
   
           p = (struct termp *)arg;
           putchar('\n');
           for (i = 0; i < p->defrmargin; i++)
                   putchar('-');
           putchar('\n');
           putchar('\n');
   }
   
 static size_t  static size_t
 ascii_width(const struct termp *p, int c)  ascii_width(const struct termp *p, int c)
 {  {
Line 335  ascii_uc2str(int uc)
Line 363  ascii_uc2str(int uc)
         "j",    "DZ",   "Dz",   "dz",   "'\bG", "'\bg", "HV",   "W",          "j",    "DZ",   "Dz",   "dz",   "'\bG", "'\bg", "HV",   "W",
         "`\bN", "`\bn", "A",    "a",    "'\bAE","'\bae","O",    "o"};          "`\bN", "`\bn", "A",    "a",    "'\bAE","'\bae","O",    "o"};
   
         if (uc < 0)          assert(uc >= 0);
                 return("<?>");  
         if ((size_t)uc < sizeof(tab)/sizeof(tab[0]))          if ((size_t)uc < sizeof(tab)/sizeof(tab[0]))
                 return(tab[uc]);                  return(tab[uc]);
         return(mchars_uc2str(uc));          return(mchars_uc2str(uc));

Legend:
Removed from v.1.37  
changed lines
  Added in v.1.43

CVSweb