[BACK]Return to mansearch.c CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / mandoc

Diff for /mandoc/mansearch.c between version 1.71 and 1.75

version 1.71, 2017/04/18 13:57:56 version 1.75, 2017/07/19 14:05:13
Line 104  mansearch(const struct mansearch *search,
Line 104  mansearch(const struct mansearch *search,
         }          }
   
         cur = maxres = 0;          cur = maxres = 0;
         *res = NULL;          if (res != NULL)
                   *res = NULL;
   
         outkey = KEY_Nd;          outkey = KEY_Nd;
         if (search->outkey != NULL)          if (search->outkey != NULL)
Line 155  mansearch(const struct mansearch *search,
Line 156  mansearch(const struct mansearch *search,
                 chdir_status = 1;                  chdir_status = 1;
   
                 if (dbm_open(MANDOC_DB) == -1) {                  if (dbm_open(MANDOC_DB) == -1) {
                         warn("%s/%s", paths->paths[i], MANDOC_DB);                          if (errno != ENOENT)
                                   warn("%s/%s", paths->paths[i], MANDOC_DB);
                         continue;                          continue;
                 }                  }
   
Line 172  mansearch(const struct mansearch *search,
Line 174  mansearch(const struct mansearch *search,
                             lstmatch(search->arch, page->arch) == 0)                              lstmatch(search->arch, page->arch) == 0)
                                 continue;                                  continue;
   
                           if (res == NULL) {
                                   cur = 1;
                                   break;
                           }
                         if (cur + 1 > maxres) {                          if (cur + 1 > maxres) {
                                 maxres += 1024;                                  maxres += 1024;
                                 *res = mandoc_reallocarray(*res,                                  *res = mandoc_reallocarray(*res,
Line 203  mansearch(const struct mansearch *search,
Line 209  mansearch(const struct mansearch *search,
                 if (cur && search->firstmatch)                  if (cur && search->firstmatch)
                         break;                          break;
         }          }
         qsort(*res, cur, sizeof(struct manpage), manpage_compare);          if (res != NULL)
                   qsort(*res, cur, sizeof(struct manpage), manpage_compare);
         if (chdir_status && getcwd_status && chdir(buf) == -1)          if (chdir_status && getcwd_status && chdir(buf) == -1)
                 warn("%s", buf);                  warn("%s", buf);
         exprfree(e);          exprfree(e);
         *sz = cur;          *sz = cur;
         return 1;          return res != NULL || cur;
 }  }
   
 /*  /*
Line 387  static int
Line 394  static int
 manpage_compare(const void *vp1, const void *vp2)  manpage_compare(const void *vp1, const void *vp2)
 {  {
         const struct manpage    *mp1, *mp2;          const struct manpage    *mp1, *mp2;
           const char              *cp1, *cp2;
           size_t                   sz1, sz2;
         int                      diff;          int                      diff;
   
         mp1 = vp1;          mp1 = vp1;
         mp2 = vp2;          mp2 = vp2;
         return (diff = mp2->bits - mp1->bits) ? diff :          if ((diff = mp2->bits - mp1->bits) ||
             (diff = mp1->sec - mp2->sec) ? diff :              (diff = mp1->sec - mp2->sec))
             strcasecmp(mp1->names, mp2->names);                  return diff;
   
           /* Fall back to alphabetic ordering of names. */
           sz1 = strcspn(mp1->names, "(");
           sz2 = strcspn(mp2->names, "(");
           if (sz1 < sz2)
                   sz1 = sz2;
           if ((diff = strncasecmp(mp1->names, mp2->names, sz1)))
                   return diff;
   
           /* For identical names and sections, prefer arch-dependent. */
           cp1 = strchr(mp1->names + sz1, '/');
           cp2 = strchr(mp2->names + sz2, '/');
           return cp1 != NULL && cp2 != NULL ? strcasecmp(cp1, cp2) :
               cp1 != NULL ? -1 : cp2 != NULL ? 1 : 0;
 }  }
   
 static char *  static char *
Line 672  exprterm(const struct mansearch *search, int argc, cha
Line 695  exprterm(const struct mansearch *search, int argc, cha
                 return e;                  return e;
         }          }
   
           if (strcmp("-i", argv[*argi]) == 0 && *argi + 1 < argc) {
                   cs = 0;
                   ++*argi;
           } else
                   cs = 1;
   
         e = mandoc_calloc(1, sizeof(*e));          e = mandoc_calloc(1, sizeof(*e));
         e->type = EXPR_TERM;          e->type = EXPR_TERM;
         e->bits = 0;          e->bits = 0;
Line 690  exprterm(const struct mansearch *search, int argc, cha
Line 719  exprterm(const struct mansearch *search, int argc, cha
          * If needed, request regular expression handling.           * If needed, request regular expression handling.
          */           */
   
         cs = 1;  
         if (search->argmode == ARG_WORD) {          if (search->argmode == ARG_WORD) {
                 e->bits = TYPE_Nm;                  e->bits = TYPE_Nm;
                 e->match.type = DBM_REGEX;                  e->match.type = DBM_REGEX;

Legend:
Removed from v.1.71  
changed lines
  Added in v.1.75

CVSweb