Move files around to prepare for assimilation into core
[libs/core.git] / grep.cpp
1 /* $Id$ */
2 #include <iostream>
3 #include <string>
4 #include <msp/core/getopt.h>
5 #include <msp/strings/regex.h>
6
7 using namespace std;
8 using namespace Msp;
9
10 int main(int argc, char **argv)
11 {
12         bool debug = false;
13         GetOpt getopt;
14         getopt.add_option('d', "debug", debug, GetOpt::NO_ARG);
15         getopt(argc, argv);
16
17         const vector<string> &args = getopt.get_args();
18
19         if(args.empty())
20         {
21                 cerr<<"Usage: "<<argv[0]<<" <regex>\n";
22                 return 1;
23         }
24
25         Regex regex(args[0]);
26         if(debug)
27                 cout<<regex.disassemble();
28         string line;
29         while(getline(cin, line))
30         {
31                 if(RegMatch match = regex.match(line))
32                         cout<<line<<'\n';
33         }
34
35         return 0;
36 }