man-db-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Man-db-devel] [PATCH v2] man(1): add .N names


From: Mihail Konev
Subject: [Man-db-devel] [PATCH v2] man(1): add .N names
Date: Sat, 29 Oct 2016 07:36:22 +0500

`man chmod.2` is now the same as `man 2 chmod`
---
v1 was not sent to the list

 man/man1/man.man1     |  7 +++++-
 src/man.c             | 69 +++++++++++++++++++++++++++++++++++++++++++--------
 src/tests/Makefile.am |  2 +-
 src/tests/man-11      | 45 +++++++++++++++++++++++++++++++++
 4 files changed, 110 insertions(+), 13 deletions(-)
 create mode 100755 src/tests/man-11

diff --git a/man/man1/man.man1 b/man/man1/man.man1
index d71ce6bc38ca..4df2823f1cd7 100644
--- a/man/man1/man.man1
+++ b/man/man1/man.man1
@@ -62,7 +62,7 @@
 .RI [\| dpi \|]\|]
 .RB [\| \-Z \|]
 .RI [\|[\| section \|]
-.IR page \ .\|.\|.\|]\ .\|.\|.\&
+.IR page [.\| section \|]\ \|.\|.\|.\|]\ \.\|.\|.\&
 .\" The apropos command line
 .br
 .B %man%
@@ -285,6 +285,11 @@ Display the manual page for the
 (program)
 .IR ls .
 .TP
+\fB%man% \fIman\fR.\fI7
+Display the manual page for macro package
+.I man
+from section \fI7\fR.
+.TP
 .BI %man%\ \-a \ intro
 Display, in succession, all of the available
 .I intro
diff --git a/src/man.c b/src/man.c
index ebb97dab4bad..250c96d6f745 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.
+ * *ret_name and *ret_section must be able to hold page_name string.
+ * */
+static void split_page_name(const char *page_name,
+                           char **ret_name,
+                           char **ret_section)
+{
+       char *dot;
+       char *name_to_split;
+
+       name_to_split = strdup(page_name);
+       dot = strrchr(name_to_split, '.');
+
+       if (!dot) {
+               strcpy(*ret_name, page_name);
+               *ret_section = NULL;
+       } else if (is_section(dot+1)) {
+               int name_len;
+
+               name_len = dot - name_to_split;
+               memcpy(*ret_name, name_to_split, name_len);
+               (*ret_name)[name_len] = 0;
+               strcpy(*ret_section, dot+1);
+       }
+
+       free(name_to_split);
+}
+
+void locate_page_in_manpath (const char *page_section,
+                            const char *page_name,
+                            struct candidate **candidates,
+                            int *found)
+{
+       char **mp;
+
+       for (mp = manpathlist; *mp; mp++)
+               *found += locate_page (*mp, page_section, page_name, 
candidates);
+}
+
+/*
  * 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)
 {
+       char *page_name, *page_section;
        struct candidate *candidates = NULL, *cand, *candnext;
 
        *found = 0;
@@ -3837,23 +3879,28 @@ static int man (const char *name, int *found)
                return status;
        }
 
-       if (section) {
-               char **mp;
-
-               for (mp = manpathlist; *mp; mp++)
-                       *found += locate_page (*mp, section, name, &candidates);
-       } else {
+       if (section)
+               locate_page_in_manpath(section, name, &candidates, found);
+       else {
                const char **sp;
 
                for (sp = section_list; *sp; sp++) {
-                       char **mp;
-
-                       for (mp = manpathlist; *mp; mp++)
-                               *found += locate_page (*mp, *sp, name,
-                                                      &candidates);
+                       locate_page_in_manpath(*sp, name, &candidates, found);
                }
        }
 
+       page_name = strdup(name);
+       page_section = strdup(name);
+
+       split_page_name(name, &page_name, &page_section);
+
+       if (!*found && page_section)
+               locate_page_in_manpath(page_section, page_name, &candidates,
+                                      found);
+
+       free(page_name);
+       free(page_section);
+
        sort_candidates (&candidates);
 
        if (*found)
diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am
index ba5c3d059650..27a261626c33 100644
--- a/src/tests/Makefile.am
+++ b/src/tests/Makefile.am
@@ -28,7 +28,7 @@ TESTS_ENVIRONMENT = PATH=$(abs_builddir)/..:$$PATH; export 
PATH; \
 AM_LOG_FLAGS = $(SHELL)
 ALL_TESTS = \
        lexgrog-1 \
-       man-1 man-2 man-3 man-4 man-5 man-6 man-7 man-8 man-9 man-10 \
+       man-1 man-2 man-3 man-4 man-5 man-6 man-7 man-8 man-9 man-10 man-11 \
        manconv-1 manconv-2 manconv-3 \
        mandb-1 mandb-2 mandb-3 mandb-4 mandb-5 mandb-6 mandb-7 \
        whatis-1 \
diff --git a/src/tests/man-11 b/src/tests/man-11
new file mode 100755
index 000000000000..ad6bee46137f
--- /dev/null
+++ b/src/tests/man-11
@@ -0,0 +1,45 @@
+#!/bin/sh
+
+# Test for:
+#   man chmod.2 => man 2 chmod
+#   man chmod.2p => man 2p chmod
+
+: ${srcdir=.}
+. "$srcdir/testlib.sh"
+
+: ${MAN=man}
+
+init
+fake_config /usr/share/man
+MANPATH="$tmpdir/usr/share/man"
+export MANPATH
+
+page_name="chmod"
+
+write_page "$page_name" 1 "$tmpdir/usr/share/man/man1/${page_name}.1.gz" \
+        UTF-8 gz '' "$page_name \- coreutils $page_name manual page"
+write_page "$page_name" 2 "$tmpdir/usr/share/man/man2/${page_name}.2.gz" \
+        UTF-8 gz '' "$page_name \- $page_name() syscall manual page"
+
+cat >"$tmpdir/2.exp" <<EOF
+$(pwd -P)/$tmpdir/usr/share/man/man2/${page_name}.2.gz
+EOF
+
+run $MAN -C "$tmpdir/manpath.config" -aw "$page_name".2 >"$tmpdir/2.out"
+expect_pass '"man name.2" is the same as "man 2 name"' \
+        'diff -u "$tmpdir/2.exp" "$tmpdir/2.out"'
+
+(
+        cd "$tmpdir/usr/share/man/man2/"
+        mv "${page_name}.2.gz" "${page_name}.2p.gz"
+)
+
+cat >"$tmpdir/2p.exp" <<EOF
+$(pwd -P)/$tmpdir/usr/share/man/man2/${page_name}.2p.gz
+EOF
+
+run $MAN -C "$tmpdir/manpath.config" -aw "$page_name".2p >"$tmpdir/2p.out"
+expect_pass '"man name.2p" is the same as "man 2p name"' \
+        'diff -u "$tmpdir/2p.exp" "$tmpdir/2p.out"'
+
+finish
-- 
2.9.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]