3 /// Reads an boost serialization file and dumps to stdout.
7 Copyright (C) 2008-2012, 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 // Boost is required, but since the real Boost serialization code is in
23 // util.cc, we don't need it here.
24 #undef __BARRY_BOOST_MODE__
26 #include <barry/barry.h>
36 #include "barrygetopt.h"
38 #include "boostwrap.h"
41 using namespace Barry
;
45 int logical
, major
, minor
;
46 const char *Version
= Barry::Version(logical
, major
, minor
);
49 << "bs11nread - Reads a boost serialization file (from btool)\n"
50 << " and dumps data to stdout\n"
51 << " Copyright 2008-2012, Net Direct Inc. (http://www.netdirect.ca/)\n"
52 << " Using: " << Version
<< "\n"
54 << " -f file Filename to save or load handheld data to/from\n"
56 << " -S Show list of supported database parsers\n"
60 template <class Record
>
61 bool Dump(const std::string
&dbName
, const std::string
&filename
)
63 if( dbName
!= Record::GetDBName() )
66 std::vector
<Record
> records
;
67 std::string junk
, errmsg
;
69 if( !LoadBoostFile(filename
, records
, junk
, errmsg
) ) {
70 cerr
<< errmsg
<< endl
;
74 cout
<< records
.size()
75 << " records loaded" << endl
;
76 sort(records
.begin(), records
.end());
78 typename
std::vector
<Record
>::const_iterator
79 beg
= records
.begin(), end
= records
.end();
80 for( ; beg
!= end
; beg
++ ) {
81 cout
<< (*beg
) << endl
;
87 void DumpDB(const string
&filename
)
89 // filename is available, attempt to load
90 ifstream
ifs(filename
.c_str());
95 // check for recognized database names
97 #define HANDLE_PARSER(tname) Dump<tname>(dbName, filename) ||
98 ALL_KNOWN_PARSER_TYPES
99 cerr
<< "Unknown database name: " << dbName
<< endl
;
102 int main(int argc
, char *argv
[])
109 // process command line options
111 int cmd
= getopt(argc
, argv
, "f:hS");
117 case 'f': // filename
121 case 'S': // show supported databases
122 ShowParsers(false, false);
132 // Initialize the barry library. Must be called before
136 if( !filename
.size() ) {
137 cerr
<< "Filename must be specified" << endl
;
144 catch( Usb::Error
&ue
) {
145 std::cerr
<< "Usb::Error caught: " << ue
.what() << endl
;
148 catch( Barry::Error
&se
) {
149 std::cerr
<< "Barry::Error caught: " << se
.what() << endl
;
152 catch( std::exception
&e
) {
153 std::cerr
<< "std::exception caught: " << e
.what() << endl
;