aboutsummaryrefslogtreecommitdiff
path: root/contrib/mandoc/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/mandoc/main.c')
-rw-r--r--contrib/mandoc/main.c52
1 files changed, 10 insertions, 42 deletions
diff --git a/contrib/mandoc/main.c b/contrib/mandoc/main.c
index 57b06c9b9e66..d70ff1ce77b4 100644
--- a/contrib/mandoc/main.c
+++ b/contrib/mandoc/main.c
@@ -1,6 +1,6 @@
-/* $Id: main.c,v 1.361 2022/04/14 16:43:43 schwarze Exp $ */
+/* $Id: main.c,v 1.364 2025/09/24 21:30:20 schwarze Exp $ */
/*
- * Copyright (c) 2010-2012, 2014-2021 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2010-2012,2014-2021,2025 Ingo Schwarze <schwarze@openbsd.org>
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010 Joerg Sonnenberger <joerg@netbsd.org>
*
@@ -109,7 +109,7 @@ static void parse(struct mparse *, int, const char *,
struct outstate *, struct manconf *);
static void passthrough(int, int);
static void process_onefile(struct mparse *, struct manpage *,
- int, struct outstate *, struct manconf *);
+ struct outstate *, struct manconf *);
static void run_pager(struct outstate *, char *);
static pid_t spawn_pager(struct outstate *, char *);
static void usage(enum argmode) __attribute__((__noreturn__));
@@ -144,7 +144,6 @@ main(int argc, char *argv[])
int options; /* Parser options. */
int show_usage; /* Invalid argument: give up. */
int prio, best_prio;
- int startdir;
int c;
enum mandoc_os os_e; /* Check base system conventions. */
enum outmode outmode; /* According to command line. */
@@ -514,7 +513,7 @@ main(int argc, char *argv[])
if (resnsz == 0)
(void)fs_search(&search, &conf.manpath,
*argv, &resn, &resnsz);
- if (resnsz == 0 && strchr(*argv, '/') == NULL) {
+ if (resnsz == 0) {
if (search.arch != NULL &&
arch_valid(search.arch, OSENUM) == 0)
warnx("Unknown architecture \"%s\".",
@@ -529,20 +528,6 @@ main(int argc, char *argv[])
mandoc_msg_setrc(MANDOCLEVEL_BADARG);
continue;
}
- if (resnsz == 0) {
- if (access(*argv, R_OK) == -1) {
- mandoc_msg_setinfilename(*argv);
- mandoc_msg(MANDOCERR_BADARG_BAD,
- 0, 0, "%s", strerror(errno));
- mandoc_msg_setinfilename(NULL);
- continue;
- }
- resnsz = 1;
- resn = mandoc_calloc(resnsz, sizeof(*res));
- resn->file = mandoc_strdup(*argv);
- resn->ipath = SIZE_MAX;
- resn->form = FORM_SRC;
- }
if (outmode != OUTMODE_ONE || resnsz == 1) {
res = mandoc_reallocarray(res,
ressz + resnsz, sizeof(*res));
@@ -559,7 +544,8 @@ main(int argc, char *argv[])
best_prio = 40;
for (ib = i = 0; i < resnsz; i++) {
- sec = resn[i].file;
+ sec = resn[i].file +
+ strlen(conf.manpath.paths[resn[i].ipath]);
sec += strcspn(sec, "123456789");
if (sec[0] == '\0')
continue; /* No section at all. */
@@ -647,23 +633,13 @@ main(int argc, char *argv[])
mchars_alloc();
mp = mparse_alloc(options, os_e, os_s);
- /*
- * Remember the original working directory, if possible.
- * This will be needed if some names on the command line
- * are page names and some are relative file names.
- * Do not error out if the current directory is not
- * readable: Maybe it won't be needed after all.
- */
- startdir = open(".", O_RDONLY | O_DIRECTORY);
for (i = 0; i < ressz; i++) {
- process_onefile(mp, res + i, startdir, &outst, &conf);
+ if (i > 0)
+ mparse_reset(mp);
+ process_onefile(mp, res + i, &outst, &conf);
if (outst.wstop && mandoc_msg_getrc() != MANDOCLEVEL_OK)
break;
}
- if (startdir != -1) {
- (void)fchdir(startdir);
- close(startdir);
- }
if (conf.output.tag != NULL && conf.output.tag_found == 0) {
mandoc_msg(MANDOCERR_TAG, 0, 0, "%s", conf.output.tag);
conf.output.tag = NULL;
@@ -909,7 +885,7 @@ fs_search(const struct mansearch *cfg, const struct manpaths *paths,
}
static void
-process_onefile(struct mparse *mp, struct manpage *resp, int startdir,
+process_onefile(struct mparse *mp, struct manpage *resp,
struct outstate *outst, struct manconf *conf)
{
int fd;
@@ -921,8 +897,6 @@ process_onefile(struct mparse *mp, struct manpage *resp, int startdir,
*/
if (resp->ipath != SIZE_MAX)
(void)chdir(conf->manpath.paths[resp->ipath]);
- else if (startdir != -1)
- (void)fchdir(startdir);
mandoc_msg_setinfilename(resp->file);
if (resp->file != NULL) {
@@ -982,18 +956,12 @@ parse(struct mparse *mp, int fd, const char *file,
struct outstate *outst, struct manconf *conf)
{
static struct manpaths basepaths;
- static int previous;
struct roff_meta *meta;
assert(fd >= 0);
if (file == NULL)
file = "<stdin>";
- if (previous)
- mparse_reset(mp);
- else
- previous = 1;
-
mparse_readfd(mp, fd, file);
if (fd != STDIN_FILENO)
close(fd);