lib: fixed missing endian adjustment in bookmark parser
[barry.git] / tools / btardump.cc
blobc8c63c6c00a5050ad4185ad37f392fcaf3511c66
1 ///
2 /// \file tardump.cc
3 /// Utility to dump tarball backup records to stdout.
4 ///
6 /*
7 Copyright (C) 2010, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it 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 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #include <barry/barry.h>
23 #include <barry/barrybackup.h>
24 #include <iostream>
25 #include <iomanip>
26 #include <getopt.h>
28 using namespace std;
29 using namespace Barry;
31 void Usage()
33 int major, minor;
34 const char *Version = Barry::Version(major, minor);
36 cerr
37 << "btardump - Command line parser for Barry backup files\n"
38 << " Copyright 2010, Net Direct Inc. (http://www.netdirect.ca/)\n"
39 << " Using: " << Version << "\n"
40 << "\n"
41 << " -d db Name of database to dump. Can be used multiple times\n"
42 << " to parse multiple databases at once. If not specified\n"
43 << " at all, all available databases from the backup are\n"
44 << " dumped.\n"
45 << " -h This help\n"
46 << "\n"
47 << " [files...] Backup file(s), created by btool or the backup GUI.\n"
48 << endl;
51 int main(int argc, char *argv[])
53 try {
55 vector<string> db_names;
56 vector<string> backup_files;
58 // process command line options
59 for(;;) {
60 int cmd = getopt(argc, argv, "d:h");
61 if( cmd == -1 )
62 break;
64 switch( cmd )
66 case 'd': // show dbname
67 db_names.push_back(string(optarg));
68 break;
70 case 'h': // help
71 default:
72 Usage();
73 return 0;
77 // grab all backup filenames
78 while( optind < argc ) {
79 backup_files.push_back(string(argv[optind++]));
82 if( backup_files.size() == 0 ) {
83 Usage();
84 return 0;
89 Barry::Init();
91 // create the parser, and use stdout dump objects for output
92 AllRecordParser parser(cout,
93 new HexDumpParser(cout),
94 new AllRecordDumpStore(cout));
96 for( size_t i = 0; i < backup_files.size(); i++ ) {
98 cout << "Reading file: " << backup_files[i] << endl;
100 Restore builder(backup_files[i]);
102 // add desired database names
103 for( size_t j = 0; j < db_names.size(); j++ ) {
104 builder.AddDB(db_names[i]);
107 // create the pipe to connect builder to parser and
108 // move the data
109 Pipe pipe(builder);
110 pipe.PumpFile(parser);
114 catch( exception &e ) {
115 cerr << e.what() << endl;
116 return 1;
119 return 0;