-static void dbclose(const char *, int);
-static void dbindex(struct mchars *, int,
- const struct of *, const char *);
-static int dbopen(const char *, int);
-static void dbprune(const char *);
-static void fileadd(struct of *);
-static int filecheck(const char *);
-static void filescan(const char *, const char *);
-static struct str *hashget(const char *, size_t);
-static void *hash_alloc(size_t, void *);
-static void hash_free(void *, size_t, void *);
-static void *hash_halloc(size_t, void *);
-static void inoadd(const struct stat *, struct of *);
-static int inocheck(const struct stat *);
-static void ofadd(const char *, int, const char *,
- const char *, const char *, const char *,
- const char *, const struct stat *);
-static void offree(void);
-static int ofmerge(struct mchars *, struct mparse *, const char *);
-static void parse_catpage(struct of *, const char *);
-static int parse_man(struct of *,
- const struct man_node *);
-static void parse_mdoc(struct of *, const struct mdoc_node *);
-static int parse_mdoc_body(struct of *, const struct mdoc_node *);
-static int parse_mdoc_head(struct of *, const struct mdoc_node *);
-static int parse_mdoc_Fd(struct of *, const struct mdoc_node *);
-static int parse_mdoc_Fn(struct of *, const struct mdoc_node *);
-static int parse_mdoc_In(struct of *, const struct mdoc_node *);
-static int parse_mdoc_Nd(struct of *, const struct mdoc_node *);
-static int parse_mdoc_Nm(struct of *, const struct mdoc_node *);
-static int parse_mdoc_Sh(struct of *, const struct mdoc_node *);
-static int parse_mdoc_St(struct of *, const struct mdoc_node *);
-static int parse_mdoc_Xr(struct of *, const struct mdoc_node *);
-static int path_reset(const char *, int, const char *);
-static void putkey(const struct of *,
- const char *, uint64_t);
-static void putkeys(const struct of *,
- const char *, int, uint64_t);
-static void putmdockey(const struct of *,
- const struct mdoc_node *, uint64_t);
-static char *stradd(const char *);
-static char *straddbuf(const char *, size_t);
-static int treescan(const char *);
+
+int mandocdb(int, char *[]);
+
+static void dbadd(struct dba *, struct mpage *);
+static void dbadd_mlink(const struct mlink *mlink);
+static void dbprune(struct dba *);
+static void dbwrite(struct dba *);
+static void filescan(const char *);
+#if HAVE_FTS_COMPARE_CONST
+static int fts_compare(const FTSENT *const *, const FTSENT *const *);
+#else
+static int fts_compare(const FTSENT **, const FTSENT **);
+#endif
+static void mlink_add(struct mlink *, const struct stat *);
+static void mlink_check(struct mpage *, struct mlink *);
+static void mlink_free(struct mlink *);
+static void mlinks_undupe(struct mpage *);
+static void mpages_free(void);
+static void mpages_merge(struct dba *, struct mparse *);
+static void parse_cat(struct mpage *, int);
+static void parse_man(struct mpage *, const struct roff_meta *,
+ const struct roff_node *);
+static void parse_mdoc(struct mpage *, const struct roff_meta *,
+ const struct roff_node *);
+static int parse_mdoc_head(struct mpage *, const struct roff_meta *,
+ const struct roff_node *);
+static int parse_mdoc_Fd(struct mpage *, const struct roff_meta *,
+ const struct roff_node *);
+static void parse_mdoc_fname(struct mpage *, const struct roff_node *);
+static int parse_mdoc_Fn(struct mpage *, const struct roff_meta *,
+ const struct roff_node *);
+static int parse_mdoc_Fo(struct mpage *, const struct roff_meta *,
+ const struct roff_node *);
+static int parse_mdoc_Nd(struct mpage *, const struct roff_meta *,
+ const struct roff_node *);
+static int parse_mdoc_Nm(struct mpage *, const struct roff_meta *,
+ const struct roff_node *);
+static int parse_mdoc_Sh(struct mpage *, const struct roff_meta *,
+ const struct roff_node *);
+static int parse_mdoc_Va(struct mpage *, const struct roff_meta *,
+ const struct roff_node *);
+static int parse_mdoc_Xr(struct mpage *, const struct roff_meta *,
+ const struct roff_node *);
+static void putkey(const struct mpage *, char *, uint64_t);
+static void putkeys(const struct mpage *, char *, size_t, uint64_t);
+static void putmdockey(const struct mpage *,
+ const struct roff_node *, uint64_t, int);
+static int render_string(char **, size_t *);
+static void say(const char *, const char *, ...)
+ __attribute__((__format__ (__printf__, 2, 3)));
+static int set_basedir(const char *, int);
+static int treescan(void);