Print this page
Update to 1.12.3.
   1 /*      $Id: term_ascii.c,v 1.20 2011/12/04 23:10:52 schwarze Exp $ */
   2 /*
   3  * Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
   4  *
   5  * Permission to use, copy, modify, and distribute this software for any
   6  * purpose with or without fee is hereby granted, provided that the above
   7  * copyright notice and this permission notice appear in all copies.
   8  *
   9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16  */
  17 #ifdef HAVE_CONFIG_H
  18 #include "config.h"
  19 #endif
  20 
  21 #include <sys/types.h>


  56 static  void              ascii_begin(struct termp *);
  57 static  void              ascii_end(struct termp *);
  58 static  void              ascii_endline(struct termp *);
  59 static  void              ascii_letter(struct termp *, int);
  60 
  61 #ifdef  USE_WCHAR
  62 static  void              locale_advance(struct termp *, size_t);
  63 static  void              locale_endline(struct termp *);
  64 static  void              locale_letter(struct termp *, int);
  65 static  size_t            locale_width(const struct termp *, int);
  66 #endif
  67 
  68 static struct termp *
  69 ascii_init(enum termenc enc, char *outopts)
  70 {
  71         const char      *toks[4];
  72         char            *v;
  73         struct termp    *p;
  74 
  75         p = mandoc_calloc(1, sizeof(struct termp));
  76         p->enc = enc;
  77 
  78         p->tabwidth = 5;
  79         p->defrmargin = 78;
  80 
  81         p->begin = ascii_begin;
  82         p->end = ascii_end;
  83         p->hspan = ascii_hspan;
  84         p->type = TERMTYPE_CHAR;
  85 
  86         p->enc = TERMENC_ASCII;
  87         p->advance = ascii_advance;
  88         p->endline = ascii_endline;
  89         p->letter = ascii_letter;
  90         p->width = ascii_width;
  91 
  92 #ifdef  USE_WCHAR
  93         if (TERMENC_ASCII != enc) {
  94                 v = TERMENC_LOCALE == enc ?
  95                         setlocale(LC_ALL, "") :
  96                         setlocale(LC_CTYPE, "UTF-8");
  97                 if (NULL != v && MB_CUR_MAX > 1) {
  98                         p->enc = enc;
  99                         p->advance = locale_advance;
 100                         p->endline = locale_endline;
 101                         p->letter = locale_letter;
 102                         p->width = locale_width;
 103                 }
 104         }
 105 #endif
 106 
 107         toks[0] = "indent";
 108         toks[1] = "width";
 109         toks[2] = "mdoc";
 110         toks[3] = NULL;
 111 
 112         while (outopts && *outopts)
 113                 switch (getsubopt(&outopts, UNCONST(toks), &v)) {
 114                 case (0):
 115                         p->defindent = (size_t)atoi(v);
 116                         break;


   1 /*      $Id: term_ascii.c,v 1.21 2013/06/01 14:27:20 schwarze Exp $ */
   2 /*
   3  * Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
   4  *
   5  * Permission to use, copy, modify, and distribute this software for any
   6  * purpose with or without fee is hereby granted, provided that the above
   7  * copyright notice and this permission notice appear in all copies.
   8  *
   9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16  */
  17 #ifdef HAVE_CONFIG_H
  18 #include "config.h"
  19 #endif
  20 
  21 #include <sys/types.h>


  56 static  void              ascii_begin(struct termp *);
  57 static  void              ascii_end(struct termp *);
  58 static  void              ascii_endline(struct termp *);
  59 static  void              ascii_letter(struct termp *, int);
  60 
  61 #ifdef  USE_WCHAR
  62 static  void              locale_advance(struct termp *, size_t);
  63 static  void              locale_endline(struct termp *);
  64 static  void              locale_letter(struct termp *, int);
  65 static  size_t            locale_width(const struct termp *, int);
  66 #endif
  67 
  68 static struct termp *
  69 ascii_init(enum termenc enc, char *outopts)
  70 {
  71         const char      *toks[4];
  72         char            *v;
  73         struct termp    *p;
  74 
  75         p = mandoc_calloc(1, sizeof(struct termp));

  76 
  77         p->tabwidth = 5;
  78         p->defrmargin = 78;
  79 
  80         p->begin = ascii_begin;
  81         p->end = ascii_end;
  82         p->hspan = ascii_hspan;
  83         p->type = TERMTYPE_CHAR;
  84 
  85         p->enc = TERMENC_ASCII;
  86         p->advance = ascii_advance;
  87         p->endline = ascii_endline;
  88         p->letter = ascii_letter;
  89         p->width = ascii_width;
  90 
  91 #ifdef  USE_WCHAR
  92         if (TERMENC_ASCII != enc) {
  93                 v = TERMENC_LOCALE == enc ?
  94                         setlocale(LC_ALL, "") :
  95                         setlocale(LC_CTYPE, "en_US.UTF-8");
  96                 if (NULL != v && MB_CUR_MAX > 1) {
  97                         p->enc = enc;
  98                         p->advance = locale_advance;
  99                         p->endline = locale_endline;
 100                         p->letter = locale_letter;
 101                         p->width = locale_width;
 102                 }
 103         }
 104 #endif
 105 
 106         toks[0] = "indent";
 107         toks[1] = "width";
 108         toks[2] = "mdoc";
 109         toks[3] = NULL;
 110 
 111         while (outopts && *outopts)
 112                 switch (getsubopt(&outopts, UNCONST(toks), &v)) {
 113                 case (0):
 114                         p->defindent = (size_t)atoi(v);
 115                         break;