]>
git.cameronkatri.com Git - mandoc.git/blob - eqn.c
1 /* $Id: eqn.c,v 1.39 2014/03/23 11:25:26 schwarze Exp $ */
3 * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
29 #include "mandoc_aux.h"
30 #include "libmandoc.h"
33 #define EQN_NEST_MAX 128 /* maximum nesting of defines */
34 #define EQN_MSG(t, x) mandoc_msg((t), (x)->parse, (x)->eqn.ln, (x)->eqn.pos, NULL)
126 #define STRNEQ(p1, sz1, p2, sz2) \
127 ((sz1) == (sz2) && 0 == strncmp((p1), (p2), (sz1)))
128 #define EQNSTREQ(x, p, sz) \
129 STRNEQ((x)->name, (x)->sz, (p), (sz))
133 int (*fp
)(struct eqn_node
*);
142 static enum eqn_rest
eqn_box(struct eqn_node
*, struct eqn_box
*);
143 static struct eqn_box
*eqn_box_alloc(struct eqn_node
*,
145 static void eqn_box_free(struct eqn_box
*);
146 static struct eqn_def
*eqn_def_find(struct eqn_node
*,
147 const char *, size_t);
148 static int eqn_do_gfont(struct eqn_node
*);
149 static int eqn_do_gsize(struct eqn_node
*);
150 static int eqn_do_define(struct eqn_node
*);
151 static int eqn_do_ign1(struct eqn_node
*);
152 static int eqn_do_ign2(struct eqn_node
*);
153 static int eqn_do_tdefine(struct eqn_node
*);
154 static int eqn_do_undef(struct eqn_node
*);
155 static enum eqn_rest
eqn_eqn(struct eqn_node
*, struct eqn_box
*);
156 static enum eqn_rest
eqn_list(struct eqn_node
*, struct eqn_box
*);
157 static enum eqn_rest
eqn_matrix(struct eqn_node
*, struct eqn_box
*);
158 static const char *eqn_nexttok(struct eqn_node
*, size_t *);
159 static const char *eqn_nextrawtok(struct eqn_node
*, size_t *);
160 static const char *eqn_next(struct eqn_node
*,
161 char, size_t *, int);
162 static void eqn_rewind(struct eqn_node
*);
164 static const struct eqnpart eqnparts
[EQN__MAX
] = {
165 { { "define", 6 }, eqn_do_define
}, /* EQN_DEFINE */
166 { { "ndefine", 7 }, eqn_do_define
}, /* EQN_NDEFINE */
167 { { "tdefine", 7 }, eqn_do_tdefine
}, /* EQN_TDEFINE */
168 { { "set", 3 }, eqn_do_ign2
}, /* EQN_SET */
169 { { "undef", 5 }, eqn_do_undef
}, /* EQN_UNDEF */
170 { { "gfont", 5 }, eqn_do_gfont
}, /* EQN_GFONT */
171 { { "gsize", 5 }, eqn_do_gsize
}, /* EQN_GSIZE */
172 { { "back", 4 }, eqn_do_ign1
}, /* EQN_BACK */
173 { { "fwd", 3 }, eqn_do_ign1
}, /* EQN_FWD */
174 { { "up", 2 }, eqn_do_ign1
}, /* EQN_UP */
175 { { "down", 4 }, eqn_do_ign1
}, /* EQN_DOWN */
178 static const struct eqnstr eqnmarks
[EQNMARK__MAX
] = {
179 { "", 0 }, /* EQNMARK_NONE */
180 { "dot", 3 }, /* EQNMARK_DOT */
181 { "dotdot", 6 }, /* EQNMARK_DOTDOT */
182 { "hat", 3 }, /* EQNMARK_HAT */
183 { "tilde", 5 }, /* EQNMARK_TILDE */
184 { "vec", 3 }, /* EQNMARK_VEC */
185 { "dyad", 4 }, /* EQNMARK_DYAD */
186 { "bar", 3 }, /* EQNMARK_BAR */
187 { "under", 5 }, /* EQNMARK_UNDER */
190 static const struct eqnstr eqnfonts
[EQNFONT__MAX
] = {
191 { "", 0 }, /* EQNFONT_NONE */
192 { "roman", 5 }, /* EQNFONT_ROMAN */
193 { "bold", 4 }, /* EQNFONT_BOLD */
194 { "fat", 3 }, /* EQNFONT_FAT */
195 { "italic", 6 }, /* EQNFONT_ITALIC */
198 static const struct eqnstr eqnposs
[EQNPOS__MAX
] = {
199 { "", 0 }, /* EQNPOS_NONE */
200 { "over", 4 }, /* EQNPOS_OVER */
201 { "sup", 3 }, /* EQNPOS_SUP */
202 { "sub", 3 }, /* EQNPOS_SUB */
203 { "to", 2 }, /* EQNPOS_TO */
204 { "from", 4 }, /* EQNPOS_FROM */
207 static const struct eqnstr eqnpiles
[EQNPILE__MAX
] = {
208 { "", 0 }, /* EQNPILE_NONE */
209 { "pile", 4 }, /* EQNPILE_PILE */
210 { "cpile", 5 }, /* EQNPILE_CPILE */
211 { "rpile", 5 }, /* EQNPILE_RPILE */
212 { "lpile", 5 }, /* EQNPILE_LPILE */
213 { "col", 3 }, /* EQNPILE_COL */
214 { "ccol", 4 }, /* EQNPILE_CCOL */
215 { "rcol", 4 }, /* EQNPILE_RCOL */
216 { "lcol", 4 }, /* EQNPILE_LCOL */
219 static const struct eqnsym eqnsyms
[EQNSYM__MAX
] = {
220 { { "alpha", 5 }, "*a" }, /* EQNSYM_alpha */
221 { { "beta", 4 }, "*b" }, /* EQNSYM_beta */
222 { { "chi", 3 }, "*x" }, /* EQNSYM_chi */
223 { { "delta", 5 }, "*d" }, /* EQNSYM_delta */
224 { { "epsilon", 7 }, "*e" }, /* EQNSYM_epsilon */
225 { { "eta", 3 }, "*y" }, /* EQNSYM_eta */
226 { { "gamma", 5 }, "*g" }, /* EQNSYM_gamma */
227 { { "iota", 4 }, "*i" }, /* EQNSYM_iota */
228 { { "kappa", 5 }, "*k" }, /* EQNSYM_kappa */
229 { { "lambda", 6 }, "*l" }, /* EQNSYM_lambda */
230 { { "mu", 2 }, "*m" }, /* EQNSYM_mu */
231 { { "nu", 2 }, "*n" }, /* EQNSYM_nu */
232 { { "omega", 5 }, "*w" }, /* EQNSYM_omega */
233 { { "omicron", 7 }, "*o" }, /* EQNSYM_omicron */
234 { { "phi", 3 }, "*f" }, /* EQNSYM_phi */
235 { { "pi", 2 }, "*p" }, /* EQNSYM_pi */
236 { { "psi", 2 }, "*q" }, /* EQNSYM_psi */
237 { { "rho", 3 }, "*r" }, /* EQNSYM_rho */
238 { { "sigma", 5 }, "*s" }, /* EQNSYM_sigma */
239 { { "tau", 3 }, "*t" }, /* EQNSYM_tau */
240 { { "theta", 5 }, "*h" }, /* EQNSYM_theta */
241 { { "upsilon", 7 }, "*u" }, /* EQNSYM_upsilon */
242 { { "xi", 2 }, "*c" }, /* EQNSYM_xi */
243 { { "zeta", 4 }, "*z" }, /* EQNSYM_zeta */
244 { { "DELTA", 5 }, "*D" }, /* EQNSYM_DELTA */
245 { { "GAMMA", 5 }, "*G" }, /* EQNSYM_GAMMA */
246 { { "LAMBDA", 6 }, "*L" }, /* EQNSYM_LAMBDA */
247 { { "OMEGA", 5 }, "*W" }, /* EQNSYM_OMEGA */
248 { { "PHI", 3 }, "*F" }, /* EQNSYM_PHI */
249 { { "PI", 2 }, "*P" }, /* EQNSYM_PI */
250 { { "PSI", 3 }, "*Q" }, /* EQNSYM_PSI */
251 { { "SIGMA", 5 }, "*S" }, /* EQNSYM_SIGMA */
252 { { "THETA", 5 }, "*H" }, /* EQNSYM_THETA */
253 { { "UPSILON", 7 }, "*U" }, /* EQNSYM_UPSILON */
254 { { "XI", 2 }, "*C" }, /* EQNSYM_XI */
255 { { "inter", 5 }, "ca" }, /* EQNSYM_inter */
256 { { "union", 5 }, "cu" }, /* EQNSYM_union */
257 { { "prod", 4 }, "product" }, /* EQNSYM_prod */
258 { { "int", 3 }, "integral" }, /* EQNSYM_int */
259 { { "sum", 3 }, "sum" }, /* EQNSYM_sum */
260 { { "grad", 4 }, "gr" }, /* EQNSYM_grad */
261 { { "del", 3 }, "gr" }, /* EQNSYM_del */
262 { { "times", 5 }, "mu" }, /* EQNSYM_times */
263 { { "cdot", 4 }, "pc" }, /* EQNSYM_cdot */
264 { { "nothing", 7 }, "&" }, /* EQNSYM_nothing */
265 { { "approx", 6 }, "~~" }, /* EQNSYM_approx */
266 { { "prime", 5 }, "aq" }, /* EQNSYM_prime */
267 { { "half", 4 }, "12" }, /* EQNSYM_half */
268 { { "partial", 7 }, "pd" }, /* EQNSYM_partial */
269 { { "inf", 3 }, "if" }, /* EQNSYM_inf */
270 { { ">>", 2 }, ">>" }, /* EQNSYM_muchgreat */
271 { { "<<", 2 }, "<<" }, /* EQNSYM_muchless */
272 { { "<-", 2 }, "<-" }, /* EQNSYM_larrow */
273 { { "->", 2 }, "->" }, /* EQNSYM_rarrow */
274 { { "+-", 2 }, "+-" }, /* EQNSYM_pm */
275 { { "!=", 2 }, "!=" }, /* EQNSYM_nequal */
276 { { "==", 2 }, "==" }, /* EQNSYM_equiv */
277 { { "<=", 2 }, "<=" }, /* EQNSYM_lessequal */
278 { { ">=", 2 }, ">=" }, /* EQNSYM_moreequal */
283 eqn_read(struct eqn_node
**epp
, int ln
,
284 const char *p
, int pos
, int *offs
)
293 * If we're the terminating mark, unset our equation status and
294 * validate the full equation.
297 if (0 == strncmp(p
, ".EN", 3)) {
300 while (' ' == *p
|| '\t' == *p
)
304 mandoc_msg(MANDOCERR_ARGSLOST
, ep
->parse
, ln
, pos
, NULL
);
309 * Build up the full string, replacing all newlines with regular
313 sz
= strlen(p
+ pos
) + 1;
314 ep
->data
= mandoc_realloc(ep
->data
, ep
->sz
+ sz
+ 1);
316 /* First invocation: nil terminate the string. */
322 strlcat(ep
->data
, p
+ pos
, ep
->sz
+ 1);
323 strlcat(ep
->data
, " ", ep
->sz
+ 1);
328 eqn_alloc(const char *name
, int pos
, int line
, struct mparse
*parse
)
334 p
= mandoc_calloc(1, sizeof(struct eqn_node
));
336 if (name
&& '\0' != *name
) {
341 end
= name
+ (int)sz
;
342 } while (' ' == *end
|| '\t' == *end
);
343 p
->eqn
.name
= mandoc_strndup(name
, sz
+ 1);
349 p
->gsize
= EQN_DEFSIZE
;
355 eqn_end(struct eqn_node
**epp
)
358 struct eqn_box
*root
;
364 ep
->eqn
.root
= mandoc_calloc(1, sizeof(struct eqn_box
));
367 root
->type
= EQN_ROOT
;
372 if (EQN_DESCOPE
== (c
= eqn_eqn(ep
, root
))) {
373 EQN_MSG(MANDOCERR_EQNNSCOPE
, ep
);
377 return(EQN_EOF
== c
? ROFF_EQN
: ROFF_IGN
);
381 eqn_eqn(struct eqn_node
*ep
, struct eqn_box
*last
)
386 bp
= eqn_box_alloc(ep
, last
);
387 bp
->type
= EQN_SUBEXPR
;
389 while (EQN_OK
== (c
= eqn_box(ep
, bp
)))
396 eqn_matrix(struct eqn_node
*ep
, struct eqn_box
*last
)
403 bp
= eqn_box_alloc(ep
, last
);
404 bp
->type
= EQN_MATRIX
;
406 if (NULL
== (start
= eqn_nexttok(ep
, &sz
))) {
407 EQN_MSG(MANDOCERR_EQNEOF
, ep
);
410 if ( ! STRNEQ(start
, sz
, "{", 1)) {
411 EQN_MSG(MANDOCERR_EQNSYNT
, ep
);
415 while (EQN_OK
== (c
= eqn_box(ep
, bp
)))
416 switch (bp
->last
->pile
) {
424 EQN_MSG(MANDOCERR_EQNSYNT
, ep
);
428 if (EQN_DESCOPE
!= c
) {
430 EQN_MSG(MANDOCERR_EQNEOF
, ep
);
435 start
= eqn_nexttok(ep
, &sz
);
437 if (STRNEQ(start
, sz
, "}", 1))
440 EQN_MSG(MANDOCERR_EQNBADSCOPE
, ep
);
445 eqn_list(struct eqn_node
*ep
, struct eqn_box
*last
)
452 bp
= eqn_box_alloc(ep
, last
);
455 if (NULL
== (start
= eqn_nexttok(ep
, &sz
))) {
456 EQN_MSG(MANDOCERR_EQNEOF
, ep
);
459 if ( ! STRNEQ(start
, sz
, "{", 1)) {
460 EQN_MSG(MANDOCERR_EQNSYNT
, ep
);
464 while (EQN_DESCOPE
== (c
= eqn_eqn(ep
, bp
))) {
466 start
= eqn_nexttok(ep
, &sz
);
468 if ( ! STRNEQ(start
, sz
, "above", 5))
472 if (EQN_DESCOPE
!= c
) {
474 EQN_MSG(MANDOCERR_EQNSCOPE
, ep
);
479 start
= eqn_nexttok(ep
, &sz
);
481 if (STRNEQ(start
, sz
, "}", 1))
484 EQN_MSG(MANDOCERR_EQNBADSCOPE
, ep
);
489 eqn_box(struct eqn_node
*ep
, struct eqn_box
*last
)
499 if (NULL
== (start
= eqn_nexttok(ep
, &sz
)))
502 if (STRNEQ(start
, sz
, "}", 1))
504 else if (STRNEQ(start
, sz
, "right", 5))
506 else if (STRNEQ(start
, sz
, "above", 5))
508 else if (STRNEQ(start
, sz
, "mark", 4))
510 else if (STRNEQ(start
, sz
, "lineup", 6))
513 for (i
= 0; i
< (int)EQN__MAX
; i
++) {
514 if ( ! EQNSTREQ(&eqnparts
[i
].str
, start
, sz
))
516 return((*eqnparts
[i
].fp
)(ep
) ?
520 if (STRNEQ(start
, sz
, "{", 1)) {
521 if (EQN_DESCOPE
!= (c
= eqn_eqn(ep
, last
))) {
523 EQN_MSG(MANDOCERR_EQNSCOPE
, ep
);
527 start
= eqn_nexttok(ep
, &sz
);
529 if (STRNEQ(start
, sz
, "}", 1))
531 EQN_MSG(MANDOCERR_EQNBADSCOPE
, ep
);
535 for (i
= 0; i
< (int)EQNPILE__MAX
; i
++) {
536 if ( ! EQNSTREQ(&eqnpiles
[i
], start
, sz
))
538 if (EQN_OK
== (c
= eqn_list(ep
, last
)))
539 last
->last
->pile
= (enum eqn_pilet
)i
;
543 if (STRNEQ(start
, sz
, "matrix", 6))
544 return(eqn_matrix(ep
, last
));
546 if (STRNEQ(start
, sz
, "left", 4)) {
547 if (NULL
== (start
= eqn_nexttok(ep
, &sz
))) {
548 EQN_MSG(MANDOCERR_EQNEOF
, ep
);
551 left
= mandoc_strndup(start
, sz
);
552 c
= eqn_eqn(ep
, last
);
554 last
->last
->left
= left
;
557 if (EQN_DESCOPE
!= c
)
561 start
= eqn_nexttok(ep
, &sz
);
563 if ( ! STRNEQ(start
, sz
, "right", 5))
565 if (NULL
== (start
= eqn_nexttok(ep
, &sz
))) {
566 EQN_MSG(MANDOCERR_EQNEOF
, ep
);
569 last
->last
->right
= mandoc_strndup(start
, sz
);
573 for (i
= 0; i
< (int)EQNPOS__MAX
; i
++) {
574 if ( ! EQNSTREQ(&eqnposs
[i
], start
, sz
))
576 if (NULL
== last
->last
) {
577 EQN_MSG(MANDOCERR_EQNSYNT
, ep
);
580 last
->last
->pos
= (enum eqn_post
)i
;
581 if (EQN_EOF
== (c
= eqn_box(ep
, last
))) {
582 EQN_MSG(MANDOCERR_EQNEOF
, ep
);
588 for (i
= 0; i
< (int)EQNMARK__MAX
; i
++) {
589 if ( ! EQNSTREQ(&eqnmarks
[i
], start
, sz
))
591 if (NULL
== last
->last
) {
592 EQN_MSG(MANDOCERR_EQNSYNT
, ep
);
595 last
->last
->mark
= (enum eqn_markt
)i
;
596 if (EQN_EOF
== (c
= eqn_box(ep
, last
))) {
597 EQN_MSG(MANDOCERR_EQNEOF
, ep
);
603 for (i
= 0; i
< (int)EQNFONT__MAX
; i
++) {
604 if ( ! EQNSTREQ(&eqnfonts
[i
], start
, sz
))
606 if (EQN_EOF
== (c
= eqn_box(ep
, last
))) {
607 EQN_MSG(MANDOCERR_EQNEOF
, ep
);
609 } else if (EQN_OK
== c
)
610 last
->last
->font
= (enum eqn_fontt
)i
;
614 if (STRNEQ(start
, sz
, "size", 4)) {
615 if (NULL
== (start
= eqn_nexttok(ep
, &sz
))) {
616 EQN_MSG(MANDOCERR_EQNEOF
, ep
);
619 size
= mandoc_strntoi(start
, sz
, 10);
620 if (EQN_EOF
== (c
= eqn_box(ep
, last
))) {
621 EQN_MSG(MANDOCERR_EQNEOF
, ep
);
623 } else if (EQN_OK
!= c
)
625 last
->last
->size
= size
;
628 bp
= eqn_box_alloc(ep
, last
);
630 for (i
= 0; i
< (int)EQNSYM__MAX
; i
++)
631 if (EQNSTREQ(&eqnsyms
[i
].str
, start
, sz
)) {
633 snprintf(sym
, 62, "\\[%s]", eqnsyms
[i
].sym
);
634 bp
->text
= mandoc_strdup(sym
);
638 bp
->text
= mandoc_strndup(start
, sz
);
643 eqn_free(struct eqn_node
*p
)
647 eqn_box_free(p
->eqn
.root
);
649 for (i
= 0; i
< (int)p
->defsz
; i
++) {
650 free(p
->defs
[i
].key
);
651 free(p
->defs
[i
].val
);
660 static struct eqn_box
*
661 eqn_box_alloc(struct eqn_node
*ep
, struct eqn_box
*parent
)
665 bp
= mandoc_calloc(1, sizeof(struct eqn_box
));
667 bp
->size
= ep
->gsize
;
669 if (NULL
== parent
->first
)
672 parent
->last
->next
= bp
;
679 eqn_box_free(struct eqn_box
*bp
)
683 eqn_box_free(bp
->first
);
685 eqn_box_free(bp
->next
);
694 eqn_nextrawtok(struct eqn_node
*ep
, size_t *sz
)
697 return(eqn_next(ep
, '"', sz
, 0));
701 eqn_nexttok(struct eqn_node
*ep
, size_t *sz
)
704 return(eqn_next(ep
, '"', sz
, 1));
708 eqn_rewind(struct eqn_node
*ep
)
715 eqn_next(struct eqn_node
*ep
, char quote
, size_t *sz
, int repl
)
728 /* Prevent self-definitions. */
730 if (lim
>= EQN_NEST_MAX
) {
731 EQN_MSG(MANDOCERR_ROFFLOOP
, ep
);
736 start
= &ep
->data
[(int)ep
->cur
];
742 if (quote
== *start
) {
747 start
= &ep
->data
[(int)ep
->cur
];
750 if ('{' == *start
|| '}' == *start
)
753 ssz
= strcspn(start
+ 1, " ^~\"{}\t") + 1;
754 next
= start
+ (int)ssz
;
758 next
= strchr(start
, quote
);
761 *sz
= (size_t)(next
- start
);
765 while (' ' == ep
->data
[(int)ep
->cur
] ||
766 '\t' == ep
->data
[(int)ep
->cur
] ||
767 '^' == ep
->data
[(int)ep
->cur
] ||
768 '~' == ep
->data
[(int)ep
->cur
])
772 EQN_MSG(MANDOCERR_BADQUOTE
, ep
);
773 next
= strchr(start
, '\0');
774 *sz
= (size_t)(next
- start
);
778 /* Quotes aren't expanded for values. */
783 if (NULL
!= (def
= eqn_def_find(ep
, start
, *sz
))) {
784 diff
= def
->valsz
- *sz
;
786 if (def
->valsz
> *sz
) {
788 ep
->data
= mandoc_realloc(ep
->data
, ep
->sz
+ 1);
789 ep
->data
[ep
->sz
] = '\0';
790 start
= &ep
->data
[(int)ep
->rew
];
793 diff
= def
->valsz
- *sz
;
794 memmove(start
+ *sz
+ diff
, start
+ *sz
,
795 (strlen(start
) - *sz
) + 1);
796 memcpy(start
, def
->val
, def
->valsz
);
804 eqn_do_ign1(struct eqn_node
*ep
)
807 if (NULL
== eqn_nextrawtok(ep
, NULL
))
808 EQN_MSG(MANDOCERR_EQNEOF
, ep
);
816 eqn_do_ign2(struct eqn_node
*ep
)
819 if (NULL
== eqn_nextrawtok(ep
, NULL
))
820 EQN_MSG(MANDOCERR_EQNEOF
, ep
);
821 else if (NULL
== eqn_nextrawtok(ep
, NULL
))
822 EQN_MSG(MANDOCERR_EQNEOF
, ep
);
830 eqn_do_tdefine(struct eqn_node
*ep
)
833 if (NULL
== eqn_nextrawtok(ep
, NULL
))
834 EQN_MSG(MANDOCERR_EQNEOF
, ep
);
835 else if (NULL
== eqn_next(ep
, ep
->data
[(int)ep
->cur
], NULL
, 0))
836 EQN_MSG(MANDOCERR_EQNEOF
, ep
);
844 eqn_do_define(struct eqn_node
*ep
)
851 if (NULL
== (start
= eqn_nextrawtok(ep
, &sz
))) {
852 EQN_MSG(MANDOCERR_EQNEOF
, ep
);
857 * Search for a key that already exists.
858 * Create a new key if none is found.
861 if (NULL
== (def
= eqn_def_find(ep
, start
, sz
))) {
862 /* Find holes in string array. */
863 for (i
= 0; i
< (int)ep
->defsz
; i
++)
864 if (0 == ep
->defs
[i
].keysz
)
867 if (i
== (int)ep
->defsz
) {
869 ep
->defs
= mandoc_realloc
870 (ep
->defs
, ep
->defsz
*
871 sizeof(struct eqn_def
));
872 ep
->defs
[i
].key
= ep
->defs
[i
].val
= NULL
;
875 ep
->defs
[i
].keysz
= sz
;
876 ep
->defs
[i
].key
= mandoc_realloc
877 (ep
->defs
[i
].key
, sz
+ 1);
879 memcpy(ep
->defs
[i
].key
, start
, sz
);
880 ep
->defs
[i
].key
[(int)sz
] = '\0';
884 start
= eqn_next(ep
, ep
->data
[(int)ep
->cur
], &sz
, 0);
887 EQN_MSG(MANDOCERR_EQNEOF
, ep
);
892 def
->val
= mandoc_realloc(def
->val
, sz
+ 1);
893 memcpy(def
->val
, start
, sz
);
894 def
->val
[(int)sz
] = '\0';
899 eqn_do_gfont(struct eqn_node
*ep
)
902 if (NULL
== eqn_nextrawtok(ep
, NULL
)) {
903 EQN_MSG(MANDOCERR_EQNEOF
, ep
);
910 eqn_do_gsize(struct eqn_node
*ep
)
915 if (NULL
== (start
= eqn_nextrawtok(ep
, &sz
))) {
916 EQN_MSG(MANDOCERR_EQNEOF
, ep
);
919 ep
->gsize
= mandoc_strntoi(start
, sz
, 10);
924 eqn_do_undef(struct eqn_node
*ep
)
930 if (NULL
== (start
= eqn_nextrawtok(ep
, &sz
))) {
931 EQN_MSG(MANDOCERR_EQNEOF
, ep
);
933 } else if (NULL
!= (def
= eqn_def_find(ep
, start
, sz
)))
939 static struct eqn_def
*
940 eqn_def_find(struct eqn_node
*ep
, const char *key
, size_t sz
)
944 for (i
= 0; i
< (int)ep
->defsz
; i
++)
945 if (ep
->defs
[i
].keysz
&& STRNEQ(ep
->defs
[i
].key
,
946 ep
->defs
[i
].keysz
, key
, sz
))
947 return(&ep
->defs
[i
]);