From tek at serverop.de Thu Aug 4 15:11:34 2011 From: tek at serverop.de (Thomas Penteker) Date: Thu, 4 Aug 2011 17:11:34 +0200 Subject: [crux-devel] [PATCH] Add optional pattern matching for -i option Message-ID: <20110804151134.GA8586@serverop.de> Hello list, I rolled a little patch adding pattern matching for pkginfo's -i option. Suggestions/criticism, anyone? --- pkginfo.8.in | 5 +++-- pkginfo.cc | 22 +++++++++++++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/pkginfo.8.in b/pkginfo.8.in index ee0da6c..bdd84c0 100644 --- a/pkginfo.8.in +++ b/pkginfo.8.in @@ -9,8 +9,9 @@ information about software packages that are installed on the system or that reside in a particular directory. .SH OPTIONS .TP -.B "\-i, \-\-installed" -List installed packages and their version. +.B "\-i, \-\-installed []" +List installed packages and their version. Optionally, list only packages +matching pattern. .TP .B "\-l, \-\-list " List files owned by the specified or contained in . diff --git a/pkginfo.cc b/pkginfo.cc index fb4d993..b20e78f 100644 --- a/pkginfo.cc +++ b/pkginfo.cc @@ -36,6 +36,7 @@ void pkginfo::run(int argc, char** argv) int o_installed_mode = 0; int o_list_mode = 0; int o_owner_mode = 0; + int o_grep_mode = 0; string o_root; string o_arg; @@ -47,6 +48,16 @@ void pkginfo::run(int argc, char** argv) i++; } else if (option == "-i" || option == "--installed") { o_installed_mode += 1; + try { + assert_argument(argv, argc, i); + o_grep_mode = 1; + o_arg = argv[i + 1]; + i++; + } catch (exception &e) { + // + // argument is optional + // + } } else if (option == "-l" || option == "--list") { assert_argument(argv, argc, i); o_list_mode += 1; @@ -91,8 +102,17 @@ void pkginfo::run(int argc, char** argv) // // List installed packages // + regex_t preg; + if (o_grep_mode) + if (regcomp(&preg, o_arg.c_str(), REG_EXTENDED | REG_NOSUB)) + throw runtime_error("error compiling regular expression '" + o_arg + "', aborting"); + for (packages_t::const_iterator i = packages.begin(); i != packages.end(); ++i) - cout << i->first << ' ' << i->second.version << endl; + if (!o_grep_mode || !regexec(&preg, i->first.c_str(), 0, 0, 0)) + cout << i->first << ' ' << i->second.version << endl; + + if (o_grep_mode) + regfree(&preg); } else if (o_list_mode) { // // List package or file contents -- 1.7.4.1 -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 198 bytes Desc: not available URL: From sepen at crux-arm.nu Mon Aug 15 15:26:04 2011 From: sepen at crux-arm.nu (Jose V Beneyto) Date: Mon, 15 Aug 2011 17:26:04 +0200 Subject: [crux-devel] [PATCH] Add optional pattern matching for -i option In-Reply-To: <20110804151134.GA8586@serverop.de> References: <20110804151134.GA8586@serverop.de> Message-ID: <4E493A8C.7070400@crux-arm.nu> Hello Thomas, On 08/04/11 17:11, Thomas Penteker wrote: > Hello list, > > I rolled a little patch adding pattern matching for pkginfo's -i option. > Suggestions/criticism, anyone? +1 Note, that it was a ticket: Closed by Thomas Penteker (teK) Friday, 25 September 2009, 14:33 GMT+2 Reason for closing: Fixed http://crux.nu/bugs/index.php?do=details&task_id=220 Best regards, -- Jose V Beneyto | http://sepen.mine.nu