/************************************************************************* * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. ***************************************************************************/ #include #include #include #include #include #include "regxstring.h" using namespace std; bool debug; const char * filename; static std::string Trim(std::string str){ size_t i = 0,e = str.length(); for(;i < e && std::isspace(str[i]);++i); size_t j = e; for(;j > i && std::isspace(str[j - 1]);--j); return (i < j ? str.substr(i,j - i) : ""); } static bool ExtractArg(const char * argstr,const char * pattern,const char *& result) { if(!argstr || !pattern) return false; for(;*pattern;++pattern,++argstr) if(*pattern != *argstr) return false; result = *argstr ? argstr : 0; return true; } static const char * ProgramName(const char * argstr) { const char * ret = argstr; for(const char * cur = argstr;cur && *cur;++cur) if(*cur == '/') ret = cur + 1; return ret; } static std::string pre_handle(const std::string & str) { std::string ret = Trim(str); if(!ret.empty()){ if(ret[0] != '^') ret.insert(ret.begin(),'^'); if(ret[ret.size() - 1] != '$') ret.push_back('$'); } return ret; } #ifdef TEST # include "test.h" #endif static void printUsage(const char * exe) { cout<<"Usage: "<is_open()){ delete file; cerr<<"cannot open file "<