[BACK]Return to mandocdb.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / mandoc

Diff for /src/usr.bin/mandoc/mandocdb.c between version 1.5 and 1.6

version 1.5, 2011/11/13 10:40:52 version 1.6, 2011/11/14 18:52:05
Line 38 
Line 38 
   
 struct  of {  struct  of {
         char             *fname; /* heap-allocated */          char             *fname; /* heap-allocated */
           char             *sec;
           char             *arch;
           char             *title;
         struct of        *next; /* NULL for last one */          struct of        *next; /* NULL for last one */
         struct of        *first; /* first in list */          struct of        *first; /* first in list */
 };  };
Line 79 
Line 82 
 static  void              index_merge(const struct of *, struct mparse *,  static  void              index_merge(const struct of *, struct mparse *,
                                 struct buf *, struct buf *,                                  struct buf *, struct buf *,
                                 DB *, DB *, const char *,                                  DB *, DB *, const char *,
                                 DB *, const char *, int,                                  DB *, const char *, int, int,
                                 recno_t, const recno_t *, size_t);                                  recno_t, const recno_t *, size_t);
 static  void              index_prune(const struct of *, DB *,  static  void              index_prune(const struct of *, DB *,
                                 const char *, DB *, const char *,                                  const char *, DB *, const char *,
                                 int, recno_t *, recno_t **, size_t *);                                  int, recno_t *, recno_t **, size_t *);
 static  void              ofile_argbuild(char *[], int, int, struct of **);  static  void              ofile_argbuild(char *[], int, int, int,
 static  int               ofile_dirbuild(const char *, int, struct of **);                                  struct of **);
   static  int               ofile_dirbuild(const char *, const char *,
                                   const char *, int, int, struct of **);
 static  void              ofile_free(struct of *);  static  void              ofile_free(struct of *);
 static  int               pman_node(MAN_ARGS);  static  int               pman_node(MAN_ARGS);
 static  void              pmdoc_node(MDOC_ARGS);  static  void              pmdoc_node(MDOC_ARGS);
Line 243 
Line 248 
         char             ibuf[MAXPATHLEN], /* index fname */          char             ibuf[MAXPATHLEN], /* index fname */
                          fbuf[MAXPATHLEN];  /* btree fname */                           fbuf[MAXPATHLEN];  /* btree fname */
         int              verb, /* output verbosity */          int              verb, /* output verbosity */
                            use_all, /* use all directories and files */
                          ch, i, flags;                           ch, i, flags;
         DB              *idx, /* index database */          DB              *idx, /* index database */
                         *db, /* keyword database */                          *db, /* keyword database */
Line 266 
Line 272 
                 ++progname;                  ++progname;
   
         verb = 0;          verb = 0;
           use_all = 0;
         of = NULL;          of = NULL;
         db = idx = NULL;          db = idx = NULL;
         mp = NULL;          mp = NULL;
Line 276 
Line 283 
         op = OP_NEW;          op = OP_NEW;
         dir = NULL;          dir = NULL;
   
         while (-1 != (ch = getopt(argc, argv, "d:u:v")))          while (-1 != (ch = getopt(argc, argv, "ad:u:v")))
                 switch (ch) {                  switch (ch) {
                   case ('a'):
                           use_all = 1;
                           break;
                 case ('d'):                  case ('d'):
                         dir = optarg;                          dir = optarg;
                         op = OP_UPDATE;                          op = OP_UPDATE;
Line 344 
Line 354 
                         printf("%s: Opened\n", ibuf);                          printf("%s: Opened\n", ibuf);
                 }                  }
   
                 ofile_argbuild(argv, argc, verb, &of);                  ofile_argbuild(argv, argc, use_all, verb, &of);
                 if (NULL == of)                  if (NULL == of)
                         goto out;                          goto out;
   
Line 355 
Line 365 
   
                 if (OP_UPDATE == op)                  if (OP_UPDATE == op)
                         index_merge(of, mp, &dbuf, &buf, hash,                          index_merge(of, mp, &dbuf, &buf, hash,
                                         db, fbuf, idx, ibuf, verb,                                          db, fbuf, idx, ibuf, use_all,
                                         maxrec, recs, reccur);                                          verb, maxrec, recs, reccur);
   
                 goto out;                  goto out;
         }          }
Line 396 
Line 406 
                 ofile_free(of);                  ofile_free(of);
                 of = NULL;                  of = NULL;
   
                 if ( ! ofile_dirbuild(argv[i], verb, &of))                  if ( ! ofile_dirbuild(argv[i], NULL, NULL,
                                   use_all, verb, &of))
                         exit((int)MANDOCLEVEL_SYSERR);                          exit((int)MANDOCLEVEL_SYSERR);
   
                 if (NULL == of)                  if (NULL == of)
Line 405 
Line 416 
                 of = of->first;                  of = of->first;
   
                 index_merge(of, mp, &dbuf, &buf, hash, db, fbuf,                  index_merge(of, mp, &dbuf, &buf, hash, db, fbuf,
                                 idx, ibuf, verb, maxrec, recs, reccur);                                  idx, ibuf, use_all, verb,
                                   maxrec, recs, reccur);
         }          }
   
 out:  out:
Line 430 
Line 442 
 index_merge(const struct of *of, struct mparse *mp,  index_merge(const struct of *of, struct mparse *mp,
                 struct buf *dbuf, struct buf *buf,                  struct buf *dbuf, struct buf *buf,
                 DB *hash, DB *db, const char *dbf,                  DB *hash, DB *db, const char *dbf,
                 DB *idx, const char *idxf, int verb,                  DB *idx, const char *idxf, int use_all, int verb,
                 recno_t maxrec, const recno_t *recs, size_t reccur)                  recno_t maxrec, const recno_t *recs, size_t reccur)
 {  {
         recno_t          rec;          recno_t          rec;
Line 466 
Line 478 
                 if (NULL == mdoc && NULL == man)                  if (NULL == mdoc && NULL == man)
                         continue;                          continue;
   
                   /*
                    * Make sure the manual section and architecture
                    * agree with the directory where the file is located
                    * or man(1) will not be able to find it.
                    */
   
                 msec = NULL != mdoc ?                  msec = NULL != mdoc ?
                         mdoc_meta(mdoc)->msec : man_meta(man)->msec;                          mdoc_meta(mdoc)->msec : man_meta(man)->msec;
                 mtitle = NULL != mdoc ?  
                         mdoc_meta(mdoc)->title : man_meta(man)->title;  
                 arch = NULL != mdoc ?                  arch = NULL != mdoc ?
                         mdoc_meta(mdoc)->arch : NULL;                          mdoc_meta(mdoc)->arch : NULL;
   
                   if (0 == use_all) {
                           assert(of->sec);
                           assert(msec);
                           if (strcmp(msec, of->sec))
                                   continue;
   
                           if (NULL == arch) {
                                   if (NULL != of->arch)
                                           continue;
                           } else if (NULL == of->arch ||
                                           strcmp(arch, of->arch))
                                   continue;
                   }
   
                 if (NULL == arch)                  if (NULL == arch)
                         arch = "";                          arch = "";
   
                 /*                  /*
                    * Case is relevant for man(1), so use the file name
                    * instead of the (usually) all caps page title,
                    * if the two agree.
                    */
   
                   mtitle = NULL != mdoc ?
                           mdoc_meta(mdoc)->title : man_meta(man)->title;
   
                   assert(of->title);
                   assert(mtitle);
   
                   if (0 == strcasecmp(mtitle, of->title))
                           mtitle = of->title;
                   else if (0 == use_all)
                           continue;
   
                   /*
                  * The index record value consists of a nil-terminated                   * The index record value consists of a nil-terminated
                  * filename, a nil-terminated manual section, and a                   * filename, a nil-terminated manual section, and a
                  * nil-terminated description.  Since the description                   * nil-terminated description.  Since the description
Line 1150 
Line 1197 
 }  }
   
 static void  static void
 ofile_argbuild(char *argv[], int argc, int verb, struct of **of)  ofile_argbuild(char *argv[], int argc, int use_all, int verb,
                   struct of **of)
 {  {
           char             buf[MAXPATHLEN];
           char            *sec, *arch, *title, *p;
         int              i;          int              i;
         struct of       *nof;          struct of       *nof;
   
         for (i = 0; i < argc; i++) {          for (i = 0; i < argc; i++) {
   
                   /*
                    * Analyze the path.
                    */
   
                   if (strlcpy(buf, argv[i], sizeof(buf)) >= sizeof(buf)) {
                           fprintf(stderr, "%s: Path too long\n", argv[i]);
                           continue;
                   }
                   sec = arch = title = NULL;
                   p = strrchr(buf, '\0');
                   while (p-- > buf) {
                           if (NULL == sec && '.' == *p) {
                                   sec = p + 1;
                                   *p = '\0';
                                   continue;
                           }
                           if ('/' != *p)
                                   continue;
                           if (NULL == title) {
                                   title = p + 1;
                                   *p = '\0';
                                   continue;
                           }
                           if (strncmp("man", p + 1, 3))
                                   arch = p + 1;
                           break;
                   }
                   if (NULL == title)
                           title = buf;
   
                   /*
                    * Build the file structure.
                    */
   
                 nof = mandoc_calloc(1, sizeof(struct of));                  nof = mandoc_calloc(1, sizeof(struct of));
                 nof->fname = strdup(argv[i]);                  nof->fname = mandoc_strdup(argv[i]);
                   if (NULL != sec)
                           nof->sec = mandoc_strdup(sec);
                   if (NULL != arch)
                           nof->arch = mandoc_strdup(arch);
                   nof->title = mandoc_strdup(title);
   
                   /*
                    * Add the structure to the list.
                    */
   
                 if (verb > 2)                  if (verb > 2)
                         printf("%s: Scheduling\n", argv[i]);                          printf("%s: Scheduling\n", argv[i]);
                 if (NULL == *of) {                  if (NULL == *of) {
Line 1180 
Line 1275 
  * Pass in a pointer to a NULL structure for the first invocation.   * Pass in a pointer to a NULL structure for the first invocation.
  */   */
 static int  static int
 ofile_dirbuild(const char *dir, int verb, struct of **of)  ofile_dirbuild(const char *dir, const char* psec, const char *parch,
                   int use_all, int verb, struct of **of)
 {  {
         char             buf[MAXPATHLEN];          char             buf[MAXPATHLEN];
         size_t           sz;          size_t           sz;
         DIR             *d;          DIR             *d;
         const char      *fn;          const char      *fn, *sec, *arch;
           char            *suffix;
         struct of       *nof;          struct of       *nof;
         struct dirent   *dp;          struct dirent   *dp;
   
Line 1196 
Line 1293 
   
         while (NULL != (dp = readdir(d))) {          while (NULL != (dp = readdir(d))) {
                 fn = dp->d_name;                  fn = dp->d_name;
   
                   if ('.' == *fn)
                           continue;
   
                 if (DT_DIR == dp->d_type) {                  if (DT_DIR == dp->d_type) {
                         if (0 == strcmp(".", fn))                          sec = psec;
                           arch = parch;
   
                           /*
                            * Don't bother parsing directories
                            * that man(1) won't find.
                            */
   
                           if (NULL == sec) {
                                   if(0 == strncmp("man", fn, 3))
                                           sec = fn + 3;
                                   else if (use_all)
                                           sec = fn;
                                   else
                                           continue;
                           } else if (NULL == arch && (use_all ||
                                           NULL == strchr(fn, '.')))
                                   arch = fn;
                           else if (0 == use_all)
                                 continue;                                  continue;
                         if (0 == strcmp("..", fn))  
                                 continue;  
   
                         buf[0] = '\0';                          buf[0] = '\0';
                         strlcat(buf, dir, MAXPATHLEN);                          strlcat(buf, dir, MAXPATHLEN);
                         strlcat(buf, "/", MAXPATHLEN);                          strlcat(buf, "/", MAXPATHLEN);
                         sz = strlcat(buf, fn, MAXPATHLEN);                          sz = strlcat(buf, fn, MAXPATHLEN);
   
                         if (sz < MAXPATHLEN) {                          if (MAXPATHLEN <= sz) {
                                 if ( ! ofile_dirbuild(buf, verb, of))                                  fprintf(stderr, "%s: Path too long\n", dir);
                                         return(0);                                  return(0);
                                 continue;                          }
                         } else if (sz < MAXPATHLEN)  
                                 continue;                          if (verb > 2)
                                   printf("%s: Scanning\n", buf);
   
                         fprintf(stderr, "%s: Path too long\n", dir);                          if ( ! ofile_dirbuild(buf, sec, arch,
                         return(0);                                          use_all, verb, of))
                                   return(0);
                 }                  }
                 if (DT_REG != dp->d_type)                  if (DT_REG != dp->d_type ||
                       (NULL == psec && !use_all) ||
                       !strcmp(MANDOC_DB, fn) ||
                       !strcmp(MANDOC_IDX, fn))
                         continue;                          continue;
   
                 if (0 == strcmp(MANDOC_DB, fn) ||                  /*
                                 0 == strcmp(MANDOC_IDX, fn))                   * Don't bother parsing files that man(1) won't find.
                         continue;                   */
   
                   suffix = strrchr(fn, '.');
                   if (0 == use_all) {
                           if (NULL == suffix)
                                   continue;
                           if (strcmp(suffix + 1, psec))
                                   continue;
                   }
   
                 buf[0] = '\0';                  buf[0] = '\0';
                 strlcat(buf, dir, MAXPATHLEN);                  strlcat(buf, dir, MAXPATHLEN);
                 strlcat(buf, "/", MAXPATHLEN);                  strlcat(buf, "/", MAXPATHLEN);
Line 1235 
Line 1365 
   
                 nof = mandoc_calloc(1, sizeof(struct of));                  nof = mandoc_calloc(1, sizeof(struct of));
                 nof->fname = mandoc_strdup(buf);                  nof->fname = mandoc_strdup(buf);
                   if (NULL != psec)
                           nof->sec = mandoc_strdup(psec);
                   if (NULL != parch)
                           nof->arch = mandoc_strdup(parch);
                   if (NULL != suffix)
                           *suffix = '\0';
                   nof->title = mandoc_strdup(fn);
   
                 if (verb > 2)                  if (verb > 2)
                         printf("%s: Scheduling\n", buf);                          printf("%s: Scheduling\n", buf);
Line 1261 
Line 1398 
         while (of) {          while (of) {
                 nof = of->next;                  nof = of->next;
                 free(of->fname);                  free(of->fname);
                   free(of->sec);
                   free(of->arch);
                   free(of->title);
                 free(of);                  free(of);
                 of = nof;                  of = nof;
         }          }

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6