-extern void *ascii_alloc(void);
-extern int tree_mdoc(void *, const struct mdoc *);
-extern int tree_man(void *, const struct man *);
-extern int terminal_mdoc(void *, const struct mdoc *);
-extern int terminal_man(void *, const struct man *);
-extern void terminal_free(void *);
-
-static int foptions(int *, char *);
-static int toptions(enum outt *, char *);
-static int moptions(enum intt *, char *);
-static int woptions(int *, char *);
-static int merr(void *, int, int, const char *);
-static int manwarn(void *, int, int, const char *);
-static int mdocwarn(void *, int, int,
- enum mdoc_warn, const char *);
-static int fstdin(struct buf *, struct buf *,
- struct curparse *);
-static int ffile(struct buf *, struct buf *,
- const char *, struct curparse *);
-static int fdesc(struct buf *, struct buf *,
- struct curparse *);
-static int pset(const char *, int, struct curparse *,
- struct man **, struct mdoc **);
-static struct man *man_init(struct curparse *);
-static struct mdoc *mdoc_init(struct curparse *);
-__dead static void version(void);
-__dead static void usage(void);
-
-extern char *__progname;
+
+int mandocdb(int, char *[]);
+
+static void check_xr(const char *);
+static int fs_lookup(const struct manpaths *,
+ size_t ipath, const char *,
+ const char *, const char *,
+ struct manpage **, size_t *);
+static int fs_search(const struct mansearch *,
+ const struct manpaths *, int, char**,
+ struct manpage **, size_t *);
+static int koptions(int *, char *);
+static void moptions(int *, char *);
+static void mmsg(enum mandocerr, enum mandoclevel,
+ const char *, int, int, const char *);
+static void outdata_alloc(struct curparse *);
+static void parse(struct curparse *, int, const char *);
+static void passthrough(const char *, int, int);
+static pid_t spawn_pager(struct tag_files *);
+static int toptions(struct curparse *, char *);
+static void usage(enum argmode) __attribute__((__noreturn__));
+static int woptions(struct curparse *, char *);
+
+static const int sec_prios[] = {1, 4, 5, 8, 6, 3, 7, 2, 9};
+static char help_arg[] = "help";
+static char *help_argv[] = {help_arg, NULL};
+static enum mandoclevel rc;
+static FILE *mmsg_stream;