3 /// Reads an boost serialization file and dumps to stdout.
7 Copyright (C) 2008-2013, 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
);
48 cerr
<< string_vprintf(
49 _("bs11nread - Reads a boost serialization file (from btool)\n"
50 " and dumps data to stdout\n"
51 " Copyright 2008-2013, Net Direct Inc. (http://www.netdirect.ca/)\n"
54 " -f file Filename to save or load handheld data to/from\n"
56 " -S Show list of supported database parsers\n"),
61 template <class Record
>
62 bool Dump(const std::string
&dbName
, const std::string
&filename
)
64 if( dbName
!= Record::GetDBName() )
67 std::vector
<Record
> records
;
68 std::string junk
, errmsg
;
70 if( !LoadBoostFile(filename
, records
, junk
, errmsg
) ) {
71 cerr
<< errmsg
<< endl
;
75 cout
<< records
.size()
76 << _(" records loaded") << endl
;
77 sort(records
.begin(), records
.end());
79 typename
std::vector
<Record
>::const_iterator
80 beg
= records
.begin(), end
= records
.end();
81 for( ; beg
!= end
; beg
++ ) {
82 cout
<< (*beg
) << endl
;
88 void DumpDB(const string
&filename
)
90 // filename is available, attempt to load
91 ifstream
ifs(filename
.c_str());
96 // check for recognized database names
98 #define HANDLE_PARSER(tname) Dump<tname>(dbName, filename) ||
99 ALL_KNOWN_PARSER_TYPES
100 cerr
<< _("Unknown database name: ") << dbName
<< endl
;
103 int main(int argc
, char *argv
[])
110 // process command line options
112 int cmd
= getopt(argc
, argv
, "f:hS");
118 case 'f': // filename
122 case 'S': // show supported databases
123 ShowParsers(false, false);
133 // Initialize the barry library. Must be called before
137 if( !filename
.size() ) {
138 cerr
<< _("Filename must be specified") << endl
;
145 catch( Usb::Error
&ue
) {
146 std::cerr
<< _("Usb::Error caught: ") << ue
.what() << endl
;
149 catch( Barry::Error
&se
) {
150 std::cerr
<< _("Barry::Error caught: ") << se
.what() << endl
;
153 catch( std::exception
&e
) {
154 std::cerr
<< _("std::exception caught: ") << e
.what() << endl
;