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

Diff for /mandoc/eqn.c between version 1.28 and 1.32

version 1.28, 2011/07/22 14:26:32 version 1.32, 2011/07/23 12:01:54
Line 126  enum eqnpartt {
Line 126  enum eqnpartt {
         EQN_DEFINE = 0,          EQN_DEFINE = 0,
         EQN_SET,          EQN_SET,
         EQN_UNDEF,          EQN_UNDEF,
           EQN_GFONT,
           EQN_GSIZE,
         EQN__MAX          EQN__MAX
 };  };
   
 static  enum eqn_rest    eqn_box(struct eqn_node *, struct eqn_box *);  static  enum eqn_rest    eqn_box(struct eqn_node *, struct eqn_box *);
 static  struct eqn_box  *eqn_box_alloc(struct eqn_box *);  static  struct eqn_box  *eqn_box_alloc(struct eqn_node *,
                                   struct eqn_box *);
 static  void             eqn_box_free(struct eqn_box *);  static  void             eqn_box_free(struct eqn_box *);
 static  struct eqn_def  *eqn_def_find(struct eqn_node *,  static  struct eqn_def  *eqn_def_find(struct eqn_node *,
                                 const char *, size_t);                                  const char *, size_t);
   static  int              eqn_do_gfont(struct eqn_node *);
   static  int              eqn_do_gsize(struct eqn_node *);
 static  int              eqn_do_define(struct eqn_node *);  static  int              eqn_do_define(struct eqn_node *);
 static  int              eqn_do_set(struct eqn_node *);  static  int              eqn_do_set(struct eqn_node *);
 static  int              eqn_do_undef(struct eqn_node *);  static  int              eqn_do_undef(struct eqn_node *);
 static  enum eqn_rest    eqn_eqn(struct eqn_node *, struct eqn_box *);  static  enum eqn_rest    eqn_eqn(struct eqn_node *, struct eqn_box *);
 static  enum eqn_rest    eqn_list(struct eqn_node *, struct eqn_box *);  static  enum eqn_rest    eqn_list(struct eqn_node *, struct eqn_box *);
   static  enum eqn_rest    eqn_matrix(struct eqn_node *, struct eqn_box *);
 static  const char      *eqn_nexttok(struct eqn_node *, size_t *);  static  const char      *eqn_nexttok(struct eqn_node *, size_t *);
 static  const char      *eqn_nextrawtok(struct eqn_node *, size_t *);  static  const char      *eqn_nextrawtok(struct eqn_node *, size_t *);
 static  const char      *eqn_next(struct eqn_node *,  static  const char      *eqn_next(struct eqn_node *,
Line 149  static const struct eqnpart eqnparts[EQN__MAX] = {
Line 155  static const struct eqnpart eqnparts[EQN__MAX] = {
         { { "define", 6 }, eqn_do_define }, /* EQN_DEFINE */          { { "define", 6 }, eqn_do_define }, /* EQN_DEFINE */
         { { "set", 3 }, eqn_do_set }, /* EQN_SET */          { { "set", 3 }, eqn_do_set }, /* EQN_SET */
         { { "undef", 5 }, eqn_do_undef }, /* EQN_UNDEF */          { { "undef", 5 }, eqn_do_undef }, /* EQN_UNDEF */
           { { "gfont", 5 }, eqn_do_gfont }, /* EQN_GFONT */
           { { "gsize", 5 }, eqn_do_gsize }, /* EQN_GSIZE */
 };  };
   
 static  const struct eqnstr eqnmarks[EQNMARK__MAX] = {  static  const struct eqnstr eqnmarks[EQNMARK__MAX] = {
Line 184  static const struct eqnstr eqnpiles[EQNPILE__MAX] = {
Line 192  static const struct eqnstr eqnpiles[EQNPILE__MAX] = {
         { "cpile", 5 }, /* EQNPILE_CPILE */          { "cpile", 5 }, /* EQNPILE_CPILE */
         { "rpile", 5 }, /* EQNPILE_RPILE */          { "rpile", 5 }, /* EQNPILE_RPILE */
         { "lpile", 5 }, /* EQNPILE_LPILE */          { "lpile", 5 }, /* EQNPILE_LPILE */
           { "ccol", 4 }, /* EQNPILE_CCOL */
           { "rcol", 4 }, /* EQNPILE_RCOL */
           { "lcol", 4 }, /* EQNPILE_LCOL */
 };  };
   
 static  const struct eqnsym eqnsyms[EQNSYM__MAX] = {  static  const struct eqnsym eqnsyms[EQNSYM__MAX] = {
Line 298  eqn_alloc(int pos, int line, struct mparse *parse)
Line 309  eqn_alloc(int pos, int line, struct mparse *parse)
         p->parse = parse;          p->parse = parse;
         p->eqn.ln = line;          p->eqn.ln = line;
         p->eqn.pos = pos;          p->eqn.pos = pos;
           p->gsize = EQN_DEFSIZE;
   
         return(p);          return(p);
 }  }
Line 330  eqn_eqn(struct eqn_node *ep, struct eqn_box *last)
Line 342  eqn_eqn(struct eqn_node *ep, struct eqn_box *last)
         struct eqn_box  *bp;          struct eqn_box  *bp;
         enum eqn_rest    c;          enum eqn_rest    c;
   
         bp = eqn_box_alloc(last);          bp = eqn_box_alloc(ep, last);
         bp->type = EQN_SUBEXPR;          bp->type = EQN_SUBEXPR;
   
         while (EQN_OK == (c = eqn_box(ep, bp)))          while (EQN_OK == (c = eqn_box(ep, bp)))
Line 340  eqn_eqn(struct eqn_node *ep, struct eqn_box *last)
Line 352  eqn_eqn(struct eqn_node *ep, struct eqn_box *last)
 }  }
   
 static enum eqn_rest  static enum eqn_rest
   eqn_matrix(struct eqn_node *ep, struct eqn_box *last)
   {
           struct eqn_box  *bp;
           const char      *start;
           size_t           sz;
           enum eqn_rest    c;
   
           bp = eqn_box_alloc(ep, last);
           bp->type = EQN_MATRIX;
   
           if (NULL == (start = eqn_nexttok(ep, &sz))) {
                   EQN_MSG(MANDOCERR_EQNEOF, ep);
                   return(EQN_ERR);
           }
           if ( ! STRNEQ(start, sz, "{", 1)) {
                   EQN_MSG(MANDOCERR_EQNSYNT, ep);
                   return(EQN_ERR);
           }
   
           while (EQN_OK == (c = eqn_box(ep, bp)))
                   switch (bp->last->pile) {
                   case (EQNPILE_LCOL):
                           /* FALLTHROUGH */
                   case (EQNPILE_CCOL):
                           /* FALLTHROUGH */
                   case (EQNPILE_RCOL):
                           continue;
                   default:
                           EQN_MSG(MANDOCERR_EQNSYNT, ep);
                           return(EQN_ERR);
                   };
   
           if (EQN_DESCOPE != c) {
                   if (EQN_EOF == c)
                           EQN_MSG(MANDOCERR_EQNEOF, ep);
                   return(EQN_ERR);
           }
   
           eqn_rewind(ep);
           start = eqn_nexttok(ep, &sz);
           assert(start);
           if (STRNEQ(start, sz, "}", 1))
                   return(EQN_OK);
   
           EQN_MSG(MANDOCERR_EQNBADSCOPE, ep);
           return(EQN_ERR);
   }
   
   static enum eqn_rest
 eqn_list(struct eqn_node *ep, struct eqn_box *last)  eqn_list(struct eqn_node *ep, struct eqn_box *last)
 {  {
         struct eqn_box  *bp;          struct eqn_box  *bp;
Line 347  eqn_list(struct eqn_node *ep, struct eqn_box *last)
Line 408  eqn_list(struct eqn_node *ep, struct eqn_box *last)
         size_t           sz;          size_t           sz;
         enum eqn_rest    c;          enum eqn_rest    c;
   
         bp = eqn_box_alloc(last);          bp = eqn_box_alloc(ep, last);
         bp->type = EQN_LIST;          bp->type = EQN_LIST;
   
         if (NULL == (start = eqn_nexttok(ep, &sz))) {          if (NULL == (start = eqn_nexttok(ep, &sz))) {
Line 365  eqn_list(struct eqn_node *ep, struct eqn_box *last)
Line 426  eqn_list(struct eqn_node *ep, struct eqn_box *last)
                 assert(start);                  assert(start);
                 if ( ! STRNEQ(start, sz, "above", 5))                  if ( ! STRNEQ(start, sz, "above", 5))
                         break;                          break;
                 bp->last->above = 1;  
         }          }
   
         if (EQN_DESCOPE != c) {          if (EQN_DESCOPE != c) {
Line 434  eqn_box(struct eqn_node *ep, struct eqn_box *last)
Line 494  eqn_box(struct eqn_node *ep, struct eqn_box *last)
                 return(c);                  return(c);
         }          }
   
           if (STRNEQ(start, sz, "matrix", 6))
                   return(eqn_matrix(ep, last));
   
         if (STRNEQ(start, sz, "left", 4)) {          if (STRNEQ(start, sz, "left", 4)) {
                 if (NULL == (start = eqn_nexttok(ep, &sz))) {                  if (NULL == (start = eqn_nexttok(ep, &sz))) {
                         EQN_MSG(MANDOCERR_EQNEOF, ep);                          EQN_MSG(MANDOCERR_EQNEOF, ep);
Line 516  eqn_box(struct eqn_node *ep, struct eqn_box *last)
Line 579  eqn_box(struct eqn_node *ep, struct eqn_box *last)
                 last->last->size = size;                  last->last->size = size;
         }          }
   
         bp = eqn_box_alloc(last);          bp = eqn_box_alloc(ep, last);
         bp->type = EQN_TEXT;          bp->type = EQN_TEXT;
         for (i = 0; i < (int)EQNSYM__MAX; i++)          for (i = 0; i < (int)EQNSYM__MAX; i++)
                 if (EQNSTREQ(&eqnsyms[i].str, start, sz)) {                  if (EQNSTREQ(&eqnsyms[i].str, start, sz)) {
Line 548  eqn_free(struct eqn_node *p)
Line 611  eqn_free(struct eqn_node *p)
 }  }
   
 static struct eqn_box *  static struct eqn_box *
 eqn_box_alloc(struct eqn_box *parent)  eqn_box_alloc(struct eqn_node *ep, struct eqn_box *parent)
 {  {
         struct eqn_box  *bp;          struct eqn_box  *bp;
   
         bp = mandoc_calloc(1, sizeof(struct eqn_box));          bp = mandoc_calloc(1, sizeof(struct eqn_box));
         bp->parent = parent;          bp->parent = parent;
         bp->size = EQN_DEFSIZE;          bp->size = ep->gsize;
   
         if (NULL == parent->first)          if (NULL == parent->first)
                 parent->first = bp;                  parent->first = bp;
Line 640  again:
Line 703  again:
                 if ('{' == *start || '}' == *start)                  if ('{' == *start || '}' == *start)
                         ssz = 1;                          ssz = 1;
                 else                  else
                         ssz = strcspn(start + 1, " ~\"{}\t") + 1;                          ssz = strcspn(start + 1, " ^~\"{}\t") + 1;
                 next = start + (int)ssz;                  next = start + (int)ssz;
                 if ('\0' == *next)                  if ('\0' == *next)
                         next = NULL;                          next = NULL;
Line 654  again:
Line 717  again:
                         ep->cur++;                          ep->cur++;
                 while (' ' == ep->data[(int)ep->cur] ||                  while (' ' == ep->data[(int)ep->cur] ||
                                 '\t' == ep->data[(int)ep->cur] ||                                  '\t' == ep->data[(int)ep->cur] ||
                                   '^' == ep->data[(int)ep->cur] ||
                                 '~' == ep->data[(int)ep->cur])                                  '~' == ep->data[(int)ep->cur])
                         ep->cur++;                          ep->cur++;
         } else {          } else {
Line 695  eqn_do_set(struct eqn_node *ep)
Line 759  eqn_do_set(struct eqn_node *ep)
         const char      *start;          const char      *start;
   
         if (NULL == (start = eqn_nextrawtok(ep, NULL)))          if (NULL == (start = eqn_nextrawtok(ep, NULL)))
                 EQN_MSG(MANDOCERR_EQNARGS, ep);                  EQN_MSG(MANDOCERR_EQNEOF, ep);
         else if (NULL == (start = eqn_nextrawtok(ep, NULL)))          else if (NULL == (start = eqn_nextrawtok(ep, NULL)))
                 EQN_MSG(MANDOCERR_EQNARGS, ep);                  EQN_MSG(MANDOCERR_EQNEOF, ep);
         else          else
                 return(1);                  return(1);
   
Line 713  eqn_do_define(struct eqn_node *ep)
Line 777  eqn_do_define(struct eqn_node *ep)
         int              i;          int              i;
   
         if (NULL == (start = eqn_nextrawtok(ep, &sz))) {          if (NULL == (start = eqn_nextrawtok(ep, &sz))) {
                 EQN_MSG(MANDOCERR_EQNARGS, ep);                  EQN_MSG(MANDOCERR_EQNEOF, ep);
                 return(0);                  return(0);
         }          }
   
Line 748  eqn_do_define(struct eqn_node *ep)
Line 812  eqn_do_define(struct eqn_node *ep)
         start = eqn_next(ep, ep->data[(int)ep->cur], &sz, 0);          start = eqn_next(ep, ep->data[(int)ep->cur], &sz, 0);
   
         if (NULL == start) {          if (NULL == start) {
                 EQN_MSG(MANDOCERR_EQNARGS, ep);                  EQN_MSG(MANDOCERR_EQNEOF, ep);
                 return(0);                  return(0);
         }          }
   
Line 760  eqn_do_define(struct eqn_node *ep)
Line 824  eqn_do_define(struct eqn_node *ep)
 }  }
   
 static int  static int
   eqn_do_gfont(struct eqn_node *ep)
   {
           const char      *start;
   
           if (NULL == (start = eqn_nextrawtok(ep, NULL))) {
                   EQN_MSG(MANDOCERR_EQNEOF, ep);
                   return(0);
           }
           return(1);
   }
   
   static int
   eqn_do_gsize(struct eqn_node *ep)
   {
           const char      *start;
           size_t           sz;
   
           if (NULL == (start = eqn_nextrawtok(ep, &sz))) {
                   EQN_MSG(MANDOCERR_EQNEOF, ep);
                   return(0);
           }
   
           ep->gsize = mandoc_strntoi(start, sz, 10);
           return(1);
   }
   
   static int
 eqn_do_undef(struct eqn_node *ep)  eqn_do_undef(struct eqn_node *ep)
 {  {
         const char      *start;          const char      *start;
Line 767  eqn_do_undef(struct eqn_node *ep)
Line 858  eqn_do_undef(struct eqn_node *ep)
         size_t           sz;          size_t           sz;
   
         if (NULL == (start = eqn_nextrawtok(ep, &sz))) {          if (NULL == (start = eqn_nextrawtok(ep, &sz))) {
                 EQN_MSG(MANDOCERR_EQNARGS, ep);                  EQN_MSG(MANDOCERR_EQNEOF, ep);
                 return(0);                  return(0);
         } else if (NULL != (def = eqn_def_find(ep, start, sz)))          } else if (NULL != (def = eqn_def_find(ep, start, sz)))
                 def->keysz = 0;                  def->keysz = 0;

Legend:
Removed from v.1.28  
changed lines
  Added in v.1.32

CVSweb