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

Diff for /mandoc/mandocdb.c between version 1.79 and 1.80

version 1.79, 2013/12/26 22:30:41 version 1.80, 2013/12/26 23:35:59
Line 95  struct inodev {
Line 95  struct inodev {
   
 struct  mpage {  struct  mpage {
         struct inodev    inodev;  /* used for hashing routine */          struct inodev    inodev;  /* used for hashing routine */
         struct mpage    *next; /* next in mpages_list */  
         enum form        dform; /* path-cued form */          enum form        dform; /* path-cued form */
         enum form        sform; /* suffix-cued form */          enum form        sform; /* suffix-cued form */
         char             file[PATH_MAX]; /* filename rel. to manpath */          char             file[PATH_MAX]; /* filename rel. to manpath */
Line 154  static int  parse_mdoc_Nm(struct mpage *, const struct
Line 153  static int  parse_mdoc_Nm(struct mpage *, const struct
 static  int      parse_mdoc_Sh(struct mpage *, const struct mdoc_node *);  static  int      parse_mdoc_Sh(struct mpage *, const struct mdoc_node *);
 static  int      parse_mdoc_St(struct mpage *, const struct mdoc_node *);  static  int      parse_mdoc_St(struct mpage *, const struct mdoc_node *);
 static  int      parse_mdoc_Xr(struct mpage *, const struct mdoc_node *);  static  int      parse_mdoc_Xr(struct mpage *, const struct mdoc_node *);
 static  int      set_basedir(const char *);  
 static  void     putkey(const struct mpage *,  static  void     putkey(const struct mpage *,
                         const char *, uint64_t);                          const char *, uint64_t);
 static  void     putkeys(const struct mpage *,  static  void     putkeys(const struct mpage *,
Line 162  static void  putkeys(const struct mpage *,
Line 160  static void  putkeys(const struct mpage *,
 static  void     putmdockey(const struct mpage *,  static  void     putmdockey(const struct mpage *,
                         const struct mdoc_node *, uint64_t);                          const struct mdoc_node *, uint64_t);
 static  void     say(const char *, const char *, ...);  static  void     say(const char *, const char *, ...);
   static  int      set_basedir(const char *);
 static  int      treescan(void);  static  int      treescan(void);
 static  size_t   utf8(unsigned int, char [7]);  static  size_t   utf8(unsigned int, char [7]);
 static  void     utf8key(struct mchars *, struct str *);  static  void     utf8key(struct mchars *, struct str *);
Line 177  static char   basedir[PATH_MAX]; /* current base direc
Line 176  static char   basedir[PATH_MAX]; /* current base direc
 static  struct ohash     mpages; /* table of distinct manual pages */  static  struct ohash     mpages; /* table of distinct manual pages */
 static  struct ohash     filenames; /* table of filenames */  static  struct ohash     filenames; /* table of filenames */
 static  struct ohash     strings; /* table of all strings */  static  struct ohash     strings; /* table of all strings */
 static  struct mpage    *mpages_list = NULL; /* vector of files to parse */  
 static  sqlite3         *db = NULL; /* current database */  static  sqlite3         *db = NULL; /* current database */
 static  sqlite3_stmt    *stmts[STMT__MAX]; /* current statements */  static  sqlite3_stmt    *stmts[STMT__MAX]; /* current statements */
   
Line 470  main(int argc, char *argv[])
Line 468  main(int argc, char *argv[])
                         dbclose(0);                          dbclose(0);
   
                         if (j + 1 < dirs.sz) {                          if (j + 1 < dirs.sz) {
                                   mpages_free();
                                 ohash_delete(&mpages);                                  ohash_delete(&mpages);
                                 ohash_delete(&filenames);                                  ohash_delete(&filenames);
                                 mpages_free();  
                         }                          }
                 }                  }
         }          }
Line 481  out:
Line 479  out:
         manpath_free(&dirs);          manpath_free(&dirs);
         mchars_free(mc);          mchars_free(mc);
         mparse_free(mp);          mparse_free(mp);
           mpages_free();
         ohash_delete(&mpages);          ohash_delete(&mpages);
         ohash_delete(&filenames);          ohash_delete(&filenames);
         mpages_free();  
         return(exitcode);          return(exitcode);
 usage:  usage:
         fprintf(stderr, "usage: %s [-anvW] [-C file]\n"          fprintf(stderr, "usage: %s [-anvW] [-C file]\n"
Line 806  inocheck(const struct stat *st)
Line 804  inocheck(const struct stat *st)
 static void  static void
 inoadd(const struct stat *st, struct mpage *mpage)  inoadd(const struct stat *st, struct mpage *mpage)
 {  {
         uint32_t         hash;  
         unsigned int     slot;          unsigned int     slot;
   
         mpage->inodev.st_ino = hash = st->st_ino;          mpage->inodev.st_ino = st->st_ino;
         mpage->inodev.st_dev = st->st_dev;          mpage->inodev.st_dev = st->st_dev;
         slot = ohash_lookup_memory(&mpages,          slot = ohash_lookup_memory(&mpages, (char *)&mpage->inodev,
             (char *)&mpage->inodev, sizeof(mpage->inodev), hash);              sizeof(struct inodev), st->st_ino);
   
         assert(NULL == ohash_find(&mpages, slot));          assert(NULL == ohash_find(&mpages, slot));
         ohash_insert(&mpages, slot, mpage);          ohash_insert(&mpages, slot, mpage);
Line 852  ofadd(int dform, const char *file, const char *name, c
Line 849  ofadd(int dform, const char *file, const char *name, c
         mpage->arch = mandoc_strdup(arch);          mpage->arch = mandoc_strdup(arch);
         mpage->sform = sform;          mpage->sform = sform;
         mpage->dform = dform;          mpage->dform = dform;
         mpage->next = mpages_list;  
         mpages_list = mpage;  
   
         /*          /*
          * Add to unique identifier hash.           * Add to unique identifier hash.
Line 868  static void
Line 863  static void
 mpages_free(void)  mpages_free(void)
 {  {
         struct mpage    *mpage;          struct mpage    *mpage;
           unsigned int     slot;
   
         while (NULL != (mpage = mpages_list)) {          mpage = ohash_first(&mpages, &slot);
                 mpages_list = mpage->next;          while (NULL != mpage) {
                 free(mpage->name);                  free(mpage->name);
                 free(mpage->sec);                  free(mpage->sec);
                 free(mpage->dsec);                  free(mpage->dsec);
                 free(mpage->arch);                  free(mpage->arch);
                 free(mpage);                  free(mpage);
                   mpage = ohash_next(&mpages, &slot);
         }          }
 }  }
   
 /*  /*
  * Run through the files in the global vector "mpages_list" and add them to the   * Run through the files in the global vector "mpages"
  * database specified in "basedir".   * and add them to the database specified in "basedir".
  *   *
  * This handles the parsing scheme itself, using the cues of directory   * This handles the parsing scheme itself, using the cues of directory
  * and filename to determine whether the file is parsable or not.   * and filename to determine whether the file is parsable or not.
Line 901  mpages_merge(struct mchars *mc, struct mparse *mp, int
Line 898  mpages_merge(struct mchars *mc, struct mparse *mp, int
         size_t                   sz;          size_t                   sz;
         int                      form;          int                      form;
         int                      match;          int                      match;
         unsigned int             slot;          unsigned int             pslot, tslot;
         enum mandoclevel         lvl;          enum mandoclevel         lvl;
   
         str_info.alloc = hash_alloc;          str_info.alloc = hash_alloc;
Line 917  mpages_merge(struct mchars *mc, struct mparse *mp, int
Line 914  mpages_merge(struct mchars *mc, struct mparse *mp, int
                 ohash_init(&title_table, 6, &title_info);                  ohash_init(&title_table, 6, &title_info);
         }          }
   
         for (mpage = mpages_list; NULL != mpage; mpage = mpage->next) {          mpage = ohash_first(&mpages, &pslot);
           while (NULL != mpage) {
                 /*                  /*
                  * If we're a catpage (as defined by our path), then see                   * If we're a catpage (as defined by our path), then see
                  * if a manpage exists by the same name (ignoring the                   * if a manpage exists by the same name (ignoring the
Line 931  mpages_merge(struct mchars *mc, struct mparse *mp, int
Line 929  mpages_merge(struct mchars *mc, struct mparse *mp, int
                                 if (warnings)                                  if (warnings)
                                         say(mpage->file,                                          say(mpage->file,
                                             "Filename too long");                                              "Filename too long");
                                   mpage = ohash_next(&mpages, &pslot);
                                 continue;                                  continue;
                         }                          }
                         bufp = strstr(buf, "cat");                          bufp = strstr(buf, "cat");
Line 943  mpages_merge(struct mchars *mc, struct mparse *mp, int
Line 942  mpages_merge(struct mchars *mc, struct mparse *mp, int
                                 if (warnings)                                  if (warnings)
                                         say(mpage->file, "Man "                                          say(mpage->file, "Man "
                                             "source exists: %s", buf);                                              "source exists: %s", buf);
                                   mpage = ohash_next(&mpages, &pslot);
                                 continue;                                  continue;
                         }                          }
                 }                  }
Line 1054  mpages_merge(struct mchars *mc, struct mparse *mp, int
Line 1054  mpages_merge(struct mchars *mc, struct mparse *mp, int
                                 perror(NULL);                                  perror(NULL);
                                 exit((int)MANDOCLEVEL_SYSERR);                                  exit((int)MANDOCLEVEL_SYSERR);
                         }                          }
                         slot = ohash_qlookup(&title_table, title_str);                          tslot = ohash_qlookup(&title_table, title_str);
                         title_entry = ohash_find(&title_table, slot);                          title_entry = ohash_find(&title_table, tslot);
                         if (NULL == title_entry) {                          if (NULL == title_entry) {
                                 title_entry = mandoc_malloc(                                  title_entry = mandoc_malloc(
                                                 sizeof(struct title));                                                  sizeof(struct title));
                                 title_entry->title = title_str;                                  title_entry->title = title_str;
                                 title_entry->file = mandoc_strdup(                                  title_entry->file = mandoc_strdup(
                                     match ? "" : mpage->file);                                      match ? "" : mpage->file);
                                 ohash_insert(&title_table, slot,                                  ohash_insert(&title_table, tslot,
                                                 title_entry);                                                  title_entry);
                         } else {                          } else {
                                 if (match)                                  if (match)
Line 1073  mpages_merge(struct mchars *mc, struct mparse *mp, int
Line 1073  mpages_merge(struct mchars *mc, struct mparse *mp, int
   
                 dbindex(mc, form, mpage);                  dbindex(mc, form, mpage);
                 ohash_delete(&strings);                  ohash_delete(&strings);
                   mpage = ohash_next(&mpages, &pslot);
         }          }
   
         if (check_reachable) {          if (check_reachable) {
                 title_entry = ohash_first(&title_table, &slot);                  title_entry = ohash_first(&title_table, &tslot);
                 while (NULL != title_entry) {                  while (NULL != title_entry) {
                         if ('\0' != *title_entry->file)                          if ('\0' != *title_entry->file)
                                 say(title_entry->file,                                  say(title_entry->file,
Line 1085  mpages_merge(struct mchars *mc, struct mparse *mp, int
Line 1086  mpages_merge(struct mchars *mc, struct mparse *mp, int
                         free(title_entry->title);                          free(title_entry->title);
                         free(title_entry->file);                          free(title_entry->file);
                         free(title_entry);                          free(title_entry);
                         title_entry = ohash_next(&title_table, &slot);                          title_entry = ohash_next(&title_table, &tslot);
                 }                  }
                 ohash_delete(&title_table);                  ohash_delete(&title_table);
         }          }
Line 1846  dbprune(void)
Line 1847  dbprune(void)
 {  {
         struct mpage    *mpage;          struct mpage    *mpage;
         size_t           i;          size_t           i;
           unsigned int     slot;
   
         if (nodb)          if (nodb)
                 return;                  return;
   
         for (mpage = mpages_list; NULL != mpage; mpage = mpage->next) {          mpage = ohash_first(&mpages, &slot);
           while (NULL != mpage) {
                 i = 1;                  i = 1;
                 SQL_BIND_TEXT(stmts[STMT_DELETE], i, mpage->file);                  SQL_BIND_TEXT(stmts[STMT_DELETE], i, mpage->file);
                 SQL_STEP(stmts[STMT_DELETE]);                  SQL_STEP(stmts[STMT_DELETE]);
                 sqlite3_reset(stmts[STMT_DELETE]);                  sqlite3_reset(stmts[STMT_DELETE]);
                 if (verb)                  if (verb)
                         say(mpage->file, "Deleted from index");                          say(mpage->file, "Deleted from index");
                   mpage = ohash_next(&mpages, &slot);
         }          }
 }  }
   

Legend:
Removed from v.1.79  
changed lines
  Added in v.1.80

CVSweb