=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mandoc/main.c,v retrieving revision 1.214 retrieving revision 1.215 diff -c -r1.214 -r1.215 *** src/usr.bin/mandoc/main.c 2018/12/13 11:55:14 1.214 --- src/usr.bin/mandoc/main.c 2018/12/14 01:17:46 1.215 *************** *** 1,4 **** ! /* $OpenBSD: main.c,v 1.214 2018/12/13 11:55:14 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2012, 2014-2018 Ingo Schwarze --- 1,4 ---- ! /* $OpenBSD: main.c,v 1.215 2018/12/14 01:17:46 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2012, 2014-2018 Ingo Schwarze *************** *** 76,82 **** void *outdata; /* data for output */ char *os_s; /* operating system for display */ int wstop; /* stop after a file with a warning */ - enum mandocerr mmin; /* ignore messages below this */ enum mandoc_os os_e; /* check base system conventions */ enum outt outtype; /* which output to use */ }; --- 76,81 ---- *************** *** 84,90 **** int mandocdb(int, char *[]); ! static void check_xr(const char *); static int fs_lookup(const struct manpaths *, size_t ipath, const char *, const char *, const char *, --- 83,89 ---- int mandocdb(int, char *[]); ! static void check_xr(void); static int fs_lookup(const struct manpaths *, size_t ipath, const char *, const char *, const char *, *************** *** 94,101 **** struct manpage **, size_t *); static int koptions(int *, char *); static void moptions(int *, char *); - static void mmsg(enum mandocerr, enum mandoclevel, - const char *, int, int, const char *); static void outdata_alloc(struct curparse *); static void parse(struct curparse *, int, const char *); static void passthrough(const char *, int, int); --- 93,98 ---- *************** *** 107,114 **** static const int sec_prios[] = {1, 4, 5, 8, 6, 3, 7, 2, 9}; static char help_arg[] = "help"; static char *help_argv[] = {help_arg, NULL}; - static enum mandoclevel rc; - static FILE *mmsg_stream; int --- 104,109 ---- *************** *** 168,177 **** memset(&curp, 0, sizeof(struct curparse)); curp.outtype = OUTT_LOCALE; - curp.mmin = MANDOCERR_MAX; curp.outopts = &conf.output; options = MPARSE_SO | MPARSE_UTF8 | MPARSE_LATIN1; - mmsg_stream = stderr; use_pager = 1; tag_files = NULL; --- 163,170 ---- *************** *** 344,351 **** search.arch = MACHINE; } - rc = MANDOCLEVEL_OK; - /* man(1), whatis(1), apropos(1) */ if (search.argmode != ARG_FILE) { --- 337,342 ---- *************** *** 387,393 **** if (sz == 0) { if (search.argmode != ARG_NAME) warnx("nothing appropriate"); ! rc = MANDOCLEVEL_BADARG; goto out; } --- 378,384 ---- if (sz == 0) { if (search.argmode != ARG_NAME) warnx("nothing appropriate"); ! mandoc_msg_setrc(MANDOCLEVEL_BADARG); goto out; } *************** *** 453,465 **** moptions(&options, auxpaths); mchars_alloc(); ! curp.mp = mparse_alloc(options, curp.mmin, mmsg, ! curp.os_e, curp.os_s); if (argc < 1) { if (use_pager) tag_files = tag_init(); ! parse(&curp, STDIN_FILENO, ""); } /* --- 444,458 ---- moptions(&options, auxpaths); mchars_alloc(); ! curp.mp = mparse_alloc(options, curp.os_e, curp.os_s); if (argc < 1) { if (use_pager) tag_files = tag_init(); ! thisarg = ""; ! mandoc_msg_setinfilename(thisarg); ! parse(&curp, STDIN_FILENO, thisarg); ! mandoc_msg_setinfilename(NULL); } /* *************** *** 483,491 **** (void)chdir(conf.manpath.paths[resp->ipath]); else if (startdir != -1) (void)fchdir(startdir); ! } ! fd = mparse_open(curp.mp, resp != NULL ? resp->file : *argv); if (fd != -1) { if (use_pager) { use_pager = 0; --- 476,487 ---- (void)chdir(conf.manpath.paths[resp->ipath]); else if (startdir != -1) (void)fchdir(startdir); ! thisarg = resp->file; ! } else ! thisarg = *argv; ! mandoc_msg_setinfilename(thisarg); ! fd = mparse_open(curp.mp, thisarg); if (fd != -1) { if (use_pager) { use_pager = 0; *************** *** 497,506 **** conf.output.tag : *argv; } ! if (resp == NULL) ! parse(&curp, fd, *argv); ! else if (resp->form == FORM_SRC) ! parse(&curp, fd, resp->file); else passthrough(resp->file, fd, conf.output.synopsisonly); --- 493,500 ---- conf.output.tag : *argv; } ! if (resp == NULL || resp->form == FORM_SRC) ! parse(&curp, fd, thisarg); else passthrough(resp->file, fd, conf.output.synopsisonly); *************** *** 512,518 **** tag_files = NULL; } else warn("stdout"); ! rc = MANDOCLEVEL_SYSERR; break; } --- 506,512 ---- tag_files = NULL; } else warn("stdout"); ! mandoc_msg_setrc(MANDOCLEVEL_SYSERR); break; } *************** *** 521,530 **** outdata_alloc(&curp); terminal_sepline(curp.outdata); } ! } else if (rc < MANDOCLEVEL_ERROR) ! rc = MANDOCLEVEL_ERROR; ! if (MANDOCLEVEL_OK != rc && curp.wstop) break; if (resp != NULL) --- 515,524 ---- outdata_alloc(&curp); terminal_sepline(curp.outdata); } ! } ! mandoc_msg_setinfilename(NULL); ! if (curp.wstop && mandoc_msg_getrc() != MANDOCLEVEL_OK) break; if (resp != NULL) *************** *** 615,621 **** if (pid == -1) { warn("wait"); ! rc = MANDOCLEVEL_SYSERR; break; } if (!WIFSTOPPED(status)) --- 609,615 ---- if (pid == -1) { warn("wait"); ! mandoc_msg_setrc(MANDOCLEVEL_SYSERR); break; } if (!WIFSTOPPED(status)) *************** *** 625,632 **** } tag_unlink(); } ! ! return (int)rc; } static void --- 619,625 ---- } tag_unlink(); } ! return (int)mandoc_msg_getrc(); } static void *************** *** 776,782 **** static void parse(struct curparse *curp, int fd, const char *file) { - enum mandoclevel rctmp; struct roff_man *man; /* Begin by parsing the file itself. */ --- 769,774 ---- *************** *** 784,801 **** assert(file); assert(fd >= 0); ! rctmp = mparse_readfd(curp->mp, fd, file); if (fd != STDIN_FILENO) close(fd); - if (rc < rctmp) - rc = rctmp; /* * With -Wstop and warnings or errors of at least the requested * level, do not produce output. */ ! if (rctmp != MANDOCLEVEL_OK && curp->wstop) return; if (curp->outdata == NULL) --- 776,791 ---- assert(file); assert(fd >= 0); ! mparse_readfd(curp->mp, fd, file); if (fd != STDIN_FILENO) close(fd); /* * With -Wstop and warnings or errors of at least the requested * level, do not produce output. */ ! if (curp->wstop && mandoc_msg_getrc() != MANDOCLEVEL_OK) return; if (curp->outdata == NULL) *************** *** 859,871 **** break; } } ! if (curp->mmin < MANDOCERR_STYLE) ! check_xr(file); ! mparse_updaterc(curp->mp, &rc); } static void ! check_xr(const char *file) { static struct manpaths paths; struct mansearch search; --- 849,860 ---- break; } } ! if (mandoc_msg_getmin() < MANDOCERR_STYLE) ! check_xr(); } static void ! check_xr(void) { static struct manpaths paths; struct mansearch search; *************** *** 893,900 **** 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); } } --- 882,888 ---- else mandoc_asprintf(&cp, "Xr %s %s (%d times)", xr->name, xr->sec, xr->count); ! mandoc_msg(MANDOCERR_XR_BAD, NULL, xr->line, xr->pos + 1, cp); free(cp); } } *************** *** 994,1001 **** fail: free(line); warn("%s: SYSERR: %s", file, syscall); ! if (rc < MANDOCLEVEL_SYSERR) ! rc = MANDOCLEVEL_SYSERR; } static int --- 982,988 ---- fail: free(line); warn("%s: SYSERR: %s", file, syscall); ! mandoc_msg_setrc(MANDOCLEVEL_SYSERR); } static int *************** *** 1037,1044 **** curp->outtype = OUTT_ASCII; 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")) --- 1024,1031 ---- curp->outtype = OUTT_ASCII; else if (0 == strcmp(arg, "lint")) { curp->outtype = OUTT_LINT; ! mandoc_msg_setoutfile(stdout); ! mandoc_msg_setmin(MANDOCERR_BASE); } else if (0 == strcmp(arg, "tree")) curp->outtype = OUTT_TREE; else if (0 == strcmp(arg, "man")) *************** *** 1089,1117 **** break; case 1: case 2: ! curp->mmin = MANDOCERR_BASE; break; case 3: ! curp->mmin = MANDOCERR_STYLE; break; case 4: ! curp->mmin = MANDOCERR_WARNING; break; case 5: ! curp->mmin = MANDOCERR_ERROR; break; case 6: ! curp->mmin = MANDOCERR_UNSUPP; break; case 7: ! curp->mmin = MANDOCERR_MAX; break; case 8: ! curp->mmin = MANDOCERR_BASE; curp->os_e = MANDOC_OS_OPENBSD; break; case 9: ! curp->mmin = MANDOCERR_BASE; curp->os_e = MANDOC_OS_NETBSD; break; default: --- 1076,1104 ---- break; case 1: case 2: ! mandoc_msg_setmin(MANDOCERR_BASE); break; case 3: ! mandoc_msg_setmin(MANDOCERR_STYLE); break; case 4: ! mandoc_msg_setmin(MANDOCERR_WARNING); break; case 5: ! mandoc_msg_setmin(MANDOCERR_ERROR); break; case 6: ! mandoc_msg_setmin(MANDOCERR_UNSUPP); break; case 7: ! mandoc_msg_setmin(MANDOCERR_MAX); break; case 8: ! mandoc_msg_setmin(MANDOCERR_BASE); curp->os_e = MANDOC_OS_OPENBSD; break; case 9: ! mandoc_msg_setmin(MANDOCERR_BASE); curp->os_e = MANDOC_OS_NETBSD; break; default: *************** *** 1120,1148 **** } } return 1; - } - - static void - mmsg(enum mandocerr t, enum mandoclevel lvl, - const char *file, int line, int col, const char *msg) - { - const char *mparse_msg; - - fprintf(mmsg_stream, "%s: %s:", getprogname(), - file == NULL ? "" : file); - - if (line) - fprintf(mmsg_stream, "%d:%d:", line, col + 1); - - fprintf(mmsg_stream, " %s", mparse_strlevel(lvl)); - - if ((mparse_msg = mparse_strerror(t)) != NULL) - fprintf(mmsg_stream, ": %s", mparse_msg); - - if (msg) - fprintf(mmsg_stream, ": %s", msg); - - fputc('\n', mmsg_stream); } static pid_t --- 1107,1112 ----