From 6f80a254194aa997df61c64115240de6c3230181 Mon Sep 17 00:00:00 2001 From: Chris Frey Date: Fri, 3 Feb 2012 02:16:18 -0500 Subject: [PATCH] tools: added -F sortkey support to btool --- man/btool.1 | 21 +++++++++++++++++++-- tools/btool.cc | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/man/btool.1 b/man/btool.1 index 8f613f54..590a636d 100644 --- a/man/btool.1 +++ b/man/btool.1 @@ -2,7 +2,7 @@ .\" First parameter, NAME, should be all caps .\" Second parameter, SECTION, should be 1-8, maybe w/ subsection .\" other parameters are allowed: see man(7), man(1) -.TH BTOOL 1 "December 7, 2010" +.TH BTOOL 1 "February 3, 2012" .\" Please adjust this date whenever revising the manpage. .\" .\" Some roff macros, for reference: @@ -20,7 +20,7 @@ \- Barry Project's program to interface with BlackBerry handheld .SH SYNOPSIS .B btool -[-B busname][-N devname][-a db][-c dn][-C dnattr][-d db [-f file][-r#][-R#]-D#]][-h][-i charset][-l][-L][-m cmd][-M][-p pin][-P password][-s db -f file][-S][-t][-v][-V][-X][-z][-Z] +[-B busname][-N devname][-a db][-c dn][-C dnattr][-d db [-f file][-F sortkey][-r#][-R#]-D#]][-h][-i charset][-l][-L][-m cmd][-M][-p pin][-P password][-s db -f file][-S][-t][-v][-V][-X][-z][-Z] .SH DESCRIPTION .PP .B btool @@ -75,6 +75,23 @@ Filename to write or read handheld data to/from. Used in conjunction with the -d and -s options, respectively. Note: the file format of this file is not backward compatible between devel releases. .TP +.B \-F sortkey +Sort the -d database output according to the given sortkey. +Note that the format of this field is special: 'DBName:field1,field2' + +It contains no spaces, unless the spaces are part of the name. + +This option can be used multiple times, to match your -d options. + +Example: If you used the following command: + +btool -d 'Address Book' + +You could use the following sort key to sort by Company name first, +with a subsort of last and first names. + +-F 'Address Book:Company,LastName,FirstName' +.TP .B \-i charset Specifies the iconv charset to use for converting international strings. The Blackberry uses the WINDOWS-1252 charset, which is incompatible with diff --git a/tools/btool.cc b/tools/btool.cc index 02e3be16..f015cbd5 100644 --- a/tools/btool.cc +++ b/tools/btool.cc @@ -46,6 +46,8 @@ using namespace std; using namespace std::tr1; using namespace Barry; +std::map SortKeys; + void Usage() { int logical, major, minor; @@ -84,6 +86,11 @@ void Usage() #ifdef __BARRY_BOOST_MODE__ << " -f file Filename to save or load handheld data to/from\n" #endif + << " -F sort Field name by which to sort the output. Note that the\n" + << " format of this field is special: 'DBName:field1,field2'\n" + << " with no spaces unless the spaces are part of the name.\n" + << " Can be used multiple times, to match your -d options.\n" + << " Example: -F 'Address Book:Company,LastName,FirstName'\n" << " -h This help\n" << " -i cs International charset for string conversions\n" << " Valid values here are available with 'iconv --list'\n" @@ -153,7 +160,7 @@ struct Store : rec_it(records.end()), filename(filename), load(load), - immediate_display(immediate_display), + immediate_display(immediate_display && !SortKeys.size()), vformat_mode(vformat_mode), from_device_count(0), to_device_count(0) @@ -193,7 +200,13 @@ struct Store { if( !immediate_display ) { // not dumped yet, sort then dump - sort(records.begin(), records.end()); + if( SortKeys.size() && SortKeys.find(Record::GetDBName()) != SortKeys.end() ) { + sort(records.begin(), records.end(), + NamedFieldCmp(SortKeys[Record::GetDBName()])); + } + else { + sort(records.begin(), records.end()); + } DumpAll(); } @@ -485,6 +498,17 @@ bool ParseEpOverride(const char *arg, Usb::EndpointPair *epp) return true; } +void ParseSortKey(const std::string &key) +{ + istringstream iss(key); + string db, spec; + getline(iss, db, ':'); + getline(iss, spec, ':'); + + if( db.size() && spec.size() ) + SortKeys[db] = spec; +} + int main(int argc, char *argv[]) { INIT_I18N(PACKAGE); @@ -524,7 +548,7 @@ int main(int argc, char *argv[]) // process command line options for(;;) { - int cmd = getopt(argc, argv, "a:b:B:c:C:d:D:e:f:hi:IlLm:MnN:p:P:r:R:Ss:tT:vVXzZ"); + int cmd = getopt(argc, argv, "a:b:B:c:C:d:D:e:f:F:hi:IlLm:MnN:p:P:r:R:Ss:tT:vVXzZ"); if( cmd == -1 ) break; @@ -598,6 +622,10 @@ int main(int argc, char *argv[]) #endif break; + case 'F': // sort key + ParseSortKey(optarg); + break; + case 'i': // international charset (iconv) iconvCharset = optarg; break; -- 2.11.4.GIT