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

Diff for /mandoc/Attic/apropos_db.c between version 1.18 and 1.26

version 1.18, 2011/12/01 23:55:58 version 1.26, 2011/12/16 20:06:58
Line 15 
Line 15 
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF   * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.   * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */   */
   #ifdef HAVE_CONFIG_H
   #include "config.h"
   #endif
   
 #include <assert.h>  #include <assert.h>
 #include <fcntl.h>  #include <fcntl.h>
 #include <regex.h>  #include <regex.h>
Line 24 
Line 28 
 #include <string.h>  #include <string.h>
 #include <unistd.h>  #include <unistd.h>
   
 #ifdef __linux__  #if defined(__linux__)
   # include <endian.h>
 # include <db_185.h>  # include <db_185.h>
   #elif defined(__APPLE__)
   # include <libkern/OSByteOrder.h>
   # include <db.h>
 #else  #else
 # include <db.h>  # include <db.h>
 #endif  #endif
Line 109  static const struct type types[] = {
Line 117  static const struct type types[] = {
         { TYPE_Va, "Va" },          { TYPE_Va, "Va" },
         { TYPE_Va, "Vt" },          { TYPE_Va, "Vt" },
         { TYPE_Xr, "Xr" },          { TYPE_Xr, "Xr" },
         { INT_MAX, "any" },          { UINT64_MAX, "any" },
         { 0, NULL }          { 0, NULL }
 };  };
   
Line 189  btree_read(const DBT *k, const DBT *v, 
Line 197  btree_read(const DBT *k, const DBT *v, 
 static size_t  static size_t
 norm_utf8(unsigned int cp, char out[7])  norm_utf8(unsigned int cp, char out[7])
 {  {
         size_t           rc;          int              rc;
   
         rc = 0;          rc = 0;
   
Line 230  norm_utf8(unsigned int cp, char out[7])
Line 238  norm_utf8(unsigned int cp, char out[7])
                 return(0);                  return(0);
   
         out[rc] = '\0';          out[rc] = '\0';
         return(rc);          return((size_t)rc);
 }  }
   
 /*  /*
Line 357  index_read(const DBT *key, const DBT *val, int index,
Line 365  index_read(const DBT *key, const DBT *val, int index,
 {  {
         size_t           left;          size_t           left;
         char            *np, *cp;          char            *np, *cp;
           char             type;
   
 #define INDEX_BREAD(_dst) \  #define INDEX_BREAD(_dst) \
         do { \          do { \
Line 367  index_read(const DBT *key, const DBT *val, int index,
Line 376  index_read(const DBT *key, const DBT *val, int index,
                 cp = np + 1; \                  cp = np + 1; \
         } while (/* CONSTCOND */ 0)          } while (/* CONSTCOND */ 0)
   
         left = val->size;          if (0 == (left = val->size))
         cp = (char *)val->data;                  return(0);
   
           cp = val->data;
         rec->res.rec = *(recno_t *)key->data;          rec->res.rec = *(recno_t *)key->data;
         rec->res.volume = index;          rec->res.volume = index;
   
         INDEX_BREAD(rec->res.type);          if ('d' == (type = *cp++))
                   rec->res.type = RESTYPE_MDOC;
           else if ('a' == type)
                   rec->res.type = RESTYPE_MAN;
           else if ('c' == type)
                   rec->res.type = RESTYPE_CAT;
           else
                   return(0);
   
           left--;
         INDEX_BREAD(rec->res.file);          INDEX_BREAD(rec->res.file);
         INDEX_BREAD(rec->res.cat);          INDEX_BREAD(rec->res.cat);
         INDEX_BREAD(rec->res.title);          INDEX_BREAD(rec->res.title);
Line 533  single_search(struct rectree *tree, const struct opts 
Line 552  single_search(struct rectree *tree, const struct opts 
   
                 if (opts->cat && strcasecmp(opts->cat, r.res.cat))                  if (opts->cat && strcasecmp(opts->cat, r.res.cat))
                         continue;                          continue;
                 if (opts->arch && strcasecmp(opts->arch, r.res.arch))  
                         continue;  
   
                   if (opts->arch && *r.res.arch)
                           if (strcasecmp(opts->arch, r.res.arch))
                                   continue;
   
                 tree->node = rs = mandoc_realloc                  tree->node = rs = mandoc_realloc
                         (rs, (tree->len + 1) * sizeof(struct rec));                          (rs, (tree->len + 1) * sizeof(struct rec));
   
                 memcpy(&rs[tree->len], &r, sizeof(struct rec));                  memcpy(&rs[tree->len], &r, sizeof(struct rec));
                   memset(&r, 0, sizeof(struct rec));
                 rs[tree->len].matches =                  rs[tree->len].matches =
                         mandoc_calloc(terms, sizeof(int));                          mandoc_calloc(terms, sizeof(int));
   
Line 555  single_search(struct rectree *tree, const struct opts 
Line 577  single_search(struct rectree *tree, const struct opts 
                 } else                  } else
                         root = tree->len;                          root = tree->len;
   
                 memset(&r, 0, sizeof(struct rec));  
                 tree->len++;                  tree->len++;
         }          }
   
Line 563  single_search(struct rectree *tree, const struct opts 
Line 584  single_search(struct rectree *tree, const struct opts 
         (*idx->close)(idx);          (*idx->close)(idx);
   
         free(buf);          free(buf);
           recfree(&r);
         return(1 == ch);          return(1 == ch);
 }  }
   
Line 570  static void
Line 592  static void
 recfree(struct rec *rec)  recfree(struct rec *rec)
 {  {
   
         free(rec->res.type);  
         free(rec->res.file);          free(rec->res.file);
         free(rec->res.cat);          free(rec->res.cat);
         free(rec->res.title);          free(rec->res.title);

Legend:
Removed from v.1.18  
changed lines
  Added in v.1.26

CVSweb