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

Diff for /mandoc/Attic/makewhatis.c between version 1.5 and 1.9

version 1.5, 2011/06/21 13:54:05 version 1.9, 2011/06/22 09:10:36
Line 52 
Line 52 
 #define TYPE_STANDARD   0x20  #define TYPE_STANDARD   0x20
 #define TYPE_AUTHOR     0x40  #define TYPE_AUTHOR     0x40
 #define TYPE_CONFIG     0x80  #define TYPE_CONFIG     0x80
 #define TYPE__MAX       TYPE_CONFIG  #define TYPE_DESC       0x100
   
 /* Buffer for storing growable data. */  /* Buffer for storing growable data. */
   
Line 241  main(int argc, char *argv[])
Line 241  main(int argc, char *argv[])
                         *db, /* keyword database */                          *db, /* keyword database */
                         *hash; /* temporary keyword hashtable */                          *hash; /* temporary keyword hashtable */
         DBT              key, val;          DBT              key, val;
         size_t           sv, rsz;          size_t           sv;
         BTREEINFO        info; /* btree configuration */          BTREEINFO        info; /* btree configuration */
         recno_t          rec; /* current record number */          recno_t          rec; /* current record number */
         struct buf       buf, /* keyword buffer */          struct buf       buf, /* keyword buffer */
Line 306  main(int argc, char *argv[])
Line 306  main(int argc, char *argv[])
          * For the keyword database, open a BTREE database that allows           * For the keyword database, open a BTREE database that allows
          * duplicates.           * duplicates.
          * For the index database, use a standard RECNO database type.           * For the index database, use a standard RECNO database type.
          * For the temporary keyword hashtable, use the HASH database  
          * type.  
          */           */
   
         hash = dbopen(NULL, MANDOC_FLAGS, 0644, DB_HASH, NULL);  
         if (NULL == hash) {  
                 perror("hash");  
                 exit((int)MANDOCLEVEL_SYSERR);  
         }  
   
         memset(&info, 0, sizeof(BTREEINFO));          memset(&info, 0, sizeof(BTREEINFO));
         info.flags = R_DUP;          info.flags = R_DUP;
         db = dbopen(fbbuf, MANDOC_FLAGS, 0644, DB_BTREE, &info);          db = dbopen(fbbuf, MANDOC_FLAGS, 0644, DB_BTREE, &info);
   
         if (NULL == db) {          if (NULL == db) {
                 perror(fbbuf);                  perror(fbbuf);
                 (*hash->close)(hash);  
                 exit((int)MANDOCLEVEL_SYSERR);                  exit((int)MANDOCLEVEL_SYSERR);
         }          }
   
Line 331  main(int argc, char *argv[])
Line 322  main(int argc, char *argv[])
         if (NULL == db) {          if (NULL == db) {
                 perror(ibbuf);                  perror(ibbuf);
                 (*db->close)(db);                  (*db->close)(db);
                 (*hash->close)(hash);  
                 exit((int)MANDOCLEVEL_SYSERR);                  exit((int)MANDOCLEVEL_SYSERR);
         }          }
   
Line 345  main(int argc, char *argv[])
Line 335  main(int argc, char *argv[])
         mp = mparse_alloc(MPARSE_AUTO, MANDOCLEVEL_FATAL, NULL, NULL);          mp = mparse_alloc(MPARSE_AUTO, MANDOCLEVEL_FATAL, NULL, NULL);
   
         rec = 1;          rec = 1;
         rsz = 0;          hash = NULL;
   
         memset(&buf, 0, sizeof(struct buf));          memset(&buf, 0, sizeof(struct buf));
         memset(&dbuf, 0, sizeof(struct buf));          memset(&dbuf, 0, sizeof(struct buf));
Line 358  main(int argc, char *argv[])
Line 348  main(int argc, char *argv[])
         while (NULL != (fn = *argv++)) {          while (NULL != (fn = *argv++)) {
                 mparse_reset(mp);                  mparse_reset(mp);
   
                   if (hash)
                           (*hash->close)(hash);
   
                   hash = dbopen(NULL, MANDOC_FLAGS, 0644, DB_HASH, NULL);
   
                   if (NULL == hash) {
                           perror("hash");
                           exit((int)MANDOCLEVEL_SYSERR);
                   }
   
                 /* Parse and get (non-empty) AST. */                  /* Parse and get (non-empty) AST. */
   
                 if (mparse_readfd(mp, -1, fn) >= MANDOCLEVEL_FATAL) {                  if (mparse_readfd(mp, -1, fn) >= MANDOCLEVEL_FATAL) {
Line 416  main(int argc, char *argv[])
Line 416  main(int argc, char *argv[])
   
                 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;
   
                         memcpy(vbuf, val.data, sizeof(uint32_t));                          memcpy(vbuf, val.data, sizeof(uint32_t));
                         val.size = sizeof(vbuf);                          val.size = sizeof(vbuf);
                         val.data = vbuf;                          val.data = vbuf;
   
                           printf("Added: %s (%zu): 0x%x\n",
                                           (char *)key.data, key.size,
                                           *(int *)val.data);
   
                         dbt_put(db, fbbuf, &key, &val);                          dbt_put(db, fbbuf, &key, &val);
   
                         if ((*hash->del)(hash, &key, 0) < 0) {  
                                 perror("hash");  
                                 exit((int)MANDOCLEVEL_SYSERR);  
                         }  
                         seq = R_NEXT;  
                 }                  }
   
                 if (ch < 0) {                  if (ch < 0) {
Line 447  main(int argc, char *argv[])
Line 449  main(int argc, char *argv[])
                 val.data = dbuf.cp;                  val.data = dbuf.cp;
                 val.size = dbuf.len;                  val.size = dbuf.len;
   
                   printf("Indexed: %s\n", fn);
   
                 dbt_put(idx, ibbuf, &key, &val);                  dbt_put(idx, ibbuf, &key, &val);
                 rec++;                  rec++;
         }          }
   
         (*db->close)(db);          (*db->close)(db);
         (*idx->close)(idx);          (*idx->close)(idx);
         (*hash->close)(hash);          if (hash)
                   (*hash->close)(hash);
   
         mparse_free(mp);          mparse_free(mp);
   
Line 695  static void
Line 700  static void
 pmdoc_Nd(MDOC_ARGS)  pmdoc_Nd(MDOC_ARGS)
 {  {
         int              first;          int              first;
           size_t           sz;
   
         for (first = 1, n = n->child; n; n = n->next) {          for (first = 1, n = n->child; n; n = n->next) {
                 if (MDOC_TEXT != n->type)                  if (MDOC_TEXT != n->type)
                         continue;                          continue;
                 if (first)  
                         buf_appendb(dbuf, n->string, strlen(n->string) + 1);                  if (first) {
                 else                          sz = strlen(n->string) + 1;
                           buf_appendb(dbuf, n->string, sz);
                           buf_appendb(buf, n->string, sz);
                   } else {
                         buf_append(dbuf, n->string);                          buf_append(dbuf, n->string);
                           buf_append(buf, n->string);
                   }
   
                 first = 0;                  first = 0;
         }          }
   
           hash_put(hash, buf, TYPE_DESC);
 }  }
   
 /* ARGSUSED */  /* ARGSUSED */
Line 737  hash_put(DB *db, const struct buf *buf, int mask)
Line 751  hash_put(DB *db, const struct buf *buf, int mask)
         DBT              key, val;          DBT              key, val;
         int              rc;          int              rc;
   
         key.data = buf->cp;          if (buf->len < 2)
   
         if ((key.size = buf->len) < 2)  
                 return;                  return;
   
           key.data = buf->cp;
           key.size = buf->len;
   
         if ((rc = (*db->get)(db, &key, &val, 0)) < 0) {          if ((rc = (*db->get)(db, &key, &val, 0)) < 0) {
                 perror("hash");                  perror("hash");
                 exit((int)MANDOCLEVEL_SYSERR);                  exit((int)MANDOCLEVEL_SYSERR);
Line 751  hash_put(DB *db, const struct buf *buf, int mask)
Line 766  hash_put(DB *db, const struct buf *buf, int mask)
         val.data = &mask;          val.data = &mask;
         val.size = sizeof(int);          val.size = sizeof(int);
   
         /*fprintf(stderr, "Hashing: [%s] (0x%x)\n",  
                         (char *)key.data, mask);*/  
   
         if ((rc = (*db->put)(db, &key, &val, 0)) < 0) {          if ((rc = (*db->put)(db, &key, &val, 0)) < 0) {
                 perror("hash");                  perror("hash");
                 exit((int)MANDOCLEVEL_SYSERR);                  exit((int)MANDOCLEVEL_SYSERR);
Line 764  static void
Line 776  static void
 dbt_put(DB *db, const char *dbn, DBT *key, DBT *val)  dbt_put(DB *db, const char *dbn, DBT *key, DBT *val)
 {  {
   
         if (0 == key->size)  
                 return;  
   
         assert(key->size);          assert(key->size);
         assert(val->size);          assert(val->size);
   
Line 897  pman_node(MAN_ARGS)
Line 906  pman_node(MAN_ARGS)
                         while (' ' == *start)                          while (' ' == *start)
                                 start++;                                  start++;
   
                         buf_appendb(dbuf, start, strlen(start) + 1);                          sz = strlen(start) + 1;
                           buf_appendb(dbuf, start, sz);
                           buf_appendb(buf, start, sz);
                 }                  }
         }          }
   

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

CVSweb