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

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

version 1.25, 2011/12/07 01:57:20 version 1.30, 2011/12/09 01:21:10
Line 107  static void    index_merge(const struct of *, struct m
Line 107  static void    index_merge(const struct of *, struct m
                                 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 *,
                                 recno_t *, recno_t **, size_t *);                                  recno_t *, recno_t **, size_t *,
                                   size_t *);
 static  void              ofile_argbuild(int, char *[], struct of **);  static  void              ofile_argbuild(int, char *[], struct of **);
 static  int               ofile_dirbuild(const char *, const char *,  static  int               ofile_dirbuild(const char *, const char *,
                                 const char *, int, struct of **);                                  const char *, int, struct of **);
Line 272  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             ibuf[MAXPATHLEN], /* index fname */          char            *cp;
           char             pbuf[PATH_MAX],
                            ibuf[MAXPATHLEN], /* index fname */
                          fbuf[MAXPATHLEN];  /* btree fname */                           fbuf[MAXPATHLEN];  /* btree fname */
         int              ch, i, flags;          int              ch, i, flags;
         DB              *idx, /* index database */          DB              *idx, /* index database */
Line 388  main(int argc, char *argv[])
Line 391  main(int argc, char *argv[])
                 of = of->first;                  of = of->first;
   
                 index_prune(of, db, fbuf, idx, ibuf,                  index_prune(of, db, fbuf, idx, ibuf,
                                 &maxrec, &recs, &recsz);                                  &maxrec, &recs, &recsz, &reccur);
   
                 /*                  /*
                  * Go to the root of the respective manual tree                   * Go to the root of the respective manual tree
Line 413  main(int argc, char *argv[])
Line 416  main(int argc, char *argv[])
          */           */
   
         if (argc > 0) {          if (argc > 0) {
                 dirs.paths = mandoc_malloc(argc * sizeof(char *));                  dirs.paths = mandoc_calloc(argc, sizeof(char *));
                 dirs.sz = argc;                  dirs.sz = argc;
                 for (i = 0; i < argc; i++)                  for (i = 0; i < argc; i++) {
                         dirs.paths[i] = mandoc_strdup(argv[i]);                          if (NULL == (cp = realpath(argv[i], pbuf))) {
                                   perror(argv[i]);
                                   goto out;
                           }
                           dirs.paths[i] = mandoc_strdup(cp);
                   }
         } else          } else
                 manpath_parse(&dirs, NULL, NULL);                  manpath_parse(&dirs, NULL, NULL);
   
Line 675  index_merge(const struct of *of, struct mparse *mp,
Line 683  index_merge(const struct of *of, struct mparse *mp,
  */   */
 static void  static void
 index_prune(const struct of *ofile, DB *db, const char *dbf,  index_prune(const struct of *ofile, DB *db, const char *dbf,
                 DB *idx, const char *idxf,                  DB *idx, const char *idxf, recno_t *maxrec,
                 recno_t *maxrec, recno_t **recs, size_t *recsz)                  recno_t **recs, size_t *recsz, size_t *reccur)
 {  {
         const struct of *of;          const struct of *of;
         const char      *fn, *cp;          const char      *fn, *cp;
         struct db_val   *vbuf;          struct db_val   *vbuf;
         unsigned         seq, sseq;          unsigned         seq, sseq;
         DBT              key, val;          DBT              key, val;
         size_t           reccur;  
         int              ch;          int              ch;
   
         reccur = 0;          *reccur = 0;
         seq = R_FIRST;          seq = R_FIRST;
         while (0 == (ch = (*idx->seq)(idx, &key, &val, seq))) {          while (0 == (ch = (*idx->seq)(idx, &key, &val, seq))) {
                 seq = R_NEXT;                  seq = R_NEXT;
Line 760  index_prune(const struct of *ofile, DB *db, const char
Line 767  index_prune(const struct of *ofile, DB *db, const char
                 if (ch < 0)                  if (ch < 0)
                         break;                          break;
 cont:  cont:
                 if (reccur >= *recsz) {                  if (*reccur >= *recsz) {
                         *recsz += MANDOC_SLOP;                          *recsz += MANDOC_SLOP;
                         *recs = mandoc_realloc                          *recs = mandoc_realloc
                                 (*recs, *recsz * sizeof(recno_t));                                  (*recs, *recsz * sizeof(recno_t));
                 }                  }
   
                 (*recs)[(int)reccur] = *maxrec;                  (*recs)[(int)*reccur] = *maxrec;
                 reccur++;                  (*reccur)++;
         }          }
   
         if (ch < 0) {          if (ch < 0) {
Line 1281  pformatted(DB *hash, struct buf *buf, struct buf *dbuf
Line 1288  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);
   
         while (NULL != (line = fgetln(stream, &len)) && '\n' != *line)          /* Skip to first blank line. */
                 /* Skip to first blank line. */ ;  
   
         while (NULL != (line = fgetln(stream, &len)) &&          while (NULL != (line = fgetln(stream, &len)))
                         ('\n' == *line || ' ' == *line))                  if (len && '\n' == *line)
                 /* Skip to first section header. */ ;                          break;
   
           /*
            * Skip to first section header.
            * This happens when text is flush-left.
            */
   
           while (NULL != (line = fgetln(stream, &len)))
                   if (len && '\n' != *line && ' ' != *line)
                           break;
   
         /*          /*
          * If no page content can be found,           * If no page content can be found or the input line is
          * reuse the page title as the page description.           * malformed (zer-length or has no trailing newline), reuse the
            * page title as the page description.
          */           */
   
         if (NULL == (line = fgetln(stream, &len))) {          line = fgetln(stream, &len);
           if (NULL == line || len == 0 || '\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);
                 return;                  return;
         }          }
         fclose(stream);  
   
         /*          line[(int)--len] = '\0';
          * If there is a dash, skip to the text following it.  
           /*
            * Skip to the last dash.
            * Use the remaining line as the description (no more than 70
            * bytes).
          */           */
   
         for (p = line, plen = len; plen; p++, plen--)          if (NULL != (p = strstr(line, "- "))) {
                 if ('-' == *p)                  for (p += 2; ' ' == *p || '\b' == *p; p++)
                         break;                          /* Skip to next word. */ ;
         for ( ; plen; p++, plen--)          } else
                 if ('-' != *p && ' ' != *p && 8 != *p)  
                         break;  
         if (0 == plen) {  
                 p = line;                  p = line;
                 plen = len;  
           if ((plen = strlen(p)) > 70) {
                   plen = 70;
                   p[plen] = '\0';
         }          }
   
         /*          /* Strip backspace-encoding from line. */
          * Copy the rest of the line, but no more than 70 bytes.  
          */  
   
         if (70 < plen)          while (NULL != (line = memchr(p, '\b', plen))) {
                 plen = 70;                  len = line - p;
         p[plen-1] = '\0';                  if (0 == len) {
         buf_appendb(dbuf, p, plen);                          memmove(line, line + 1, plen--);
                           continue;
                   }
                   memmove(line - 1, line + 1, plen - len);
                   plen -= 2;
           }
   
           buf_appendb(dbuf, p, plen + 1);
         buf->len = 0;          buf->len = 0;
         buf_appendb(buf, p, plen);          buf_appendb(buf, p, plen + 1);
         hash_put(hash, buf, TYPE_Nd);          hash_put(hash, buf, TYPE_Nd);
           fclose(stream);
 }  }
   
 static void  static void

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

CVSweb