From 3cfd064738dd1ac7b31bfbb5b6eab47b4ea99b2c Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Thu, 20 Dec 2018 21:30:32 +0000 Subject: Move the full responsibility for reporting open(2) errors from mparse_open() to the caller. That is better because only the caller knows its preferred reporting method and format and only the caller has access to all the data that should be included - like the column number in .so processing or the current manpath in makewhatis(8). Moving the mandoc_msg() call out is possible because the caller can call strerror(3) just as easily as mparse_open() can. Move mandoc_msg_setinfilename() closer to the parsing of the file contents, to avoid problems *with* the file (like non-existence, lack of permissions, etc.) getting misreported as problems *in* the file. Fix the column number reported for .so failure: let it point to the beginning of the filename. Taken together, this prevents makewhatis(8) from spewing confusing messages about .so failures to stderr, a bug reported by Raf Czlonka on ports@. It also prevents mandoc(1) from issuing *two* messages for every single .so failure. --- main.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 0acc9c3a..150e808a 100644 --- a/main.c +++ b/main.c @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.313 2018/12/14 05:18:02 schwarze Exp $ */ +/* $Id: main.c,v 1.314 2018/12/20 21:30:32 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2012, 2014-2018 Ingo Schwarze @@ -510,7 +510,6 @@ main(int argc, char *argv[]) } else thisarg = *argv; - mandoc_msg_setinfilename(thisarg); fd = mparse_open(curp.mp, thisarg); if (fd != -1) { if (use_pager) { @@ -523,11 +522,13 @@ main(int argc, char *argv[]) conf.output.tag : *argv; } + mandoc_msg_setinfilename(thisarg); if (resp == NULL || resp->form == FORM_SRC) parse(&curp, fd, thisarg); else passthrough(resp->file, fd, conf.output.synopsisonly); + mandoc_msg_setinfilename(NULL); if (ferror(stdout)) { if (tag_files != NULL) { @@ -545,8 +546,9 @@ main(int argc, char *argv[]) outdata_alloc(&curp); terminal_sepline(curp.outdata); } - } - mandoc_msg_setinfilename(NULL); + } else + mandoc_msg(MANDOCERR_FILE, 0, 0, + "%s", strerror(errno)); if (curp.wstop && mandoc_msg_getrc() != MANDOCLEVEL_OK) break; -- cgit v1.2.3