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

Diff for /mandoc/mandocdb.c between version 1.30 and 1.34

version 1.30, 2011/12/09 01:21:10 version 1.34, 2011/12/12 02:00:49
Line 273  main(int argc, char *argv[])
Line 273  main(int argc, char *argv[])
         struct manpaths  dirs;          struct manpaths  dirs;
         enum op          op; /* current operation */          enum op          op; /* current operation */
         const char      *dir;          const char      *dir;
           char            *conf_file;
         char            *cp;          char            *cp;
         char             pbuf[PATH_MAX],          char             pbuf[PATH_MAX],
                          ibuf[MAXPATHLEN], /* index fname */                           ibuf[MAXPATHLEN], /* index fname */
Line 312  main(int argc, char *argv[])
Line 313  main(int argc, char *argv[])
         maxrec = 0;          maxrec = 0;
         op = OP_NEW;          op = OP_NEW;
         dir = NULL;          dir = NULL;
           conf_file = NULL;
   
         while (-1 != (ch = getopt(argc, argv, "ad:u:v")))          while (-1 != (ch = getopt(argc, argv, "aC:d:u:v")))
                 switch (ch) {                  switch (ch) {
                 case ('a'):                  case ('a'):
                         use_all = 1;                          use_all = 1;
                         break;                          break;
                   case ('C'):
                           conf_file = optarg;
                           break;
                 case ('d'):                  case ('d'):
                         dir = optarg;                          dir = optarg;
                         op = OP_UPDATE;                          op = OP_UPDATE;
Line 426  main(int argc, char *argv[])
Line 431  main(int argc, char *argv[])
                         dirs.paths[i] = mandoc_strdup(cp);                          dirs.paths[i] = mandoc_strdup(cp);
                 }                  }
         } else          } else
                 manpath_parse(&dirs, NULL, NULL);                  manpath_parse(&dirs, conf_file, NULL, NULL);
   
         for (i = 0; i < dirs.sz; i++) {          for (i = 0; i < dirs.sz; i++) {
                 ibuf[0] = fbuf[0] = '\0';                  ibuf[0] = fbuf[0] = '\0';
Line 528  index_merge(const struct of *of, struct mparse *mp,
Line 533  index_merge(const struct of *of, struct mparse *mp,
                 fn = of->fname;                  fn = of->fname;
   
                 /*                  /*
                  * Reclaim an empty index record, if available.                   * Try interpreting the file as mdoc(7) or man(7)
                    * source code, unless it is already known to be
                    * formatted.  Fall back to formatted mode.
                  */                   */
   
                 if (reccur > 0) {  
                         --reccur;  
                         rec = recs[(int)reccur];  
                 } else if (maxrec > 0) {  
                         rec = maxrec;  
                         maxrec = 0;  
                 } else  
                         rec++;  
   
                 mparse_reset(mp);                  mparse_reset(mp);
                 hash_reset(&hash);  
                 mdoc = NULL;                  mdoc = NULL;
                 man = NULL;                  man = NULL;
   
                 /*  
                  * Try interpreting the file as mdoc(7) or man(7)  
                  * source code, unless it is already known to be  
                  * formatted.  Fall back to formatted mode.  
                  */  
   
                 if ((MANDOC_SRC & of->src_form ||                  if ((MANDOC_SRC & of->src_form ||
                     ! (MANDOC_FORM & of->src_form)) &&                      ! (MANDOC_FORM & of->src_form)) &&
                     MANDOCLEVEL_FATAL > mparse_readfd(mp, -1, fn))                      MANDOCLEVEL_FATAL > mparse_readfd(mp, -1, fn))
Line 579  index_merge(const struct of *of, struct mparse *mp,
Line 570  index_merge(const struct of *of, struct mparse *mp,
                 if (0 == use_all) {                  if (0 == use_all) {
                         assert(of->sec);                          assert(of->sec);
                         assert(msec);                          assert(msec);
                         if (strcmp(msec, of->sec))                          if (strcasecmp(msec, of->sec))
                                 continue;                                  continue;
   
                         if (NULL == arch) {                          if (NULL == arch) {
                                 if (NULL != of->arch)                                  if (NULL != of->arch)
                                         continue;                                          continue;
                         } else if (NULL == of->arch ||                          } else if (NULL == of->arch ||
                                         strcmp(arch, of->arch))                                          strcasecmp(arch, of->arch))
                                 continue;                                  continue;
                 }                  }
   
Line 625  index_merge(const struct of *of, struct mparse *mp,
Line 616  index_merge(const struct of *of, struct mparse *mp,
   
                 sv = dbuf->len;                  sv = dbuf->len;
   
                 /* Fix the record number in the btree value. */                  /*
                    * Collect keyword/mask pairs.
                    * Each pair will become a new btree node.
                    */
   
                   hash_reset(&hash);
                 if (mdoc)                  if (mdoc)
                         pmdoc_node(hash, buf, dbuf,                          pmdoc_node(hash, buf, dbuf,
                                 mdoc_node(mdoc), mdoc_meta(mdoc));                                  mdoc_node(mdoc), mdoc_meta(mdoc));
Line 636  index_merge(const struct of *of, struct mparse *mp,
Line 631  index_merge(const struct of *of, struct mparse *mp,
                         pformatted(hash, buf, dbuf, of);                          pformatted(hash, buf, dbuf, of);
   
                 /*                  /*
                  * Copy from the in-memory hashtable of pending keywords                   * Reclaim an empty index record, if available.
                  * into the database.                   * Use its record number for all new btree nodes.
                  */                   */
   
                   if (reccur > 0) {
                           --reccur;
                           rec = recs[(int)reccur];
                   } else if (maxrec > 0) {
                           rec = maxrec;
                           maxrec = 0;
                   } else
                           rec++;
                 vbuf.rec = htobe32(rec);                  vbuf.rec = htobe32(rec);
   
                   /*
                    * Copy from the in-memory hashtable of pending
                    * keyword/mask pairs into the database.
                    */
   
                 seq = R_FIRST;                  seq = R_FIRST;
                 while (0 == (ch = (*hash->seq)(hash, &key, &val, seq))) {                  while (0 == (ch = (*hash->seq)(hash, &key, &val, seq))) {
                         seq = R_NEXT;                          seq = R_NEXT;
Line 1288  pformatted(DB *hash, struct buf *buf, struct buf *dbuf
Line 1297  pformatted(DB *hash, struct buf *buf, struct buf *dbuf
         buf_append(buf, of->title);          buf_append(buf, of->title);
         hash_put(hash, buf, TYPE_Nm);          hash_put(hash, buf, TYPE_Nm);
   
         /* Skip to first blank line. */          /* Skip to first blank line. */
   
         while (NULL != (line = fgetln(stream, &len)))          while (NULL != (line = fgetln(stream, &len)))
                 if (len && '\n' == *line)                  if ('\n' == *line)
                         break;                          break;
   
         /*          /*
          * Skip to first section header.           * Assume the first line that is not indented
          * This happens when text is flush-left.           * is the first section header.  Skip to it.
          */           */
   
         while (NULL != (line = fgetln(stream, &len)))          while (NULL != (line = fgetln(stream, &len)))
                 if (len && '\n' != *line && ' ' != *line)                  if ('\n' != *line && ' ' != *line)
                         break;                          break;
   
         /*          /*
          * If no page content can be found or the input line is           * If no page content can be found, or the input line
          * malformed (zer-length or has no trailing newline), reuse the           * is already the next section header, or there is no
          * page title as the page description.           * trailing newline, reuse the page title as the page
            * description.
          */           */
   
         line = fgetln(stream, &len);          line = fgetln(stream, &len);
         if (NULL == line || len == 0 || '\n' != line[(int)len - 1]) {          if (NULL == line || ' ' != *line || '\n' != line[(int)len - 1]) {
                 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 1319  pformatted(DB *hash, struct buf *buf, struct buf *dbuf
Line 1329  pformatted(DB *hash, struct buf *buf, struct buf *dbuf
   
         line[(int)--len] = '\0';          line[(int)--len] = '\0';
   
         /*          /*
          * Skip to the last dash.           * Skip to the first dash.
          * Use the remaining line as the description (no more than 70           * Use the remaining line as the description (no more than 70
          * bytes).           * bytes).
          */           */
Line 1558  ofile_dirbuild(const char *dir, const char* psec, cons
Line 1568  ofile_dirbuild(const char *dir, const char* psec, cons
                         buf[0] = '\0';                          buf[0] = '\0';
                         strlcat(buf, dir, MAXPATHLEN);                          strlcat(buf, dir, MAXPATHLEN);
                         p = strrchr(buf, '/');                          p = strrchr(buf, '/');
                           if (NULL != parch && NULL != p)
                                   for (p--; p > buf; p--)
                                           if ('/' == *p)
                                                   break;
                         if (NULL == p)                          if (NULL == p)
                                 p = buf;                                  p = buf;
                         else                          else
Line 1651  usage(void)
Line 1665  usage(void)
 {  {
   
         fprintf(stderr, "usage: %s [-v] "          fprintf(stderr, "usage: %s [-v] "
                         "[-d dir [files...] |"                          "[-C file] |"
                         " -u dir [files...] |"                          " dir ... |"
                         " dir...]\n", progname);                          " -d dir [file ...] |"
                           " -u dir [file ...]\n", progname);
 }  }

Legend:
Removed from v.1.30  
changed lines
  Added in v.1.34

CVSweb