A grep like boost::iostreams filter.

Hi folks, I tried to use the regex_filter for grep like functionality, but I think it doesn't work like that. So, here goes a grep_filter and a driver main() function as an example. It is an input filter which returns only the matching lines of the given regex. I think it can be used by others, too. Is it possible to put this class into distribution, as an example maybe? Thanks, Emre Türkay

Emre Turkay wrote:
Yes, that would be a good idea. I think it should go in the core library, not in the examples. Before I put it in, though, it should be made into a DualUserFilter (http://tinyurl.com/2rxh7m), and it should have a test case. If you want to do this work yourself, that would be great. Otherwise, you can just add what you have so far to the wiki here (http://svn.boost.org/trac/boost/wiki/IostreamsFiltersAndDevices), or, if you don't have editing permission, submit a feature request here (http://svn.boost.org/trac/boost/newticket). Thanks for your contribution!
Thanks,
Emre Türkay
-- Jonathan Turkanis CodeRage http://www.coderage.com

This looks rather useful (and even more using your later refinement) but with a brief attempt, I've failed to get this to work. with MSVC 8.0 debug I get linking against libboost_regex-vc80-mt-gd-1_35.lib (built using a recent library build from trunk). Compiling... demo_grep.cpp Linking... demo_grep.obj : error LNK2019: unresolved external symbol "public: void __thiscall boost::re_detail::raw_storage::resize(unsigned int)" (?resize@raw_storage@re_detail@boost@@QAEXI@Z) referenced in function "public: void * __thiscall boost::re_detail::raw_storage::extend(unsigned int)" (?extend@raw_storage@re_detail@boost@@QAEPAXI@Z) demo_grep.obj : error LNK2019: unresolved external symbol "public: void * __thiscall boost::re_detail::raw_storage::insert(unsigned int,unsigned int)" (?insert@raw_storage@re_detail@boost@@QAEPAXII@Z) referenced in function "public: struct boost::re_detail::re_syntax_base * __thiscall boost::re_detail::basic_regex_creator<char,struct boost::regex_traits<char,class boost::cpp_regex_traits<char> > >::insert_state(int,enum boost::re_detail::syntax_element_type,unsigned int)" (?insert_state@?$basic_regex_creator@DU?$regex_traits@DV?$cpp_regex_traits@D@boost@@@boost@@@re_detail@boost@@QAEPAUre_syntax_base@2 3@HW4syntax_element_type@23@I@Z) J:\Cpp\Misc\Debug\grep.exe : fatal error LNK1120: 2 unresolved externals In release mode, it compiles and links, but promptly crashes :-( Suggestions what I am doing wrong? Thanks Paul --- Paul A Bristow Prizet Farmhouse, Kendal, Cumbria UK LA8 8AB +44 1539561830 & SMS, Mobile +44 7714 330204 & SMS pbristow@hetp.u-net.com

Hi Paul, I don't have a Visual C compiler around but the link error you got is probably not related with the grep filter. For the run time bug, one of my friends had the same experience and we have found out that visual c cannot handle iterators of the empty strings. So I made a workaround for it, I don't know if it works, since I couldn't try it with VC yet. Can you download, give it a try and let me know if it works for you? http://emreturkay.googlepages.com/grep.hpp Thanks, Emre Turkay On Feb 5, 2008 8:47 PM, Paul A Bristow <pbristow@hetp.u-net.com> wrote:

Sadly, this gives me the same result in both debug (link failure - missing include?) and release (crashes). :-( Paul Linking... demo_grep.obj : error LNK2019: unresolved external symbol "public: void __thiscall boost::re_detail::raw_storage::resize(unsigned int)" (?resize@raw_storage@re_detail@boost@@QAEXI@Z) referenced in function "public: void * __thiscall boost::re_detail::raw_storage::extend(unsigned int)" (?extend@raw_storage@re_detail@boost@@QAEPAXI@Z) demo_grep.obj : error LNK2019: unresolved external symbol "public: void * __thiscall boost::re_detail::raw_storage::insert(unsigned int,unsigned int)" (?insert@raw_storage@re_detail@boost@@QAEPAXII@Z) referenced in function "public: struct boost::re_detail::re_syntax_base * __thiscall boost::re_detail::basic_regex_creator<char,struct boost::regex_traits<char,class boost::cpp_regex_traits<char> > >::insert_state(int,enum boost::re_detail::syntax_element_type,unsigned int)" (?insert_state@?$basic_regex_creator@DU?$regex_traits@DV?$cpp_regex_traits@D@boost@@@boost@@@re_detail@boost@@QAEPAUre_syntax_base@2 3@HW4syntax_element_type@23@I@Z) J:\Cpp\Misc\Debug\grep.exe : fatal error LNK1120: 2 unresolved externals

Hi Paul, I have found a Visual Studio 2005 installed windows PC and tried to compile. The first one was apparently failing because of the problem I mentioned before. However, the last one compiles and runs fine for both release and debug targets. I used Boost Consulting's BoostPro 1.34.1 installer. My main.cpp file is below, you need to change the full_path_to_the_main.cpp. HTH, emre int main() { boost::iostreams::grep_filter filter("main"); boost::iostreams::filtering_istream is; is.unsetf(std::ios::skipws); is.push(filter); is.push(boost::iostreams::file_source("full_path_to_the_main.cpp")); std::copy(std::istream_iterator<char>(is), std::istream_iterator<char>(), std::ostream_iterator<char>(std::cout)); } On Feb 6, 2008 11:26 AM, Paul A Bristow <pbristow@hetp.u-net.com> wrote:

I've looked a tiny amount further (but don't have time to investigate further). I'm sure this will prove useful. Paul If MS Extensions are Disabled (my default setting): It would seem that BOOST_REGEX_CALL?? is not defined for __thiscall - only for __decl and __fastcall Compiling... in debug mode demo_grep.cpp Linking... demo_grep.obj : error LNK2019: unresolved external symbol "public: void __thiscall boost::re_detail::raw_storage::resize(unsigned int)" (?resize@raw_storage@re_detail@boost@@QAEXI@Z) referenced in function "public: void * __thiscall boost::re_detail::raw_storage::extend(unsigned int)" (?extend@raw_storage@re_detail@boost@@QAEPAXI@Z) demo_grep.obj : error LNK2019: unresolved external symbol "public: void * __thiscall boost::re_detail::raw_storage::insert(unsigned int,unsigned int)" (?insert@raw_storage@re_detail@boost@@QAEPAXII@Z) referenced in function "public: struct boost::re_detail::re_syntax_base * __thiscall boost::re_detail::basic_regex_creator<char,struct boost::regex_traits<char,class boost::cpp_regex_traits<char> > >::insert_state(int,enum boost::re_detail::syntax_element_type,unsigned int)" (?insert_state@?$basic_regex_creator@DU?$regex_traits@DV?$cpp_regex_traits@D@boost@@@boost@@@re_detail@boost@@QAEPAUre_syntax_base@2 3@HW4syntax_element_type@23@I@Z) J:\Cpp\Misc\Debug\grep.exe : fatal error LNK1120: 2 unresolved externals If MS Extensions are enabled, it compiles but fails an assert line 271 in xstring - "string iterators incompatible" In release mode the program simply bombs :-(

Emre Turkay wrote:
Each time you make a revision, please post it here: http://svn.boost.org/trac/boost/ticket/1627. Best Regards, -- Jonathan Turkanis CodeRage http://www.coderage.com
participants (3)
-
Emre Turkay
-
Jonathan Turkanis
-
Paul A Bristow