Exemple #1
0
bool CDolo8264COM::SearchLayer1(CString &str_url)
{

	CString cs_webContent;
	vector<string> astr;  //下载链接集合
	// http://u.8264.com/home-space-uid-104370-do-album-id-1496-page-1.html#comment
	// http://u.8264.com/home-space-uid-104370-do-album-view-me-from-space.html
	int t1 = str_url.Find(_T("album-id"));
	if(t1 >-1)
	{
		str_url.Delete(t1,str_url.GetLength() - t1);
		str_url+=_T("album-view-me-from-space.html");
	}

	DownloadUrlPage(str_url,cs_webContent);	
	regex reg("[a-zA-z]+://[^\\s]*.html\"  class=\"xi2\"");  	//图片模式
	smatch m1; 

	string s = cs_webContent.GetBuffer();	
	string::const_iterator it = s.begin(); 
	string::const_iterator end=s.end();
	while(regex_search(it,end,m1,reg))
	{
/*		int size = m1[0].length();*/
		string msg(m1[0].first,m1[0].second);	
		msg.erase(msg.size()-14,msg.size());
		astr.push_back(msg);
		it = m1[0].second; 
		msg.empty();
		myidle();
	}
	s.empty();
	for(unsigned int i=0; i<astr.size();i++)
	{
		CString strMfc=astr[i].c_str();
		SearchLayer3(strMfc);
	}
	astr.empty();
	return true;
}
/** Given a string such as
 *      "<glob> <glob> ... *.{abc,def} <glob>",
 *  convert the csh-style brace expresions:
 *      "<glob> <glob> ... *.abc *.def <glob>".
 *  Requires no system support, so should work equally on Unix, Mac, Win32.
 */
static string const convert_brace_glob(string const & glob)
{
	// Matches " *.{abc,def,ghi}", storing "*." as group 1 and
	// "abc,def,ghi" as group 2, while allowing spaces in group 2.
	static lyx::regex const glob_re(" *([^ {]*)\\{([^}]+)\\}");
	// Matches "abc" and "abc,", storing "abc" as group 1,
	// while ignoring surrounding spaces.
	static lyx::regex const block_re(" *([^ ,}]+) *,? *");

	string pattern;

	string::const_iterator it = glob.begin();
	string::const_iterator const end = glob.end();
	while (true) {
		match_results<string::const_iterator> what;
		if (!regex_search(it, end, what, glob_re)) {
			// Ensure that no information is lost.
			pattern += string(it, end);
			break;
		}

		// Everything from the start of the input to
		// the start of the match.
		pattern += string(what[-1].first, what[-1].second);

		// Given " *.{abc,def}", head == "*." and tail == "abc,def".
		string const head = string(what[1].first, what[1].second);
		string const tail = string(what[2].first, what[2].second);

		// Split the ','-separated chunks of tail so that
		// $head{$chunk1,$chunk2} becomes "$head$chunk1 $head$chunk2".
		string const fmt = " " + head + "$1";
		pattern += regex_replace(tail, block_re, fmt);

		// Increment the iterator to the end of the match.
		it += distance(it, what[0].second);
	}

	return pattern;
}
Exemple #3
0
string WebPage::evaluateRegexOnXPath_first(string exp, string xpath)
{
	evaluateXPath(xpath);
	if (xpathObj)
	{
		string flattened;
		for (int i = 0; i < xpathObj->nodesetval->nodeNr; i++)
		{
			xmlChar *strRep = xmlXPathCastNodeToString(xpathObj->nodesetval->nodeTab[i]);
			string nodeStr((char*)strRep);
			if (!nodeStr.empty())
				flattened += nodeStr + string("\n");
			xmlFree(strRep);
		}
		regex rankREGEX(exp);
		smatch match;
		regex_search(flattened, match, rankREGEX);
		return match.str();
	}
	else
		return "";
}
Exemple #4
0
    regex_search_result<ForwardIteratorT>
    operator()(
        ForwardIteratorT Begin,
        ForwardIteratorT End ) const
    {
        typedef ForwardIteratorT input_iterator_type;
        typedef regex_search_result<ForwardIteratorT> result_type;

        // instantiate match result
        match_results<input_iterator_type> result;
        // search for a match
        if ( regex_search( Begin, End, result, m_Rx, m_MatchFlags ) )
        {
            // construct a result
            return result_type( result );
        }
        else
        {
            // empty result
            return result_type( End );
        }
    }
Exemple #5
0
void SignalFrame::insert( std::vector<std::string>& input )
{
  // extract:   variable_name:type=value   or   variable_name:array[type]=value1,value2
  boost::regex expression(  "([[:word:]]+)(\\:([[:word:]]+)(\\[([[:word:]]+)\\])?=(.*))?"  );
  boost::match_results<std::string::const_iterator> what;

  boost_foreach (const std::string& arg, input)
  {

    std::string name;
    std::string type;
    std::string subtype; // in case of array<type>
    std::string value;

    if (regex_search(arg,what,expression))
    {
      name=what[1];
      type=what[3];
      subtype=what[5];
      value=what[6];

      //CFinfo << name << ":" << type << (subtype.empty() ? std::string() : std::string("["+subtype+"]"))  << "=" << value << CFendl;

      if(type == "array")
      {
        set_array(name, subtype, value, " ; ");
      }
      else
      {
        set_option(name, type, value);
      }
    }
    else
      throw ParsingFailed(FromHere(), "Could not parse [" + arg + "].\n"+
                          "Format should be:\n"
                          " -  for simple types:  variable_name:type=value\n"
                          " -  for array types:   variable_name:array[type]=value1,value2\n"
                          "  with possible type: [bool,unsigned,integer,real,string,uri]");
  }
void bcp_implementation::add_dependent_lib(const std::string& libname, const fs::path& p, const fileview& view)
{
   //
   // if the boost library libname has source associated with it
   // then add the source to our list:
   //
   if(fs::exists(m_boost_path / "libs" / libname / "src"))
   {
      if(!m_dependencies.count(fs::path("libs") / libname / "src")) 
      {
         if(scanner.count(libname) == 0)
            init_library_scanner(m_boost_path / "libs" / libname / "src", m_cvs_mode, libname);
         boost::cmatch what;
         if(regex_search(view.begin(), view.end(), what, scanner[libname]))
         {
            std::cout << "INFO: tracking source dependencies of library " << libname
               << " due to presence of \"" << what << "\" in file " << p << std::endl;
            //std::cout << "Full text match was: " << what << std::endl;
            m_dependencies[fs::path("libs") / libname / "src"] = p; // set up dependency tree
            add_path(fs::path("libs") / libname / "src");

            if(fs::exists(m_boost_path / "libs" / libname / "build"))
            {
               if(!m_dependencies.count(fs::path("libs") / libname / "build")) 
               {
                  m_dependencies[fs::path("libs") / libname / "build"] = p; // set up dependency tree
                  add_path(fs::path("libs") / libname / "build");
                  //m_dependencies[fs::path("boost-build.jam")] = p;
                  //add_path(fs::path("boost-build.jam"));
                  m_dependencies[fs::path("Jamroot")] = p;
                  add_path(fs::path("Jamroot"));
                  //m_dependencies[fs::path("tools/build")] = p;
                  //add_path(fs::path("tools/build"));
               }
            }
         }
      }
   }
}
Exemple #7
0
HAMIGAKI_BJAM_DECL string_list transform(context& ctx)
{
    frame& f = ctx.current_frame();
    const list_of_list& args = f.arguments();

    const string_list& list = args[0];
    const std::string& pattern = bjam::convert_regex(args[1][0]);
    const string_list& arg3 = args[2];

    std::vector<int> indices;
    if (arg3.empty())
        indices.push_back(1);
    else
    {
        indices.reserve(arg3.size());
        for (std::size_t i = 0; i < arg3.size(); ++i)
            indices.push_back(std::atoi(arg3[i].c_str()));
    }

    string_list result;

    // Note: bjam's regex is not the same as "egrep" and "ECMAScript"
    boost::regex rex(pattern);
    for (std::size_t i = 0; i < list.size(); ++i)
    {
        boost::smatch what;
        if (regex_search(list[i], what, rex))
        {
            for (std::size_t j = 0; j < indices.size(); ++j)
            {
                const std::string& s = what[indices[j]].str();
                if (!s.empty())
                    result += s;
            }
        }
    }

    return result;
}
Exemple #8
0
    CommandResponse CommandInterface::SendCommand(std::string cmd) {
        CURLcode rc;
        CURL *handle = connection->getHandle();

        last_response.clear();
        read_buffer.clear();
        std::ostringstream cmd_url;

        cmd_url << "http://" << connection->host() << ":" << connection->port() << "/" << cmd;
        last_cmd_url = cmd_url.str();


        curl_easy_setopt(handle, CURLOPT_USERAGENT, "curl/7.58.0");
        /* send all data to this function  */
        curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, WriteCallback);
        curl_easy_setopt(handle, CURLOPT_WRITEDATA, &read_buffer);
        curl_easy_setopt(handle, CURLOPT_URL, cmd_url.str().c_str());

        rc = curl_easy_perform(handle);

        if (rc != CURLE_OK) {
            throw std::runtime_error(curl_easy_strerror(rc));
        }

        // all responses are hidden in HTML comments ...
        std::regex response_comment_re("<!--(.*)-->", std::regex_constants::ECMAScript);
        std::smatch comment_match;
        if (!regex_search(read_buffer, comment_match, response_comment_re)) {
            throw std::runtime_error("parsing error, response not found ");
        }

        last_response = comment_match[1].str();
        if (last_response.empty()) {
            throw std::runtime_error("parsing error, response empty");
        }

        return CommandResponse(comment_match[1].str());
    }
HAMIGAKI_BJAM_DECL string_list subst(context& ctx)
{
    frame& f = ctx.current_frame();
    const list_of_list& args = f.arguments();
    const string_list& arg1 = args[0];

    const std::string& str = arg1[0];
    const std::string& pattern = bjam::convert_regex(arg1[1]);

    // Note: bjam's regex is not the same as "egrep" and "ECMAScript"
    boost::regex rex(pattern);

    string_list result;

    boost::smatch what;
    if (regex_search(str, what, rex))
    {
        for (std::size_t i = 2, size = arg1.size(); i < size; ++i)
            result += what.format(arg1[i]);
    }

    return result;
}
Exemple #10
0
void IndexClasses(map_type& m, const std::string& file)
{
   std::string::const_iterator start, end;
   start = file.begin();
   end = file.end();
      boost::match_results<std::string::const_iterator> what;
   boost::match_flag_type flags = boost::match_default;
   while(regex_search(start, end, what, expression, flags))
   {
      // what[0] contains the whole string 
      // what[5] contains the class name. 
      // what[6] contains the template specialisation if any. 
      // add class name and position to map: 
      m[std::string(what[5].first, what[5].second)
            + std::string(what[6].first, what[6].second)]
         = what[5].first - file.begin();
      // update search position: 
      start = what[0].second;
      // update flags: 
      flags |= boost::match_prev_avail;
      flags |= boost::match_not_bob;
   }
}
		/*
		  Looks for a partial match
		  Checked
		*/
		void BookCollection::partialMatch(std::string title, 
			std::vector<std::list<BookData>::iterator>&found)
		{
			// To hold the position of the found book
			std::list<BookData>::iterator pos = bookList.begin();

			// creates a regular expression using the string that is passed 
			// and flags the expression to be case insensitive
			std::regex e(title, std::regex_constants::ECMAScript 
				| std::regex_constants::icase);

			// look through the array of books
			for (unsigned int index = 0; index < bookList.size(); index++)
			{
				// if string matches a subtring of the title
				if (regex_search(pos->getTitle(), e))
				{
					// add the index to the array
					found.push_back(pos);
				} // end if
				pos++;
			} // end for
		} // end function partialMatch
void SocketServer::run()
{
	cout << "Server start at " << this->tcpServer.getPort() << endl;
	idCli = 0;
	string dataR;
	while (this->servRun) {
		
		this->tcpServer.waitConnectedClient();
		for (int i = 0; i < this->tcpServer.getLastID(); i++) {

			if (this->tcpServer.isClientConnected(i)) {
				idCli = i;
				cout << "Client Add ID :" << this->tcpServer.getLastID() << endl;
				while (this->tcpServer.isClientConnected(idCli)) {
					dataR = this->tcpServer.receive(idCli);
					if (dataR != "") {
						//regex self_regex("SpeedLife ([0-9]+)",regex_constants::ECMAScript | regex_constants::icase);
						regex self_regex("PUSH But", regex_constants::ECMAScript | regex_constants::icase);
						smatch match;
						//cout << dataR << endl;
						if (regex_search(dataR, match, self_regex )) {
							this->dataLife->launchInvade = true;
							//std::cout << (unsigned int)stoul(match[1]) << " ok ok \n";
							//this->dataLife->speedLifeGame = (unsigned int) stoul(match[1]);
						}
						//this->tcpServer.send(idCli, "You sent: " + dataR);
					}
					this->tcpServer.sleep(50);
					
				}
				cout << "Client Out" << endl;
			}
		}
		this->tcpServer.sleep(1000);
	}
	cout << "Server close" << endl;
}
Exemple #13
0
/*!
 *  \brief Calcule la littérale résultante de l'expression
 */
Litterale* LitteraleExpression::eval() {
    
    Interpreteur& inter=Interpreteur::getInstance();
    FactoryLitterale& fl=FactoryLitterale::getInstance();
    FactoryOperateur& fo=FactoryOperateur::getInstance();
    
    string s(exp);
    regex e;
    smatch m;

    // Traitement des opérateurs unaires s'appliquant à l'expression
    regex opUnaire("([A-Z](?:[A-Z]|[0-9])*)\\(([^,\\(\\)]+)\\)");
    while (std::regex_search (s,m,opUnaire)) {
        cout<<m[0]<<" "<<m[1]<<" "<<m[2]<<endl;
        // m[1] l'opérateur et m[2] l'argument
        if(inter.isOperateur(m[1])) {
            Litterale* l1 = fl.newLitteraleExpression(m[2])->eval();
            Operateur* op= inter.toOperateur(m[1]);
            return op->applyUnaire(l1);
        }
    }
    
    // Traitement des opérateurs binaires s'appliquant à l'expression
    regex opBinaire("([A-Z](?:[A-Z]|[0-9])*)\\(([^,\\(]+),([^,\\(\\)]+)\\)");
    while (std::regex_search (s,m,opBinaire)) {
        //cout<<m[0]<<" "<<m[1]<<" "<<m[2]<<" "<<m[3]<<endl;
        // m[1] l'opérateur et m[2] l'argument 1 et m[2] l'argument 2
        if(inter.isOperateur(m[1])) {
            Litterale* l1 = fl.newLitteraleExpression(m[2])->eval();
            Litterale* l2 = fl.newLitteraleExpression(m[3])->eval();
            Operateur* op= inter.toOperateur(m[1]);
            return op->applyBinaire(l1,l2);
        }
    }

    // Remplacement des variables par leur contenu
    regex atome("((?:[[:upper:]]{1})(?:[[:upper:]]|[[:digit:]])*)");
    while (regex_search(s,m,atome)) {
        LitteraleAtome* var = LitteraleAtome::getVar(m[1]);
        if(var) {
            Litterale* c = var->getValeur();
            s.replace(s.find(m[0]), m[0].length(), c->toString());
        }
    }
    
    // Traitement des groupes parenthésés
    // Le but est de ne se retrouver qu'avec
    // une suite d'opérations arithmétiques sans parenthèses
    regex paren("\\(([^\\(]*?)\\)");
    while (regex_search(s,m,paren)) {
        //cout<<m[0]<<" va être remplcé par "<<m[1]<<endl;
        Litterale* c = fl.newLitteraleExpression(m[1])->eval();
        //cout<<"av. "<<s<<endl;
        s.replace(s.find(m[0]), m[0].length(), c->toString());
        //cout<<"apr. "<<s<<endl;
    }
    
    // Traitement des + et -
    regex somme("([^\\+]*[1-9])([\\+-])(.+)");
    if (regex_search(s,m,somme)) {
        //cout<<m[1]<<" "<<m[2]<<" "<<m[3]<<endl;
            
        // Conversion en littérale des deux cotés
        Litterale* l1=fl.newLitteraleExpression(m[1])->eval();  // On converti en littérale la partie gauche
        Litterale* l2=fl.newLitteraleExpression(m[3])->eval();  // On converti en littérale la partie droite
        
        // Création de l'opérateur
        OperateurNumerique* op=fo.newOperateurNumerique(m[2]);
        
        // Application du résultat
        Litterale* l3=op->applyBinaire(l1, l2);
        return l3;
    }
    
    // Traitement des * et /
    regex produit("([^\\+]*[1-9])([\\*/])(.+)");
    if (regex_search(s,m,produit)) {
        //cout<<m[1]<<" "<<m[2]<<" "<<m[3]<<endl;
        
        // Conversion en littérale des deux cotés
        Litterale* l1=fl.newLitteraleExpression(m[1])->eval();  // On converti en littérale la partie gauche
        Litterale* l2=fl.newLitteraleExpression(m[3])->eval();  // On converti en littérale la partie droite
        
        // Création de l'opérateur
        OperateurNumerique* op=fo.newOperateurNumerique(m[2]);
        
        // Application du résultat
        Litterale* l3=op->applyBinaire(l1, l2);
        return l3;
    }

    // On vérifie que ce n'est pas tout simplement une littérale
    if(inter.isLitterale(s)) {
        return inter.toLitterale(s);
    }
    
    return nullptr;
}
Exemple #14
0
int main(int argc , char* argv[])
{
    if (88 == initial_arg(argc , argv))
        return 88;

    char AppPath[MAX_PATH] = {0};
    GetAppDir(AppPath);

    string date_txt = string(AppPath) + "\\date.txt";
    string listfile_txt = string(AppPath) + "\\listfile.txt";

    if (_chdir(Path_Argv.c_str())) {
        printf("无法找到的目录: %s\n\a\n\n", Path_Argv.c_str());
        print_help();
        if (argc == 1) getchar();
        return -1;
    } else if (!Direct_Datelog_Flag) {
        printf("正在扫描目录: %s\n", Path_Argv.c_str());
        // 获得文件名和路径数据输入文件 ,和差不多DIR . /S /AA /TW >\date.txt
        int file_sum = find_path_save_file(Path_Argv.c_str(), date_txt.c_str());
        printf("扫描文件总数量: %d 个文件\t" , file_sum);
    }

    ifstream datefile(date_txt.c_str());
    ofstream listfile(listfile_txt.c_str());

    string readline;    // 读取每行,然后使用正则搜索匹配
    smatch m;
    regex e(Reg_Argv);

    F_STRUCT d_file ;  // 简单的文件属性结构
    map<string, string> mss_date;
    size_t file_size_sum = 0 ;

    while (getline(datefile , readline)) {
        char buf[MAX_PATH * 2];
        char* pch = NULL;
        if (regex_search(readline, m, e)) {      // 符合条件的的文件列表存如容器
            //  sscanf(readline.c_str() + 32 , "%s | %s" ,  d_file.name, d_file.path);  // 不能处理路径和文件名中有空格
            sscanf(readline.c_str() + 20 , "%d" , &d_file.size);  file_size_sum += d_file.size;
            sprintf(buf, "%s", readline.c_str() + 32);

            pch = strchr(buf, '|'); // 查找分割标记
            if (pch != NULL) {
                *pch = '\0';
                strcpy(d_file.name , buf);
                strcpy(d_file.path , pch + 1);

                csTrim(d_file.name);  csTrim(d_file.path); // 删除前后空格
                mss_date.insert(make_pair(string(d_file.path) + "\\" + d_file.name  , string(d_file.name)));
            }
        }
    }
    printf("符合条件文件数量: %d 个文件  大小: %d字节\n" , mss_date.size() , file_size_sum);
    for (auto it = mss_date.begin() ; it != mss_date.end(); ++it)
        listfile << it->first.substr(it->first.find(":\\") + 2) << "\n"; // 输出结果

    datefile.close();  listfile.close();

    // 调用7z命令行打包文件,
    string pkcmd = string("7z.exe a -scsWIN  ") + Packfile_Argv + " @" + listfile_txt;

    if (IsFileExist((string(AppPath) + "\\res\\7z.exe").c_str()))
        pkcmd = string(AppPath) + "\\res\\" + pkcmd;
    if (Test_List_Flag) pkcmd = string("TYPE ") + listfile_txt;   // 只是显示 listfiel.txt, 不打包文件

    _chdir("\\"); system("COLOR F9");
    if (system(pkcmd.c_str()) != 0) {
        fprintf(stdout, "%s\t%s %s\n" , "调用打包命令:" , pkcmd.c_str(), "失败!请检查软件目录下是否有 7z.exe");
    }
    print_help();
    if (Delete_Datelog_Flag) {
        remove(date_txt.c_str());   remove(listfile_txt.c_str());
    }
    if (argc == 1) getchar();

    return 0;
}
BOOST_REGEX_DECL int BOOST_REGEX_CCALL regexecW(const regex_tW* expression, const wchar_t* buf, regsize_t n, regmatch_t* array, int eflags)
{
#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable:4267)
#endif
   bool result = false;
   match_flag_type flags = match_default | expression->eflags;
   const wchar_t* end;
   const wchar_t* start;
   wcmatch m;
   
   if(eflags & REG_NOTBOL)
      flags |= match_not_bol;
   if(eflags & REG_NOTEOL)
      flags |= match_not_eol;
   if(eflags & REG_STARTEND)
   {
      start = buf + array[0].rm_so;
      end = buf + array[0].rm_eo;
   }
   else
   {
      start = buf;
      end = buf + std::wcslen(buf);
   }

#ifndef BOOST_NO_EXCEPTIONS
   try{
#endif
   if(expression->re_magic == wmagic_value)
   {
      result = regex_search(start, end, m, *static_cast<wc_regex_type*>(expression->guts), flags);
   }
   else
      return result;
#ifndef BOOST_NO_EXCEPTIONS
   } catch(...)
   {
      return REG_E_UNKNOWN;
   }
#endif
   if(result)
   {
      // extract what matched:
      std::size_t i;
      for(i = 0; (i < n) && (i < expression->re_nsub + 1); ++i)
      {
         array[i].rm_so = (m[i].matched == false) ? -1 : (m[i].first - buf);
         array[i].rm_eo = (m[i].matched == false) ? -1 : (m[i].second - buf);
      }
      // and set anything else to -1:
      for(i = expression->re_nsub + 1; i < n; ++i)
      {
         array[i].rm_so = -1;
         array[i].rm_eo = -1;
      }
      return 0;
   }
   return REG_NOMATCH;
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
}
Exemple #16
0
inline bool regex_search(const std::basic_string<charT, ST, SA>& s, 
                 const basic_regex<charT, traits>& e, 
                 match_flag_type flags = match_default)
{
   return regex_search(s.begin(), s.end(), e, flags);
}
Exemple #17
0
inline bool regex_search(const charT* str, 
                        const basic_regex<charT, traits>& e, 
                        match_flag_type flags = match_default)
{
   return regex_search(str, str + traits::length(str), e, flags);
}
PIN_ControllerKeyComboSet* PIN_GameControllerManager::BuildComboSet(PIN_GameControllerEntry* ctrl, PIN_String comboData)
{
    std::string strData(comboData);

    std::string::const_iterator start, end;
    start = strData.begin();
    end = strData.end();
    boost::match_results<std::string::const_iterator> what;
    boost::match_flag_type flags = boost::match_default;

    PIN_ControllerKeyComboSet* newSet = new PIN_ControllerKeyComboSet();
    std::string strComboString("");

    printf("BuildComboSet '%s'\n",comboData);

    while(regex_search(start, end, what, _keyListRegex, flags))
    {
        std::string strX  = what[0].str();

        printf("\tBuildComboSet FOUND '%s'\n",strX.c_str());

        //SDL_Scancode code = SDL_GetScancodeFromName(strX.c_str());

        PIN_String code = strX.c_str();

        PIN_GameControllerKeyInfo key = GenerateKeyInfo(code);

        strComboString+=std::string(start,what[0].first);

        if(key.KeyType == PIN_GKT_BUTTON)
        {
            strComboString+=PIN_KEYFORMAT;
        }
        else
        {
            char strFormula[PIN_MAXBUFFER_SIZE];
            memset(strFormula,0,PIN_MAXBUFFER_SIZE);

            switch(key.AxisDirection)
            {
            case PIN_GAD_BOTH:
                sprintf(strFormula,"(%%d < -%d | %%d > %d)", ctrl->AxisDeadZone, ctrl->AxisDeadZone);
                break;
            case PIN_GAD_NEGATIVE:
                sprintf(strFormula,"(%%d < -%d)", ctrl->AxisDeadZone);
                break;
            case PIN_GAD_POSITIVE:
                sprintf(strFormula,"(%%d > %d)", ctrl->AxisDeadZone);
                break;
            }

            printf("\t\tAxis formula: %s\n",strFormula);

            strComboString+=strFormula;
        }

        newSet->ComboKeys.push_back(key);

        // update search position:
        start = what[0].second;
        // update flags:
        flags |= boost::match_prev_avail;
        flags |= boost::match_not_bob;
    }
    strComboString+=std::string(start,end);

    newSet->ComboString = new char[PIN_MAXBUFFER_SIZE];
    memset(newSet->ComboString,0,PIN_MAXBUFFER_SIZE);
    strcat(newSet->ComboString,strComboString.c_str());

    if(newSet->ComboKeys.size() > 0)
    {
        return newSet;
    }
    else
    {
        delete newSet;
        return NULL;
    }
}
Exemple #19
0
static std::string FixShaderCode(char *text, int textLength, const UniformRules &uniformsRename, bool vertexShader)
{
    struct ReplacePair
    {
        ReplacePair(const char *pat, const char *rep) :
            pattern(boost::xpressive::sregex::compile(pat,
                                                      (boost::xpressive::regex_constants::ECMAScript |
                                                       boost::xpressive::regex_constants::optimize))),
            replace(rep)
        {
        }

        boost::xpressive::sregex pattern;
        std::string replace;
    };

    static const ReplacePair sFixPairs[] =
    {
        ReplacePair("\\.0+E\\+0+\\b", ".0"),
        ReplacePair("0*E\\+0+\\b", ""),
        ReplacePair("(\\d+)\\.([0-9][1-9])0*E\\+0+2\\b", "$1$2.0"),
        ReplacePair("(\\d+)\\.([1-9])0*E\\+0+1\\b", "$1$2.0"),
        ReplacePair("(\\d+)\\.0+E\\-0+1\\b", "0.$1"),
        ReplacePair("(\\d+)\\.00+E(\\+\\d+)\\b", "$1.0E$2"),
        ReplacePair("ATI_draw_buffers", "ARB_draw_buffers"),
        ReplacePair("\\:require\\n", ":enable\n"),
        ReplacePair("#version \\d+", ""),
    };

    static const boost::xpressive::sregex structPattern(boost::xpressive::sregex::compile("\\bstruct\\s+(\\w+)\\s*{[^}]*};",
                                                                                          (boost::xpressive::regex_constants::ECMAScript |
                                                                                           boost::xpressive::regex_constants::optimize)));
    static const int subs[] = {1};

    std::string newtext(text, textLength);

    // Find all the struct declarations
    std::list<std::string> structsList;
    boost::xpressive::sregex_token_iterator cur(newtext.begin(), newtext.end(), structPattern, subs);
    boost::xpressive::sregex_token_iterator end;
    for(; cur != end; ++cur )
    {
        structsList.push_back(*cur);
    }

    // Remove unused struct declarations
    if (!structsList.empty())
    {
        const std::list<std::string>::const_iterator itEnd(structsList.end());
        for (std::list<std::string>::const_iterator it = structsList.begin(); it != itEnd; ++it)
        {
            const std::string &structName(*it);
            boost::xpressive::sregex_iterator cur(newtext.begin(), newtext.end(),
                                                  (boost::xpressive::_b >> structName >> boost::xpressive::_b));
            boost::xpressive::sregex_iterator end;
            int count = 0;
            for(; cur != end; ++cur, ++count)
            {
            }
            if (1 >= count)
            {
                const boost::xpressive::sregex removeStructPattern(boost::xpressive::sregex::compile("\\bstruct\\s+" + structName + "\\s*{[^}]*};"));
                newtext = regex_replace(newtext, removeStructPattern, std::string(""));
            }
        }
        structsList.clear();
    }

    // Fix numbers and GLSL 'require's
    const size_t numPairs = sizeof(sFixPairs) / sizeof(ReplacePair);
    for (size_t n = 0; n < numPairs; n++)
    {
        newtext = regex_replace(newtext, sFixPairs[n].pattern, sFixPairs[n].replace);
    }

    // Fix names of uniform values
    const UniformRules::const_iterator itEnd(uniformsRename.end());
    for (UniformRules::const_iterator it = uniformsRename.begin(); it != itEnd; ++it)
    {
        newtext = regex_replace(newtext, (it->first), (it->second));
    }

    // Fix vertex attributes
    if (vertexShader)
    {
        struct AttributeReplaceRule
        {
            AttributeReplaceRule(const char *src, const char *dst, const char *tn) :
                re(boost::xpressive::_b >> src >> boost::xpressive::_b),
                replace(dst),
                typeName(tn)
            {
            }

            boost::xpressive::sregex re;
            std::string replace;
            const char *typeName;
        };

        static const AttributeReplaceRule sAttributeReplaceRules[] =
        {
            AttributeReplaceRule("gl_Vertex",         "ATTR0",  "vec4"),
            AttributeReplaceRule("gl_Normal",         "ATTR2",  "vec3"),
            AttributeReplaceRule("gl_Color",          "ATTR3",  "vec4"),
            AttributeReplaceRule("gl_SecondaryColor", "ATTR4",  "vec4"),
            AttributeReplaceRule("gl_FogCoord",       "ATTR5",  "float"),
            AttributeReplaceRule("gl_MultiTexCoord0", "ATTR8",  "vec4"),
            AttributeReplaceRule("gl_MultiTexCoord1", "ATTR9",  "vec4"),
            AttributeReplaceRule("gl_MultiTexCoord2", "ATTR10", "vec4"),
            AttributeReplaceRule("gl_MultiTexCoord3", "ATTR11", "vec4"),
            AttributeReplaceRule("gl_MultiTexCoord4", "ATTR12", "vec4"),
            AttributeReplaceRule("gl_MultiTexCoord5", "ATTR13", "vec4"),
            AttributeReplaceRule("gl_MultiTexCoord6", "ATTR14", "vec4"),
            AttributeReplaceRule("gl_MultiTexCoord7", "ATTR15", "vec4")
        };

        const size_t numRules = sizeof(sAttributeReplaceRules) / sizeof(AttributeReplaceRule);
        for (size_t n = numRules; n--; )
        {
            const AttributeReplaceRule &rule(sAttributeReplaceRules[n]);
            if (regex_search(newtext, rule.re))
            {
                newtext = regex_replace(newtext, rule.re, rule.replace);
                newtext = std::string("attribute ") + rule.typeName + " " + rule.replace + ";" + newtext;
            }
        }
    }
Exemple #20
0
void
YamlConfiguration::read_meta_doc(YAML::Node &doc, std::queue<LoadQueueEntry> &load_queue,
                                 std::string &host_file)
{
  try {
    const YAML::Node &includes = doc["include"];
#ifdef HAVE_YAMLCPP_0_5
    for (YAML::const_iterator it = includes.begin(); it != includes.end(); ++it) {
      std::string include = it->as<std::string>();
#else
    for (YAML::Iterator it = includes.begin(); it != includes.end(); ++it) {
      std::string include;
      *it >> include;
#endif
      bool ignore_missing = false;
      if (it->Tag() == "tag:fawkesrobotics.org,cfg/ignore-missing") {
	ignore_missing = true;
      }

      if (it->Tag() == "tag:fawkesrobotics.org,cfg/host-specific") {
	if (host_file != "") {
	  throw Exception("YamlConfig: Only one host-specific file can be specified");
	}
#ifdef HAVE_YAMLCPP_0_5
	host_file = abs_cfg_path(it->Scalar());
#else
	it->GetScalar(host_file);
	host_file = abs_cfg_path(host_file);
#endif
	continue;
      }

      if (include.empty()) {
	throw Exception("YamlConfig: invalid empty include");
      }
 
      if (include[include.size() - 1] == '/') {
	// this should be a directory
	std::string dirname = abs_cfg_path(include);
	struct stat dir_stat;
	if ((stat(dirname.c_str(), &dir_stat) != 0)) {
	  if (ignore_missing) continue;
	  throw Exception(errno, "YamlConfig: Failed to stat directory %s", dirname.c_str());
	}

	if (! S_ISDIR(dir_stat.st_mode)) {
	  throw Exception("YamlConfig: %s is not a directory", dirname.c_str());
	}

	DIR *d = opendir(dirname.c_str());
	if (! d) {
	  throw Exception(errno, "YamlConfig: failed to open directory %s",
			  dirname.c_str());
	}

        load_queue.push(LoadQueueEntry(dirname, ignore_missing, true));

	std::list<std::string> files;

	struct dirent *dent;
	while ((dent = readdir(d)) != NULL) {
#ifdef USE_REGEX_CPP
	  if (regex_search(dent->d_name, __yaml_regex)) {
#  if 0
	    // just for emacs auto-indentation
	  }
#  endif
#else
	  if (regexec(&__yaml_regex, dent->d_name, 0, NULL, 0) != REG_NOMATCH) {
#endif
	    std::string dn = dent->d_name;
	    files.push_back(dirname + dn);
	  }
	}
	closedir(d);

	files.sort();
	for (std::list<std::string>::iterator f = files.begin(); f != files.end(); ++f) {
	    load_queue.push(LoadQueueEntry(*f, ignore_missing));
	}

      } else {
	load_queue.push(LoadQueueEntry(abs_cfg_path(include), ignore_missing));
      }
    }
  } catch (YAML::KeyNotFound &e) {
    //ignored, no includes
  }
}
int main(int argc, char* argv[])
{
    std::string server;
    std::string port;
    std::string user;
    std::string folder;
    std::string password;
    std::vector<fs::path> from;
    std::vector<fs::path> entity;
    fs::path to;
    
    //[Gmail]/Sent Mail
    po::options_description general_options("General");
    general_options.add_options()
        ("help", "list options");
    po::options_description file_options("Load");
    file_options.add_options()
        ("save-raw", po::value<fs::path>(&to), "path to save the data (after download phase)");
    po::options_description download_options("Download");
    download_options.add_options()
        ("server", po::value<std::string>(&server), "imap server dns/ip")
        ("port", po::value<std::string>(&port)->default_value("993"), "imap port")
        ("folder", po::value<std::string>(&folder)->default_value("Sent"), "imap folder")
        ("user", po::value<std::string>(&user), "imap username")
        ("password", po::value<std::string>(&password), "imap password (will ask if not specified)");
    po::options_description run_options("Run");
    
    po::options_description all_options("Email Topology Options");
    all_options
        .add(general_options)
        .add(file_options)
        .add(download_options);

    if(argc < 2) {
        std::cout << all_options << std::endl;
        return 1;
    }

    po::variables_map vm;
    try {
        int options_style = po::command_line_style::default_style;
        po::store(po::parse_command_line(argc, argv, all_options, options_style), vm);
        po::notify(vm);
    } catch(std::exception& e) {
        std::cout << all_options << std::endl;
        std::cout << "Command line parsing failed: " << e.what() << std::endl;
        return 1;
    }
    
    if(vm.count("help")) {
        std::cout << all_options << std::endl;
        return 1;
    }

    email_id_bimap email_id;
    connectedness_graph cg;
    entity_map em;
    initial_group_partition_map igpm;

    if(!vm.count("save-raw")) {
        std::cout << "you must specify --save-raw with a file name" << std::endl;
        return 1;
    }
    if(!vm.count("password")) {
        password = getpass("Password: "******"missing server for download" << std::endl;
        return 1;
    }
    if(user.empty()) {
        std::cout << "missing user for download" << std::endl;
        return 1;
    }
    if(password.empty()) {
        std::cout << "missing user for download" << std::endl;
        return 1;
    }
    //this is our network block, downloads all messages headers
    try
    {
        std::cout << "downloading " << folder << " from " << server << std::endl;
        //use to dedupe if there are dupes
        message_id_set message_id;        

        typedef boost::function<void (const std::string&, const std::list<std::string>& args)> untagged_handler;
        std::string pending_tag = "* ";
        std::list<std::string> pending_command;
        pending_command.push_back("WAIT_FOR_ACK");
        untagged_handler pending_handler;
        unsigned int command_id = 0;

        //The sequence of imap commands we want to run
        std::list<std::list<std::string> > commands;
        std::list<untagged_handler> handlers;

        handlers.push_back(log_handler());
        commands.push_back(std::list<std::string>());
        std::ostringstream login_os;
        login_os << "LOGIN \"" << user << "\" {" << password.size() << "}";
        commands.back().push_back(login_os.str()); 
        commands.back().push_back(password); 

        handlers.push_back(log_handler());
        commands.push_back(std::list<std::string>());
        commands.back().push_back("LIST \"\" *"); 

        handlers.push_back(log_handler());
        commands.push_back(std::list<std::string>());
        commands.back().push_back("SELECT \"" + folder + "\""); 

        handlers.push_back(header_handler(email_id, cg, em, message_id, igpm));
        commands.push_back(std::list<std::string>());
        commands.back().push_back("FETCH 1:* (BODY.PEEK[HEADER.FIELDS (MESSAGE-ID FROM TO CC)])");
        commands.push_back(std::list<std::string>());

        handlers.push_back(log_handler());
        commands.back().push_back("LOGOUT");
    
        //open ssl connection to the server, no cert checking
        asio::io_service io_service;
        asio::ip::tcp::resolver resolver(io_service);
        asio::ip::tcp::resolver::query query(server, port);
        asio::ip::tcp::resolver::iterator iterator = resolver.resolve(query);
        asio::ssl::context context(io_service, asio::ssl::context::sslv23);
        context.set_verify_mode(asio::ssl::context::verify_none);
        asio::ssl::stream<asio::ip::tcp::socket> socket(io_service, context);
        socket.lowest_layer().connect(*iterator);
        socket.handshake(asio::ssl::stream_base::client);
        asio::streambuf buf;

        while(true) {
            //read the next line of data
            std::size_t line_length = asio::read_until(socket, buf, re_crlf);
            std::string line(
                asio::buffers_begin(buf.data()),
                asio::buffers_begin(buf.data()) + line_length);
            buf.consume(line_length);
            boost::match_results<std::string::iterator> what;
            std::size_t initial = 0;
            std::list<std::string> args;
            //the line may be split into segments with chunks of data embedded, this is the case
            //for bodies or message header blocks that are returned, we only handle this case if it
            //comes in untagged response (*) not a continuation (+), i think that is normal
            while(regex_search(line.begin() + initial, line.end(), what, re_byte_buffer, boost::match_default)) {
                unsigned int bytes = boost::lexical_cast<unsigned int>(what[1].str());
                if(buf.size() < bytes)
                    asio::read(socket, buf, asio::transfer_at_least(bytes - buf.size()));
                args.push_back(
                    std::string(
                        asio::buffers_begin(buf.data()),
                        asio::buffers_begin(buf.data()) + bytes));
                buf.consume(bytes);
                line.resize(what[1].second - line.begin());
                initial = line.size();
                //read the next line of data
                line_length = asio::read_until(socket, buf, re_crlf);
                line += std::string(
                    asio::buffers_begin(buf.data()),
                    asio::buffers_begin(buf.data()) + line_length);
                buf.consume(line_length);
            }
            if(boost::algorithm::starts_with(line, pending_tag)) {
                //if the command is being completed, then we will go here, bail out if the response wasn't ok
                if(!boost::algorithm::starts_with(line, pending_tag + "OK")) {
                    std::cout << line;
                    throw std::runtime_error("command failed");
                }
                //pull the next command off the list
                pending_tag = "A" + boost::lexical_cast<std::string>(command_id++) + " ";
                if(commands.size() == 0)
                    break;
                pending_handler = handlers.front();
                pending_command = commands.front();
                commands.pop_front();
                handlers.pop_front();

                //send the command along with any data arguments
                std::cout << pending_tag << pending_command.front() << std::endl;
                asio::write(socket, asio::buffer(pending_tag.data(), pending_tag.size()));
                for(std::list<std::string>::iterator i = pending_command.begin(); i != pending_command.end(); ++i) {
                    if(i != pending_command.begin()) {
                        //print the continuation response
                        std::size_t line_length = asio::read_until(socket, buf, re_crlf);
                        std::string line(
                            asio::buffers_begin(buf.data()),
                            asio::buffers_begin(buf.data()) + line_length);
                        buf.consume(line_length);
                        std::cout << line << std::flush;
                        if(!boost::algorithm::starts_with(line, "+ ")) {
                            throw std::runtime_error("bad response when writing extra data");
                        }
                    } else {
                        //print it out as well (but not the args)
                        std::cout << *i << std::endl;
                    }
                    asio::write(socket, asio::buffer(i->data(), i->size()));
                    asio::write(socket, asio::buffer("\r\n", 2));
                }
            } else if(boost::algorithm::starts_with(line, "* ")) {
                //if there is a registered handler, dispatch to it
                if(pending_handler)
                    pending_handler(line, args);
            } else {
                throw std::runtime_error("unrecognized response");
            }
        }
    }
    catch (std::exception& e) {
        std::cout << "Exception: " << e.what() << std::endl;
        return 1;
    }
    std::cout << std::endl;
    
    if(to.empty()) {
        std::cout << "Missing output file for save" << std::endl;
        return 1;
    }
    if(fs::exists(to))
        fs::remove(to);
    fs::ofstream out(to);
    std::cout << "saving data to " << to.file_string();        
    for(connectedness_graph::vertex_iterator i = gr::vertices(cg).first; i != gr::vertices(cg).second; ++i) {
        out << (unsigned long long)cg[*i].weight;
        for(members_t::iterator j = cg[*i].members.begin(); j != cg[*i].members.end(); ++j) {
            out << "\t" << email_id.by<bit>().equal_range(*j).first->second;
        }
        out << std::endl;
    }
    out << "-" << std::endl;
    for(entity_map::iterator i = em.begin(); i != em.end(); ++i) {
        out << i->first;
        for(std::set<std::string>::iterator k = i->second.begin(); k != i->second.end(); ++k) {
            out << "\t" << *k; 
        }
        out << std::endl;
    }
    return 0;
}
Exemple #22
0
//==========================================================================================================
// Since the original regular expressions contain references, it is needed to resolove them, i.e. replace
// occurrences of _<ELEM_NAME>_ inside the string with the actual value of the regex string for that element
//==========================================================================================================
void SipParser::SipMatcher::finalize(SipParser* parser)
{
    if(final)
    {
        return;
    }
    
    re_str = highlevel_re_str;
    smatch match;
    string::const_iterator first = re_str.begin();
    string::const_iterator last = re_str.end();
    long first_pos = 0; // The position of the first iterator; needed for getting absolute positons from relative match positions
    
    //-------------------------------------------------------------------------------------------------------
    // Go over all references to other SIP elements in the original string, and replace them with the actual
    // string of the regex of that element.
    // In the process keep track of sub-matches and their positons.
    //-------------------------------------------------------------------------------------------------------
    while(regex_search(first, last, match, parser->sip_element_re))
    {
        // NOTE: if matcher for the matched element is not finalized yet, it will first be finalized before
        // returning it!
        SipMatcher *matcher = parser->get_matcher(match.str());
        long pos = first_pos + match.position();

        //---------------------------------------------------------------------------------------------------
        // Add to the submatches list a pair of the found element and the number of its sub match, so later
        // we can retrieve it using the SipElement enum.
        // Add also the list of submatches that the matcher for this element contains, but need to adjust
        // their positions by adding an offset of the current submatch position.
        // All this is done only if the current element is surrounded by () in the original high level re.
        //---------------------------------------------------------------------------------------------------
        if((pos > 0 && re_str[pos-1] == '(') &&
           (pos + match.length() < re_str.length() && re_str[pos + match.length()] == ')' ))
        {
            long num_subs = count_num_subs(pos); // Number of submatches up to and including the current one
            SipElement elem = parser->get_sip_elem(match.str());
            subs.emplace(subs.end(), elem, num_subs); // Add a new pair to the vector
            
            auto element_subs = matcher->subs;
            
            for(auto &p: element_subs)
            {
                p.second += num_subs;
            }
            
            subs.insert(subs.end(), element_subs.begin(), element_subs.end());
        }
        
        // Replace reference with actual regex string in final_re
        re_str.replace(pos, match.length(), matcher->get_re());
        
        // Adjust first to point to after the replaced portion
        first_pos = pos + matcher->get_re_length();
        first = re_str.begin() + first_pos;

        // Adjust last to the new end, because string length might have changed
        last = re_str.end();
        
    } // while
    
    re = re_str;
    final = true;
Exemple #23
0
void
YamlConfiguration::read_config_doc(const YAML::Node &doc, YamlConfigurationNode *&node)
{
  if (! node) {
    node = new YamlConfigurationNode("root");
  }

  if (doc.Type() == YAML::NodeType::Map) {
#ifdef HAVE_YAMLCPP_0_5
    for (YAML::const_iterator it = doc.begin(); it != doc.end(); ++it) {
      std::string key = it->first.as<std::string>();
#else
    for (YAML::Iterator it = doc.begin(); it != doc.end(); ++it) {
      std::string key;
      it.first() >> key;
#endif
      YamlConfigurationNode *in = node;
      if (key.find("/") != std::string::npos) {
	// we need to split and find the proper insertion node
	std::vector<std::string> pel = str_split(key);
	for (size_t i = 0; i < pel.size() - 1; ++i) {
	  YamlConfigurationNode *n = (*in)[pel[i]];
	  if (! n) {
	    n = new YamlConfigurationNode(pel[i]);
	    in->add_child(pel[i], n);
	  }
	  in = n;
	}

	key = pel.back();
      }

      YamlConfigurationNode *tmp = (*in)[key];
      if (tmp) {
#ifdef HAVE_YAMLCPP_0_5
	if (tmp->is_scalar() && it->second.Type() != YAML::NodeType::Scalar)
#else
	if (tmp->is_scalar() && it.second().Type() != YAML::NodeType::Scalar)
#endif
	{
	  throw Exception("YamlConfig: scalar %s cannot be overwritten by non-scalar",
			  tmp->name().c_str());
	}
#ifdef HAVE_YAMLCPP_0_5
	tmp->set_scalar(it->second.Scalar());
#else
	std::string s;
	if (it.second().GetScalar(s)) {
	  tmp->set_scalar(s);
	}
#endif
      } else {
#ifdef HAVE_YAMLCPP_0_5
	YamlConfigurationNode *tmp = new YamlConfigurationNode(key, it->second);
	in->add_child(key, tmp);
	read_config_doc(it->second, tmp);
#else
	YamlConfigurationNode *tmp = new YamlConfigurationNode(key, it.second());
	in->add_child(key, tmp);
	read_config_doc(it.second(), tmp);
#endif
      }
    }

  } else if (doc.Type() == YAML::NodeType::Scalar) {
    if (doc.Tag() == "tag:fawkesrobotics.org,cfg/tcp-port" ||
	doc.Tag() == "tag:fawkesrobotics.org,cfg/udp-port")
    {
      unsigned int p = 0;
      try {
	p = node->get_uint();
      } catch (Exception &e) {
	e.prepend("YamlConfig: Invalid TCP/UDP port number (not an unsigned int)");
	throw;
      }
      if (p <= 0 || p >= 65535) {
	throw Exception("YamlConfig: Invalid TCP/UDP port number "
			"(%u out of allowed range)", p);
      }
    } else if (doc.Tag() == "tag:fawkesrobotics.org,cfg/url") {
#ifdef HAVE_YAMLCPP_0_5
      std::string scalar = doc.Scalar();
#else
      std::string scalar;
      doc.GetScalar(scalar);
#endif
#ifdef USE_REGEX_CPP
      if (regex_search(scalar, __url_regex)) {
#  if 0
	// just for emacs auto-indentation
      }
#  endif
#else
      if (regexec(&__url_regex, scalar.c_str(), 0, NULL, 0) == REG_NOMATCH) {
	throw Exception("YamlConfig: %s is not a valid URL", scalar.c_str());
      }
#endif
    } else if (doc.Tag() == "tag:fawkesrobotics.org,cfg/frame") {
#ifdef HAVE_YAMLCPP_0_5
      std::string scalar = doc.Scalar();
#else
      std::string scalar;
      doc.GetScalar(scalar);
#endif
#ifdef USE_REGEX_CPP
      if (regex_search(scalar, __frame_regex)) {
#  if 0
	// just for emacs auto-indentation
      }
#  endif
#else
      if (regexec(&__frame_regex, scalar.c_str(), 0, NULL, 0) == REG_NOMATCH) {
	throw Exception("YamlConfig: %s is not a valid frame ID", scalar.c_str());
      }
#endif
    }

  }
}
Exemple #24
0
void Shader::ShaderCode::load(ifstream &ShaderStream)
{
	string Line = "";
	if (ShaderStream.is_open())
	{
		while (getline(ShaderStream, Line))
		{
			if (ShaderStream.eof() || ShaderStream.bad())
				break;
			_code += Line + "\n";
		}
	}
	else
	{
		LOG << string(_path) + " wasn't open :/\n";
		return;
	}

	//Analyze Code
	try {
		//get Structures
		smatch _structs, _vars;

		regex structRegex = regex("struct .*?\\n?\\{\\n(.*?;\\n)*\\};");
		auto StructBegin = std::sregex_iterator(_code.begin(), _code.end(), structRegex);

		unsigned int _counter(0);
		for (auto i = StructBegin; i != std::sregex_iterator(); i++) {
			std::string temp = (*i).str();
			vector<string> structVar = vector<string>();
			regex_search(temp, _vars, regex("struct .*?\\n\\{\\n"));
			temp = _vars[0].str();
			structVar.push_back(temp.substr(7, temp.size() - 10));//adds name
			temp = (*i).str();

			regex structVarRegex = regex("\\t.*? .*?;\\n");
			auto StructVarBegin = std::sregex_iterator(temp.begin(), temp.end(), structVarRegex);

			for (std::sregex_iterator i = StructVarBegin; i != std::sregex_iterator(); ++i) {
				std::string match_str = (*i).str();
				structVar.push_back(match_str.substr(1, match_str.size() - 3)); //write the variables
			}
			structVariables.push_back(structVar);
			_counter++;
		}
		LOG << string(_path) + " contains " + to_string(_counter) + " Structures\n";

		//read uniforms
		_counter = 0;
		regex structVarRegex = regex("uniform .*? .*?;\\n");
		auto UniformsBegin = std::sregex_iterator(_code.begin(), _code.end(), structVarRegex);
		for (auto i = UniformsBegin; i != std::sregex_iterator(); i++) {
			std::string match_str = (*i).str();
			addUniform(match_str.substr(match_str.find_first_of(' ') + 1, match_str.size() - 3 - match_str.find_first_of(' ')));
			_counter++;
		}
		LOG << string(_path) + " contains " + to_string(_counter) + " Uniforms\n";
	}
	catch (regex_error &e)
	{
		LOG << string(e.what()) + "\n";
		LOG << "Could not Resolve Uniforms in Shader \n";
	}

}
Exemple #25
0
static void AddMappedParameter(JSON &json,
                               const char *paramName,
                               const char *programString,
                               UniformsMap &uniformRemapping)
{
    const bool isAssembly = (0 == memcmp(programString, "!!ARB", 5));
    const char * const vars = strstr(programString, (isAssembly ? "#var" : "//var"));
    if (NULL != vars)
    {
        const size_t paramNameLength = strlen(paramName);

        const char *var = vars;
        do
        {
            // to skip previous search
            var += 1;
            var = strstr(var, paramName);
        }
        while (NULL != var &&
               ' ' != var[paramNameLength] &&
               ':' != var[paramNameLength] &&
               '[' != var[paramNameLength]);

        if (NULL != var)
        {
            const char * const semantic = strchr(var, ':');
            if (NULL != semantic)
            {
                const char *mappedVariable = strchr((semantic + 1), ':');
                if (NULL != mappedVariable)
                {
                    do
                    {
                        mappedVariable++;
                    }
                    while (*mappedVariable <= ' ');
                    const char *mappedVariableEnd = mappedVariable;
                    while (' ' != *mappedVariableEnd &&
                           ':' != *mappedVariableEnd &&
                           '[' != *mappedVariableEnd &&
                           ',' != *mappedVariableEnd &&
                           0 != *mappedVariableEnd)
                    {
                        mappedVariableEnd++;
                    }

                    const size_t mappedVariableLength = (size_t)(mappedVariableEnd - mappedVariable);

                    if (isAssembly)
                    {
                        if (0 < mappedVariableLength)
                        {
                            // Append location to end of string
                            std::string paramString(paramName, paramNameLength);
                            paramString += ':';
                            // mappedVariable should have the format 'c[{location}]' or 'texunit {location}'
                            const char *location = mappedVariableEnd;
                            while (0 != *location &&
                                   ('0' > *location  ||
                                    '9' < *location))
                            {
                                location++;
                            }
                            if (0 != *location)
                            {
                                const char *locationEnd = location;
                                do
                                {
                                    locationEnd++;
                                }
                                while (0 != *locationEnd &&
                                       '0' <= *locationEnd &&
                                       '9' >= *locationEnd);
                                if (0 != *locationEnd)
                                {
                                    paramString.append(location, (size_t)(locationEnd - location));
                                    json.AddData(paramString.c_str(), paramString.size());
                                }
                            }
                        }
                        return;
                    }

                    const std::string mappedVariableString(mappedVariable, mappedVariableLength);
                    const char * const mappedVariableName = mappedVariableString.c_str();

                    // Check that it is actually used
                    const char * const main = strstr(mappedVariableEnd, "main()");
                    if (NULL != main)
                    {
                        const boost::xpressive::cregex re(boost::xpressive::_b >> mappedVariableString >> boost::xpressive::_b);
                        if (!regex_search((main + 6), re))
                        {
                            return;
                        }
                    }

                    json.AddData(paramName, paramNameLength);

                    const UniformsMap::const_iterator it = uniformRemapping.find(mappedVariableString);
                    if (it == uniformRemapping.end())
                    {
                        uniformRemapping[mappedVariableString] = paramName;
                    }
                    else if (it->second != paramName)
                    {
                        printf("\nUniform variable conflict '%s':\n\t%s\n\t%s\n",
                               mappedVariableName,
                               it->second.c_str(),
                               paramName);
                        exit(1);
                    }
                }
            }
        }
    }
}
Exemple #26
0
 bool init(BidirectionalIterator first)
 {
    base = first;
    return regex_search(first, end, what, re, flags);
 }
Exemple #27
0
bool CLogDlgFilter::Match (char* text, size_t size) const
{
    // empty text does not match

    if (size == 0)
        return false;

    if (patterns.empty())
    {
        // normalize to lower case

        if (!caseSensitive)
            if (fastLowerCase)
                FastLowerCaseConversion (text, size);
            else
            {
                // all these strings are in utf-8, which means all the
                // standard c-APIs to convert the string directly to
                // lowercase won't work: we first have to convert
                // the string to wide-char. Very very slow, but unavoidable
                // if we want to make this work right.
                CStringA as = CStringA(text, (int)size);
                CString s = CUnicodeUtils::GetUnicode(as);
                s.MakeLower();
                as = CUnicodeUtils::GetUTF8(s);
                strncpy_s(text, size+1, as, size);
            }

        // require all strings to be present

        bool current_value = true;
        for (size_t i = 0, count = subStringConditions.size(); i < count; ++i)
        {
            const SCondition& condition = subStringConditions[i];
            bool found = strstr (text, condition.subString.c_str()) != NULL;
            switch (condition.prefix)
            {
                case and_not:
                    found = !found;
                    // fallthrough
                case and:
                    if (!found)
                    {
                        // not a match, so skip to the next "+"-prefixed item

                        if (condition.nextOrIndex == 0)
                            return false;

                        current_value = false;
                        i = condition.nextOrIndex-1;
                    }
                    break;

                case or:
                    current_value |= found;
                    if (!current_value)
                    {
                        // not a match, so skip to the next "+"-prefixed item

                        if (condition.nextOrIndex == 0)
                            return false;

                        i = condition.nextOrIndex-1;
                    }
                    break;
            }
        }
    }
    else
    {
        for ( std::vector<std::tr1::regex>::const_iterator it = patterns.begin()
            ; it != patterns.end()
            ; ++it)
        {
            if (!regex_search(text, text + size, *it, std::tr1::regex_constants::match_any))
                return false;
        }
    }

    return true;
}
void oclraster_program::process_program(const string& raw_code, const kernel_spec default_spec) {
	// preprocess
	const string code = preprocess_code(raw_code);
	
	// parse
	static const array<const pair<const char*, const STRUCT_TYPE>, 6> oclraster_struct_types {
		{
			{ u8"oclraster_in", STRUCT_TYPE::INPUT },
			{ u8"oclraster_out", STRUCT_TYPE::OUTPUT },
			{ u8"oclraster_uniforms", STRUCT_TYPE::UNIFORMS },
			{ u8"oclraster_buffers", STRUCT_TYPE::BUFFERS },
			{ u8"oclraster_images", STRUCT_TYPE::IMAGES },
			{ u8"oclraster_framebuffer", STRUCT_TYPE::FRAMEBUFFER }
		}
	};
	static const set<const string> specifiers {
		"read_only", "write_only", "read_write"
	};
	
	// current oclraster_struct grammar limitations/requirements:
	// * no interior/nested structs/unions
	// * no multi-variable declarations (e.g. "float x, y, z;")
	// * no __attribute__ (oclraster_structs already have a __attribute__ qualifier)
	// * use of any oclraster_struct specifier in other places is disallowed (no typedefs, comments, ...)
	// * otherwise standard OpenCL C
	//
	// example:
	// oclraster_in vertex_input {
	// 		float4 vertex;
	// 		float4 normal;
	// 		float2 tex_coord;
	// } inputs;
	//
	vector<size2> image_struct_positions;
	try {
		// parse and extract
		for(const auto& type : oclraster_struct_types) {
			size_t struct_pos = 0;
			while((struct_pos = code.find(type.first, struct_pos)) != string::npos) {
				// find first ' ' space char and open '{' bracket and extract the structs name
				const size_t space_pos = code.find_first_of(" {", struct_pos);
				const size_t open_bracket_pos = code.find("{", struct_pos);
				if(space_pos == string::npos || code[space_pos] == '{') throw oclraster_exception("no struct name");
				if(open_bracket_pos == string::npos) throw oclraster_exception("no struct open bracket");
				const string struct_name = core::trim(code.substr(space_pos+1, open_bracket_pos-space_pos-1));
				//oclr_msg("struct type: \"%s\"", type.first);
				//oclr_msg("struct name: \"%s\"", struct_name);
				
				// open/close bracket match
				size_t bracket_pos = open_bracket_pos;
				size_t open_bracket_count = 1;
				while(open_bracket_count > 0) {
					bracket_pos = code.find_first_of("{}", bracket_pos + 1);
					if(bracket_pos == string::npos) throw oclraster_exception("struct open/close bracket mismatch");
					code[bracket_pos] == '{' ? open_bracket_count++ : open_bracket_count--;
				}
				const size_t close_bracket_pos = bracket_pos;
				
				//
				const size_t end_semicolon_pos = code.find(";", close_bracket_pos+1);
				if(end_semicolon_pos == string::npos) {
					throw oclraster_exception("end-semicolon missing from struct \""+struct_name+"\"!");
				}
				const string object_name = core::trim(code.substr(close_bracket_pos+1,
																  end_semicolon_pos-close_bracket_pos-1));
				//oclr_msg("object name: \"%s\"", object_name);
				
				//
				string struct_interior = code.substr(open_bracket_pos+1, close_bracket_pos-open_bracket_pos-1);
				//oclr_msg("struct interior:\n\t%s\n", struct_interior);
				
				// strip unnecessary whitespace and comments, and condense
				static const regex rx_space("\\s+", regex::optimize);
				static const regex rx_semicolon_space("[ ]*;[ ]*", regex::optimize);
				static const regex rx_newline("\n|\r", regex::optimize);
				static const regex rx_comments_sl("//(.*)", regex::optimize);
				static const regex rx_comments_ml("/\\*(.*)\\*/", regex::optimize);

				struct_interior = regex_replace(struct_interior, rx_comments_sl, "");
				struct_interior = regex_replace(struct_interior, rx_newline, "");
				struct_interior = regex_replace(struct_interior, rx_comments_ml, "");
				struct_interior = regex_replace(struct_interior, rx_space, " ");
				struct_interior = regex_replace(struct_interior, rx_semicolon_space, ";");
				struct_interior = core::trim(struct_interior);
				//oclr_msg("post-regex interior: >%s<", struct_interior);
				
				// extract all member variables
				vector<string> variable_names, variable_types, variable_specifiers;
				size_t semicolon_pos = 0, last_semicolon_pos = 0;
				while((semicolon_pos = struct_interior.find(";", last_semicolon_pos)) != string::npos) {
					const string var_decl = struct_interior.substr(last_semicolon_pos,
																   semicolon_pos-last_semicolon_pos);
					//oclr_msg("decl: >%s<", var_decl);
					
					const size_t name_start_pos = var_decl.rfind(" ");
					if(name_start_pos == string::npos) {
						throw oclraster_exception("invalid variable declaration: \""+var_decl+"\"");
					}
					const string var_name = var_decl.substr(name_start_pos+1, var_decl.length()-name_start_pos-1);
					//oclr_msg("name: >%s<", var_name);
					variable_names.emplace_back(var_name);
					
					// check if type has an additional specifier (for images: read_only, write_only, read_write)
					const size_t type_start_pos = var_decl.find(" ");
					const string start_token = var_decl.substr(0, type_start_pos);
					if(specifiers.find(start_token) != specifiers.end()) {
						const string var_type = regex_replace(var_decl.substr(type_start_pos+1, name_start_pos-type_start_pos-1),
															  rx_space, ""); // need to strip any whitespace
						//oclr_msg("type (s): >%s<", var_type);
						variable_types.emplace_back(var_type);
						
						const string var_spec = var_decl.substr(0, type_start_pos);
						//oclr_msg("spec: >%s<", var_spec);
						variable_specifiers.emplace_back(var_spec);
					}
					else {
						const string var_type = core::trim(var_decl.substr(0, name_start_pos));
						//oclr_msg("type: >%s<", var_type);
						variable_types.emplace_back(var_type);
						variable_specifiers.emplace_back("");
					}
					
					// continue
					last_semicolon_pos = semicolon_pos+1;
				}
				
				// create info struct
				if(type.second != STRUCT_TYPE::IMAGES &&
				   type.second != STRUCT_TYPE::FRAMEBUFFER) {
					const bool empty = (variable_names.size() == 0); // can't use variable_names when moving
					structs.push_back(new oclraster_struct_info {
						type.second,
						size2(struct_pos, end_semicolon_pos+1),
						struct_name,
						object_name,
						std::move(variable_names),
						std::move(variable_types),
						std::move(variable_specifiers),
						empty,
						{}
					});
				}
				else {
					image_struct_positions.emplace_back(size2 { struct_pos, end_semicolon_pos+1 });
					process_image_struct(variable_names, variable_types, variable_specifiers,
										 (type.second == STRUCT_TYPE::FRAMEBUFFER));
				}
				
				// continue
				struct_pos++;
			}
		}
		
		// process found structs
		for(auto& oclr_struct : structs) {
			if(oclr_struct->empty) continue;
			if(oclr_struct->type == STRUCT_TYPE::BUFFERS) continue;
			generate_struct_info_cl_program(*oclr_struct);
		}
		
		// order
		sort(structs.begin(), structs.end(),
			 [](const oclraster_struct_info* info_0, const oclraster_struct_info* info_1) -> bool {
				 return info_0->code_pos.x < info_1->code_pos.x;
			 });
		
		// write framebuffer struct
		bool has_framebuffer = false;
		string framebuffer_code = "typedef struct __attribute__((packed)) {\n";
		for(size_t i = 0, fb_img_idx = 0, image_count = images.image_names.size(); i < image_count; i++) {
			if(!images.is_framebuffer[i]) continue;
			has_framebuffer = true;
			// TODO: for now, let the access always be read/write, so "const data" (depth) can be modified
			// between user program calls (downside: user has also read/write access -> create 2 structs?)
			/*if(images.image_specifiers[i] == ACCESS_TYPE::READ) {
				framebuffer_code += "const ";
			}*/
			framebuffer_code += "###OCLRASTER_FRAMEBUFFER_IMAGE_" + size_t2string(fb_img_idx) + "### " + images.image_names[i] + ";\n";
			fb_img_idx++;
		}
		framebuffer_code += "} oclraster_framebuffer;\n";
		
		// recreate structs (in reverse, so that the offsets stay valid)
		processed_code = code;
		const size_t struct_count = structs.size() + image_struct_positions.size();
		for(size_t i = 0, cur_struct = structs.size(), cur_image = image_struct_positions.size();
			i < struct_count; i++) {
			// figure out which struct comes next (normal struct or image struct)
			size_t image_code_pos = 0, struct_code_pos = 0;
			if(cur_image > 0) image_code_pos = image_struct_positions[cur_image-1].x;
			if(cur_struct > 0) struct_code_pos = structs[cur_struct-1]->code_pos.x;
			
			// image
			if(image_code_pos > struct_code_pos) {
				cur_image--;
				processed_code.erase(image_struct_positions[cur_image].x,
									 image_struct_positions[cur_image].y - image_struct_positions[cur_image].x);
				
				// insert framebuffer struct code at the last image or framebuffer struct position
				if(has_framebuffer && cur_image == (image_struct_positions.size()-1)) {
					processed_code.insert(image_struct_positions[cur_image].x, framebuffer_code);
				}
			}
			// struct
			else {
				cur_struct--;
				const oclraster_struct_info& oclr_struct = *structs[cur_struct];
				processed_code.erase(oclr_struct.code_pos.x,
									 oclr_struct.code_pos.y - oclr_struct.code_pos.x);
				
				if(!oclr_struct.empty && oclr_struct.type != STRUCT_TYPE::BUFFERS) {
					string struct_code = "";
					switch(oclr_struct.type) {
						case STRUCT_TYPE::INPUT:
							struct_code += "oclraster_in";
							break;
						case STRUCT_TYPE::OUTPUT:
							struct_code += "oclraster_out";
							break;
						case STRUCT_TYPE::UNIFORMS:
							struct_code += "oclraster_uniforms";
							break;
						case STRUCT_TYPE::BUFFERS:
						case STRUCT_TYPE::IMAGES:
						case STRUCT_TYPE::FRAMEBUFFER: oclr_unreachable();
					}
					struct_code += " {\n";
					for(size_t var_index = 0; var_index < oclr_struct.variables.size(); var_index++) {
						struct_code += oclr_struct.variable_types[var_index] + " " + oclr_struct.variables[var_index] + ";\n";
					}
					struct_code += "} " + oclr_struct.name + ";\n";
					processed_code.insert(oclr_struct.code_pos.x, struct_code);
				}
			}
		}
		
		// remove empty structs
		for(auto iter = structs.begin(); iter != structs.end();) {
			if((*iter)->empty) {
				delete *iter;
				iter = structs.erase(iter);
			}
			else iter++;
		}
		
		// build entry function parameter string
		const string entry_function_params = create_entry_function_parameters();
		
		// check if entry function exists, and if so, replace it with a modified function name
		const regex rx_entry_function("("+entry_function+")\\s*\\(\\s*\\)", regex::optimize);
		if(!regex_search(code, rx_entry_function)) {
			throw oclraster_exception("entry function \""+entry_function+"\" not found!");
		}
		processed_code = regex_replace(processed_code, rx_entry_function,
									   "OCLRASTER_FUNC oclraster_user_"+entry_function+"("+entry_function_params+")");
		
		// create default/first/hinted image spec, do the final processing and compile
		kernel_spec spec { default_spec };
		if(!images.image_names.empty() && spec.image_spec.size() != images.image_names.size()) {
			// create kernel image spec for the hinted or default image specs
			// note: if default_spec already contains some image_spec entries, only insert the remaining ones
			for(size_t i = spec.image_spec.size(); i < images.image_names.size(); i++) {
				spec.image_spec.emplace_back(images.image_hints[i].is_valid() ?
											 images.image_hints[i] :
											 image_type { IMAGE_TYPE::UINT_8, IMAGE_CHANNEL::RGBA });
			}
		}
		else if(images.image_names.empty() && !spec.image_spec.empty()) {
			// default spec contains image_spec entries, but the are no images -> clear
			spec.image_spec.clear();
		}
		// else: no images in kernel/program -> just one kernel / "empty image spec"
		build_kernel(spec);
	}
	catch(oclraster_exception& ex) {
		invalidate(ex.what());
	}
	valid = true;
}
Exemple #29
0
//下载像册信息
// http://u.8264.com/home-space-uid-16752722-do-album-id-1766.html
// http://u.8264.com/home-space-uid-16752722-do-album-id-1766-page-4.html#comment
bool CDolo8264COM::SearchLayer3(CString &str_url)
{
	CString cs_webContent;
	CString cs_tmp;
	int photo_num=0;		//像册数量
	int i_tmp;
	vector<string> astr;  //下载链接集合
	int m_page= 1;			//设置页面数
	CString cs_album_name;	//用户目录
	CString cs_sub_album;	//像册目录

	if(str_url.Find(_T("#comment")) < 0)
	{
		str_url.Delete(str_url.GetLength()-5,5);
		str_url+=_T("-page-1.html#comment");
	}
	else
		str_url.SetAt(str_url.GetLength()-14,_T('1'));

	//获得页面
	bool en_P=false;
	bool en_G=false;
	do 
	{
		cs_webContent.Empty();
		DownloadUrlPage(str_url,cs_webContent);	

		i_tmp = cs_webContent.Find(_T("张图片"),0);
		if(i_tmp>-1)
		{
			cs_tmp = cs_webContent.Left(i_tmp);
			cs_tmp = cs_tmp.Right(4);
			cs_tmp.TrimLeft(_T(" ")); 
			cs_tmp.TrimRight( _T(" "));
			if((atoi(cs_tmp)==0)||(cs_tmp.IsEmpty()))
			{
				return false;
			}
			else
				photo_num = atoi(cs_tmp);
		}
		//获得像册的题目
		if(en_P == false)
		{
			int i=cs_webContent.Find(_T("keywords\" content=\""),0);
			if(i>-1)
			{
				cs_sub_album= cs_webContent.Right(cs_webContent.GetLength() -i -19);
				cs_sub_album = cs_sub_album.Left(cs_sub_album.Find(_T("\"")));
				en_P = true;
			}
		}
		//获得用户题目cs_album_name
		if(en_G == false)
		{
			int i=cs_webContent.Find(_T("<h2 class=\"xs2\">"),0);
			if(i>-1)
			{
				i=cs_webContent.Find(_T("html"),i);
				cs_album_name= cs_webContent.Right(cs_webContent.GetLength() -i -6);
				cs_album_name = cs_album_name.Left(cs_album_name.Find(_T("<"),0));
				en_G = true;
			}
		}
		checkDirname(cs_album_name);
		checkDirname(cs_sub_album);
		CreateDirectory(_T("8264com\\")+cs_album_name,NULL);
		CreateDirectory(_T("8264com\\")+cs_album_name+_T("\\")+cs_sub_album,NULL);

		regex reg("html\"><img src=\"[a-zA-z]+://[^\\s]*thumb.jpg");  	//图片模式
		smatch m1; 

		string s = cs_webContent.GetBuffer();	
		string::const_iterator it = s.begin(); 
		string::const_iterator end=s.end();

		while(regex_search(it,end,m1,reg))
		{
/*			int size = m1[0].length();*/
			string msg(m1[0].first,m1[0].second);	
			msg.erase(0,16);
			msg.erase(msg.size()-10,msg.size());
			//astr.push_back(msg);
			
			s_dolo.cs_url=msg.c_str();
			s_dolo.cs_LocalFullPath=_T("8264com\\")+cs_album_name+_T("\\")+cs_sub_album;
			s_dolo.cs_ReferHead=_T("");
			v_doloST.push_back(s_dolo);

			it = m1[0].second; 
			msg.empty();
			myidle();
		}
		s.empty();

		str_url.Delete(str_url.Find(_T("page")),str_url.GetLength()-str_url.Find(_T("page")) );
		str_url.Insert(str_url.GetLength(), _T("page-"));
		CString tc;
		m_page++;
		tc.Format(_T("%d"),m_page);
		str_url.Insert(str_url.GetLength(), tc);
		str_url.Insert(str_url.GetLength(), _T(".html#comment"));	
		tc.Empty();
	} while (photo_num/20 +2 >m_page);
	


	// 	CString cs_album_name;	//主目录名字
	// 	int photo_num;		//像册数量
	// 	CString cs_sub_album;  //子相册名字
//	checkDirname(cs_album_name);


// 	st_lp.urlGroup=astr;
// 	st_lp.strFileURLInServer.IsEmpty();
// 	st_lp.strFileLocalFullPath=_T("8264com\\")+cs_album_name+_T("\\")+cs_sub_album;
// 	st_lp.strReferHead=_T("");					//_T("Referer: http://mm.taobao.com");
// 	st_lp.hWnd=(HWND)this;
// 	m_pMyThread=AfxBeginThread(Download1,(LPVOID)&st_lp);//&st_lp[n]);
// 	astr.empty();
	return true;
}
Exemple #30
0
int main(int argc, char * argv[])
{
#if defined(OMIM_UNIT_TEST_WITH_QT_EVENT_LOOP) && !defined(OMIM_OS_IPHONE)
  QAPP theApp(argc, argv);
  UNUSED_VALUE(theApp);
#else
  UNUSED_VALUE(argc);
  UNUSED_VALUE(argv);
#endif

  base::ScopedLogLevelChanger const infoLogLevel(LINFO);
#if defined(OMIM_OS_MAC) || defined(OMIM_OS_LINUX) || defined(OMIM_OS_IPHONE)
  base::SetLogMessageFn(base::LogMessageTests);
#endif

  vector<string> testNames;
  vector<bool> testResults;
  int numFailedTests = 0;

  ParseOptions(argc, argv, g_testingOptions);
  if (g_testingOptions.m_help)
  {
    Usage(argv[0]);
    return STATUS_SUCCESS;
  }

  regex filterRegExp;
  if (g_testingOptions.m_filterRegExp)
    filterRegExp.assign(g_testingOptions.m_filterRegExp);

  regex suppressRegExp;
  if (g_testingOptions.m_suppressRegExp)
    suppressRegExp.assign(g_testingOptions.m_suppressRegExp);

#ifndef OMIM_UNIT_TEST_DISABLE_PLATFORM_INIT
  // Setting stored paths from testingmain.cpp
  Platform & pl = GetPlatform();
  CommandLineOptions const & options = GetTestingOptions();
  if (options.m_dataPath)
    pl.SetWritableDirForTests(options.m_dataPath);
  if (options.m_resourcePath)
    pl.SetResourceDir(options.m_resourcePath);
#endif

  for (TestRegister * pTest = TestRegister::FirstRegister(); pTest; pTest = pTest->m_pNext)
  {
    string fileName(pTest->m_FileName);
    string testName(pTest->m_TestName);

    // Retrieve fine file name
    auto const lastSlash = fileName.find_last_of("\\/");
    if (lastSlash != string::npos)
      fileName.erase(0, lastSlash + 1);

    testNames.push_back(fileName + "::" + testName);
    testResults.push_back(true);
  }

  if (GetTestingOptions().m_listTests)
  {
    for (auto const & name : testNames)
      cout << name << endl;
    return 0;
  }

  int iTest = 0;
  for (TestRegister * pTest = TestRegister::FirstRegister(); pTest; ++iTest, pTest = pTest->m_pNext)
  {
    auto const & testName = testNames[iTest];
    if (g_testingOptions.m_filterRegExp &&
        !regex_search(testName.begin(), testName.end(), filterRegExp))
    {
      continue;
    }
    if (g_testingOptions.m_suppressRegExp &&
        regex_search(testName.begin(), testName.end(), suppressRegExp))
    {
      continue;
    }

    LOG(LINFO, ("Running", testName));
    if (!g_bLastTestOK)
    {
      // Somewhere else global variables have been reset.
      LOG(LERROR, ("\n\nSOMETHING IS REALLY WRONG IN THE UNIT TEST FRAMEWORK!!!"));
      return STATUS_BROKEN_FRAMEWORK;
    }

    base::HighResTimer timer(true);

    try
    {
      // Run the test.
      pTest->m_Fn();

      if (g_bLastTestOK)
      {
        LOG(LINFO, ("OK"));
      }
      else
      {
        // You can set Break here if test failed,
        // but it is already set in OnTestFail - to fail immediately.
        testResults[iTest] = false;
        ++numFailedTests;
      }

    }
    catch (TestFailureException const & )
    {
      testResults[iTest] = false;
      ++numFailedTests;
    }
    catch (std::exception const & ex)
    {
      LOG(LERROR, ("FAILED", "<<<Exception thrown [", ex.what(), "].>>>"));
      testResults[iTest] = false;
      ++numFailedTests;
    }
    catch (...)
    {
      LOG(LERROR, ("FAILED<<<Unknown exception thrown.>>>"));
      testResults[iTest] = false;
      ++numFailedTests;
    }
    g_bLastTestOK = true;

    uint64_t const elapsed = timer.ElapsedNano();
    LOG(LINFO, ("Test took", elapsed / 1000000, "ms\n"));
  }

  if (numFailedTests != 0)
  {
    LOG(LINFO, (numFailedTests, " tests failed:"));
    for (size_t i = 0; i < testNames.size(); ++i)
    {
      if (!testResults[i])
        LOG(LINFO, (testNames[i]));
    }
    LOG(LINFO, ("Some tests FAILED."));
    return STATUS_FAILED;
  }

  LOG(LINFO, ("All tests passed."));
  return STATUS_SUCCESS;
}