Lines Matching full:ep

309 	struct eqn_node *ep;  in eqn_alloc()  local
311 ep = mandoc_calloc(1, sizeof(*ep)); in eqn_alloc()
312 ep->gsize = EQN_DEFSIZE; in eqn_alloc()
313 return ep; in eqn_alloc()
317 eqn_reset(struct eqn_node *ep) in eqn_reset() argument
319 free(ep->data); in eqn_reset()
320 ep->data = ep->start = ep->end = NULL; in eqn_reset()
321 ep->sz = ep->toksz = 0; in eqn_reset()
325 eqn_read(struct eqn_node *ep, const char *p) in eqn_read() argument
329 if (ep->data == NULL) { in eqn_read()
330 ep->sz = strlen(p); in eqn_read()
331 ep->data = mandoc_strdup(p); in eqn_read()
333 ep->sz = mandoc_asprintf(&cp, "%s %s", ep->data, p); in eqn_read()
334 free(ep->data); in eqn_read()
335 ep->data = cp; in eqn_read()
337 ep->sz += 1; in eqn_read()
344 eqn_def_find(struct eqn_node *ep) in eqn_def_find() argument
348 for (i = 0; i < (int)ep->defsz; i++) in eqn_def_find()
349 if (ep->defs[i].keysz && STRNEQ(ep->defs[i].key, in eqn_def_find()
350 ep->defs[i].keysz, ep->start, ep->toksz)) in eqn_def_find()
351 return &ep->defs[i]; in eqn_def_find()
358 * MODE_QUOTED: Use *ep->start as the delimiter; the token ends
361 * MODE_QUOTED when *ep->start is '"'.
362 * MODE_NOSUB: If *ep->start is a curly brace, the token ends after it;
372 * a token match, *ep->start is set to an allocated string that the
377 eqn_next(struct eqn_node *ep, enum parse_mode mode) in eqn_next() argument
388 if (ep->end - ep->data >= ep->sublen) in eqn_next()
389 ep->subcnt = 0; in eqn_next()
391 ep->start = ep->end; in eqn_next()
394 switch (*ep->start) { in eqn_next()
396 ep->toksz = 0; in eqn_next()
407 ep->start++; in eqn_next()
413 ep->end = strchr(ep->start + 1, *ep->start); in eqn_next()
414 ep->start++; /* Skip opening quote. */ in eqn_next()
415 if (ep->end == NULL) { in eqn_next()
417 ep->node->line, ep->node->pos, NULL); in eqn_next()
418 ep->end = strchr(ep->start, '\0'); in eqn_next()
421 ep->end = ep->start + 1; in eqn_next()
422 if (*ep->start != '{' && *ep->start != '}') in eqn_next()
423 ep->end += strcspn(ep->end, " ^~\"{}\t"); in eqn_next()
425 ep->toksz = ep->end - ep->start; in eqn_next()
426 if (quoted && *ep->end != '\0') in eqn_next()
427 ep->end++; /* Skip closing quote. */ in eqn_next()
428 while (*ep->end != '\0' && strchr(" \t^~", *ep->end) != NULL) in eqn_next()
429 ep->end++; in eqn_next()
434 if ((def = eqn_def_find(ep)) == NULL) in eqn_next()
436 if (++ep->subcnt > EQN_NEST_MAX) { in eqn_next()
438 ep->node->line, ep->node->pos, NULL); in eqn_next()
443 if ((diff = def->valsz - ep->toksz) > 0) { in eqn_next()
444 start = ep->start - ep->data; in eqn_next()
445 ep->sz += diff; in eqn_next()
446 ep->data = mandoc_realloc(ep->data, ep->sz + 1); in eqn_next()
447 ep->start = ep->data + start; in eqn_next()
448 ep->sublen += diff; in eqn_next()
451 memmove(ep->start + def->valsz, ep->start + ep->toksz, in eqn_next()
452 strlen(ep->start + ep->toksz) + 1); in eqn_next()
453 memcpy(ep->start, def->val, def->valsz); in eqn_next()
454 newlen = ep->start - ep->data + def->valsz; in eqn_next()
455 if (ep->sublen < newlen) in eqn_next()
456 ep->sublen = newlen; in eqn_next()
461 ep->start = mandoc_strndup(ep->start, ep->toksz); in eqn_next()
465 if (STRNEQ(ep->start, ep->toksz, in eqn_next()
470 if (STRNEQ(ep->start, ep->toksz, in eqn_next()
472 mandoc_asprintf(&ep->start, in eqn_next()
477 ep->start = mandoc_strndup(ep->start, ep->toksz); in eqn_next()
479 if (STRNEQ(ep->start, ep->toksz, in eqn_next()
518 eqn_box_alloc(struct eqn_node *ep, struct eqn_box *parent) in eqn_box_alloc() argument
526 bp->size = ep->gsize; in eqn_box_alloc()
545 eqn_box_makebinary(struct eqn_node *ep, struct eqn_box *parent) in eqn_box_makebinary() argument
556 newb = eqn_box_alloc(ep, parent); in eqn_box_makebinary()
570 eqn_delim(struct eqn_node *ep) in eqn_delim() argument
572 if (ep->end[0] == '\0' || ep->end[1] == '\0') { in eqn_delim()
574 ep->node->line, ep->node->pos, "delim"); in eqn_delim()
575 if (ep->end[0] != '\0') in eqn_delim()
576 ep->end++; in eqn_delim()
577 } else if (strncmp(ep->end, "off", 3) == 0) { in eqn_delim()
578 ep->delim = 0; in eqn_delim()
579 ep->end += 3; in eqn_delim()
580 } else if (strncmp(ep->end, "on", 2) == 0) { in eqn_delim()
581 if (ep->odelim && ep->cdelim) in eqn_delim()
582 ep->delim = 1; in eqn_delim()
583 ep->end += 2; in eqn_delim()
585 ep->odelim = *ep->end++; in eqn_delim()
586 ep->cdelim = *ep->end++; in eqn_delim()
587 ep->delim = 1; in eqn_delim()
595 eqn_undef(struct eqn_node *ep) in eqn_undef() argument
599 if (eqn_next(ep, MODE_NOSUB) == EQN_TOK_EOF) { in eqn_undef()
601 ep->node->line, ep->node->pos, "undef"); in eqn_undef()
604 if ((def = eqn_def_find(ep)) == NULL) in eqn_undef()
613 eqn_def(struct eqn_node *ep) in eqn_def() argument
618 if (eqn_next(ep, MODE_NOSUB) == EQN_TOK_EOF) { in eqn_def()
620 ep->node->line, ep->node->pos, "define"); in eqn_def()
628 if ((def = eqn_def_find(ep)) == NULL) { in eqn_def()
630 for (i = 0; i < (int)ep->defsz; i++) in eqn_def()
631 if (0 == ep->defs[i].keysz) in eqn_def()
634 if (i == (int)ep->defsz) { in eqn_def()
635 ep->defsz++; in eqn_def()
636 ep->defs = mandoc_reallocarray(ep->defs, in eqn_def()
637 ep->defsz, sizeof(struct eqn_def)); in eqn_def()
638 ep->defs[i].key = ep->defs[i].val = NULL; in eqn_def()
641 def = ep->defs + i; in eqn_def()
643 def->key = mandoc_strndup(ep->start, ep->toksz); in eqn_def()
644 def->keysz = ep->toksz; in eqn_def()
647 if (eqn_next(ep, MODE_QUOTED) == EQN_TOK_EOF) { in eqn_def()
649 ep->node->line, ep->node->pos, "define %s", def->key); in eqn_def()
657 def->val = mandoc_strndup(ep->start, ep->toksz); in eqn_def()
658 def->valsz = ep->toksz; in eqn_def()
662 eqn_parse(struct eqn_node *ep) in eqn_parse() argument
671 parent = ep->node->eqn; in eqn_parse()
679 if (ep->data == NULL) in eqn_parse()
682 ep->start = ep->end = ep->data; in eqn_parse()
683 ep->sublen = 0; in eqn_parse()
684 ep->subcnt = 0; in eqn_parse()
687 tok = eqn_next(ep, MODE_TOK); in eqn_parse()
690 eqn_undef(ep); in eqn_parse()
694 eqn_def(ep); in eqn_parse()
697 if (eqn_next(ep, MODE_NOSUB) == EQN_TOK_EOF || in eqn_parse()
698 eqn_next(ep, MODE_QUOTED) == EQN_TOK_EOF) in eqn_parse()
700 ep->node->line, ep->node->pos, "tdefine"); in eqn_parse()
703 eqn_delim(ep); in eqn_parse()
706 if (eqn_next(ep, MODE_SUB) == EQN_TOK_EOF) in eqn_parse()
707 mandoc_msg(MANDOCERR_REQ_EMPTY, ep->node->line, in eqn_parse()
708 ep->node->pos, "%s", eqn_toks[tok]); in eqn_parse()
723 mandoc_msg(MANDOCERR_EQN_NOBOX, ep->node->line, in eqn_parse()
724 ep->node->pos, "%s", eqn_toks[tok]); in eqn_parse()
725 cur = eqn_box_alloc(ep, parent); in eqn_parse()
729 parent = eqn_box_makebinary(ep, parent); in eqn_parse()
767 if (eqn_next(ep, MODE_SUB) == EQN_TOK_EOF) in eqn_parse()
768 mandoc_msg(MANDOCERR_REQ_EMPTY, ep->node->line, in eqn_parse()
769 ep->node->pos, "%s", eqn_toks[tok]); in eqn_parse()
782 parent = eqn_box_alloc(ep, parent); in eqn_parse()
805 if (eqn_next(ep, MODE_SUB) == EQN_TOK_EOF) { in eqn_parse()
806 mandoc_msg(MANDOCERR_REQ_EMPTY, ep->node->line, in eqn_parse()
807 ep->node->pos, "%s", eqn_toks[tok]); in eqn_parse()
810 size = mandoc_strntoi(ep->start, ep->toksz, 10); in eqn_parse()
812 mandoc_msg(MANDOCERR_IT_NONUM, ep->node->line, in eqn_parse()
813 ep->node->pos, "%s", eqn_toks[tok]); in eqn_parse()
817 ep->gsize = size; in eqn_parse()
822 parent = eqn_box_alloc(ep, parent); in eqn_parse()
837 mandoc_msg(MANDOCERR_EQN_NOBOX, ep->node->line, in eqn_parse()
838 ep->node->pos, "%s", eqn_toks[tok]); in eqn_parse()
839 cur = eqn_box_alloc(ep, parent); in eqn_parse()
866 parent = eqn_box_makebinary(ep, parent); in eqn_parse()
892 parent = eqn_box_alloc(ep, parent); in eqn_parse()
904 mandoc_msg(MANDOCERR_EQN_NOBOX, ep->node->line, in eqn_parse()
905 ep->node->pos, "%s", eqn_toks[tok]); in eqn_parse()
906 cur = eqn_box_alloc(ep, parent); in eqn_parse()
914 parent = eqn_box_makebinary(ep, parent); in eqn_parse()
931 mandoc_msg(MANDOCERR_BLK_NOTOPEN, ep->node->line, in eqn_parse()
932 ep->node->pos, "%s", eqn_toks[tok]); in eqn_parse()
937 if (eqn_next(ep, MODE_SUB) == EQN_TOK_EOF) { in eqn_parse()
939 ep->node->line, ep->node->pos, in eqn_parse()
944 if (STRNEQ(ep->start, ep->toksz, "ceiling", 7)) in eqn_parse()
946 else if (STRNEQ(ep->start, ep->toksz, "floor", 5)) in eqn_parse()
950 mandoc_strndup(ep->start, ep->toksz); in eqn_parse()
973 eqn_next(ep, MODE_SUB) == EQN_TOK_EOF) { in eqn_parse()
974 mandoc_msg(MANDOCERR_REQ_EMPTY, ep->node->line, in eqn_parse()
975 ep->node->pos, "%s", eqn_toks[tok]); in eqn_parse()
978 parent = eqn_box_alloc(ep, parent); in eqn_parse()
981 if (STRNEQ(ep->start, ep->toksz, "ceiling", 7)) in eqn_parse()
983 else if (STRNEQ(ep->start, ep->toksz, "floor", 5)) in eqn_parse()
987 mandoc_strndup(ep->start, ep->toksz); in eqn_parse()
999 parent = eqn_box_alloc(ep, parent); in eqn_parse()
1008 mandoc_msg(MANDOCERR_IT_STRAY, ep->node->line, in eqn_parse()
1009 ep->node->pos, "%s", eqn_toks[tok]); in eqn_parse()
1012 parent = eqn_box_alloc(ep, cur); in eqn_parse()
1018 parent = eqn_box_alloc(ep, parent); in eqn_parse()
1028 p = ep->start; in eqn_parse()
1036 cur = eqn_box_alloc(ep, parent); in eqn_parse()
1086 split = eqn_box_alloc(ep, parent); in eqn_parse()
1095 nbox = eqn_box_alloc(ep, parent); in eqn_parse()