]> git.tdb.fi Git - libs/core.git/commitdiff
Add a simple grep program
authorMikko Rasa <tdb@tdb.fi>
Wed, 20 Jun 2007 20:19:10 +0000 (20:19 +0000)
committerMikko Rasa <tdb@tdb.fi>
Wed, 20 Jun 2007 20:19:10 +0000 (20:19 +0000)
Build
grep.cpp [new file with mode: 0644]

diff --git a/Build b/Build
index 8a7d481ee334aec0c03e8d4198492a1b61695448..688fe615fe70b98e709894345dcd837b265472d7 100644 (file)
--- a/Build
+++ b/Build
@@ -10,4 +10,15 @@ package "mspstrings"
                install true;
                install_headers "msp/strings";
        };
+
+       program "grep"
+       {
+               source "grep.cpp";
+               build_info
+               {
+                       incpath "source";
+                       libpath ".";
+                       library "mspstrings";
+               };
+       };
 };
diff --git a/grep.cpp b/grep.cpp
new file mode 100644 (file)
index 0000000..8c369a5
--- /dev/null
+++ b/grep.cpp
@@ -0,0 +1,29 @@
+/* $Id$ */
+#include <iostream>
+#include <string>
+#include "regex.h"
+
+using namespace std;
+using namespace Msp;
+
+int main(int argc, char **argv)
+{
+       if(argc<2)
+       {
+               cerr<<"Usage: "<<argv[0]<<" <regex>\n";
+               return 1;
+       }
+
+       Regex regex(argv[1]);
+       cout<<regex.disassemble();
+       string line;
+       while(getline(cin, line))
+       {
+               if(RegMatch match=regex.match(line))
+               {
+                       cout<<line<<'\n';
+               }
+       }
+
+       return 0;
+}