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

Diff for /mandoc/mandocdb.c between version 1.44 and 1.45

version 1.44, 2012/03/23 05:07:35 version 1.45, 2012/03/23 05:45:45
Line 25 
Line 25 
 #include <assert.h>  #include <assert.h>
 #include <ctype.h>  #include <ctype.h>
 #include <dirent.h>  #include <dirent.h>
   #include <errno.h>
 #include <fcntl.h>  #include <fcntl.h>
 #include <getopt.h>  #include <getopt.h>
 #include <stdio.h>  #include <stdio.h>
Line 55 
Line 56 
 #define MANDOC_SRC        0x1  #define MANDOC_SRC        0x1
 #define MANDOC_FORM       0x2  #define MANDOC_FORM       0x2
   
   #define WARNING(_f, _b, _fmt, _args...) \
           do if (warnings) { \
                   fprintf(stderr, "%s: ", (_b)); \
                   fprintf(stderr, (_fmt), ##_args); \
                   if ('\0' != *(_f)) \
                           fprintf(stderr, ": %s", (_f)); \
                   fprintf(stderr, "\n"); \
           } while (/* CONSTCOND */ 0)
   
 /* Access to the mandoc database on disk. */  /* Access to the mandoc database on disk. */
   
 struct  mdb {  struct  mdb {
Line 130  static void    index_prune(const struct of *, struct m
Line 140  static void    index_prune(const struct of *, struct m
 static  void              ofile_argbuild(int, char *[],  static  void              ofile_argbuild(int, char *[],
                                 struct of **, const char *);                                  struct of **, const char *);
 static  void              ofile_dirbuild(const char *, const char *,  static  void              ofile_dirbuild(const char *, const char *,
                                 const char *, int, struct of **);                                  const char *, int, struct of **, char *);
 static  void              ofile_free(struct of *);  static  void              ofile_free(struct of *);
 static  void              pformatted(DB *, struct buf *, struct buf *,  static  void              pformatted(DB *, struct buf *, struct buf *,
                                 const struct of *, const char *);                                  const struct of *, const char *);
Line 295  main(int argc, char *argv[])
Line 305  main(int argc, char *argv[])
         enum op          op; /* current operation */          enum op          op; /* current operation */
         const char      *dir;          const char      *dir;
         int              ch, i, flags;          int              ch, i, flags;
           char             dirbuf[MAXPATHLEN];
         DB              *hash; /* temporary keyword hashtable */          DB              *hash; /* temporary keyword hashtable */
         BTREEINFO        info; /* btree configuration */          BTREEINFO        info; /* btree configuration */
         size_t           sz1, sz2;          size_t           sz1, sz2;
Line 500  main(int argc, char *argv[])
Line 511  main(int argc, char *argv[])
                  * Search for manuals and fill the new database.                   * Search for manuals and fill the new database.
                  */                   */
   
                 ofile_dirbuild(".", "", "", 0, &of);                  strlcpy(dirbuf, dirs.paths[i], MAXPATHLEN);
                   ofile_dirbuild(".", "", "", 0, &of, dirbuf);
   
                 if (NULL != of) {                  if (NULL != of) {
                         index_merge(of, mp, &dbuf, &buf, hash,                          index_merge(of, mp, &dbuf, &buf, hash,
Line 617  index_merge(const struct of *of, struct mparse *mp,
Line 629  index_merge(const struct of *of, struct mparse *mp,
                 skip = 0;                  skip = 0;
                 assert(of->sec);                  assert(of->sec);
                 assert(msec);                  assert(msec);
                 if (warnings && strcasecmp(msec, of->sec))                  if (strcasecmp(msec, of->sec))
                         fprintf(stderr, "%s: section \"%s\" manual "                          WARNING(fn, basedir, "Section \"%s\" manual "
                                         "in \"%s\" directory\n",                                  "in \"%s\" directory", msec, of->sec);
                                         fn, msec, of->sec);  
   
   
                 /*                  /*
                  * Manual page directories exist for each kernel                   * Manual page directories exist for each kernel
                  * architecture as returned by machine(1).                   * architecture as returned by machine(1).
Line 640  index_merge(const struct of *of, struct mparse *mp,
Line 649  index_merge(const struct of *of, struct mparse *mp,
   
                 assert(of->arch);                  assert(of->arch);
                 assert(march);                  assert(march);
                 if (warnings && strcasecmp(march, of->arch))                  if (strcasecmp(march, of->arch))
                         fprintf(stderr, "%s: architecture \"%s\" manual "                          WARNING(fn, basedir, "Architecture \"%s\" "
                                         "in \"%s\" directory\n",                                  "manual in \"%s\" directory",
                                         fn, march, of->arch);                                  march, of->arch);
   
                 /*                  /*
                  * By default, skip a file if the title given                   * By default, skip a file if the title given
Line 1425  pformatted(DB *hash, struct buf *buf, struct buf *dbuf
Line 1434  pformatted(DB *hash, struct buf *buf, struct buf *dbuf
         size_t           len, plen, titlesz;          size_t           len, plen, titlesz;
   
         if (NULL == (stream = fopen(of->fname, "r"))) {          if (NULL == (stream = fopen(of->fname, "r"))) {
                 if (warnings)                  WARNING(of->fname, basedir, "%s", strerror(errno));
                         perror(of->fname);  
                 return;                  return;
         }          }
   
Line 1481  pformatted(DB *hash, struct buf *buf, struct buf *dbuf
Line 1489  pformatted(DB *hash, struct buf *buf, struct buf *dbuf
                 title[(int)titlesz - 1] = ' ';                  title[(int)titlesz - 1] = ' ';
         }          }
   
   
         /*          /*
          * If no page content can be found, or the input line           * If no page content can be found, or the input line
          * is already the next section header, or there is no           * is already the next section header, or there is no
Line 1490  pformatted(DB *hash, struct buf *buf, struct buf *dbuf
Line 1497  pformatted(DB *hash, struct buf *buf, struct buf *dbuf
          */           */
   
         if (NULL == title || '\0' == *title) {          if (NULL == title || '\0' == *title) {
                 if (warnings)                  WARNING(of->fname, basedir,
                         fprintf(stderr, "%s: Cannot find NAME "                          "Cannot find NAME section");
                                 "section: %s\n", basedir, of->fname);  
                 buf_appendb(dbuf, buf->cp, buf->size);                  buf_appendb(dbuf, buf->cp, buf->size);
                 hash_put(hash, buf, TYPE_Nd);                  hash_put(hash, buf, TYPE_Nd);
                 fclose(stream);                  fclose(stream);
Line 1513  pformatted(DB *hash, struct buf *buf, struct buf *dbuf
Line 1519  pformatted(DB *hash, struct buf *buf, struct buf *dbuf
                 for (p += 2; ' ' == *p || '\b' == *p; p++)                  for (p += 2; ' ' == *p || '\b' == *p; p++)
                         /* Skip to next word. */ ;                          /* Skip to next word. */ ;
         } else {          } else {
                 if (warnings)                  WARNING(of->fname, basedir,
                         fprintf(stderr, "%s/%s: No dash in "                          "No dash in title line");
                                 "title line\n", basedir, of->fname);  
                 p = title;                  p = title;
         }          }
   
Line 1593  ofile_argbuild(int argc, char *argv[], 
Line 1598  ofile_argbuild(int argc, char *argv[], 
                         break;                          break;
                 }                  }
                 if ('\0' == *title) {                  if ('\0' == *title) {
                         if (warnings)                          WARNING(argv[i], basedir,
                                 fprintf(stderr, "%s/%s: Cannot deduce "                                  "Cannot deduce title from filename");
                                         "title from filename\n",  
                                         basedir, argv[i]);  
                         title = buf;                          title = buf;
                 }                  }
   
Line 1636  ofile_argbuild(int argc, char *argv[], 
Line 1639  ofile_argbuild(int argc, char *argv[], 
  */   */
 static void  static void
 ofile_dirbuild(const char *dir, const char* psec, const char *parch,  ofile_dirbuild(const char *dir, const char* psec, const char *parch,
                 int p_src_form, struct of **of)                  int p_src_form, struct of **of, char *basedir)
 {  {
         char             buf[MAXPATHLEN];          char             buf[MAXPATHLEN];
         size_t           sz;          size_t           sz;
Line 1648  ofile_dirbuild(const char *dir, const char* psec, cons
Line 1651  ofile_dirbuild(const char *dir, const char* psec, cons
         int              src_form;          int              src_form;
   
         if (NULL == (d = opendir(dir))) {          if (NULL == (d = opendir(dir))) {
                 if (warnings)                  WARNING("", dir, "%s", strerror(errno));
                         perror(dir);  
                 return;                  return;
         }          }
   
Line 1679  ofile_dirbuild(const char *dir, const char* psec, cons
Line 1681  ofile_dirbuild(const char *dir, const char* psec, cons
                                         src_form |= MANDOC_FORM;                                          src_form |= MANDOC_FORM;
                                         sec = fn + 3;                                          sec = fn + 3;
                                 } else {                                  } else {
                                         if (warnings) fprintf(stderr,                                          WARNING(fn, basedir, "Bad section");
                                             "%s/%s: bad section\n",  
                                             dir, fn);  
                                         if (use_all)                                          if (use_all)
                                                 sec = fn;                                                  sec = fn;
                                         else                                          else
Line 1689  ofile_dirbuild(const char *dir, const char* psec, cons
Line 1689  ofile_dirbuild(const char *dir, const char* psec, cons
                                 }                                  }
                         } else if ('\0' == *arch) {                          } else if ('\0' == *arch) {
                                 if (NULL != strchr(fn, '.')) {                                  if (NULL != strchr(fn, '.')) {
                                         if (warnings) fprintf(stderr,                                          WARNING(fn, basedir, "Bad architecture");
                                             "%s/%s: bad architecture\n",  
                                             dir, fn);  
                                         if (0 == use_all)                                          if (0 == use_all)
                                                 continue;                                                  continue;
                                 }                                  }
                                 arch = fn;                                  arch = fn;
                         } else {                          } else {
                                 if (warnings) fprintf(stderr, "%s/%s: "                                  WARNING(fn, basedir, "Excessive subdirectory");
                                     "excessive subdirectory\n", dir, fn);  
                                 if (0 == use_all)                                  if (0 == use_all)
                                         continue;                                          continue;
                         }                          }
Line 1706  ofile_dirbuild(const char *dir, const char* psec, cons
Line 1703  ofile_dirbuild(const char *dir, const char* psec, cons
                         buf[0] = '\0';                          buf[0] = '\0';
                         strlcat(buf, dir, MAXPATHLEN);                          strlcat(buf, dir, MAXPATHLEN);
                         strlcat(buf, "/", MAXPATHLEN);                          strlcat(buf, "/", MAXPATHLEN);
                           strlcat(basedir, "/", MAXPATHLEN);
                           strlcat(basedir, fn, MAXPATHLEN);
                         sz = strlcat(buf, fn, MAXPATHLEN);                          sz = strlcat(buf, fn, MAXPATHLEN);
   
                         if (MAXPATHLEN <= sz) {                          if (MAXPATHLEN <= sz) {
                                 if (warnings) fprintf(stderr, "%s/%s: "                                  WARNING(fn, basedir, "Path too long");
                                     "path too long\n", dir, fn);  
                                 continue;                                  continue;
                         }                          }
   
                         ofile_dirbuild(buf, sec, arch, src_form, of);                          ofile_dirbuild(buf, sec, arch,
                                           src_form, of, basedir);
   
                           p = strrchr(basedir, '/');
                           *p = '\0';
                         continue;                          continue;
                 }                  }
   
                 if (DT_REG != dp->d_type) {                  if (DT_REG != dp->d_type) {
                         if (warnings)                          WARNING(fn, basedir, "Not a regular file");
                                 fprintf(stderr,  
                                     "%s/%s: not a regular file\n",  
                                     dir, fn);  
                         continue;                          continue;
                 }                  }
                 if (!strcmp(MANDOC_DB, fn) || !strcmp(MANDOC_IDX, fn))                  if (!strcmp(MANDOC_DB, fn) || !strcmp(MANDOC_IDX, fn))
                         continue;                          continue;
                 if ('\0' == *psec) {                  if ('\0' == *psec) {
                         if (warnings)                          WARNING(fn, basedir, "File outside section");
                                 fprintf(stderr,  
                                     "%s/%s: file outside section\n",  
                                     dir, fn);  
                         if (0 == use_all)                          if (0 == use_all)
                                 continue;                                  continue;
                 }                  }
Line 1744  ofile_dirbuild(const char *dir, const char* psec, cons
Line 1740  ofile_dirbuild(const char *dir, const char* psec, cons
   
                 suffix = strrchr(fn, '.');                  suffix = strrchr(fn, '.');
                 if (NULL == suffix) {                  if (NULL == suffix) {
                         if (warnings)                          WARNING(fn, basedir, "No filename suffix");
                                 fprintf(stderr,  
                                     "%s/%s: no filename suffix\n",  
                                     dir, fn);  
                         if (0 == use_all)                          if (0 == use_all)
                                 continue;                                  continue;
                 } else if ((MANDOC_SRC & src_form &&                  } else if ((MANDOC_SRC & src_form &&
                                 strcmp(suffix + 1, psec)) ||                                  strcmp(suffix + 1, psec)) ||
                             (MANDOC_FORM & src_form &&                              (MANDOC_FORM & src_form &&
                                 strcmp(suffix + 1, "0"))) {                                  strcmp(suffix + 1, "0"))) {
                         if (warnings)                          WARNING(fn, basedir, "Wrong filename suffix");
                                 fprintf(stderr,  
                                     "%s/%s: wrong filename suffix\n",  
                                     dir, fn);  
                         if (0 == use_all)                          if (0 == use_all)
                                 continue;                                  continue;
                         if ('0' == suffix[1])                          if ('0' == suffix[1])
Line 1791  ofile_dirbuild(const char *dir, const char* psec, cons
Line 1781  ofile_dirbuild(const char *dir, const char* psec, cons
                         strlcat(buf, "/", MAXPATHLEN);                          strlcat(buf, "/", MAXPATHLEN);
                         sz = strlcat(buf, fn, MAXPATHLEN);                          sz = strlcat(buf, fn, MAXPATHLEN);
                         if (sz >= MAXPATHLEN) {                          if (sz >= MAXPATHLEN) {
                                 if (warnings) fprintf(stderr,                                  WARNING(fn, basedir, "Path too long");
                                     "%s/%s: path too long\n",  
                                     dir, fn);  
                                 continue;                                  continue;
                         }                          }
                         q = strrchr(buf, '.');                          q = strrchr(buf, '.');
Line 1801  ofile_dirbuild(const char *dir, const char* psec, cons
Line 1789  ofile_dirbuild(const char *dir, const char* psec, cons
                                 *q = '\0';                                  *q = '\0';
                                 sz = strlcat(buf, psec, MAXPATHLEN);                                  sz = strlcat(buf, psec, MAXPATHLEN);
                                 if (sz >= MAXPATHLEN) {                                  if (sz >= MAXPATHLEN) {
                                         if (warnings) fprintf(stderr,                                          WARNING(fn, basedir, "Path too long");
                                             "%s/%s: path too long\n",  
                                             dir, fn);  
                                         continue;                                          continue;
                                 }                                  }
                                 if (0 == access(buf, R_OK))                                  if (0 == access(buf, R_OK))
Line 1819  ofile_dirbuild(const char *dir, const char* psec, cons
Line 1805  ofile_dirbuild(const char *dir, const char* psec, cons
                 }                  }
                 sz = strlcat(buf, fn, MAXPATHLEN);                  sz = strlcat(buf, fn, MAXPATHLEN);
                 if (sz >= MAXPATHLEN) {                  if (sz >= MAXPATHLEN) {
                         if (warnings) fprintf(stderr,                          WARNING(fn, basedir, "Path too long");
                             "%s/%s: path too long\n", dir, fn);  
                         continue;                          continue;
                 }                  }
   

Legend:
Removed from v.1.44  
changed lines
  Added in v.1.45

CVSweb