]> git.tdb.fi Git - libs/core.git/blobdiff - grep.cpp
Move files around to prepare for assimilation into core
[libs/core.git] / grep.cpp
index 8c369a56f0c2fb3834c9d3ba5b0eed998ed92e67..68ecf874f46b919306c703f5e6fc07c2af4b5249 100644 (file)
--- a/grep.cpp
+++ b/grep.cpp
@@ -1,28 +1,35 @@
 /* $Id$ */
 #include <iostream>
 #include <string>
-#include "regex.h"
+#include <msp/core/getopt.h>
+#include <msp/strings/regex.h>
 
 using namespace std;
 using namespace Msp;
 
 int main(int argc, char **argv)
 {
-       if(argc<2)
+       bool debug = false;
+       GetOpt getopt;
+       getopt.add_option('d', "debug", debug, GetOpt::NO_ARG);
+       getopt(argc, argv);
+
+       const vector<string> &args = getopt.get_args();
+
+       if(args.empty())
        {
                cerr<<"Usage: "<<argv[0]<<" <regex>\n";
                return 1;
        }
 
-       Regex regex(argv[1]);
-       cout<<regex.disassemble();
+       Regex regex(args[0]);
+       if(debug)
+               cout<<regex.disassemble();
        string line;
        while(getline(cin, line))
        {
-               if(RegMatch match=regex.match(line))
-               {
+               if(RegMatch match = regex.match(line))
                        cout<<line<<'\n';
-               }
        }
 
        return 0;