]> git.tdb.fi Git - libs/core.git/blobdiff - grep.cpp
Add a simple grep program
[libs/core.git] / grep.cpp
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;
+}