- *with_mmap = 0;
- off = 0;
- fb->sz = 0;
- fb->buf = NULL;
- for (;;) {
- if (off == fb->sz) {
- if (fb->sz == (1U << 31)) {
- fprintf(stderr, "%s: input too large\n",
- curp->file);
- break;
- }
- if (! resize_buf(fb, 65536))
- break;
- }
- ssz = read(curp->fd, fb->buf + (int)off, fb->sz - off);
- if (ssz == 0) {
- fb->sz = off;
- return(1);
- }
- if (ssz == -1) {
- perror(curp->file);
- break;
- }
- off += (size_t)ssz;
- }
-
- free(fb->buf);
- fb->buf = NULL;
- with_error = 1;
- return(0);
-}
-
-
-static void
-fdesc(struct curparse *curp)
-{
- struct buf ln, blk;
- int i, pos, lnn, lnn_start, with_mmap;
- enum rofferr re;
- struct man *man;
- struct mdoc *mdoc;
- struct roff *roff;
-
- man = NULL;
- mdoc = NULL;
- roff = NULL;
- memset(&ln, 0, sizeof(struct buf));
-
- /*
- * Two buffers: ln and buf. buf is the input file and may be
- * memory mapped. ln is a line buffer and grows on-demand.
- */
-
- if ( ! read_whole_file(curp, &blk, &with_mmap))
- return;
-
- if (NULL == curp->roff)
- curp->roff = roff_init(curp);
- if (NULL == (roff = curp->roff))
- goto bailout;
-
- for (i = 0, lnn = 1; i < (int)blk.sz;) {
- pos = 0;
- lnn_start = lnn;
- while (i < (int)blk.sz) {
- if ('\n' == blk.buf[i]) {
- ++i;
- ++lnn;
- break;
- }
- /* Trailing backslash is like a plain character. */
- if ('\\' != blk.buf[i] || i + 1 == (int)blk.sz) {
- if (pos >= (int)ln.sz)
- if (! resize_buf(&ln, 256))
- goto bailout;
- ln.buf[pos++] = blk.buf[i++];
- continue;
- }
- /* Found an escape and at least one other character. */
- if ('\n' == blk.buf[i + 1]) {
- /* Escaped newlines are skipped over */
- i += 2;
- ++lnn;
- continue;
- }
- if ('"' == blk.buf[i + 1]) {
- i += 2;
- /* Comment, skip to end of line */
- for (; i < (int)blk.sz; ++i) {
- if ('\n' == blk.buf[i]) {
- ++i;
- ++lnn;
- break;
- }
- }
- /* Backout trailing whitespaces */
- for (; pos > 0; --pos) {
- if (ln.buf[pos - 1] != ' ')
- break;
- if (pos > 2 && ln.buf[pos - 2] == '\\')
- break;
- }
- break;
- }
- /* Some other escape sequence, copy and continue. */
- if (pos + 1 >= (int)ln.sz)
- if (! resize_buf(&ln, 256))
- goto bailout;
-
- ln.buf[pos++] = blk.buf[i++];
- ln.buf[pos++] = blk.buf[i++];
- }
-
- if (pos >= (int)ln.sz)
- if (! resize_buf(&ln, 256))
- goto bailout;
- ln.buf[pos] = '\0';
-
- re = roff_parseln(roff, lnn_start, &ln.buf, &ln.sz);
- if (ROFF_IGN == re)
- continue;
- else if (ROFF_ERR == re)
- goto bailout;
-
- /* If unset, assign parser in pset(). */
-
- if ( ! (man || mdoc) && ! pset(ln.buf, pos, curp, &man, &mdoc))
- goto bailout;
-
- /* Pass down into parsers. */
-
- if (man && ! man_parseln(man, lnn_start, ln.buf))
- goto bailout;
- if (mdoc && ! mdoc_parseln(mdoc, lnn_start, ln.buf))
- goto bailout;
- }
-
- /* NOTE a parser may not have been assigned, yet. */
-
- if ( ! (man || mdoc)) {
- fprintf(stderr, "%s: Not a manual\n", curp->file);
- goto bailout;
- }
-
- if (mdoc && ! mdoc_endparse(mdoc))
- goto bailout;
- if (man && ! man_endparse(man))
- goto bailout;
- if (roff && ! roff_endparse(roff))
- goto bailout;