=================================================================== RCS file: /cvs/mandoc/main.c,v retrieving revision 1.312 retrieving revision 1.321 diff -u -p -r1.312 -r1.321 --- mandoc/main.c 2018/12/14 01:18:25 1.312 +++ mandoc/main.c 2019/03/04 18:15:06 1.321 @@ -1,7 +1,7 @@ -/* $Id: main.c,v 1.312 2018/12/14 01:18:25 schwarze Exp $ */ +/* $Id: main.c,v 1.321 2019/03/04 18:15:06 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons - * Copyright (c) 2010-2012, 2014-2018 Ingo Schwarze + * Copyright (c) 2010-2012, 2014-2019 Ingo Schwarze * Copyright (c) 2010 Joerg Sonnenberger * * Permission to use, copy, modify, and distribute this software for any @@ -21,7 +21,6 @@ #include #include #include /* MACHINE */ -#include #include #include @@ -40,6 +39,7 @@ #include #include #include +#include #include #include @@ -123,7 +123,7 @@ main(int argc, char *argv[]) struct manpage *res, *resp; const char *progname, *sec, *thisarg; char *conf_file, *defpaths, *auxpaths; - char *oarg; + char *oarg, *tagarg; unsigned char *uc; size_t i, sz; int prio, best_prio; @@ -148,6 +148,7 @@ main(int argc, char *argv[]) setprogname(progname); #endif + mandoc_msg_setoutfile(stderr); if (strncmp(progname, "mandocdb", 8) == 0 || strcmp(progname, BINM_MAKEWHATIS) == 0) return mandocdb(argc, argv); @@ -308,6 +309,9 @@ main(int argc, char *argv[]) } } + if (curp.outtype != OUTT_TREE || !curp.outopts->noval) + options |= MPARSE_VALIDATE; + if (outmode == OUTMODE_FLN || outmode == OUTMODE_LST || !isatty(STDOUT_FILENO)) @@ -365,6 +369,17 @@ main(int argc, char *argv[]) #endif } + /* + * Use the first argument for -O tag in addition to + * using it as a search term for man(1) or apropos(1). + */ + + if (conf.output.tag != NULL && *conf.output.tag == '\0') { + tagarg = argc > 0 && search.argmode == ARG_EXPR ? + strchr(*argv, '=') : NULL; + conf.output.tag = tagarg == NULL ? *argv : tagarg + 1; + } + /* man(1), whatis(1), apropos(1) */ if (search.argmode != ARG_FILE) { @@ -477,8 +492,10 @@ main(int argc, char *argv[]) curp.mp = mparse_alloc(options, curp.os_e, curp.os_s); if (argc < 1) { - if (use_pager) + if (use_pager) { tag_files = tag_init(); + tag_files->tagname = conf.output.tag; + } thisarg = ""; mandoc_msg_setinfilename(thisarg); parse(&curp, STDIN_FILENO, thisarg); @@ -510,24 +527,21 @@ main(int argc, char *argv[]) } else thisarg = *argv; - mandoc_msg_setinfilename(thisarg); fd = mparse_open(curp.mp, thisarg); if (fd != -1) { if (use_pager) { use_pager = 0; tag_files = tag_init(); - if (conf.output.tag != NULL && - tag_files->tagname == NULL) - tag_files->tagname = - *conf.output.tag != '\0' ? - conf.output.tag : *argv; + tag_files->tagname = conf.output.tag; } + 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 +559,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: %s", thisarg, strerror(errno)); if (curp.wstop && mandoc_msg_getrc() != MANDOCLEVEL_OK) break; @@ -782,7 +797,11 @@ fs_search(const struct mansearch *cfg, const struct ma } if (res != NULL && *ressz == lastsz && strchr(*argv, '/') == NULL) { - if (cfg->sec == NULL) + if (cfg->arch != NULL && + arch_valid(cfg->arch, OSENUM) == 0) + warnx("Unknown architecture \"%s\".", + cfg->arch); + else if (cfg->sec == NULL) warnx("No entry for %s in the manual.", *argv); else @@ -799,7 +818,7 @@ fs_search(const struct mansearch *cfg, const struct ma static void parse(struct curparse *curp, int fd, const char *file) { - struct roff_man *man; + struct roff_meta *meta; /* Begin by parsing the file itself. */ @@ -820,50 +839,46 @@ parse(struct curparse *curp, int fd, const char *file) if (curp->outdata == NULL) outdata_alloc(curp); + else if (curp->outtype == OUTT_HTML) + html_reset(curp); - mparse_result(curp->mp, &man, NULL); + mandoc_xr_reset(); + meta = mparse_result(curp->mp); /* Execute the out device, if it exists. */ - if (man == NULL) - return; - mandoc_xr_reset(); - if (man->macroset == MACROSET_MDOC) { - if (curp->outtype != OUTT_TREE || !curp->outopts->noval) - mdoc_validate(man); + if (meta->macroset == MACROSET_MDOC) { switch (curp->outtype) { case OUTT_HTML: - html_mdoc(curp->outdata, man); + html_mdoc(curp->outdata, meta); break; case OUTT_TREE: - tree_mdoc(curp->outdata, man); + tree_mdoc(curp->outdata, meta); break; case OUTT_MAN: - man_mdoc(curp->outdata, man); + man_mdoc(curp->outdata, meta); break; case OUTT_PDF: case OUTT_ASCII: case OUTT_UTF8: case OUTT_LOCALE: case OUTT_PS: - terminal_mdoc(curp->outdata, man); + terminal_mdoc(curp->outdata, meta); break; case OUTT_MARKDOWN: - markdown_mdoc(curp->outdata, man); + markdown_mdoc(curp->outdata, meta); break; default: break; } } - if (man->macroset == MACROSET_MAN) { - if (curp->outtype != OUTT_TREE || !curp->outopts->noval) - man_validate(man); + if (meta->macroset == MACROSET_MAN) { switch (curp->outtype) { case OUTT_HTML: - html_man(curp->outdata, man); + html_man(curp->outdata, meta); break; case OUTT_TREE: - tree_man(curp->outdata, man); + tree_man(curp->outdata, meta); break; case OUTT_MAN: mparse_copy(curp->mp); @@ -873,7 +888,7 @@ parse(struct curparse *curp, int fd, const char *file) case OUTT_UTF8: case OUTT_LOCALE: case OUTT_PS: - terminal_man(curp->outdata, man); + terminal_man(curp->outdata, meta); break; default: break; @@ -889,7 +904,6 @@ check_xr(void) static struct manpaths paths; struct mansearch search; struct mandoc_xr *xr; - char *cp; size_t sz; if (paths.sz == 0) @@ -908,12 +922,12 @@ check_xr(void) if (fs_search(&search, &paths, 1, &xr->name, NULL, &sz)) continue; if (xr->count == 1) - mandoc_asprintf(&cp, "Xr %s %s", xr->name, xr->sec); + mandoc_msg(MANDOCERR_XR_BAD, xr->line, + xr->pos + 1, "Xr %s %s", xr->name, xr->sec); else - mandoc_asprintf(&cp, "Xr %s %s (%d times)", + mandoc_msg(MANDOCERR_XR_BAD, xr->line, + xr->pos + 1, "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); } }