Print this page
9718 update mandoc to 1.14.4

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/mandoc/eqn_term.c
          +++ new/usr/src/cmd/mandoc/eqn_term.c
   1      -/*      $Id: eqn_term.c,v 1.13 2017/07/08 14:51:04 schwarze Exp $ */
        1 +/*      $Id: eqn_term.c,v 1.17 2017/08/23 21:56:20 schwarze Exp $ */
   2    2  /*
   3    3   * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
   4    4   * Copyright (c) 2014, 2015, 2017 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 AUTHOR DISCLAIMS ALL WARRANTIES
  11   11   * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
↓ open down ↓ 1 lines elided ↑ open up ↑
  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 +#include <ctype.h>
  23   24  #include <stdio.h>
  24   25  #include <stdlib.h>
  25   26  #include <string.h>
  26   27  
  27   28  #include "mandoc.h"
  28   29  #include "out.h"
  29   30  #include "term.h"
  30   31  
  31   32  static  const enum termfont fontmap[EQNFONT__MAX] = {
  32   33          TERMFONT_NONE, /* EQNFONT_NONE */
↓ open down ↓ 11 lines elided ↑ open up ↑
  44   45  {
  45   46  
  46   47          eqn_box(p, bp);
  47   48          p->flags &= ~TERMP_NOSPACE;
  48   49  }
  49   50  
  50   51  static void
  51   52  eqn_box(struct termp *p, const struct eqn_box *bp)
  52   53  {
  53   54          const struct eqn_box *child;
       55 +        const char *cp;
  54   56          int delim;
  55   57  
  56   58          /* Delimiters around this box? */
  57   59  
  58   60          if ((bp->type == EQN_LIST && bp->expectargs > 1) ||
  59   61              (bp->type == EQN_PILE && (bp->prev || bp->next)) ||
  60   62              (bp->parent != NULL && (bp->parent->pos == EQNPOS_SQRT ||
  61   63              /* Diacritic followed by ^ or _. */
  62   64              ((bp->top != NULL || bp->bottom != NULL) &&
  63   65               bp->parent->type == EQN_SUBEXPR &&
  64   66               bp->parent->pos != EQNPOS_OVER && bp->next != NULL) ||
  65   67              /* Nested over, sub, sup, from, to. */
  66   68              (bp->type == EQN_SUBEXPR && bp->pos != EQNPOS_SQRT &&
  67   69               ((bp->parent->type == EQN_LIST && bp->expectargs == 1) ||
  68   70                (bp->parent->type == EQN_SUBEXPR &&
  69   71                 bp->pos != EQNPOS_SQRT)))))) {
  70      -                if (bp->parent->type == EQN_SUBEXPR && bp->prev != NULL)
       72 +                if ((bp->parent->type == EQN_SUBEXPR && bp->prev != NULL) ||
       73 +                    (bp->type == EQN_LIST &&
       74 +                     bp->first != NULL &&
       75 +                     bp->first->type != EQN_PILE &&
       76 +                     bp->first->type != EQN_MATRIX &&
       77 +                     bp->prev != NULL &&
       78 +                     (bp->prev->type == EQN_LIST ||
       79 +                      (bp->prev->type == EQN_TEXT &&
       80 +                       (*bp->prev->text == '\\' ||
       81 +                        isalpha((unsigned char)*bp->prev->text))))))
  71   82                          p->flags |= TERMP_NOSPACE;
  72   83                  term_word(p, bp->left != NULL ? bp->left : "(");
  73   84                  p->flags |= TERMP_NOSPACE;
  74   85                  delim = 1;
  75   86          } else
  76   87                  delim = 0;
  77   88  
  78   89          /* Handle Fonts and text. */
  79   90  
  80   91          if (bp->font != EQNFONT_NONE)
  81   92                  term_fontpush(p, fontmap[(int)bp->font]);
  82   93  
  83      -        if (bp->text != NULL)
       94 +        if (bp->text != NULL) {
       95 +                if (strchr("!\"'),.:;?]}", *bp->text) != NULL)
       96 +                        p->flags |= TERMP_NOSPACE;
  84   97                  term_word(p, bp->text);
       98 +                if ((cp = strchr(bp->text, '\0')) > bp->text &&
       99 +                    (strchr("\"'([{", cp[-1]) != NULL ||
      100 +                     (bp->prev == NULL && (cp[-1] == '-' ||
      101 +                      (cp >= bp->text + 5 &&
      102 +                       strcmp(cp - 5, "\\[mi]") == 0)))))
      103 +                        p->flags |= TERMP_NOSPACE;
      104 +        }
  85  105  
  86  106          /* Special box types. */
  87  107  
  88  108          if (bp->pos == EQNPOS_SQRT) {
  89  109                  term_word(p, "sqrt");
  90  110                  if (bp->first != NULL) {
  91  111                          p->flags |= TERMP_NOSPACE;
  92  112                          eqn_box(p, bp->first);
  93  113                  }
  94  114          } else if (bp->type == EQN_SUBEXPR) {
  95  115                  child = bp->first;
  96  116                  eqn_box(p, child);
  97  117                  p->flags |= TERMP_NOSPACE;
  98  118                  term_word(p, bp->pos == EQNPOS_OVER ? "/" :
  99  119                      (bp->pos == EQNPOS_SUP ||
 100  120                       bp->pos == EQNPOS_TO) ? "^" : "_");
 101      -                p->flags |= TERMP_NOSPACE;
 102  121                  child = child->next;
 103  122                  if (child != NULL) {
      123 +                        p->flags |= TERMP_NOSPACE;
 104  124                          eqn_box(p, child);
 105  125                          if (bp->pos == EQNPOS_FROMTO ||
 106  126                              bp->pos == EQNPOS_SUBSUP) {
 107  127                                  p->flags |= TERMP_NOSPACE;
 108  128                                  term_word(p, "^");
 109  129                                  p->flags |= TERMP_NOSPACE;
 110  130                                  child = child->next;
 111  131                                  if (child != NULL)
 112  132                                          eqn_box(p, child);
 113  133                          }
↓ open down ↓ 41 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX