=================================================================== RCS file: /cvs/mandoc/main.c,v retrieving revision 1.297 retrieving revision 1.303 diff -u -p -r1.297 -r1.303 --- mandoc/main.c 2017/07/02 15:31:59 1.297 +++ mandoc/main.c 2018/02/23 16:47:10 1.303 @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.297 2017/07/02 15:31:59 schwarze Exp $ */ +/* $Id: main.c,v 1.303 2018/02/23 16:47:10 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2012, 2014-2017 Ingo Schwarze @@ -111,6 +111,7 @@ static const int sec_prios[] = {1, 4, 5, 8, 6, 3, 7, 2 static char help_arg[] = "help"; static char *help_argv[] = {help_arg, NULL}; static enum mandoclevel rc; +static FILE *mmsg_stream; int @@ -190,6 +191,7 @@ main(int argc, char *argv[]) curp.mmin = MANDOCERR_MAX; curp.outopts = &conf.output; options = MPARSE_SO | MPARSE_UTF8 | MPARSE_LATIN1; + mmsg_stream = stderr; use_pager = 1; tag_files = NULL; @@ -476,12 +478,23 @@ main(int argc, char *argv[]) parse(&curp, fd, *argv); else if (resp->form == FORM_SRC) { /* For .so only; ignore failure. */ - chdir(conf.manpath.paths[resp->ipath]); + (void)chdir(conf.manpath.paths[resp->ipath]); parse(&curp, fd, resp->file); } else passthrough(resp->file, fd, conf.output.synopsisonly); + if (ferror(stdout)) { + if (tag_files != NULL) { + warn("%s", tag_files->ofn); + tag_unlink(); + tag_files = NULL; + } else + warn("stdout"); + rc = MANDOCLEVEL_SYSERR; + break; + } + if (argc > 1 && curp.outtype <= OUTT_UTF8) { if (curp.outdata == NULL) outdata_alloc(&curp); @@ -844,7 +857,11 @@ check_xr(const char *file) continue; if (fs_search(&search, &paths, 1, &xr->name, NULL, &sz)) continue; - mandoc_asprintf(&cp, "Xr %s %s", xr->name, xr->sec); + if (xr->count == 1) + mandoc_asprintf(&cp, "Xr %s %s", xr->name, xr->sec); + else + mandoc_asprintf(&cp, "Xr %s %s (%d times)", + xr->name, xr->sec, xr->count); mmsg(MANDOCERR_XR_BAD, MANDOCLEVEL_STYLE, file, xr->line, xr->pos + 1, cp); free(cp); @@ -990,6 +1007,7 @@ toptions(struct curparse *curp, char *arg) else if (0 == strcmp(arg, "lint")) { curp->outtype = OUTT_LINT; curp->mmin = MANDOCERR_BASE; + mmsg_stream = stdout; } else if (0 == strcmp(arg, "tree")) curp->outtype = OUTT_TREE; else if (0 == strcmp(arg, "man")) @@ -1079,22 +1097,21 @@ mmsg(enum mandocerr t, enum mandoclevel lvl, { const char *mparse_msg; - fprintf(stderr, "%s: %s:", getprogname(), + fprintf(mmsg_stream, "%s: %s:", getprogname(), file == NULL ? "" : file); if (line) - fprintf(stderr, "%d:%d:", line, col + 1); + fprintf(mmsg_stream, "%d:%d:", line, col + 1); - fprintf(stderr, " %s", - t < MANDOCERR_STYLE ? "BASE" : mparse_strlevel(lvl)); + fprintf(mmsg_stream, " %s", mparse_strlevel(lvl)); if ((mparse_msg = mparse_strerror(t)) != NULL) - fprintf(stderr, ": %s", mparse_msg); + fprintf(mmsg_stream, ": %s", mparse_msg); if (msg) - fprintf(stderr, ": %s", msg); + fprintf(mmsg_stream, ": %s", msg); - fputc('\n', stderr); + fputc('\n', mmsg_stream); } static pid_t @@ -1167,7 +1184,7 @@ spawn_pager(struct tag_files *tag_files) if (dup2(tag_files->ofd, STDOUT_FILENO) == -1) err((int)MANDOCLEVEL_SYSERR, "pager stdout"); close(tag_files->ofd); - close(tag_files->tfd); + assert(tag_files->tfd == -1); /* Do not start the pager before controlling the terminal. */