]> git.tdb.fi Git - libs/core.git/commitdiff
Remove the "optimization" of omitting MATCH_CHAR instruction for characters >LAST_INS...
authorMikko Rasa <tdb@tdb.fi>
Wed, 28 May 2008 23:56:45 +0000 (23:56 +0000)
committerMikko Rasa <tdb@tdb.fi>
Wed, 28 May 2008 23:56:45 +0000 (23:56 +0000)
Fix commandline handling in grep

grep.cpp
source/regex.cpp

index eaf1663e7cf1098b42aabd4b9dc454b5f09f61e6..07743072be997253e83356cd5704ea414be7c282 100644 (file)
--- a/grep.cpp
+++ b/grep.cpp
@@ -14,7 +14,7 @@ int main(int argc, char **argv)
        getopt.add_option('d', "debug", debug, GetOpt::NO_ARG);
        getopt(argc, argv);
 
-       const list<string> &args=getopt.get_args();
+       const vector<string> &args=getopt.get_args();
 
        if(args.empty())
        {
@@ -22,7 +22,7 @@ int main(int argc, char **argv)
                return 1;
        }
 
-       Regex regex(argv[1]);
+       Regex regex(args[0]);
        if(debug)
                cout<<regex.disassemble();
        string line;
index d3fd0b7ebc4e58b733947387a6e4f349e83bd7ce..48fe4a7c3422fb027c40481d1f7d39b8fc7010d3 100644 (file)
@@ -244,8 +244,7 @@ Regex::Code Regex::parse_atom(const string &expr, string::const_iterator &i, uns
 
        if(flag)
        {
-               if(static_cast<unsigned char>(*i)<=LAST_INSTRUCTION_)
-                       result+=MATCH_CHAR;
+               result+=MATCH_CHAR;
                result+=*i;
        }
 
@@ -388,11 +387,7 @@ bool Regex::run(const string &str, const string::const_iterator &begin, RegMatch
                        bool negate_match=false;
                        for(; j->citer!=code.end();)
                        {
-                               Instruction instr=static_cast<Instruction>(*j->citer);
-                               if(instr>LAST_INSTRUCTION_)
-                                       instr=MATCH_CHAR;
-                               else
-                                       ++j->citer;
+                               Instruction instr=static_cast<Instruction>(*j->citer++);
 
                                if(instr==NEGATE)
                                        negate_match=true;
@@ -517,11 +512,7 @@ bool Regex::group_compare(const RegMatch::Group &g1, const RegMatch::Group &g2)
 
 string Regex::disassemble_instruction(Code::const_iterator &i) const
 {
-       Instruction instr=static_cast<Instruction>(*i);
-       if(instr>=LAST_INSTRUCTION_)
-               instr=MATCH_CHAR;
-       else
-               ++i;
+       Instruction instr=static_cast<Instruction>(*i++);
 
        ostringstream result;
        switch(instr)
@@ -575,8 +566,7 @@ string Regex::disassemble_instruction(Code::const_iterator &i) const
        case MATCH_ANY:
                result<<"MATCH_ANY";
                break;
-       case FIRST_INSTRUCTION_:
-       case LAST_INSTRUCTION_:
+       default:
                result<<"UNKNOWN "<<instr;
        }