Lines Matching defs:curp

260 choose_parser(struct mparse *curp)
271 if ((format = roff_getformat(curp->roff)) == 0) {
272 cp = curp->primary->buf;
273 ep = cp + curp->primary->sz;
294 if (NULL == curp->pmdoc)
295 curp->pmdoc = mdoc_alloc(
296 curp->roff, curp, curp->defos,
297 MPARSE_QUICK & curp->options ? 1 : 0);
298 assert(curp->pmdoc);
299 curp->mdoc = curp->pmdoc;
305 if (NULL == curp->pman)
306 curp->pman = man_alloc(
307 curp->roff, curp, curp->defos,
308 MPARSE_QUICK & curp->options ? 1 : 0);
309 assert(curp->pman);
310 curp->man = curp->pman;
321 mparse_buf_r(struct mparse *curp, struct buf blk, size_t i, int start)
337 lnn = curp->line;
345 curp->line = lnn;
346 curp->reparse_count = 0;
349 curp->filenc & MPARSE_UTF8 &&
350 curp->filenc & MPARSE_LATIN1)
351 curp->filenc = preconv_cue(&blk, i);
385 if ( ! (curp->filenc && preconv_encode(
386 &blk, &i, &ln, &pos, &curp->filenc))) {
387 mandoc_vmsg(MANDOCERR_CHAR_BAD, curp,
388 curp->line, pos, "0x%x", c);
403 curp, curp->line, pos, "0x%x", c);
460 mandoc_vmsg(MANDOCERR_CHAR_BAD, curp,
461 curp->line, pos, "0x%x", c);
495 if (curp->secondary) {
496 curp->secondary->buf = mandoc_realloc(
497 curp->secondary->buf,
498 curp->secondary->sz + pos + 2);
499 memcpy(curp->secondary->buf +
500 curp->secondary->sz,
502 curp->secondary->sz += pos;
503 curp->secondary->buf
504 [curp->secondary->sz] = '\n';
505 curp->secondary->sz++;
506 curp->secondary->buf
507 [curp->secondary->sz] = '\0';
510 rr = roff_parseln(curp->roff, curp->line, &ln, &of);
514 if (REPARSE_LIMIT >= ++curp->reparse_count)
515 mparse_buf_r(curp, ln, of, 0);
517 mandoc_msg(MANDOCERR_ROFFLOOP, curp,
518 curp->line, pos, NULL);
530 if ( ! (curp->options & MPARSE_SO) &&
532 curp->sodest = mandoc_strdup(ln.buf + of);
541 if (curp->secondary)
542 curp->secondary->sz -= pos + 1;
543 save_file = curp->file;
544 save_child = curp->child;
545 if (mparse_open(curp, &fd, ln.buf + of) ==
547 mparse_readfd(curp, fd, ln.buf + of);
548 curp->file = save_file;
550 curp->file = save_file;
552 curp, curp->line, pos,
560 mparse_buf_r(curp, ln, of, 0);
562 curp->child = save_child;
576 if ( ! (curp->man || curp->mdoc))
577 choose_parser(curp);
589 while ((span = roff_span(curp->roff)) != NULL)
590 if (curp->man == NULL)
591 mdoc_addspan(curp->mdoc, span);
593 man_addspan(curp->man, span);
595 if (curp->man == NULL)
596 mdoc_addeqn(curp->mdoc, roff_eqn(curp->roff));
598 man_addeqn(curp->man, roff_eqn(curp->roff));
599 } else if ((curp->man == NULL ?
600 mdoc_parseln(curp->mdoc, curp->line, ln.buf, of) :
601 man_parseln(curp->man, curp->line, ln.buf, of)) == 2)
618 read_whole_file(struct mparse *curp, const char *file, int fd,
640 mandoc_msg(MANDOCERR_TOOLARGE, curp, 0, 0, NULL);
663 mandoc_msg(MANDOCERR_TOOLARGE, curp,
687 mparse_end(struct mparse *curp)
690 if (curp->mdoc == NULL &&
691 curp->man == NULL &&
692 curp->sodest == NULL) {
693 if (curp->options & MPARSE_MDOC)
694 curp->mdoc = curp->pmdoc;
696 if (curp->pman == NULL)
697 curp->pman = man_alloc(
698 curp->roff, curp, curp->defos,
699 curp->options & MPARSE_QUICK ? 1 : 0);
700 curp->man = curp->pman;
703 if (curp->mdoc)
704 mdoc_endparse(curp->mdoc);
705 if (curp->man)
706 man_endparse(curp->man);
707 roff_endparse(curp->roff);
711 mparse_parse_buffer(struct mparse *curp, struct buf blk, const char *file)
719 mandoc_msg(MANDOCERR_ROFFLOOP, curp, curp->line, 0, NULL);
724 svfile = curp->file;
725 curp->file = file;
726 svprimary = curp->primary;
727 curp->primary = &blk;
728 curp->line = 1;
732 if (curp->filenc & MPARSE_UTF8 && blk.sz > 2 &&
737 curp->filenc &= ~MPARSE_LATIN1;
741 mparse_buf_r(curp, blk, offset, 1);
744 mparse_end(curp);
746 curp->primary = svprimary;
747 curp->file = svfile;
751 mparse_readmem(struct mparse *curp, void *buf, size_t len,
759 mparse_parse_buffer(curp, blk, file);
760 return(curp->file_status);
768 mparse_readfd(struct mparse *curp, int fd, const char *file)
774 if (read_whole_file(curp, file, fd, &blk, &with_mmap)) {
775 save_filenc = curp->filenc;
776 curp->filenc = curp->options &
778 mparse_parse_buffer(curp, blk, file);
779 curp->filenc = save_filenc;
791 mparse_wait(curp);
792 return(curp->file_status);
796 mparse_open(struct mparse *curp, int *fd, const char *file)
802 curp->file = file;
808 curp->child = 0;
827 curp->child = 0;
828 mandoc_msg(MANDOCERR_FILE, curp, 0, 0, strerror(errno));
839 switch (curp->child = fork()) {
860 mparse_wait(struct mparse *curp)
864 if (curp->child == 0)
867 if (waitpid(curp->child, &status, 0) == -1) {
871 curp->child = 0;
873 mandoc_vmsg(MANDOCERR_FILE, curp, 0, 0,
878 mandoc_vmsg(MANDOCERR_FILE, curp, 0, 0,
889 struct mparse *curp;
891 curp = mandoc_calloc(1, sizeof(struct mparse));
893 curp->options = options;
894 curp->wlevel = wlevel;
895 curp->mmsg = mmsg;
896 curp->defos = defos;
898 curp->mchars = mchars;
899 curp->roff = roff_alloc(curp, curp->mchars, options);
900 if (curp->options & MPARSE_MDOC)
901 curp->pmdoc = mdoc_alloc(
902 curp->roff, curp, curp->defos,
903 curp->options & MPARSE_QUICK ? 1 : 0);
904 if (curp->options & MPARSE_MAN)
905 curp->pman = man_alloc(
906 curp->roff, curp, curp->defos,
907 curp->options & MPARSE_QUICK ? 1 : 0);
909 return(curp);
913 mparse_reset(struct mparse *curp)
916 roff_reset(curp->roff);
918 if (curp->mdoc)
919 mdoc_reset(curp->mdoc);
920 if (curp->man)
921 man_reset(curp->man);
922 if (curp->secondary)
923 curp->secondary->sz = 0;
925 curp->file_status = MANDOCLEVEL_OK;
926 curp->mdoc = NULL;
927 curp->man = NULL;
929 free(curp->sodest);
930 curp->sodest = NULL;
934 mparse_free(struct mparse *curp)
937 if (curp->pmdoc)
938 mdoc_free(curp->pmdoc);
939 if (curp->pman)
940 man_free(curp->pman);
941 if (curp->roff)
942 roff_free(curp->roff);
943 if (curp->secondary)
944 free(curp->secondary->buf);
946 free(curp->secondary);
947 free(curp->sodest);
948 free(curp);
952 mparse_result(struct mparse *curp,
956 if (sodest && NULL != (*sodest = curp->sodest)) {
962 *mdoc = curp->mdoc;
964 *man = curp->man;