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

Diff for /mandoc/mansearch.c between version 1.53 and 1.54

version 1.53, 2015/01/20 18:21:18 version 1.54, 2015/02/27 16:02:10
Line 24 
Line 24 
 #include <errno.h>  #include <errno.h>
 #include <fcntl.h>  #include <fcntl.h>
 #include <getopt.h>  #include <getopt.h>
   #include <glob.h>
 #include <limits.h>  #include <limits.h>
 #include <regex.h>  #include <regex.h>
 #include <stdio.h>  #include <stdio.h>
Line 412  buildnames(const struct mansearch *search, struct manp
Line 413  buildnames(const struct mansearch *search, struct manp
                 sqlite3 *db, sqlite3_stmt *s,                  sqlite3 *db, sqlite3_stmt *s,
                 uint64_t pageid, const char *path, int form)                  uint64_t pageid, const char *path, int form)
 {  {
         char            *newnames, *prevsec, *prevarch;          glob_t           globinfo;
           char            *firstname, *newnames, *prevsec, *prevarch;
         const char      *oldnames, *sep1, *name, *sec, *sep2, *arch, *fsec;          const char      *oldnames, *sep1, *name, *sec, *sep2, *arch, *fsec;
         size_t           i;          size_t           i;
         int              c;          int              c, globres;
   
         mpage->file = NULL;          mpage->file = NULL;
         mpage->names = NULL;          mpage->names = NULL;
         prevsec = prevarch = NULL;          firstname = prevsec = prevarch = NULL;
         i = 1;          i = 1;
         SQL_BIND_INT64(db, s, i, pageid);          SQL_BIND_INT64(db, s, i, pageid);
         while (SQLITE_ROW == (c = sqlite3_step(s))) {          while (SQLITE_ROW == (c = sqlite3_step(s))) {
Line 494  buildnames(const struct mansearch *search, struct manp
Line 496  buildnames(const struct mansearch *search, struct manp
                 sep2 = *arch == '\0' ? "" : "/";                  sep2 = *arch == '\0' ? "" : "/";
                 mandoc_asprintf(&mpage->file, "%s/%s%s%s%s/%s.%s",                  mandoc_asprintf(&mpage->file, "%s/%s%s%s%s/%s.%s",
                     path, sep1, sec, sep2, arch, name, fsec);                      path, sep1, sec, sep2, arch, name, fsec);
                   if (access(mpage->file, R_OK) != -1)
                           continue;
   
                   /* Handle unusual file name extensions. */
   
                   if (firstname == NULL)
                           firstname = mpage->file;
                   else
                           free(mpage->file);
                   mandoc_asprintf(&mpage->file, "%s/%s%s%s%s/%s.*",
                       path, sep1, sec, sep2, arch, name);
                   globres = glob(mpage->file, 0, NULL, &globinfo);
                   free(mpage->file);
                   mpage->file = globres ? NULL :
                       mandoc_strdup(*globinfo.gl_pathv);
                   globfree(&globinfo);
         }          }
         if (c != SQLITE_DONE)          if (c != SQLITE_DONE)
                 fprintf(stderr, "%s\n", sqlite3_errmsg(db));                  fprintf(stderr, "%s\n", sqlite3_errmsg(db));
         sqlite3_reset(s);          sqlite3_reset(s);
   
           /* If none of the files is usable, use the first name. */
   
           if (mpage->file == NULL)
                   mpage->file = firstname;
           else if (mpage->file != firstname)
                   free(firstname);
   
         /* Append one final section to the names. */          /* Append one final section to the names. */
   

Legend:
Removed from v.1.53  
changed lines
  Added in v.1.54

CVSweb