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

Diff for /mandoc/eqn_term.c between version 1.8 and 1.14

version 1.8, 2015/01/01 15:36:08 version 1.14, 2017/08/23 20:03:17
Line 1 
Line 1 
 /*      $Id$ */  /*      $Id$ */
 /*  /*
  * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>   * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>   * Copyright (c) 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
  *   *
  * Permission to use, copy, modify, and distribute this software for any   * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above   * purpose with or without fee is hereby granted, provided that the above
Line 20 
Line 20 
 #include <sys/types.h>  #include <sys/types.h>
   
 #include <assert.h>  #include <assert.h>
   #include <ctype.h>
 #include <stdio.h>  #include <stdio.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
Line 40  static void eqn_box(struct termp *, const struct eqn_b
Line 41  static void eqn_box(struct termp *, const struct eqn_b
   
   
 void  void
 term_eqn(struct termp *p, const struct eqn *ep)  term_eqn(struct termp *p, const struct eqn_box *bp)
 {  {
   
         eqn_box(p, ep->root);          eqn_box(p, bp);
         p->flags &= ~TERMP_NOSPACE;          p->flags &= ~TERMP_NOSPACE;
 }  }
   
Line 51  static void
Line 52  static void
 eqn_box(struct termp *p, const struct eqn_box *bp)  eqn_box(struct termp *p, const struct eqn_box *bp)
 {  {
         const struct eqn_box *child;          const struct eqn_box *child;
           int delim;
   
         if (bp->type == EQN_LIST ||          /* Delimiters around this box? */
   
           if ((bp->type == EQN_LIST && bp->expectargs > 1) ||
             (bp->type == EQN_PILE && (bp->prev || bp->next)) ||              (bp->type == EQN_PILE && (bp->prev || bp->next)) ||
             (bp->parent != NULL && bp->parent->pos == EQNPOS_SQRT)) {              (bp->parent != NULL && (bp->parent->pos == EQNPOS_SQRT ||
                 if (bp->parent->type == EQN_SUBEXPR && bp->prev != NULL)              /* Diacritic followed by ^ or _. */
               ((bp->top != NULL || bp->bottom != NULL) &&
                bp->parent->type == EQN_SUBEXPR &&
                bp->parent->pos != EQNPOS_OVER && bp->next != NULL) ||
               /* Nested over, sub, sup, from, to. */
               (bp->type == EQN_SUBEXPR && bp->pos != EQNPOS_SQRT &&
                ((bp->parent->type == EQN_LIST && bp->expectargs == 1) ||
                 (bp->parent->type == EQN_SUBEXPR &&
                  bp->pos != EQNPOS_SQRT)))))) {
                   if ((bp->parent->type == EQN_SUBEXPR && bp->prev != NULL) ||
                       (bp->type == EQN_LIST &&
                        bp->first != NULL &&
                        bp->first->type != EQN_PILE &&
                        bp->first->type != EQN_MATRIX &&
                        bp->prev != NULL &&
                        (bp->prev->type == EQN_LIST ||
                         (bp->prev->type == EQN_TEXT &&
                          (*bp->prev->text == '\\' ||
                           isalpha((unsigned char)*bp->prev->text))))))
                         p->flags |= TERMP_NOSPACE;                          p->flags |= TERMP_NOSPACE;
                 term_word(p, bp->left != NULL ? bp->left : "(");                  term_word(p, bp->left != NULL ? bp->left : "(");
                 p->flags |= TERMP_NOSPACE;                  p->flags |= TERMP_NOSPACE;
         }                  delim = 1;
           } else
                   delim = 0;
   
           /* Handle Fonts and text. */
   
         if (bp->font != EQNFONT_NONE)          if (bp->font != EQNFONT_NONE)
                 term_fontpush(p, fontmap[(int)bp->font]);                  term_fontpush(p, fontmap[(int)bp->font]);
   
         if (bp->text != NULL)          if (bp->text != NULL)
                 term_word(p, bp->text);                  term_word(p, bp->text);
   
           /* Special box types. */
   
         if (bp->pos == EQNPOS_SQRT) {          if (bp->pos == EQNPOS_SQRT) {
                 term_word(p, "sqrt");                  term_word(p, "sqrt");
                 p->flags |= TERMP_NOSPACE;                  if (bp->first != NULL) {
                 eqn_box(p, bp->first);                          p->flags |= TERMP_NOSPACE;
                           eqn_box(p, bp->first);
                   }
         } else if (bp->type == EQN_SUBEXPR) {          } else if (bp->type == EQN_SUBEXPR) {
                 child = bp->first;                  child = bp->first;
                 eqn_box(p, child);                  eqn_box(p, child);
Line 77  eqn_box(struct termp *p, const struct eqn_box *bp)
Line 108  eqn_box(struct termp *p, const struct eqn_box *bp)
                 term_word(p, bp->pos == EQNPOS_OVER ? "/" :                  term_word(p, bp->pos == EQNPOS_OVER ? "/" :
                     (bp->pos == EQNPOS_SUP ||                      (bp->pos == EQNPOS_SUP ||
                      bp->pos == EQNPOS_TO) ? "^" : "_");                       bp->pos == EQNPOS_TO) ? "^" : "_");
                 p->flags |= TERMP_NOSPACE;  
                 child = child->next;                  child = child->next;
                 if (child != NULL) {                  if (child != NULL) {
                           p->flags |= TERMP_NOSPACE;
                         eqn_box(p, child);                          eqn_box(p, child);
                         if (bp->pos == EQNPOS_FROMTO ||                          if (bp->pos == EQNPOS_FROMTO ||
                             bp->pos == EQNPOS_SUBSUP) {                              bp->pos == EQNPOS_SUBSUP) {
Line 93  eqn_box(struct termp *p, const struct eqn_box *bp)
Line 124  eqn_box(struct termp *p, const struct eqn_box *bp)
                 }                  }
         } else {          } else {
                 child = bp->first;                  child = bp->first;
                 if (bp->type == EQN_MATRIX && child->type == EQN_LIST)                  if (bp->type == EQN_MATRIX &&
                       child != NULL &&
                       child->type == EQN_LIST &&
                       child->expectargs > 1)
                         child = child->first;                          child = child->first;
                 while (child != NULL) {                  while (child != NULL) {
                         eqn_box(p,                          eqn_box(p,
                             bp->type == EQN_PILE &&                              bp->type == EQN_PILE &&
                             child->type == EQN_LIST &&                              child->type == EQN_LIST &&
                               child->expectargs > 1 &&
                             child->args == 1 ?                              child->args == 1 ?
                             child->first : child);                              child->first : child);
                         child = child->next;                          child = child->next;
                 }                  }
         }          }
   
           /* Handle Fonts and diacritics. */
   
         if (bp->font != EQNFONT_NONE)          if (bp->font != EQNFONT_NONE)
                 term_fontpop(p);                  term_fontpop(p);
         if (bp->type == EQN_LIST ||  
             (bp->type == EQN_PILE && (bp->prev || bp->next)) ||  
             (bp->parent != NULL && bp->parent->pos == EQNPOS_SQRT)) {  
                 p->flags |= TERMP_NOSPACE;  
                 term_word(p, bp->right != NULL ? bp->right : ")");  
                 if (bp->parent->type == EQN_SUBEXPR && bp->next != NULL)  
                         p->flags |= TERMP_NOSPACE;  
         }  
   
         if (bp->top != NULL) {          if (bp->top != NULL) {
                 p->flags |= TERMP_NOSPACE;                  p->flags |= TERMP_NOSPACE;
                 term_word(p, bp->top);                  term_word(p, bp->top);
Line 123  eqn_box(struct termp *p, const struct eqn_box *bp)
Line 151  eqn_box(struct termp *p, const struct eqn_box *bp)
         if (bp->bottom != NULL) {          if (bp->bottom != NULL) {
                 p->flags |= TERMP_NOSPACE;                  p->flags |= TERMP_NOSPACE;
                 term_word(p, "_");                  term_word(p, "_");
           }
   
           /* Right delimiter after this box? */
   
           if (delim) {
                   p->flags |= TERMP_NOSPACE;
                   term_word(p, bp->right != NULL ? bp->right : ")");
                   if (bp->parent->type == EQN_SUBEXPR && bp->next != NULL)
                           p->flags |= TERMP_NOSPACE;
         }          }
 }  }

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.14

CVSweb