Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/man Instead of guessing the suffix in the code, use ...



details:   https://anonhg.NetBSD.org/src/rev/e9f5a441307e
branches:  trunk
changeset: 790973:e9f5a441307e
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Oct 28 23:46:17 2013 +0000

description:
Instead of guessing the suffix in the code, use the suffix list previously
loaded via man.conf(5). While there, zap unused iteration code.
(Franco Fichtner)

diffstat:

 usr.bin/man/man.c |  87 ++++++++++++++++++++++++++++++++----------------------
 1 files changed, 51 insertions(+), 36 deletions(-)

diffs (131 lines):

diff -r 1ebae25d2551 -r e9f5a441307e usr.bin/man/man.c
--- a/usr.bin/man/man.c Mon Oct 28 22:52:04 2013 +0000
+++ b/usr.bin/man/man.c Mon Oct 28 23:46:17 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: man.c,v 1.59 2013/10/06 17:14:49 christos Exp $        */
+/*     $NetBSD: man.c,v 1.60 2013/10/28 23:46:17 christos Exp $        */
 
 /*
  * Copyright (c) 1987, 1993, 1994, 1995
@@ -40,7 +40,7 @@
 #if 0
 static char sccsid[] = "@(#)man.c      8.17 (Berkeley) 1/31/95";
 #else
-__RCSID("$NetBSD: man.c,v 1.59 2013/10/06 17:14:49 christos Exp $");
+__RCSID("$NetBSD: man.c,v 1.60 2013/10/28 23:46:17 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -465,8 +465,46 @@
 }
 
 static int
+manual_find_literalfile(struct manstate *mp, char **pv)
+{
+       ENTRY *suffix;
+       int found;
+       char buf[MAXPATHLEN];
+       const char *p;
+       int suflen;
+
+       found = 0;
+
+       /*
+        * Expand both '*' and suffix to force an actual
+        * match via fnmatch(3). Since the only match in pg
+        * is the literal file, the match is genuine.
+        */
+
+       TAILQ_FOREACH(suffix, &mp->buildlist->entrylist, q) {
+               for (p = suffix->s, suflen = 0;
+                   *p != '\0' && !isspace((unsigned char)*p);
+                   ++p)
+                       ++suflen;
+               if (*p == '\0')
+                       continue;
+
+               (void)snprintf(buf, sizeof(buf), "*%.*s", suflen, suffix->s);
+
+               if (!fnmatch(buf, *pv, 0)) {
+                       if (!mp->where)
+                               build_page(p + 1, pv, mp);
+                       found = 1;
+                       break;
+               }
+       }
+
+       return found;
+}
+
+static int
 manual_find_buildkeyword(const char *prefix, const char *escpage,
-       struct manstate *mp, glob_t *pg, size_t cnt)
+    struct manstate *mp, char **pv)
 {
        ENTRY *suffix;
        int found;
@@ -485,10 +523,10 @@
                        continue;
 
                (void)snprintf(buf, sizeof(buf), "%s%s%.*s",
-                              prefix, escpage, suflen, suffix->s);
-               if (!fnmatch(buf, pg->gl_pathv[cnt], 0)) {
+                   prefix, escpage, suflen, suffix->s);
+               if (!fnmatch(buf, *pv, 0)) {
                        if (!mp->where)
-                               build_page(p + 1, &pg->gl_pathv[cnt], mp);
+                               build_page(p + 1, pv, mp);
                        found = 1;
                        break;
                }
@@ -554,35 +592,12 @@
                if (pg->gl_matchc == 0)
                        goto notfound;
 
-               /* clip suffix for the suffix check below */
-               if ((p = strrchr(escpage, '.')) != NULL) {
-                       /* Should get suffixes from the configuration file */
-                       if (strcmp(p, ".gz") == 0 || strcmp(p, ".bz2") == 0 ||
-                           strcmp(p, ".Z") == 0 || strcmp(p, ".xz") == 0) {
-                               *p = '\0';
-                               p = strrchr(escpage, '.');
-                       }
-                       if (p && strchr("0123456789ln", p[1]) != NULL)
-                               *p = '\0';
-               }
-
-               found = 0;
-               for (cnt = pg->gl_pathc - pg->gl_matchc;
-                   cnt < pg->gl_pathc; ++cnt)
-               {
-                       found = manual_find_buildkeyword("", escpage,
-                               mp, pg, cnt);
-                       if (found) {
-                               anyfound = 1;
-                               if (!mp->all) {
-                                       /* Delete any other matches. */
-                                       while (++cnt< pg->gl_pathc)
-                                               *pg->gl_pathv[cnt] = '\0';
-                                       break;
-                               }
-                               continue;
-                       }
-
+               /* literal file only yields one match */
+               cnt = pg->gl_pathc - pg->gl_matchc;
+ 
+               if (manual_find_literalfile(mp, &pg->gl_pathv[cnt])) {
+                       anyfound = 1;
+               } else {
                        /* It's not a man page, forget about it. */
                        *pg->gl_pathv[cnt] = '\0';
                }
@@ -666,7 +681,7 @@
 
                        /* Try the _build keywords next. */
                        found = manual_find_buildkeyword("*/", escpage,
-                               mp, pg, cnt);
+                               mp, &pg->gl_pathv[cnt]);
                        if (found) {
 next:                          anyfound = 1;
                                if (!mp->all) {



Home | Main Index | Thread Index | Old Index