=================================================================== RCS file: /cvs/mandoc/eqn.c,v retrieving revision 1.76 retrieving revision 1.81 diff -u -p -r1.76 -r1.81 --- mandoc/eqn.c 2017/07/08 14:51:04 1.76 +++ mandoc/eqn.c 2018/12/13 05:23:38 1.81 @@ -1,7 +1,7 @@ -/* $Id: eqn.c,v 1.76 2017/07/08 14:51:04 schwarze Exp $ */ +/* $Id: eqn.c,v 1.81 2018/12/13 05:23:38 schwarze Exp $ */ /* * Copyright (c) 2011, 2014 Kristaps Dzonsons - * Copyright (c) 2014, 2015, 2017 Ingo Schwarze + * Copyright (c) 2014, 2015, 2017, 2018 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -30,8 +30,9 @@ #include "mandoc_aux.h" #include "mandoc.h" #include "roff.h" +#include "eqn.h" #include "libmandoc.h" -#include "libroff.h" +#include "eqn_parse.h" #define EQN_NEST_MAX 128 /* maximum nesting of defines */ #define STRNEQ(p1, sz1, p2, sz2) \ @@ -284,6 +285,13 @@ enum parse_mode { MODE_TOK }; +struct eqn_def { + char *key; + size_t keysz; + char *val; + size_t valsz; +}; + static struct eqn_box *eqn_box_alloc(struct eqn_node *, struct eqn_box *); static struct eqn_box *eqn_box_makebinary(struct eqn_node *, struct eqn_box *); @@ -468,6 +476,8 @@ eqn_next(struct eqn_node *ep, enum parse_mode mode) void eqn_box_free(struct eqn_box *bp) { + if (bp == NULL) + return; if (bp->first) eqn_box_free(bp->first); @@ -482,6 +492,16 @@ eqn_box_free(struct eqn_box *bp) free(bp); } +struct eqn_box * +eqn_box_new(void) +{ + struct eqn_box *bp; + + bp = mandoc_calloc(1, sizeof(*bp)); + bp->expectargs = UINT_MAX; + return bp; +} + /* * Allocate a box as the last child of the parent node. */ @@ -490,10 +510,9 @@ eqn_box_alloc(struct eqn_node *ep, struct eqn_box *par { struct eqn_box *bp; - bp = mandoc_calloc(1, sizeof(struct eqn_box)); + bp = eqn_box_new(); bp->parent = parent; bp->parent->args++; - bp->expectargs = UINT_MAX; bp->font = bp->parent->font; bp->size = ep->gsize; @@ -717,7 +736,7 @@ next_tok: parent->bottom = mandoc_strdup("\\[ul]"); break; case EQN_TOK_BAR: - parent->top = mandoc_strdup("\\[rl]"); + parent->top = mandoc_strdup("\\[rn]"); break; case EQN_TOK_DOT: parent->top = mandoc_strdup("\\[a.]"); @@ -1041,7 +1060,7 @@ next_tok: /* No boundary after last character. */ if (*cpn == '\0') break; - if (ccln == ccl) + if (ccln == ccl && *cp != ',' && *cpn != ',') continue; /* Boundary found, split the text. */ if (parent->args == parent->expectargs) { @@ -1091,6 +1110,9 @@ void eqn_free(struct eqn_node *p) { int i; + + if (p == NULL) + return; for (i = 0; i < (int)p->defsz; i++) { free(p->defs[i].key);