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

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

version 1.73, 2017/05/17 21:19:32 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 173  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 204  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 388  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 *

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

CVSweb