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

Diff for /mandoc/eqn.c between version 1.82 and 1.86

version 1.82, 2018/12/14 05:18:02 version 1.86, 2023/04/28 19:11:03
Line 1 
Line 1 
 /*      $Id$ */  /* $Id$ */
 /*  /*
    * Copyright (c) 2014, 2015, 2017, 2018, 2020, 2022
    *               Ingo Schwarze <schwarze@openbsd.org>
  * Copyright (c) 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>   * Copyright (c) 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2014, 2015, 2017, 2018 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 303  static void   eqn_undef(struct eqn_node *);
Line 304  static void   eqn_undef(struct eqn_node *);
   
   
 struct eqn_node *  struct eqn_node *
 eqn_alloc(struct mparse *parse)  eqn_alloc(void)
 {  {
         struct eqn_node *ep;          struct eqn_node *ep;
   
         ep = mandoc_calloc(1, sizeof(*ep));          ep = mandoc_calloc(1, sizeof(*ep));
         ep->parse = parse;  
         ep->gsize = EQN_DEFSIZE;          ep->gsize = EQN_DEFSIZE;
         return ep;          return ep;
 }  }
Line 356  eqn_def_find(struct eqn_node *ep)
Line 356  eqn_def_find(struct eqn_node *ep)
 /*  /*
  * Parse a token from the input text.  The modes are:   * Parse a token from the input text.  The modes are:
  * MODE_QUOTED: Use *ep->start as the delimiter; the token ends   * MODE_QUOTED: Use *ep->start as the delimiter; the token ends
  *   before its next occurence.  Do not interpret the token in any   *   before its next occurrence.  Do not interpret the token in any
  *   way and return EQN_TOK_QUOTED.  All other modes behave like   *   way and return EQN_TOK_QUOTED.  All other modes behave like
  *   MODE_QUOTED when *ep->start is '"'.   *   MODE_QUOTED when *ep->start is '"'.
  * MODE_NOSUB: If *ep->start is a curly brace, the token ends after it;   * MODE_NOSUB: If *ep->start is a curly brace, the token ends after it;
Line 376  eqn_def_find(struct eqn_node *ep)
Line 376  eqn_def_find(struct eqn_node *ep)
 static enum eqn_tok  static enum eqn_tok
 eqn_next(struct eqn_node *ep, enum parse_mode mode)  eqn_next(struct eqn_node *ep, enum parse_mode mode)
 {  {
         static int       last_len, lim;  
   
         struct eqn_def  *def;          struct eqn_def  *def;
         size_t           start;          size_t           start;
         int              diff, i, quoted;          int              diff, i, newlen, quoted;
         enum eqn_tok     tok;          enum eqn_tok     tok;
   
         /*          /*
          * Reset the recursion counter after advancing           * Reset the recursion counter after advancing
          * beyond the end of the previous substitution.           * beyond the end of the rightmost substitution.
          */           */
         if (ep->end - ep->data >= last_len)          if (ep->end - ep->data >= ep->sublen)
                 lim = 0;                  ep->subcnt = 0;
   
         ep->start = ep->end;          ep->start = ep->end;
         quoted = mode == MODE_QUOTED;          quoted = mode == MODE_QUOTED;
Line 400  eqn_next(struct eqn_node *ep, enum parse_mode mode)
Line 398  eqn_next(struct eqn_node *ep, enum parse_mode mode)
                 case '"':                  case '"':
                         quoted = 1;                          quoted = 1;
                         break;                          break;
                   case ' ':
                   case '\t':
                   case '~':
                   case '^':
                           if (quoted)
                                   break;
                           ep->start++;
                           continue;
                 default:                  default:
                         break;                          break;
                 }                  }
Line 427  eqn_next(struct eqn_node *ep, enum parse_mode mode)
Line 433  eqn_next(struct eqn_node *ep, enum parse_mode mode)
                         return EQN_TOK__MAX;                          return EQN_TOK__MAX;
                 if ((def = eqn_def_find(ep)) == NULL)                  if ((def = eqn_def_find(ep)) == NULL)
                         break;                          break;
                 if (++lim > EQN_NEST_MAX) {                  if (++ep->subcnt > EQN_NEST_MAX) {
                         mandoc_msg(MANDOCERR_ROFFLOOP,                          mandoc_msg(MANDOCERR_ROFFLOOP,
                             ep->node->line, ep->node->pos, NULL);                              ep->node->line, ep->node->pos, NULL);
                         return EQN_TOK_EOF;                          break;
                 }                  }
   
                 /* Replace a defined name with its string value. */                  /* Replace a defined name with its string value. */
Line 439  eqn_next(struct eqn_node *ep, enum parse_mode mode)
Line 445  eqn_next(struct eqn_node *ep, enum parse_mode mode)
                         ep->sz += diff;                          ep->sz += diff;
                         ep->data = mandoc_realloc(ep->data, ep->sz + 1);                          ep->data = mandoc_realloc(ep->data, ep->sz + 1);
                         ep->start = ep->data + start;                          ep->start = ep->data + start;
                           ep->sublen += diff;
                 }                  }
                 if (diff)                  if (diff)
                         memmove(ep->start + def->valsz, ep->start + ep->toksz,                          memmove(ep->start + def->valsz, ep->start + ep->toksz,
                             strlen(ep->start + ep->toksz) + 1);                              strlen(ep->start + ep->toksz) + 1);
                 memcpy(ep->start, def->val, def->valsz);                  memcpy(ep->start, def->val, def->valsz);
                 last_len = ep->start - ep->data + def->valsz;                  newlen = ep->start - ep->data + def->valsz;
                   if (ep->sublen < newlen)
                           ep->sublen = newlen;
         }          }
         if (mode != MODE_TOK)          if (mode != MODE_TOK)
                 return quoted ? EQN_TOK_QUOTED : EQN_TOK__MAX;                  return quoted ? EQN_TOK_QUOTED : EQN_TOK__MAX;
Line 670  eqn_parse(struct eqn_node *ep)
Line 679  eqn_parse(struct eqn_node *ep)
         if (ep->data == NULL)          if (ep->data == NULL)
                 return;                  return;
   
         ep->start = ep->end = ep->data + strspn(ep->data, " ^~");          ep->start = ep->end = ep->data;
           ep->sublen = 0;
           ep->subcnt = 0;
   
 next_tok:  next_tok:
         tok = eqn_next(ep, MODE_TOK);          tok = eqn_next(ep, MODE_TOK);

Legend:
Removed from v.1.82  
changed lines
  Added in v.1.86

CVSweb