[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.81

version 1.79, 2013/12/26 22:30:41 version 1.81, 2013/12/27 01:16:54
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 112  struct title {
Line 111  struct title {
 };  };
   
 enum    stmt {  enum    stmt {
         STMT_DELETE = 0, /* delete manpage */          STMT_DELETE_PAGE = 0,   /* delete mpage */
         STMT_INSERT_DOC, /* insert manpage */          STMT_INSERT_PAGE,       /* insert mpage */
         STMT_INSERT_KEY, /* insert parsed key */          STMT_INSERT_LINK,       /* insert mlink */
           STMT_INSERT_KEY,        /* insert parsed key */
         STMT__MAX          STMT__MAX
 };  };
   
Line 154  static int  parse_mdoc_Nm(struct mpage *, const struct
Line 154  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 161  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 177  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 469  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 480  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 805  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 850  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 864  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 899  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 915  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 930  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 943  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 1055  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 1074  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 1087  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 1813  dbindex(struct mchars *mc, int form, const struct mpag
Line 1815  dbindex(struct mchars *mc, int form, const struct mpag
         SQL_EXEC("BEGIN TRANSACTION");          SQL_EXEC("BEGIN TRANSACTION");
   
         i = 1;          i = 1;
         SQL_BIND_TEXT(stmts[STMT_INSERT_DOC], i, mpage->file);          /*
         SQL_BIND_TEXT(stmts[STMT_INSERT_DOC], i, mpage->sec);           * XXX The following three lines are obsolete
         SQL_BIND_TEXT(stmts[STMT_INSERT_DOC], i, mpage->arch);           * and only kept for backward compatibility
         SQL_BIND_TEXT(stmts[STMT_INSERT_DOC], i, desc);           * until apropos(1) and friends have caught up.
         SQL_BIND_INT(stmts[STMT_INSERT_DOC], i, form);           */
         SQL_STEP(stmts[STMT_INSERT_DOC]);          SQL_BIND_TEXT(stmts[STMT_INSERT_PAGE], i, mpage->file);
           SQL_BIND_TEXT(stmts[STMT_INSERT_PAGE], i, mpage->sec);
           SQL_BIND_TEXT(stmts[STMT_INSERT_PAGE], i, mpage->arch);
           SQL_BIND_TEXT(stmts[STMT_INSERT_PAGE], i, desc);
           SQL_BIND_INT(stmts[STMT_INSERT_PAGE], i, form);
           SQL_STEP(stmts[STMT_INSERT_PAGE]);
         recno = sqlite3_last_insert_rowid(db);          recno = sqlite3_last_insert_rowid(db);
         sqlite3_reset(stmts[STMT_INSERT_DOC]);          sqlite3_reset(stmts[STMT_INSERT_PAGE]);
   
           i = 1;
           SQL_BIND_TEXT(stmts[STMT_INSERT_LINK], i, mpage->sec);
           SQL_BIND_TEXT(stmts[STMT_INSERT_LINK], i, mpage->arch);
           SQL_BIND_TEXT(stmts[STMT_INSERT_LINK], i, mpage->file);
           SQL_BIND_INT64(stmts[STMT_INSERT_LINK], i, recno);
           SQL_STEP(stmts[STMT_INSERT_LINK]);
           sqlite3_reset(stmts[STMT_INSERT_LINK]);
   
         for (key = ohash_first(&strings, &slot); NULL != key;          for (key = ohash_first(&strings, &slot); NULL != key;
              key = ohash_next(&strings, &slot)) {               key = ohash_next(&strings, &slot)) {
                 assert(key->mpage == mpage);                  assert(key->mpage == mpage);
Line 1846  dbprune(void)
Line 1861  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_PAGE], i, mpage->file);
                 SQL_STEP(stmts[STMT_DELETE]);                  SQL_STEP(stmts[STMT_DELETE_PAGE]);
                 sqlite3_reset(stmts[STMT_DELETE]);                  sqlite3_reset(stmts[STMT_DELETE_PAGE]);
                 if (verb)                  if (verb)
                         say(mpage->file, "Deleted from index");                          say(mpage->file, "Deleted from index");
                   mpage = ohash_next(&mpages, &slot);
         }          }
 }  }
   
Line 1936  dbopen(int real)
Line 1954  dbopen(int real)
                 return(0);                  return(0);
         }          }
   
         sql = "CREATE TABLE \"docs\" (\n"          /*
            * XXX The first three columns in table mpages are obsolete
            * and only kept for backward compatibility
            * until apropos(1) and friends have caught up.
            */
           sql = "CREATE TABLE \"mpages\" (\n"
               " \"file\" TEXT NOT NULL,\n"                " \"file\" TEXT NOT NULL,\n"
               " \"sec\" TEXT NOT NULL,\n"                " \"sec\" TEXT NOT NULL,\n"
               " \"arch\" TEXT NOT NULL,\n"                " \"arch\" TEXT NOT NULL,\n"
Line 1945  dbopen(int real)
Line 1968  dbopen(int real)
               " \"id\" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL\n"                " \"id\" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL\n"
               ");\n"                ");\n"
               "\n"                "\n"
                 "CREATE TABLE \"mlinks\" (\n"
                 " \"sec\" TEXT NOT NULL,\n"
                 " \"arch\" TEXT NOT NULL,\n"
                 " \"name\" TEXT NOT NULL,\n"
                 " \"pageid\" INTEGER NOT NULL REFERENCES mpages(id) "
                   "ON DELETE CASCADE,\n"
                 " \"id\" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL\n"
                 ");\n"
                 "\n"
               "CREATE TABLE \"keys\" (\n"                "CREATE TABLE \"keys\" (\n"
               " \"bits\" INTEGER NOT NULL,\n"                " \"bits\" INTEGER NOT NULL,\n"
               " \"key\" TEXT NOT NULL,\n"                " \"key\" TEXT NOT NULL,\n"
               " \"docid\" INTEGER NOT NULL REFERENCES docs(id) "                " \"pageid\" INTEGER NOT NULL REFERENCES mpages(id) "
                 "ON DELETE CASCADE,\n"                  "ON DELETE CASCADE,\n"
               " \"id\" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL\n"                " \"id\" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL\n"
               ");\n"                ");\n"
               "\n"                "\n"
Line 1963  dbopen(int real)
Line 1995  dbopen(int real)
   
 prepare_statements:  prepare_statements:
         SQL_EXEC("PRAGMA foreign_keys = ON");          SQL_EXEC("PRAGMA foreign_keys = ON");
         sql = "DELETE FROM docs where file=?";          sql = "DELETE FROM mpages where file=?";
         sqlite3_prepare_v2(db, sql, -1, &stmts[STMT_DELETE], NULL);          sqlite3_prepare_v2(db, sql, -1, &stmts[STMT_DELETE_PAGE], NULL);
         sql = "INSERT INTO docs "          sql = "INSERT INTO mpages "
                 "(file,sec,arch,desc,form) VALUES (?,?,?,?,?)";                  "(file,sec,arch,desc,form) VALUES (?,?,?,?,?)";
         sqlite3_prepare_v2(db, sql, -1, &stmts[STMT_INSERT_DOC], NULL);          sqlite3_prepare_v2(db, sql, -1, &stmts[STMT_INSERT_PAGE], NULL);
           sql = "INSERT INTO mlinks "
                   "(sec,arch,name,pageid) VALUES (?,?,?,?)";
           sqlite3_prepare_v2(db, sql, -1, &stmts[STMT_INSERT_LINK], NULL);
         sql = "INSERT INTO keys "          sql = "INSERT INTO keys "
                 "(bits,key,docid) VALUES (?,?,?)";                  "(bits,key,pageid) VALUES (?,?,?)";
         sqlite3_prepare_v2(db, sql, -1, &stmts[STMT_INSERT_KEY], NULL);          sqlite3_prepare_v2(db, sql, -1, &stmts[STMT_INSERT_KEY], NULL);
   
 #ifndef __APPLE__  #ifndef __APPLE__

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

CVSweb