Print this page
9718 update mandoc to 1.14.4

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/mandoc/term_ascii.c
          +++ new/usr/src/cmd/mandoc/term_ascii.c
   1      -/*      $Id: term_ascii.c,v 1.58 2017/06/14 14:24:20 schwarze Exp $ */
        1 +/*      $Id: term_ascii.c,v 1.61 2018/05/20 21:37:34 schwarze Exp $ */
   2    2  /*
   3    3   * Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
   4      - * Copyright (c) 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
        4 + * Copyright (c) 2014, 2015, 2017, 2018 Ingo Schwarze <schwarze@openbsd.org>
   5    5   *
   6    6   * Permission to use, copy, modify, and distribute this software for any
   7    7   * purpose with or without fee is hereby granted, provided that the above
   8    8   * copyright notice and this permission notice appear in all copies.
   9    9   *
  10   10   * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
  11   11   * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  12   12   * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
  13   13   * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  14   14   * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  15   15   * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  16   16   * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  17   17   */
  18   18  #include "config.h"
  19   19  
  20   20  #include <sys/types.h>
  21   21  
  22   22  #include <assert.h>
  23   23  #if HAVE_WCHAR
       24 +#include <langinfo.h>
  24   25  #include <locale.h>
  25   26  #endif
  26   27  #include <stdint.h>
  27   28  #include <stdio.h>
  28   29  #include <stdlib.h>
       30 +#include <string.h>
  29   31  #include <unistd.h>
  30   32  #if HAVE_WCHAR
  31   33  #include <wchar.h>
  32   34  #endif
  33   35  
  34   36  #include "mandoc.h"
  35   37  #include "mandoc_aux.h"
  36   38  #include "out.h"
  37   39  #include "term.h"
  38   40  #include "manconf.h"
↓ open down ↓ 54 lines elided ↑ open up ↑
  93   95                  /*
  94   96                   * Do not change any of this to LC_ALL.  It might break
  95   97                   * the formatting by subtly changing the behaviour of
  96   98                   * various functions, for example strftime(3).  As a
  97   99                   * worst case, it might even cause buffer overflows.
  98  100                   */
  99  101  
 100  102                  v = TERMENC_LOCALE == enc ?
 101  103                      setlocale(LC_CTYPE, "") :
 102  104                      setlocale(LC_CTYPE, UTF8_LOCALE);
 103      -                if (NULL != v && MB_CUR_MAX > 1) {
      105 +
      106 +                /*
      107 +                 * We only support UTF-8,
      108 +                 * so revert to ASCII for anything else.
      109 +                 */
      110 +
      111 +                if (v != NULL &&
      112 +                    strcmp(nl_langinfo(CODESET), "UTF-8") != 0)
      113 +                        v = setlocale(LC_CTYPE, "C");
      114 +
      115 +                if (v != NULL && MB_CUR_MAX > 1) {
 104  116                          p->enc = enc;
 105  117                          p->advance = locale_advance;
 106  118                          p->endline = locale_endline;
 107  119                          p->letter = locale_letter;
 108  120                          p->width = locale_width;
 109  121                  }
 110  122          }
 111  123  #endif
 112  124  
 113  125          if (outopts->mdoc) {
 114  126                  p->mdocstyle = 1;
 115  127                  p->defindent = 5;
 116  128          }
 117  129          if (outopts->indent)
 118  130                  p->defindent = outopts->indent;
 119  131          if (outopts->width)
 120  132                  p->defrmargin = outopts->width;
 121  133          if (outopts->synopsisonly)
 122  134                  p->synopsisonly = 1;
 123  135  
      136 +        assert(p->defindent < UINT16_MAX);
      137 +        assert(p->defrmargin < UINT16_MAX);
 124  138          return p;
 125  139  }
 126  140  
 127  141  void *
 128  142  ascii_alloc(const struct manoutput *outopts)
 129  143  {
 130  144  
 131  145          return ascii_init(TERMENC_ASCII, outopts);
 132  146  }
 133  147  
↓ open down ↓ 18 lines elided ↑ open up ↑
 152  166          width /= 24;
 153  167          p->tcol->rmargin = p->defrmargin;
 154  168          if (iop > 0)
 155  169                  p->defrmargin += width;
 156  170          else if (iop == 0)
 157  171                  p->defrmargin = width ? (size_t)width : p->lastrmargin;
 158  172          else if (p->defrmargin > (size_t)width)
 159  173                  p->defrmargin -= width;
 160  174          else
 161  175                  p->defrmargin = 0;
      176 +        if (p->defrmargin > 1000)
      177 +                p->defrmargin = 1000;
 162  178          p->lastrmargin = p->tcol->rmargin;
 163  179          p->tcol->rmargin = p->maxrmargin = p->defrmargin;
 164  180  }
 165  181  
 166  182  void
 167  183  terminal_sepline(void *arg)
 168  184  {
 169  185          struct termp    *p;
 170  186          size_t           i;
 171  187  
↓ open down ↓ 48 lines elided ↑ open up ↑
 220  236          p->tcol->offset -= p->ti;
 221  237          p->ti = 0;
 222  238          putchar('\n');
 223  239  }
 224  240  
 225  241  static void
 226  242  ascii_advance(struct termp *p, size_t len)
 227  243  {
 228  244          size_t          i;
 229  245  
      246 +        assert(len < UINT16_MAX);
 230  247          for (i = 0; i < len; i++)
 231  248                  putchar(' ');
 232  249  }
 233  250  
 234  251  static int
 235  252  ascii_hspan(const struct termp *p, const struct roffsu *su)
 236  253  {
 237  254          double           r;
 238  255  
 239  256          switch (su->unit) {
↓ open down ↓ 47 lines elided ↑ open up ↑
 287  304          "P",    "Q",    "R",    "S",    "T",    "U",    "V",    "W",
 288  305          "X",    "Y",    "Z",    "[",    "\\",   "]",    "^",    "_",
 289  306          "`",    "a",    "b",    "c",    "d",    "e",    "f",    "g",
 290  307          "h",    "i",    "j",    "k",    "l",    "m",    "n",    "o",
 291  308          "p",    "q",    "r",    "s",    "t",    "u",    "v",    "w",
 292  309          "x",    "y",    "z",    "{",    "|",    "}",    "~",    "<DEL>",
 293  310          "<80>", "<81>", "<82>", "<83>", "<84>", "<85>", "<86>", "<87>",
 294  311          "<88>", "<89>", "<8A>", "<8B>", "<8C>", "<8D>", "<8E>", "<8F>",
 295  312          "<90>", "<91>", "<92>", "<93>", "<94>", "<95>", "<96>", "<97>",
 296  313          "<98>", "<99>", "<9A>", "<9B>", "<9C>", "<9D>", "<9E>", "<9F>",
 297      -        nbrsp,  "!",    "/\bc", "GBP",  "o\bx", "=\bY", "|",    "<sec>",
      314 +        nbrsp,  "!",    "/\bc", "GBP",  "o\bx", "=\bY", "|",    "<section>",
 298  315          "\"",   "(C)",  "_\ba", "<<",   "~",    "",     "(R)",  "-",
 299      -        "<deg>","+-",   "2",    "3",    "'",    ",\bu", "<par>",".",
 300      -        ",",    "1",    "_\bo", ">>",   "1/4",  "1/2",  "3/4",  "?",
      316 +        "<degree>","+-","^2",   "^3",   "'","<micro>","<paragraph>",".",
      317 +        ",",    "^1",   "_\bo", ">>",   "1/4",  "1/2",  "3/4",  "?",
 301  318          "`\bA", "'\bA", "^\bA", "~\bA", "\"\bA","o\bA", "AE",   ",\bC",
 302  319          "`\bE", "'\bE", "^\bE", "\"\bE","`\bI", "'\bI", "^\bI", "\"\bI",
 303      -        "-\bD", "~\bN", "`\bO", "'\bO", "^\bO", "~\bO", "\"\bO","x",
      320 +        "Dh",   "~\bN", "`\bO", "'\bO", "^\bO", "~\bO", "\"\bO","x",
 304  321          "/\bO", "`\bU", "'\bU", "^\bU", "\"\bU","'\bY", "Th",   "ss",
 305  322          "`\ba", "'\ba", "^\ba", "~\ba", "\"\ba","o\ba", "ae",   ",\bc",
 306  323          "`\be", "'\be", "^\be", "\"\be","`\bi", "'\bi", "^\bi", "\"\bi",
 307      -        "d",    "~\bn", "`\bo", "'\bo", "^\bo", "~\bo", "\"\bo","-:-",
      324 +        "dh",   "~\bn", "`\bo", "'\bo", "^\bo", "~\bo", "\"\bo","/",
 308  325          "/\bo", "`\bu", "'\bu", "^\bu", "\"\bu","'\by", "th",   "\"\by",
 309  326          "A",    "a",    "A",    "a",    "A",    "a",    "'\bC", "'\bc",
 310  327          "^\bC", "^\bc", "C",    "c",    "C",    "c",    "D",    "d",
 311  328          "/\bD", "/\bd", "E",    "e",    "E",    "e",    "E",    "e",
 312  329          "E",    "e",    "E",    "e",    "^\bG", "^\bg", "G",    "g",
 313  330          "G",    "g",    ",\bG", ",\bg", "^\bH", "^\bh", "/\bH", "/\bh",
 314  331          "~\bI", "~\bi", "I",    "i",    "I",    "i",    "I",    "i",
 315  332          "I",    "i",    "IJ",   "ij",   "^\bJ", "^\bj", ",\bK", ",\bk",
 316  333          "q",    "'\bL", "'\bl", ",\bL", ",\bl", "L",    "l",    "L",
 317  334          "l",    "/\bL", "/\bl", "'\bN", "'\bn", ",\bN", ",\bn", "N",
↓ open down ↓ 39 lines elided ↑ open up ↑
 357  374          if (rc < 0)
 358  375                  rc = 0;
 359  376          return rc;
 360  377  }
 361  378  
 362  379  static void
 363  380  locale_advance(struct termp *p, size_t len)
 364  381  {
 365  382          size_t          i;
 366  383  
      384 +        assert(len < UINT16_MAX);
 367  385          for (i = 0; i < len; i++)
 368  386                  putwchar(L' ');
 369  387  }
 370  388  
 371  389  static void
 372  390  locale_endline(struct termp *p)
 373  391  {
 374  392  
 375  393          p->line++;
 376  394          p->tcol->offset -= p->ti;
↓ open down ↓ 11 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX