[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Man-db-devel] [PATCH 1/2] man(1): add NAME.[N] names
From: |
Mihail Konev |
Subject: |
[Man-db-devel] [PATCH 1/2] man(1): add NAME.[N] names |
Date: |
Mon, 3 Oct 2016 20:47:26 +0000 |
`man chmod.` is now the same as 'man -a chmod'
`man chmod.2` is now the same as 'man 2 chmod'.
TODO: update manpages
TODO: check for incompatible arguments
---
A possible convenience enhancement.
Assumes there are no pages whose name ends with a dot.
src/man.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 73 insertions(+), 9 deletions(-)
diff --git a/src/man.c b/src/man.c
index ebb97dab4bad..e7b76d66063a 100644
--- a/src/man.c
+++ b/src/man.c
@@ -3810,6 +3810,47 @@ executable_out:
}
/*
+ * Splits a "name[.section]" into { "name", "section" }.
+ * Section would be NULL if not present.
+ * */
+static void split_page_name(const char *page_name,
+ const char **ret_name,
+ const char **ret_section)
+{
+ static char *buf = NULL;
+
+ char *dot;
+
+ *ret_section = NULL;
+ dot = strrchr(page_name, '.');
+ if (!dot)
+ *ret_name = page_name;
+ else {
+ int name_len;
+ char *dot0 = dot;
+
+ while (dot > page_name) {
+ if (dot[-1] != '.')
+ break;
+ dot--;
+ }
+
+ if (is_section(dot0+1) || !dot0[1]) {
+ name_len = dot - page_name;
+ if (!buf)
+ buf = xmalloc(name_len + 1);
+ else
+ buf = xrealloc(buf, name_len + 1);
+
+ memcpy(buf, page_name, name_len);
+ buf[name_len] = 0;
+ *ret_name = buf;
+ *ret_section = dot + 1;
+ }
+ }
+}
+
+/*
* Search for manual pages.
*
* If preformatted manual pages are supported, look for the formatted
@@ -3825,6 +3866,7 @@ executable_out:
*/
static int man (const char *name, int *found)
{
+ const char *page_name, *page_section;
struct candidate *candidates = NULL, *cand, *candnext;
*found = 0;
@@ -3837,20 +3879,42 @@ static int man (const char *name, int *found)
return status;
}
- if (section) {
- char **mp;
+ split_page_name(name, &page_name, &page_section);
- for (mp = manpathlist; *mp; mp++)
- *found += locate_page (*mp, section, name, &candidates);
- } else {
- const char **sp;
+ if (page_section) {
+ if (page_section[0]) {
+ char **mp;
- for (sp = section_list; *sp; sp++) {
+ for (mp = manpathlist; *mp; mp++)
+ *found += locate_page (*mp, page_section,
page_name, &candidates);
+ } else {
+ const char **sp;
+
+ findall = 1;
+ for (sp = section_list; *sp; sp++) {
+ char **mp;
+
+ for (mp = manpathlist; *mp; mp++)
+ *found += locate_page (*mp, *sp,
page_name, &candidates);
+ }
+ }
+ }
+
+ if (!*found) {
+ if (section) {
char **mp;
for (mp = manpathlist; *mp; mp++)
- *found += locate_page (*mp, *sp, name,
- &candidates);
+ *found += locate_page (*mp, section, name,
&candidates);
+ } else {
+ const char **sp;
+
+ for (sp = section_list; *sp; sp++) {
+ char **mp;
+
+ for (mp = manpathlist; *mp; mp++)
+ *found += locate_page (*mp, *sp, name,
&candidates);
+ }
}
}
--
2.9.2
- [Man-db-devel] [PATCH 1/2] man(1): add NAME.[N] names,
Mihail Konev <=