2 * accessdb.c: show every key/content pair in the database.
4 * Copyright (C) 1994, 1995 Graeme W. Wilford. (Wilf.)
5 * Copyright (C) 2002 Colin Watson.
7 * This file is part of man-db.
9 * man-db is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * man-db is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with man-db; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 * Tue Apr 26 12:56:44 BST 1994 Wilf. (G.Wilford@ee.surrey.ac.uk)
28 #endif /* HAVE_CONFIG_H */
37 #include "xvasprintf.h"
40 #define _(String) gettext (String)
41 #define N_(String) gettext_noop (String)
43 #include "manconfig.h"
51 man_sandbox *sandbox; /* unused, but needed by libman */
53 /* for db_storage.c */
56 const char *argp_program_version = "accessdb " PACKAGE_VERSION;
57 const char *argp_program_bug_address = PACKAGE_BUGREPORT;
58 error_t argp_err_exit_status = FAIL;
60 static const char args_doc[] = N_("[MAN DATABASE]");
61 static const char doc[] = "\v" N_("The man database defaults to %s%s.");
63 static struct argp_option options[] = {
64 { "debug", 'd', 0, 0, N_("emit debugging messages") },
65 { 0, 'h', 0, OPTION_HIDDEN, 0 }, /* compatibility for --help */
69 static error_t parse_opt (int key, char *arg, struct argp_state *state)
76 argp_state_help (state, state->out_stream,
85 case ARGP_KEY_NO_ARGS:
86 database = mkdbname (cat_root);
89 return ARGP_ERR_UNKNOWN;
92 static char *help_filter (int key, const char *text,
93 void *input ATTRIBUTE_UNUSED)
96 case ARGP_KEY_HELP_PRE_DOC:
97 /* We have no pre-options help text, but the input
98 * text may contain header junk due to gettext ("").
101 case ARGP_KEY_HELP_POST_DOC:
102 return xasprintf (text, cat_root, MAN_DB);
104 return (char *) text;
108 static struct argp argp = { options, parse_opt, args_doc, doc, 0,
111 int main (int argc, char *argv[])
117 set_program_name (argv[0]);
122 if (is_directory (FHS_CAT_ROOT) == 1)
123 cat_root = FHS_CAT_ROOT;
124 else if (is_directory (CAT_ROOT) == 1)
127 if (argp_parse (&argp, argc, argv, 0, 0, 0))
130 dbf = MYDBM_RDOPEN (database);
131 if (dbf && dbver_rd (dbf)) {
136 error (FATAL, errno, _("can't open %s for reading"), database);
138 key = MYDBM_FIRSTKEY (dbf);
140 while (MYDBM_DPTR (key) != NULL) {
141 datum content, nextkey;
144 content = MYDBM_FETCH (dbf, key);
145 if (!MYDBM_DPTR (content)) {
146 debug ("key %s has no content!\n", MYDBM_DPTR (key));
150 nicekey = xstrdup (MYDBM_DPTR (key));
151 while ( (t = strchr (nicekey, '\t')) )
153 while ( (t = strchr (MYDBM_DPTR (content), '\t')) )
155 printf ("%s -> \"%s\"\n", nicekey, MYDBM_DPTR (content));
157 MYDBM_FREE_DPTR (content);
159 nextkey = MYDBM_NEXTKEY (dbf, key);
160 MYDBM_FREE_DPTR (key);