- if (-1 == fstat(curp->fd, &st))
- perror(curp->file);
- else if ((size_t)st.st_blksize > sz)
- sz = st.st_blksize;
-
- if (sz > blk->sz) {
- blk->buf = realloc(blk->buf, sz);
- if (NULL == blk->buf) {
- perror(NULL);
- exit(EXIT_FAILURE);
- }
- blk->sz = sz;
- }
-
- /* Fill buf with file blocksize. */
-
- for (lnn = pos = comment = 0; ; ) {
- if (-1 == (ssz = read(curp->fd, blk->buf, sz))) {
- perror(curp->file);
- return(-1);
- } else if (0 == ssz)
- break;
-
- /* Parse the read block into partial or full lines. */
-
- for (i = 0; i < (int)ssz; i++) {
- if (pos >= (int)ln->sz) {
- ln->sz += 256; /* Step-size. */
- ln->buf = realloc(ln->buf, ln->sz);
- if (NULL == ln->buf) {
- perror(NULL);
- return(EXIT_FAILURE);
- }
- }
-
- if ('\n' != blk->buf[i]) {
- if (comment)
- continue;
- ln->buf[pos++] = blk->buf[i];
-
- /* Handle in-line `\"' comments. */
-
- if (1 == pos || '\"' != ln->buf[pos - 1])
- continue;
-
- for (j = pos - 2; j >= 0; j--)
- if ('\\' != ln->buf[j])
- break;
-
- if ( ! ((pos - 2 - j) % 2))
- continue;
-
- comment = 1;
- pos -= 2;
- for (; pos > 0; --pos) {
- if (ln->buf[pos] != ' ')
- break;
- if (ln->buf[pos - 1] == '\\')
- break;
- }
- continue;
- }
-
- /* Handle escaped `\\n' newlines. */
-
- if (pos > 0 && 0 == comment &&
- '\\' == ln->buf[pos - 1]) {
- for (j = pos - 1; j >= 0; j--)
- if ('\\' != ln->buf[j])
- break;
- if ( ! ((pos - j) % 2)) {
- pos--;
- lnn++;
- continue;
- }
- }
-
- ln->buf[pos] = 0;
- lnn++;
-
- /* If unset, assign parser in pset(). */
-
- if ( ! (man || mdoc) && ! pset(ln->buf,
- pos, curp, &man, &mdoc))
- return(-1);
-
- pos = comment = 0;
-
- /* Pass down into parsers. */
-
- if (man && ! man_parseln(man, lnn, ln->buf))
- return(0);
- if (mdoc && ! mdoc_parseln(mdoc, lnn, ln->buf))
- return(0);
- }
- }
-
- /* NOTE a parser may not have been assigned, yet. */
-
- if ( ! (man || mdoc)) {
- fprintf(stderr, "%s: Not a manual\n", curp->file);
- return(0);
- }
-
- if (mdoc && ! mdoc_endparse(mdoc))
- return(0);
- if (man && ! man_endparse(man))
- return(0);