]> git.tdb.fi Git - libs/core.git/blobdiff - grep.cpp
Fix a bug in Regex with brackets
[libs/core.git] / grep.cpp
index 8c369a56f0c2fb3834c9d3ba5b0eed998ed92e67..eaf1663e7cf1098b42aabd4b9dc454b5f09f61e6 100644 (file)
--- a/grep.cpp
+++ b/grep.cpp
@@ -1,6 +1,7 @@
 /* $Id$ */
 #include <iostream>
 #include <string>
+#include <msp/core/getopt.h>
 #include "regex.h"
 
 using namespace std;
@@ -8,21 +9,27 @@ 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 list<string> &args=getopt.get_args();
+
+       if(args.empty())
        {
                cerr<<"Usage: "<<argv[0]<<" <regex>\n";
                return 1;
        }
 
        Regex regex(argv[1]);
-       cout<<regex.disassemble();
+       if(debug)
+               cout<<regex.disassemble();
        string line;
        while(getline(cin, line))
        {
                if(RegMatch match=regex.match(line))
-               {
                        cout<<line<<'\n';
-               }
        }
 
        return 0;