Add a simple grep program
[libs/core.git] / grep.cpp
1 /* $Id$ */
2 #include <iostream>
3 #include <string>
4 #include "regex.h"
5
6 using namespace std;
7 using namespace Msp;
8
9 int main(int argc, char **argv)
10 {
11         if(argc<2)
12         {
13                 cerr<<"Usage: "<<argv[0]<<" <regex>\n";
14                 return 1;
15         }
16
17         Regex regex(argv[1]);
18         cout<<regex.disassemble();
19         string line;
20         while(getline(cin, line))
21         {
22                 if(RegMatch match=regex.match(line))
23                 {
24                         cout<<line<<'\n';
25                 }
26         }
27
28         return 0;
29 }