1 /* This file is part of GDBM, the GNU data base manager.
2 Copyright (C) 2011, 2013 Free Software Foundation, Inc.
4 GDBM is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3, or (at your option)
9 GDBM is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with GDBM. If not, see <http://www.gnu.org/licenses/>. */
17 # include "autoconf.h"
20 # include "gdbmdefs.h"
22 char *parseopt_program_doc = "dump a GDBM database to a file";
23 char *parseopt_program_args = "DB_FILE [FILE]";
24 struct gdbm_option optab[] = {
25 { 'H', "format", "binary|ascii|0|1", N_("select dump format") },
29 int format = GDBM_DUMP_FMT_ASCII;
32 main (int argc, char **argv)
36 char *dbname, *filename;
40 setlocale (LC_ALL, "");
42 bindtextdomain (PACKAGE, LOCALEDIR);
45 set_progname (argv[0]);
47 for (opt = parseopt_first (argc, argv, optab);
49 opt = parseopt_next ())
54 if (strcmp (optarg, "binary") == 0)
55 format = GDBM_DUMP_FMT_BINARY;
56 else if (strcmp (optarg, "ascii") == 0)
57 format = GDBM_DUMP_FMT_ASCII;
60 format = atoi (optarg);
63 case GDBM_DUMP_FMT_BINARY:
64 case GDBM_DUMP_FMT_ASCII:
67 error (_("unknown dump format"));
74 error (_("unknown option"));
84 parseopt_print_help ();
90 error (_("too many arguments; try `%s -h' for more info"), progname);
100 if (!filename || strcmp (filename, "-") == 0)
102 filename = "<stdout>";
107 fp = fopen (filename, "w");
110 sys_perror (errno, _("cannot open %s"), filename);
115 dbf = gdbm_open (dbname, 0, GDBM_READER, 0600, NULL);
118 gdbm_perror (_("gdbm_open failed"));
122 rc = gdbm_dump_to_file (dbf, fp, format);
125 gdbm_perror (_("dump error"), filename);
130 exit (rc ? EXIT_OK : EXIT_FATAL);