]> git.cameronkatri.com Git - mandoc.git/blobdiff - mansearch.c
If the layout or data of an individual cell in a tbl(7) contains
[mandoc.git] / mansearch.c
index c889aecf52f2e1e2debff93354e4c1bb342ecd80..59a35771970cb4ab0bae0c4a9b6cbbfd9eaadc3e 100644 (file)
@@ -1,7 +1,7 @@
-/*     $OpenBSD: mansearch.c,v 1.50 2016/07/09 15:23:36 schwarze Exp $ */
+/*     $Id: mansearch.c,v 1.82 2019/07/01 22:56:24 schwarze Exp $ */
 /*
  * Copyright (c) 2012 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2013-2017 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2013-2018 Ingo Schwarze <schwarze@openbsd.org>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -36,7 +36,6 @@
 #include <string.h>
 #include <unistd.h>
 
-#include "mandoc.h"
 #include "mandoc_aux.h"
 #include "mandoc_ohash.h"
 #include "manconf.h"
@@ -171,7 +170,9 @@ mansearch(const struct mansearch *search,
                        page = dbm_page_get(rp->page);
 
                        if (lstmatch(search->sec, page->sect) == 0 ||
-                           lstmatch(search->arch, page->arch) == 0)
+                           lstmatch(search->arch, page->arch) == 0 ||
+                           (search->argmode == ARG_NAME &&
+                            rp->bits <= (int32_t)(NAME_SYN & NAME_MASK)))
                                continue;
 
                        if (res == NULL) {
@@ -186,10 +187,20 @@ mansearch(const struct mansearch *search,
                        mpage = *res + cur;
                        mandoc_asprintf(&mpage->file, "%s/%s",
                            paths->paths[i], page->file + 1);
+                       if (access(chdir_status ? page->file + 1 :
+                           mpage->file, R_OK) == -1) {
+                               warn("%s", mpage->file);
+                               warnx("outdated mandoc.db contains "
+                                   "bogus %s entry, run makewhatis %s",
+                                   page->file + 1, paths->paths[i]);
+                               free(mpage->file);
+                               free(rp);
+                               continue;
+                       }
                        mpage->names = buildnames(page);
                        mpage->output = buildoutput(outkey, page);
+                       mpage->bits = search->firstmatch ? rp->bits : 0;
                        mpage->ipath = i;
-                       mpage->bits = rp->bits;
                        mpage->sec = *page->sect - '0';
                        if (mpage->sec < 0 || mpage->sec > 9)
                                mpage->sec = 10;
@@ -452,14 +463,28 @@ lstlen(const char *cp, size_t sep)
 {
        size_t   sz;
 
-       for (sz = 0;; sz++) {
-               if (cp[0] == '\0') {
-                       if (cp[1] == '\0')
-                               break;
-                       sz += sep - 1;
-               } else if (cp[0] < ' ')
-                       sz--;
-               cp++;
+       for (sz = 0; *cp != '\0'; cp++) {
+
+               /* Skip names appearing only in the SYNOPSIS. */
+               if (*cp <= (char)(NAME_SYN & NAME_MASK)) {
+                       while (*cp != '\0')
+                               cp++;
+                       continue;
+               }
+
+               /* Skip name class markers. */
+               if (*cp < ' ')
+                       cp++;
+
+               /* Print a separator before each but the first string. */
+               if (sz)
+                       sz += sep;
+
+               /* Copy one string. */
+               while (*cp != '\0') {
+                       sz++;
+                       cp++;
+               }
        }
        return sz;
 }
@@ -471,19 +496,34 @@ lstlen(const char *cp, size_t sep)
 static void
 lstcat(char *buf, size_t *i, const char *cp, const char *sep)
 {
-       const char *s;
+       const char      *s;
+       size_t           i_start;
 
-       for (;;) {
-               if (cp[0] == '\0') {
-                       if (cp[1] == '\0')
-                               break;
+       for (i_start = *i; *cp != '\0'; cp++) {
+
+               /* Skip names appearing only in the SYNOPSIS. */
+               if (*cp <= (char)(NAME_SYN & NAME_MASK)) {
+                       while (*cp != '\0')
+                               cp++;
+                       continue;
+               }
+
+               /* Skip name class markers. */
+               if (*cp < ' ')
+                       cp++;
+
+               /* Print a separator before each but the first string. */
+               if (*i > i_start) {
                        s = sep;
                        while (*s != '\0')
                                buf[(*i)++] = *s++;
-               } else if (cp[0] >= ' ')
-                       buf[(*i)++] = cp[0];
-               cp++;
+               }
+
+               /* Copy one string. */
+               while (*cp != '\0')
+                       buf[(*i)++] = *cp++;
        }
+
 }
 
 /*
@@ -733,8 +773,9 @@ exprterm(const struct mansearch *search, int argc, char *argv[], int *argi)
                cs = 0;
        } else if ((val = strpbrk(argv[*argi], "=~")) == NULL) {
                e->bits = TYPE_Nm | TYPE_Nd;
-               e->match.type = DBM_SUB;
-               e->match.str = argv[*argi];
+               e->match.type = DBM_REGEX;
+               val = argv[*argi];
+               cs = 0;
        } else {
                if (val == argv[*argi])
                        e->bits = TYPE_Nm | TYPE_Nd;