diff options
author | 2019-05-03 16:14:31 +0000 | |
---|---|---|
committer | 2019-05-03 16:14:31 +0000 | |
commit | 88412cd248dedd2264170a5eca7de2241b4d7a9c (patch) | |
tree | e844b91f36837a7bcdc4d5f068295107b630f1ec | |
parent | Correct ordering when adding after an existing item. (diff) | |
download | wireguard-openbsd-88412cd248dedd2264170a5eca7de2241b4d7a9c.tar.xz wireguard-openbsd-88412cd248dedd2264170a5eca7de2241b4d7a9c.zip |
In man(1) mode with a specific section requested,
try harder to find the best match.
Use this order of preference:
1. The section in both the directory name and the file name matches exactly.
2. The section in the file name matches exactly.
3. The section in the directory name matches exactly.
4. Neither of them matches exactly.
The latter can happen when mansearch() finds substring matches
or when the second .Dt argument mismatches the dir and file names.
Lorenzo Beretta <loreb at github> reported that this caused real
problems on Void Linux, like "man 3 readline" showing readline(3m).
See https://github.com/void-linux/void-packages/issues/9868 for details.
-rw-r--r-- | usr.bin/mandoc/main.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/usr.bin/mandoc/main.c b/usr.bin/mandoc/main.c index 024c8c82dcc..2dc9851f9b0 100644 --- a/usr.bin/mandoc/main.c +++ b/usr.bin/mandoc/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.226 2019/05/03 09:39:01 schwarze Exp $ */ +/* $OpenBSD: main.c,v 1.227 2019/05/03 16:14:31 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2012, 2014-2019 Ingo Schwarze <schwarze@openbsd.org> @@ -119,7 +119,7 @@ main(int argc, char *argv[]) char *conf_file, *defpaths, *auxpaths; char *oarg, *tagarg; unsigned char *uc; - size_t i, sz; + size_t i, sz, ssz; int prio, best_prio; enum outmode outmode; int fd, startdir; @@ -406,7 +406,7 @@ main(int argc, char *argv[]) if (outmode == OUTMODE_ONE) { argc = 1; - best_prio = 20; + best_prio = 40; } else if (outmode == OUTMODE_ALL) argc = (int)sz; @@ -425,10 +425,21 @@ main(int argc, char *argv[]) sec = res[i].file; sec += strcspn(sec, "123456789"); if (sec[0] == '\0') - continue; + continue; /* No section at all. */ prio = sec_prios[sec[0] - '1']; - if (sec[1] != '/') - prio += 10; + if (search.sec != NULL) { + ssz = strlen(search.sec); + if (strncmp(sec, search.sec, ssz) == 0) + sec += ssz; + } else + sec++; /* Prefer without suffix. */ + if (*sec != '/') + prio += 10; /* Wrong dir name. */ + if (search.sec != NULL && + (strlen(sec) <= ssz + 3 || + strcmp(sec + strlen(sec) - ssz, + search.sec) != 0)) + prio += 20; /* Wrong file ext. */ if (prio >= best_prio) continue; best_prio = prio; |