X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=ntsimulator%2Fregxstring%2Fmain.cpp;fp=ntsimulator%2Fregxstring%2Fmain.cpp;h=bfc18e38591fb869e880bbe1443bf5d9b6d27980;hb=f1d5c9198acde7a7ce296490087cad37e008f688;hp=0000000000000000000000000000000000000000;hpb=f2d8f1002fa93848c80a88e5658db4816cba3020;p=sim%2Fo1-interface.git diff --git a/ntsimulator/regxstring/main.cpp b/ntsimulator/regxstring/main.cpp new file mode 100644 index 0000000..bfc18e3 --- /dev/null +++ b/ntsimulator/regxstring/main.cpp @@ -0,0 +1,149 @@ +/************************************************************************* +* +* 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 "<