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

Diff for /mandoc/eqn.c between version 1.67 and 1.68

version 1.67, 2017/06/22 00:30:20 version 1.68, 2017/06/23 00:30:38
Line 573  eqn_box_alloc(struct eqn_node *ep, struct eqn_box *par
Line 573  eqn_box_alloc(struct eqn_node *ep, struct eqn_box *par
         bp->parent = parent;          bp->parent = parent;
         bp->parent->args++;          bp->parent->args++;
         bp->expectargs = UINT_MAX;          bp->expectargs = UINT_MAX;
           bp->font = bp->parent->font;
         bp->size = ep->gsize;          bp->size = ep->gsize;
   
         if (NULL != parent->first) {          if (NULL != parent->first) {
Line 721  static enum rofferr
Line 722  static enum rofferr
 eqn_parse(struct eqn_node *ep, struct eqn_box *parent)  eqn_parse(struct eqn_node *ep, struct eqn_box *parent)
 {  {
         char             sym[64];          char             sym[64];
         struct eqn_box  *cur, *fontp, *nbox;          struct eqn_box  *cur, *nbox;
         const char      *cp, *cpn, *start;          const char      *cp, *cpn, *start;
         char            *p;          char            *p;
         size_t           sz;          size_t           sz;
         enum eqn_tok     tok, subtok;          enum eqn_tok     tok, subtok;
         enum eqn_post    pos;          enum eqn_post    pos;
           enum { CCL_LET, CCL_DIG, CCL_PUN } ccl, ccln;
         int              size;          int              size;
   
         assert(parent != NULL);          assert(parent != NULL);
Line 787  this_tok:
Line 789  this_tok:
                 parent = eqn_box_makebinary(ep, EQNPOS_NONE, parent);                  parent = eqn_box_makebinary(ep, EQNPOS_NONE, parent);
                 parent->type = EQN_LISTONE;                  parent->type = EQN_LISTONE;
                 parent->expectargs = 1;                  parent->expectargs = 1;
                   parent->font = EQNFONT_ROMAN;
                 switch (tok) {                  switch (tok) {
                 case EQN_TOK_DOTDOT:                  case EQN_TOK_DOTDOT:
                         strlcpy(sym, "\\[ad]", sizeof(sym));                          strlcpy(sym, "\\[ad]", sizeof(sym));
Line 1097  this_tok:
Line 1100  this_tok:
                  */                   */
                 while (parent->args == parent->expectargs)                  while (parent->args == parent->expectargs)
                         parent = parent->parent;                          parent = parent->parent;
                 /*  
                  * Wrap well-known function names in a roman box,  
                  * unless they already are in roman context.  
                  */  
                 for (fontp = parent; fontp != NULL; fontp = fontp->parent)  
                         if (fontp->font != EQNFONT_NONE)  
                                 break;  
                 if (tok == EQN_TOK_FUNC &&  
                     (fontp == NULL || fontp->font != EQNFONT_ROMAN)) {  
                         parent = fontp = eqn_box_alloc(ep, parent);  
                         parent->type = EQN_LISTONE;  
                         parent->font = EQNFONT_ROMAN;  
                         parent->expectargs = 1;  
                 }  
                 cur = eqn_box_alloc(ep, parent);                  cur = eqn_box_alloc(ep, parent);
                 cur->type = EQN_TEXT;                  cur->type = EQN_TEXT;
                 cur->text = p;                  cur->text = p;
                 /*                  switch (tok) {
                  * If not inside any explicit font context,                  case EQN_TOK_FUNC:
                  * quoted strings become italic, and every letter                          cur->font = EQNFONT_ROMAN;
                  * of a bare string gets its own italic box.                          break;
                  */                  case EQN_TOK_QUOTED:
                 do {                          if (cur->font == EQNFONT_NONE)
                         if (fontp != NULL || *p == '\0' ||  
                             tok == EQN_TOK_SYM)  
                                 break;  
                         if (tok == EQN_TOK_QUOTED) {  
                                 cur->font = EQNFONT_ITALIC;                                  cur->font = EQNFONT_ITALIC;
                           break;
                   case EQN_TOK_SYM:
                           break;
                   default:
                           if (cur->font != EQNFONT_NONE || *p == '\0')
                                 break;                                  break;
                         }                          cpn = p - 1;
                         cp = p;                          ccln = CCL_LET;
                         for (;;) {                          for (;;) {
                                 if (isalpha((unsigned char)*cp))                                  /* Advance to next character. */
                                         cur->font = EQNFONT_ITALIC;                                  cp = cpn++;
                                 cpn = cp + 1;                                  ccl = ccln;
                                   ccln = isalpha((unsigned char)*cpn) ? CCL_LET :
                                       isdigit((unsigned char)*cpn) ||
                                       (*cpn == '.' && (ccl == CCL_DIG ||
                                        isdigit((unsigned char)cpn[1]))) ?
                                       CCL_DIG : CCL_PUN;
                                   /* No boundary before first character. */
                                   if (cp < p)
                                           continue;
                                   cur->font = ccl == CCL_LET ?
                                       EQNFONT_ITALIC : EQNFONT_ROMAN;
                                 if (*cp == '\\')                                  if (*cp == '\\')
                                         mandoc_escape(&cpn, NULL, NULL);                                          mandoc_escape(&cpn, NULL, NULL);
                                   /* No boundary after last character. */
                                 if (*cpn == '\0')                                  if (*cpn == '\0')
                                         break;                                          break;
                                 if (cur->font != EQNFONT_ITALIC &&                                  if (ccln == ccl)
                                     isalpha((unsigned char)*cpn) == 0) {  
                                         cp = cpn;  
                                         continue;                                          continue;
                                 }                                  /* Boundary found, add a new box. */
                                 nbox = eqn_box_alloc(ep, parent);                                  nbox = eqn_box_alloc(ep, parent);
                                 nbox->type = EQN_TEXT;                                  nbox->type = EQN_TEXT;
                                 nbox->text = mandoc_strdup(cpn);                                  nbox->text = mandoc_strdup(cpn);
                                   /* Truncate the old box. */
                                 p = mandoc_strndup(cur->text,                                  p = mandoc_strndup(cur->text,
                                     cpn - cur->text);                                      cpn - cur->text);
                                 free(cur->text);                                  free(cur->text);
                                 cur->text = p;                                  cur->text = p;
                                   /* Setup to process the new box. */
                                 cur = nbox;                                  cur = nbox;
                                 cp = nbox->text;                                  p = nbox->text;
                                   cpn = p - 1;
                                   ccln = CCL_LET;
                         }                          }
                 } while (0);                          break;
                   }
                 /*                  /*
                  * Post-process list status.                   * Post-process list status.
                  */                   */

Legend:
Removed from v.1.67  
changed lines
  Added in v.1.68

CVSweb