コード例 #1
0
ファイル: AnalyzeODB.cpp プロジェクト: dyao-vu/meta-core
// [CompID]MType:MID,MType:MID,MType:MID
void ParseMetricIDs(string metricIDs)
{
	vector<string> tokens;
	Tokenizer(metricIDs, tokens, "[");
	for (unsigned int i = 0; i < tokens.size(); i++)
	{
		string tmp = tokens[i];
		unsigned int begin = tmp.find("]");
		vector<Metric> metricsVec;

		if (begin == string::npos)
		{
			throw analyzer_exception("CommandLine (-p) parsing error: Missing Component ID."); // throw exception
		}
		else
		{
			string id = tmp.substr(0, begin);
			tmp = tmp.substr(begin+1);
			vector<string> pairs;
			Tokenizer(tmp, pairs, ",");

			for (unsigned int k = 0; k < pairs.size(); k++)
			{			
				Metric metric;
				begin = pairs[k].find(":");
				if (begin == string::npos)
				{
					throw analyzer_exception("CommandLine (-p) parsing error: Missing metric type encountered."); // throw exception
				}
				else
				{
					string type = pairs[k].substr(0, begin);
					if (type == "FactorOfSafety")
						metric.type = FACTOR_OF_SAFETY;
					else if (type == "QualityIndicator")
						metric.type = RESULT_QUALITY;
					else if (type == "Mises")
						metric.type = PART_MAX_VON_MISES;
					else if (type == "Bearing")
						metric.type = PART_MAX_BEARING;
					else if (type == "Shear")
						metric.type = PART_MAX_SHEAR;
					else if (type == "Displacement")
						metric.type = DISPLACEMENT;
					else
					{
						throw analyzer_exception("CommandLine (-m) parsing error: Incorrect metric type encounctered [" + type + "]"); // throw exception;
					}
					metric.MetricID = pairs[k].substr(begin+1);
				}
				metricsVec.push_back(metric);
			}
			gMetricPairs[id] = metricsVec;
		}
	}
}
コード例 #2
0
bool VRSDClientLuaImplementation::IsGlobalUserDataOfType(const char* Name, const char* Type)
{
  VASSERT(m_pLuaState);

  if(!m_pLuaState || !m_pActivationRecord)
    return false;

  // we can only get local symbols without a crash if we are really in a Lua code execution path
  if(strcmp(m_pActivationRecord->what, "Lua"))
    return true;

  VLuaStackCleaner stackCleaner(m_pLuaState);
  ScopedBooleanToTrue disableDebugHook(m_bDebuggerRetrievingValues);

  VMemoryTempBuffer<512> copyBuffer(Name); // operate on a copy string in the tokenizer
  
  VStringTokenizerInPlace Tokenizer(copyBuffer.AsChar(), '.');

  lua_getfield(m_pLuaState, LUA_GLOBALSINDEX, Tokenizer.Next());
  if(LookupPath(Tokenizer) != HKV_SUCCESS)
    return false;

  // now the variable should be at the top of the stack
  return LUA_TestUserData(m_pLuaState, -1, Type) != NULL;
}
コード例 #3
0
bool VRSDClientLuaImplementation::GetGlobalType(const char*pVariableName, char * pUserDataTypeName)
{
  VASSERT(m_pLuaState);

  if(!m_pLuaState || !m_pActivationRecord)
    return false;

  // we can only get local symbols without a crash if we are really in a Lua code execution path
  if(strcmp(m_pActivationRecord->what, "Lua"))
    return true;

  VLuaStackCleaner stackCleaner(m_pLuaState);
  ScopedBooleanToTrue disableDebugHook(m_bDebuggerRetrievingValues);

  VMemoryTempBuffer<512> copyBuffer(pVariableName); // operate on a copy string in the tokenizer

  VStringTokenizerInPlace Tokenizer(copyBuffer.AsChar(), '.');
  lua_getfield(m_pLuaState, LUA_GLOBALSINDEX, Tokenizer.Next());

  if(LookupPath(Tokenizer) != HKV_SUCCESS)
    return false;

  const char * szName = VSWIG_Lua_typename(m_pLuaState, -1);
  sprintf(pUserDataTypeName, "%s", szName);
  
  return pUserDataTypeName[0] != 0;
}
コード例 #4
0
    StreamHandler::StreamHandler(const std::string & appDir_)
        :_appDir(appDir_)
    {
        boost::filesystem::path path(appDir_);
        _oStreamPtr.reset(new std::ofstream(appDir_+"/Merged.txt"));

        FormatAnalyzer analyzer(readFormatString());
        std::regex formatRegex = analyzer.getRegex();
        
        if (boost::filesystem::exists(path) && boost::filesystem::is_directory(path))
        {
            
            boost::filesystem::directory_iterator end_itr;
            for (boost::filesystem::directory_iterator it(path); it != end_itr; it++)
            {
                if (boost::filesystem::is_regular_file(it->status()))
                {
                    if (it->path().filename().string() == ".loginfo")
                    {
                        continue;
                    }

                    _streams.push_back(Tokenizer(
                                           std::shared_ptr<std::ifstream>(
                                               new std::ifstream(appDir_ + "/" + it->path().
                                                                 filename().string())),
                                           formatRegex));
                }
            }
        }
    }
コード例 #5
0
ファイル: AnalyzeODB.cpp プロジェクト: dyao-vu/meta-core
void ParseMaterials(string materialProps)
{
	vector<string> tokens;
	Tokenizer(materialProps, tokens, "[");
	for (unsigned int i = 0; i < tokens.size(); i++)
	{
		string tmp = tokens[i];
		unsigned int begin = tmp.find("]");
		if (begin == string::npos)
		{
			throw analyzer_exception("CommandLine (-p) parsing error: Missing Component ID."); // throw exception
		}
		else
		{
			string id = tmp.substr(0, begin);
			tmp = tmp.substr(begin+1);
			vector<string> pairs;
			Tokenizer(tmp, pairs, ",");

			Material material;
			for (unsigned int k = 0; k < pairs.size(); k++)
			{
				begin = pairs[k].find(":");
				if (begin == string::npos)
				{
					throw analyzer_exception("CommandLine (-p) parsing error: Missing material property type."); // throw exception
				}
				else
				{
					string type = pairs[k].substr(0, begin);
					float value = atof(pairs[k].substr(begin+1).c_str());
					if (type == "Bearing")
						material.bearing = value;
					else if (type == "Mises")
						material.mises = value;
					else if (type == "Shear")
						material.shear = value;
					else
					{
						throw analyzer_exception("CommandLine (-p) parsing error: Incorrect material property type encounctered [" + type + "]");	// throw exception
					}
				}
			}
			gMaterials[id] = material;
		}
	}
}
コード例 #6
0
bool VRSDClientLuaImplementation::UpdateGlobalVariable(const char* szVarName, const char* szNewValue)
{
  if(!szVarName || !szNewValue || szVarName[0]==0)
    return false;

  // we can only get global symbols without a crash if we are really in a Lua code execution path
  if(strcmp(m_pActivationRecord->what, "Lua"))
    return true;

  VMemoryTempBuffer<512> copyBuffer(szVarName); // operate on a copy string in the tokenizer

  VLuaStackCleaner stackCleaner(m_pLuaState);
  ScopedBooleanToTrue disableDebugHook(m_bDebuggerRetrievingValues);

  VStringTokenizerInPlace Tokenizer(copyBuffer.AsChar(), '.');
  const char* pCurrent = Tokenizer.Next();
  unsigned int i = 0;

  const char* pLastField = NULL;

  lua_getfield(m_pLuaState, LUA_GLOBALSINDEX, pCurrent);
  if(lua_isnil(m_pLuaState, -1))
    return false;
  if(LookupPath(Tokenizer, &pLastField) != HKV_SUCCESS)
    return false;

  // now the variable is at the top of the stack, update its value
  int iLuaType = lua_type(m_pLuaState, -1);
  lua_pop(m_pLuaState, 1);

  bool bIsIntegerKey = false;
  if(pLastField && VStringUtil::IsIntegerString(pLastField))
  {
    bIsIntegerKey = true;
    lua_pushnumber(m_pLuaState, (LUA_NUMBER)atoi(pLastField));
  }

  if (!PushValue(iLuaType, szNewValue))
    return false;

  if( Tokenizer.GetTokenCount() > 1 )
  {
    VASSERT(pLastField != NULL);
    if(bIsIntegerKey)
    {
      lua_settable(m_pLuaState, -3);
    }
    else
    {
      lua_setfield(m_pLuaState, -2, pLastField);
    }
  }
  else
  {
    lua_setglobal(m_pLuaState, szVarName);
  }

  return true;
}
コード例 #7
0
ファイル: Mapping.cpp プロジェクト: jaabell/gmESSI
void Mapping::makeFunction(string Id, string GmshCommandList, string EssiCommand) {

    Tokenizer str = Tokenizer(GmshCommandList,"|");
    while(str.hasMoreTokens()) {

        Semantics semantic = Semantics( str.nextToken(),EssiCommand);
        semantic.setElementId(Id);
        this->Function.insert(pair<string,Semantics> (semantic.getEssiTag(),semantic));
    }
}
コード例 #8
0
ファイル: Parser.cpp プロジェクト: paglian/QSimpleCalc
Node *Parser::parse(const QString &str)
{
    QStringList tokens;

    if (Tokenizer().tokenize(str, tokens)) {
        return SyntaxTree().buildTree(tokens);
    } else {
        throw InvalidSyntaxException();
    }
}
コード例 #9
0
//##ModelId=474D3064011B
bool CHTMFormatStruct::GetData(LPCSTR HTML)
{
	CTokenizer Tokenizer(HTML, "\r\n");
	CString Token;
	while(Tokenizer.Next(Token))
	{
		CTokenizer ItemTokenizer(Token, ":");
		CString csParam;
		ItemTokenizer.Next(csParam);
		CString csValue = ItemTokenizer.Tail();

		if(csParam == "Version")
		{
			m_csVersion = csValue;
		}
		else if(csParam == "StartHTML")
		{
			m_lStartHTML = ATOI(csValue);
		}
		else if(csParam == "EndHTML")
		{
			m_lEndHTML = ATOI(csValue);
		}
		else if(csParam == "StartFragment")
		{
			m_lStartFragment = ATOI(csValue);
		}
		else if(csParam == "EndFragment")
		{
			m_lEndFragment = ATOI(csValue);
		}
		else if(csParam == "SourceURL")
		{
			m_csSourceURL = csValue;
			break;
		}
		else if(csParam.Left(5) == "<html")
		{
			break;
		}
	}

	if(m_lStartFragment >= 0 && m_lEndFragment >= 0 && m_lStartFragment < m_lEndFragment)
	{
		m_csFragment = Tokenizer.m_cs.Mid(m_lStartFragment, m_lEndFragment-m_lStartFragment);
		m_csFragment = m_csFragment.Trim();
	}

	if(m_csFragment.IsEmpty())
	{
		return false;
	}

	return true;
}
コード例 #10
0
ファイル: tokenizer_test.cpp プロジェクト: 1Hgm/fatal
void tokenizer_test(T &&data, std::vector<char const *> const &expected) {
  auto i = expected.begin();

  for (auto const &token: Tokenizer(std::forward<T>(data))) {
    FATAL_ASSERT_NE(expected.end(), i);
    FATAL_EXPECT_EQ(*i, token);
    ++i;
  }

  FATAL_EXPECT_EQ(expected.end(), i);
}
コード例 #11
0
ファイル: zztoopInterp.cpp プロジェクト: ARMoir/freezzt
KILLENUM Runtime::parseNext()
{
  if ( ip >= size ) return ENDCYCLE;
  startLineIP = ip;
  advanceIP = true;

  ZString line = readLine();
  tokenizer = Tokenizer(line);

  KILLENUM ret = FREEBIE;
  Token::Code main = tokenizer.token();
  switch ( main )
  {
    case Token::AT:
    case Token::SINGLEQUOTE:
    case Token::COLON:
      zdebug() << __FILE__ << ":" << __LINE__ << " ignored type";
      break;

    case Token::CRUNCH:
    {
      zdebug() << __FILE__ << ":" << __LINE__ << " crunch";
      ret = executeCrunch();
      break;
    }

    case Token::QUESTION:
    case Token::SLASH: // currently unimplemented
      zdebug() << __FILE__ << ":" << __LINE__ << " sugar move";
      ret = sugarMove();
      break;

    case Token::NEWLINE:
    case Token::EXCLAIM:
    case Token::DOLLAR:
    default:
    {
      zdebug() << __FILE__ << ":" << __LINE__ << " strings";
      addString( line );
      break;
    }
  }

  // Post line cleanup
  ip = startLineIP;
  if ( advanceIP ) {
    seekNextLine();
  }

  return FREEBIE;
}
コード例 #12
0
String D3PosDirUpScale::toString(int dec) const {
  const StringArray va(Tokenizer(::toString(getViewMatrix() ,dec),_T("\n")));
  const StringArray wa(Tokenizer(::toString(getWorldMatrix(),dec),_T("\n")));
  const int         ml = (int)va.maxLength();
  StringArray a;
  for(size_t i = 0; i < va.size(); i++) {
    a.add(format(_T("%-5s %-*.*s %-6s %-*.*s")
                ,(i==0)?_T("View:"):EMPTYSTRING
                ,ml,ml,va[i].cstr()
                ,(i==0)?_T("World:"):EMPTYSTRING
                ,ml,ml,wa[i].cstr()
                ));
  }

  return format(_T("P:%s D:%s U:%s R:%s S:%s\n%s")
               ,::toString(m_pos,dec).cstr()
               ,::toString(m_dir,dec).cstr()
               ,::toString(m_up,dec).cstr()
               ,::toString(getRight(),dec).cstr()
               ,::toString(m_scale,dec).cstr()
               ,a.toString(_T("\n")).remove(0,1).removeLast().cstr()
               );
}
コード例 #13
0
void CColoredStatic::repaint(CDC &dc) {
  CFont *font = GetFont();
  if(font == NULL) {
    font = GetParent()->GetFont();
  }
  CFont *oldFont = dc.SelectObject(font);
  if(m_bkColorSet) {
    dc.SetBkColor(m_bkColor);
  }
  dc.SetTextColor(m_textColor);

  String text = getWindowText(this);
  StringArray lineArray(Tokenizer(text, "\n"));

  const int textAlign = GetStyle() & 0x3;
  int y = 0;
  switch(textAlign) {
  case SS_LEFT:
    { for(size_t i = 0; i < lineArray.size(); i++) {
        const String &line = lineArray[i];
        const CSize lineSize = getTextExtent(dc, line);
        dc.TextOut(0,y,line.cstr());
        y += lineSize.cy;
      }
    }
    break;
  case SS_RIGHT:
    { const CSize winSize = getWindowSize(this);
      for(size_t i = 0; i < lineArray.size(); i++) {
        const String &line = lineArray[i];
        const CSize lineSize = getTextExtent(dc, line);
        dc.TextOut(max(0, winSize.cx - lineSize.cx), y, line.cstr());
        y += lineSize.cy;
      }
    }
    break;
  case SS_CENTER:
    { const CSize winSize = getWindowSize(this);
      for(size_t i = 0; i < lineArray.size(); i++) {
        const String &line = lineArray[i];
        const CSize lineSize = getTextExtent(dc, line);
        dc.TextOut(max(0, (winSize.cx - lineSize.cx)/2), y, line.cstr());
        y += lineSize.cy;
      }
    }
    break;
  }
  dc.SelectObject(oldFont);
}
コード例 #14
0
ファイル: Semantics.cpp プロジェクト: SumeetSinha/gmESSI
void Semantics::setMatchMode(){

	Tokenizer tknzr = Tokenizer(this->ElementId,"-");
	this->ElementId = tknzr.nextToken();
	string str= tknzr.currToken();
	if(str.empty() || ((!isdigit(str[0])) && (str[0] != '-') && (str[0] != '+'))) this->MatchMode=false ;
   	char * p ;
   	strtol(str.c_str(), &p, 10) ;
   	this->MatchMode = (*p == 0) ;

   	while(tknzr.hasMoreTokens()){
   		this->SemanticsId = tknzr.nextToken();
   		break;
   	}
}
コード例 #15
0
std::vector<std::string> ColumnTextParser::tokenizeLine(const std::string& Line)
{
  std::vector<std::string> Splitted;

  boost::tokenizer<boost::escaped_list_separator<char>>
    Tokenizer(Line, boost::escaped_list_separator<char>("\\",m_Delimiter,"\""));

  for (auto it=Tokenizer.begin(); it!=Tokenizer.end(); ++it)
  {
    if (!(*it).empty())
      Splitted.push_back(*it);
  }

  return Splitted;
}
コード例 #16
0
ファイル: Interpreter.cpp プロジェクト: Volha/how-to-do
void Interpreter::RunInterpret(const std::string& commandLine)
{
	m_tokens = Tokenizer(commandLine);
	for(std::vector<std::string>::iterator it = m_tokens.begin(); it != m_tokens.end(); ++it)
	{
		if (IsTokenNumber(*it))
		{
			m_stack->push(boost::lexical_cast<int>(*it));
		}
		else
		{
			FindAndRun(*it);
			return;
		}
	}
}
コード例 #17
0
ファイル: AnalyzeODB.cpp プロジェクト: dyao-vu/meta-core
// helper
void ParseElementIDs(string elementIDs)
{
	vector<string> tokens;
	Tokenizer(elementIDs, tokens, ",");
	for (unsigned int i = 0; i < tokens.size(); i++)
	{
		unsigned int pos = tokens[i].find(":");
		if (pos == string::npos)
		{
			throw analyzer_exception("CommandLine (-e) parsing error: Missing Element Set ID."); // throw exception
		}
		else
		{			
			gElementSets[tokens[i].substr(0, pos)] = tokens[i].substr(pos+1);		// map[ComponentID] = ElementID;
		}
	}
}
コード例 #18
0
bool VRSDClientLuaImplementation::GetLocalType(const char* pVariableName, char * pUserDataTypeName)
{
  VASSERT(m_pLuaState);

  if(!m_pLuaState || !m_pActivationRecord)
    return false;

  // we can only get local symbols without a crash if we are really in a Lua code execution path
  if(strcmp(m_pActivationRecord->what, "Lua"))
    return true;

  VLuaStackCleaner stackCleaner(m_pLuaState);
  ScopedBooleanToTrue disableDebugHook(m_bDebuggerRetrievingValues);

  const char* pSymbolName = NULL;
  int iLocalIndex = 1;

  VMemoryTempBuffer<512> copyBuffer(pVariableName); // operate on a copy string in the tokenizer

  VStringTokenizerInPlace Tokenizer(copyBuffer.AsChar(), '.');
  char* pCurrent = Tokenizer.Next();

  pUserDataTypeName[0] = 0;

  while((pSymbolName = lua_getlocal(m_pLuaState, m_pActivationRecord, iLocalIndex)) != NULL)
  {                                                             //stack: ..., localX, TOP
    // check if this local variable is the one we want
    if(!strcmp(pSymbolName, pCurrent))
    {
      // there is already the local on the stack
      if(LookupPath(Tokenizer) != HKV_SUCCESS)
        return false;

      const char * szName = VSWIG_Lua_typename(m_pLuaState, -1);
      sprintf(pUserDataTypeName, "%s", szName);

      return pUserDataTypeName[0] != 0;
    }

    // clean up the stack and increment the index to get the next local variable
    lua_pop(m_pLuaState, 1);                                    //stack: ..., TOP
    iLocalIndex++;
  }

  return false;
}
コード例 #19
0
bool VRSDClientLuaImplementation::GetUserDataPointerFromLocal(const char* szVariable, void** ppUserData, void ** ppEnvironment)
{
  VASSERT(m_pLuaState);

  if(!m_pLuaState || !m_pActivationRecord)
    return false;

  // we can only get local symbols without a crash if we are really in a Lua code execution path
  if(strcmp(m_pActivationRecord->what, "Lua"))
    return true;

  ScopedBooleanToTrue disableDebugHook(m_bDebuggerRetrievingValues);
  VLuaStackCleaner stackCleaner(m_pLuaState);


  char* pSymbolName = NULL;
  int iLocalIndex = 1;

  VMemoryTempBuffer<512> copyBuffer(szVariable); // operate on a copy string in the tokenizer
  
  VStringTokenizerInPlace Tokenizer(copyBuffer.AsChar(), '.');
  char* pCurrent = Tokenizer.Next();

  while((pSymbolName = (char*)lua_getlocal(m_pLuaState, m_pActivationRecord, iLocalIndex)) != NULL)
  {                                                       //Stack: ..., localX, TOP
    // check if this local variable is the one we want
    if(!strcmp(pSymbolName, pCurrent))
    {
      VLuaStackCleaner innerStackCleaner(m_pLuaState);
      //there is already the local on the stack...
      if(LookupPath(Tokenizer) != HKV_SUCCESS)
        return false;

      // now the variable is at the top of the stack
      *ppUserData = lua_touserdata(m_pLuaState, -1);    //Stack: ..., localX, {field}, TOP
      *ppEnvironment = m_pLuaState;
      return true;
    }

    // remove the value and update the index to get the next local variable
    lua_pop(m_pLuaState, 1);
    iLocalIndex++;
  }

  return false;
}
コード例 #20
0
void Configuration::OnHeadersText(wxCommandEvent& /*event*/)
{
  if ( m_BlockHeadersText )
    return;

  // Updating headers arrays after each text change
  wxStringTokenizer Tokenizer(m_Headers->GetValue(),_T("\n"));
  wxArrayString* Headers = (wxArrayString*)m_Identifiers->GetClientData(m_Identifiers->GetSelection());
  if ( !Headers )
    return;

  Headers->Clear();
  while ( Tokenizer.HasMoreTokens() )
    Headers->Add(Tokenizer.GetNextToken());

  m_Dirty = true;
}// OnHeadersText
コード例 #21
0
bool VRSDClientLuaImplementation::IsLocalUserDataOfType(const char* Name, const char* Type)
{
  VASSERT(m_pLuaState);

  if(!m_pLuaState || !m_pActivationRecord)
    return false;

  // we can only get local symbols without a crash if we are really in a Lua code execution path
  if(strcmp(m_pActivationRecord->what, "Lua"))
    return true;

  VLuaStackCleaner stackCleaner(m_pLuaState);
  ScopedBooleanToTrue disableDebugHook(m_bDebuggerRetrievingValues);

  const char* pSymbolName = NULL;
  int iLocalIndex = 1;

  VMemoryTempBuffer<512> copyBuffer(Name); // operate on a copy string in the tokenizer
  
  VStringTokenizerInPlace Tokenizer(copyBuffer.AsChar(), '.');
  char* pCurrent = Tokenizer.Next();

  while((pSymbolName = lua_getlocal(m_pLuaState, m_pActivationRecord, iLocalIndex)) != NULL)
  {                                                             //stack: ..., localX, TOP
    // check if this local variable is the one we want
    if(!strcmp(pSymbolName, pCurrent))
    {
      VLuaStackCleaner innerStackCleaner(m_pLuaState);
      // there is already the local on the stack

      if(LookupPath(Tokenizer) != HKV_SUCCESS)
        return false;

      // now the variable is at the top of the stack
      return LUA_TestUserData(m_pLuaState, -1, Type) != NULL;
    }

    // increment the index to get the next local variable
    iLocalIndex++;
    lua_pop(m_pLuaState, 1);
  }
 
  return false;
}
コード例 #22
0
ファイル: Semantics.cpp プロジェクト: SumeetSinha/gmESSI
void Semantics::setGmshCommand(const string& Command){

	int nofTokens = 0;
	string Gcommand = "", essiTag="";
	Tokenizer inpString = Tokenizer(Command," {,;}()");
	nofTokens = inpString.countTokens()-1;
	this->NofGmshVariables = nofTokens-1;
	Gcommand = Gcommand + inpString.nextToken() + "{ ";
	essiTag = essiTag + inpString.currToken() + "{";
	
	for( int i=0 ;i<nofTokens-1; i++){

		string variable= this->delSpaces(inpString.nextToken());
		
		vector<string>::iterator it;
		it = find(this->VarList.begin(),this->VarList.end(),variable);
		
		if (it != this->VarList.end()) 
 			*it = "variable";

		Gcommand = Gcommand +variable+" ,";
		essiTag = essiTag + " ,";
	}

	string variable= this->delSpaces(inpString.nextToken());

	if(variable.compare("")){
		this->NofGmshVariables++;
	}

	vector<string>::iterator it;
	it = find(this->VarList.begin(),this->VarList.end(),variable);
	if (it != this->VarList.end()) 
 		*it = "variable";
 	
	Gcommand = Gcommand +variable + " }";
	essiTag = essiTag + " }"+to_string(this->NofGmshVariables);
	
	// cout << Gcommand << endl;
	// cout << essiTag << endl;
	this->GmshCommand= Gcommand;
	this->setEssiTag(essiTag);

}
コード例 #23
0
ファイル: DlgUIList.cpp プロジェクト: constantinbogdan/node3d
inline std::string id2name(const std::string& strID)
{
	std::vector<std::string> out;
	Tokenizer(strID,out,"_");
	if (out.size()>1)
	{
		std::string	name;
		for(size_t i=1;i<out.size();++i)
		{
			std::string	words;
			words = out[i];
			std::transform(words.begin(),words.end(),words.begin(),std::tolower);// toLower
			std::transform(words.begin(),++words.begin(),words.begin(),std::toupper);
			name+=words;
		}
		return name;
	}
	return strID;
}
コード例 #24
0
ファイル: main.cpp プロジェクト: GaleDragon/silver
int main(int argc, const char * argv[])
{
    enum shell_cmds {
        QUIT='q',
        VIEW='v',
        ACT='a'
    };
    
    while (true){
        std::cout << ">>> ";
        
        std::string request;
        std::getline( std::cin, request );
        
        if (request.length() < 2){
            char cmd = (shell_cmds) request[0];
            if (cmd == QUIT) {
                break;
            } else if (cmd == VIEW) {
                
            } else if (cmd == ACT) {
                
            } else {
                std::cerr << "Command not recognized\n";
            }
        }
        else {
            Tokenizer t = Tokenizer();
            TokenedString tok = t.read( request );
            for (int i=1; i < tok.size(); i++) {
                std::cout << tok.get(i) << "\n";
            }
        }
    }
    return 0;
}
コード例 #25
0
bool VRSDClientLuaImplementation::GetSubSymbolsForGlobal(char* GlobalName, DynArray_cl<VRSDScriptSymbol>& SubSymbols, unsigned int& SubSymbolCount)
{
  VASSERT(m_pLuaState);

  if(!m_pLuaState || !m_pActivationRecord)
    return false;

  SubSymbolCount = 0;

  // we can only get local symbols without a crash if we are really in a Lua code execution path
  if(strcmp(m_pActivationRecord->what, "Lua"))
    return true;

  ScopedBooleanToTrue disableDebugCallback(m_bDebuggerRetrievingValues);
  VLuaStackCleaner stackCleaner(m_pLuaState);

  VMemoryTempBuffer<512> copyBuffer(GlobalName); // operate on a copy string in the tokenizer
  
  VStringTokenizerInPlace Tokenizer(copyBuffer.AsChar(), '.');
  lua_getfield(m_pLuaState, LUA_GLOBALSINDEX, Tokenizer.Next());
  if(LookupPath(Tokenizer) != HKV_SUCCESS)
    return false;

  // now the variable should be at the top of the stack and we can get the subvariables of it
  
  // first key for the iteration
  lua_pushnil(m_pLuaState);
  
  while (lua_next(m_pLuaState, -2) != 0)
  {
    // after this the key is at -2 and the value at -1
    
    // we only want string fields and numeric fields
    // (lua_isstring returns also true for numbers, using
    // tostring later on will cast the number to a string)
    int iKeyType = lua_type(m_pLuaState, -2);
    if (iKeyType==LUA_TNUMBER || iKeyType==LUA_TSTRING)
    {  
      VString sKeyBuffer;

      //this if prevents a conversion of number on the Lua stack
      if(iKeyType==LUA_TNUMBER) sKeyBuffer.Format("%1.0f", lua_tonumber(m_pLuaState, -2));
      else                      sKeyBuffer = lua_tostring(m_pLuaState, -2);

      const char* pSymbolName = sKeyBuffer.AsChar();

      if(pSymbolName)
      {
        // table member variable
        if(lua_istable(m_pLuaState, -1))
        {
          // add a symbol for the table
          AddSymbol(SubSymbols, SubSymbolCount, pSymbolName, "table", VRSDScriptSymbol::SYMBOL_TABLE);
        }
        // numeric member variable
        else if(lua_type(m_pLuaState, -1) == LUA_TNUMBER)
        {
          char buffer[32];
          sprintf(buffer, "%f", lua_tonumber(m_pLuaState, -1));
          AddSymbol(SubSymbols, SubSymbolCount, pSymbolName, buffer, VRSDScriptSymbol::SYMBOL_NUMBER);
        }
        // string member variable
        else if(lua_type(m_pLuaState, -1) == LUA_TSTRING)
        {
          AddSymbol(SubSymbols, SubSymbolCount, pSymbolName, lua_tostring(m_pLuaState, -1), VRSDScriptSymbol::SYMBOL_STRING);
        }
        // function member variable
        else if(lua_isfunction(m_pLuaState, -1))
        {
          AddSymbol(SubSymbols, SubSymbolCount, pSymbolName, "function", VRSDScriptSymbol::SYMBOL_FUNCTION);
        }
        // userdata member variable
        else if(lua_isuserdata(m_pLuaState, -1))
        {
          char buffer[128];
          swig_type_info* type = (swig_type_info *)LUA_GetSwigType(m_pLuaState, -1);
          void * pUserData = lua_touserdata(m_pLuaState, -1);

          if(type)
          {
            vis_snprintf(buffer, 128, "userdata:0x%p [%s: 0x%p]", pUserData, type->str, ((swig_lua_userdata*)pUserData)->ptr);
          }
          else
          {
            vis_snprintf(buffer, 128, "userdata:0x%p", lua_touserdata(m_pLuaState, -1));
          }
          AddSymbol(SubSymbols, SubSymbolCount, pSymbolName, buffer, VRSDScriptSymbol::SYMBOL_USERDATA);
        }
        else if(lua_isboolean(m_pLuaState, -1))
        {
          int iBoolVal = lua_toboolean(m_pLuaState, -1);
          AddSymbol(SubSymbols, SubSymbolCount, pSymbolName, iBoolVal ? "true" : "false", VRSDScriptSymbol::SYMBOL_BOOLEAN);
        }
        else if(lua_isnil(m_pLuaState, -1))
        {
          AddSymbol(SubSymbols, SubSymbolCount, pSymbolName, "nil", VRSDScriptSymbol::SYMBOL_CLASS);
        }

      }
    }
    lua_pop(m_pLuaState, 1);  // remove the value, keep the key for the next iteration
  }

  return true;
}
コード例 #26
0
bool VRSDClientLuaImplementation::GetSubSymbolsForLocal(char* LocalName, DynArray_cl<VRSDScriptSymbol>& SubSymbols, unsigned int& SubSymbolCount)
{
  VASSERT(m_pLuaState);

  if(!m_pLuaState || !m_pActivationRecord)
    return false;
  
  SubSymbolCount = 0;

  // we can only get local symbols without a crash if we are really in a Lua code execution path
  if(strcmp(m_pActivationRecord->what, "Lua"))
    return true;

  VLuaStackCleaner stackCleaner(m_pLuaState);
  ScopedBooleanToTrue disableDebugCallback(m_bDebuggerRetrievingValues);

  char* pSymbolName = NULL;
  int iLocalIndex = 1;

  VMemoryTempBuffer<512> copyBuffer(LocalName); // operate on a copy string in the tokenizer
  
  VStringTokenizerInPlace Tokenizer(copyBuffer.AsChar(), '.');
  char* pCurrent = Tokenizer.Next();

  while((pSymbolName = (char*)lua_getlocal(m_pLuaState, m_pActivationRecord, iLocalIndex)) != NULL)
  {                                                       //stack: .., localX, TOP
    // check if this local variable is the one we want
    if(!strcmp(pSymbolName, pCurrent))
    {
      //the local is already on the stack
      if(LookupPath(Tokenizer) != HKV_SUCCESS)
        return false;

      // now we can iterate over the contents of the table
      // first key for the iteration
      lua_pushnil(m_pLuaState);                           //stack: .., localX, {field}, nil, TOP

      //access the last field
      while (lua_next(m_pLuaState, -2) != 0)              //stack: .., localX, {field}, key, value TOP
      {
        // we only want string fields and numeric fields
        // (lua_isstring returns also true for numbers, using
        // tostring later on will cast the number to a string)
        int iKeyType = lua_type(m_pLuaState, -2);
        if (iKeyType==LUA_TNUMBER || iKeyType==LUA_TSTRING)
        {  
          VString sKeyBuffer;

          //this if prevents a conversion of number on the Lua stack
          if(iKeyType==LUA_TNUMBER) sKeyBuffer.Format("%1.0f", lua_tonumber(m_pLuaState, -2));
          else                      sKeyBuffer = lua_tostring(m_pLuaState, -2);

          if(!sKeyBuffer.IsEmpty())
          {
            int iValueType = lua_type(m_pLuaState, -1);
            VString sValueBuffer;

            // table member variable
            switch (iValueType) 
            {
              case LUA_TTABLE:
                // add a symbol for the table
                AddSymbol(SubSymbols, SubSymbolCount, sKeyBuffer.AsChar(), "table", VRSDScriptSymbol::SYMBOL_TABLE);
                break;
            
              case LUA_TNUMBER:
                // numeric member variable
                sValueBuffer.Format("%f", lua_tonumber(m_pLuaState, -1));
                AddSymbol(SubSymbols, SubSymbolCount, sKeyBuffer.AsChar(), sValueBuffer.AsChar(), VRSDScriptSymbol::SYMBOL_NUMBER);
                break;

              case LUA_TSTRING:
                AddSymbol(SubSymbols, SubSymbolCount, sKeyBuffer.AsChar(), lua_tostring(m_pLuaState, -1), VRSDScriptSymbol::SYMBOL_STRING);
                break;

              case LUA_TFUNCTION:
                sValueBuffer.Format("function:0x%p", lua_tocfunction(m_pLuaState, -1));
                AddSymbol(SubSymbols, SubSymbolCount, sKeyBuffer.AsChar(), sValueBuffer.AsChar(), VRSDScriptSymbol::SYMBOL_FUNCTION);
                break;
              
              case LUA_TBOOLEAN:
                AddSymbol(SubSymbols, SubSymbolCount, sKeyBuffer.AsChar(), lua_toboolean(m_pLuaState, -1) ? "true" : "false", VRSDScriptSymbol::SYMBOL_BOOLEAN);
                break;

              case LUA_TNIL:
                AddSymbol(SubSymbols, SubSymbolCount, sKeyBuffer.AsChar(), "nil", VRSDScriptSymbol::SYMBOL_CLASS);
                break;

              case LUA_TTHREAD:
                sValueBuffer.Format("thread:0x%p", lua_tothread(m_pLuaState, -1));
                AddSymbol(SubSymbols, SubSymbolCount, sKeyBuffer.AsChar(), sValueBuffer.AsChar(), VRSDScriptSymbol::SYMBOL_CLASS);
                break;

              case LUA_TUSERDATA:
                sValueBuffer.Format("userdata:0x%p", lua_touserdata(m_pLuaState, -1));
                AddSymbol(SubSymbols, SubSymbolCount, sKeyBuffer.AsChar(), sValueBuffer.AsChar(), VRSDScriptSymbol::SYMBOL_USERDATA);
                break;
            
              default:
                AddSymbol(SubSymbols, SubSymbolCount, sKeyBuffer.AsChar(), "unknown", VRSDScriptSymbol::SYMBOL_STRING);
                break;
            }
          }
        }

        // remove the value, keep the key for the next iteration
        lua_pop(m_pLuaState, 1);                        //stack: .., localX, {field}, key, TOP
      }
      return true;
    }

    // clean up the stack and increment the index to get the next local variable
    lua_pop(m_pLuaState, 1);                            //stack: .., TOP
    iLocalIndex++;
  }

  return true;
}
コード例 #27
0
ファイル: gposttl.c プロジェクト: kylebgorman/pposttl
char *check_and_tag(char ptr0[], int enhance_penntag) {
    return tag(Tokenizer(ptr0), enhance_penntag);
}
コード例 #28
0
bool VRSDClientLuaImplementation::UpdateLocalVariable(const char* Variable, const char* NewValue)
{
  if(!Variable || !NewValue)
    return false;

  VASSERT(m_pLuaState);

  if(!m_pLuaState || !m_pActivationRecord)
    return false;

  // we can only get local symbols without a crash if we are really in a Lua code execution path
  if(strcmp(m_pActivationRecord->what, "Lua"))
    return true;

  VLuaStackCleaner stackCleaner(m_pLuaState);
  ScopedBooleanToTrue disableDebugHook(m_bDebuggerRetrievingValues);

  const char* pSymbolName = NULL;
  int iLocalIndex = 1;

  VMemoryTempBuffer<512> copyBuffer(Variable); // operate on a copy string in the tokenizer
  
  VStringTokenizerInPlace Tokenizer(copyBuffer.AsChar(), '.');
  char* pCurrent = Tokenizer.Next();
  int i = 0;
  const char* pLastField = NULL;

  // go through all local variables
  while((pSymbolName = lua_getlocal(m_pLuaState, m_pActivationRecord, iLocalIndex)) != NULL)
  {
    // check if this local variable is the one we want
    if(!strcmp(pSymbolName, pCurrent))
    {
      VLuaStackCleaner innerStackCleaner(m_pLuaState);
      if(LookupPath(Tokenizer, &pLastField) != HKV_SUCCESS)
        return false;

      // now the variable is at the top of the stack, update its value
      int iLuaType = lua_type(m_pLuaState, -1);

      // pop off the field again
      lua_pop(m_pLuaState, 1);

      bool bIsIntegerKey = false;
      if(pLastField && VStringUtil::IsIntegerString(pLastField))
      {
        bIsIntegerKey = true;
        lua_pushnumber(m_pLuaState, (LUA_NUMBER)atoi(pLastField));
      }

      if (!PushValue(iLuaType, NewValue))
      {
        return false;
      }

      if(Tokenizer.GetTokenCount() > 1)
      {
        VASSERT(pLastField != NULL);
        if(bIsIntegerKey)
        {
          lua_settable(m_pLuaState, -3);
        }
        else
        {
          lua_setfield(m_pLuaState, -2, pLastField);
        }
      }
      else
      {
        lua_setlocal(m_pLuaState, m_pActivationRecord, iLocalIndex);
      }

      break;
    }

    // clean up the stack and increment the index to get the next local variable
    lua_pop(m_pLuaState, 1);
    iLocalIndex++;
  }

  return true;
}
コード例 #29
0
ファイル: processingdlg.cpp プロジェクト: stahta01/EmBlocks
void ProcessingDlg::CheckFilter(
    const wxString& OldBasePath,
    const wxStringStringMap& OldVars,
    const wxArrayString& OldCompilers,
    const LibraryDetectionConfig* Config,
    const LibraryDetectionConfigSet* Set,
    int WhichFilter)
{
    if ( (int)Config->Filters.size() <= WhichFilter )
    {
        FoundLibrary(OldBasePath,OldVars,OldCompilers,Config,Set);
        return;
    }

    const LibraryDetectionFilter& Filter = Config->Filters[WhichFilter];

    switch ( Filter.Type )
    {
        case LibraryDetectionFilter::File:
        {
            // Split path
            wxArrayString Pattern;
            SplitPath(Filter.Value,Pattern);

            // Fetch list of files with filename matching last pattern's element
            const wxArrayString& PathArray = Map[Pattern[Pattern.Count()-1]];
            if ( PathArray.empty() ) return;

            // Process those files
            for ( size_t i=0; i<PathArray.Count(); i++ )
            {
                wxArrayString Path;
                wxStringStringMap Vars = OldVars;
                SplitPath(PathArray[i],Path);

                int path_index = (int)Path.Count() - 1;
                int pattern_index = (int)Pattern.Count() - 1;

                // Check if patterns do match
                while ( ( path_index >= 0 ) && ( pattern_index >= 0 ) )
                {
                    wxString& PatternPart = Pattern[pattern_index];
                    if ( IsVariable(PatternPart) )
                    {
                        wxString VarName = PatternPart.Mid(3,PatternPart.Len()-4);
                        if ( Vars[VarName].empty() )
                        {
                            Vars[VarName] = Path[path_index];
                        }
                        else
                        {
                            if ( Vars[VarName] != Path[path_index] ) break;
                        }
                    }
                    else
                    {
                        if ( PatternPart != Path[path_index] ) break;
                    }
                    path_index--;
                    pattern_index--;
                }

                // This is when patterns did not match
                if ( pattern_index >= 0 ) continue;

                // Construct base path from the rest of file's name
                wxString BasePath;
                for ( int j=0; j<=path_index; j++ )
                {
                    BasePath += Path[j] + wxFileName::GetPathSeparator();
                }

                // And check if base path match the previous one
                if ( !OldBasePath.IsEmpty() )
                {
                    if ( BasePath != OldBasePath ) continue;
                }

                // Ok, this filter matches, let's advance to next filet
                CheckFilter(BasePath,Vars,OldCompilers,Config,Set,WhichFilter+1);
            }
            break;
        }

        case LibraryDetectionFilter::Platform:
        {
            wxStringTokenizer Tokenizer(Filter.Value,_T("| \t"));
            bool IsPlatform = false;
            while ( Tokenizer.HasMoreTokens() )
            {
                wxString Platform = Tokenizer.GetNextToken();

                if ( platform::windows )
                {
                    if ( Platform==_T("win") || Platform==_T("windows") )
                    {
                        IsPlatform = true;
                        break;
                    }
                }

                if ( platform::macosx )
                {
                    if ( Platform==_T("mac") || Platform==_T("macosx") )
                    {
                        IsPlatform = true;
                        break;
                    }
                }

                if ( platform::linux )
                {
                    if ( Platform==_T("lin") || Platform==_T("linux") )
                    {
                        IsPlatform = true;
                        break;
                    }
                }

                if ( platform::freebsd )
                {
                    if ( Platform==_T("bsd") || Platform==_T("freebsd") )
                    {
                        IsPlatform = true;
                        break;
                    }
                }

                if ( platform::netbsd )
                {
                    if ( Platform==_T("bsd") || Platform==_T("netbsd") )
                    {
                        IsPlatform = true;
                        break;
                    }
                }

                if ( platform::openbsd )
                {
                    if ( Platform==_T("bsd") || Platform==_T("openbsd") )
                    {
                        IsPlatform = true;
                        break;
                    }
                }

                if ( platform::darwin )
                {
                    if ( Platform==_T("darwin") )
                    {
                        IsPlatform = true;
                        break;
                    }
                }

                if ( platform::solaris )
                {
                    if ( Platform==_T("solaris") )
                    {
                        IsPlatform = true;
                        break;
                    }
                }

                if ( platform::unix )
                {
                    if ( Platform==_T("unix") || Platform==_T("un*x") )
                    {
                        IsPlatform = true;
                        break;
                    }
                }
            }

            if ( IsPlatform )
            {
                CheckFilter(OldBasePath,OldVars,OldCompilers,Config,Set,WhichFilter+1);
            }
            break;
        }

        case LibraryDetectionFilter::Exec:
        {
            bool IsExec = false;
            if ( wxIsAbsolutePath(Filter.Value) )
            {
                // If this is absolute path, we don't search in PATH evironment var
                IsExec = wxFileName::IsFileExecutable(Filter.Value);
            }
            else
            {
                // Let's search for the name in search paths
                wxString Path;
                if ( wxGetEnv(_T("PATH"),&Path) )
                {
                    wxString Splitter = _T(":");
                    if ( platform::windows ) Splitter = _T(";");
                    wxStringTokenizer Tokenizer(Path,Splitter);
                    while ( Tokenizer.HasMoreTokens() )
                    {
                        wxString OnePath = Tokenizer.GetNextToken();

                        // Let's skip relative paths (f.ex. ".")
                        if ( !wxIsAbsolutePath(OnePath) ) continue;

                        OnePath += wxFileName::GetPathSeparator()+Filter.Value;
                        if ( wxFileName::IsFileExecutable(OnePath) )
                        {
                            IsExec = true;
                            break;
                        }
                    }
                }
            }

            if ( IsExec )
            {
                CheckFilter(OldBasePath,OldVars,OldCompilers,Config,Set,WhichFilter+1);
            }
            break;
        }

        case LibraryDetectionFilter::PkgConfig:
        {
            if ( m_KnownResults[rtPkgConfig].IsShortCode(Filter.Value) )
            {
                CheckFilter(OldBasePath,OldVars,OldCompilers,Config,Set,WhichFilter+1);
            }
            break;
        }

        case LibraryDetectionFilter::Compiler:
        {
            if ( OldCompilers.IsEmpty() )
            {
                // If this is the first compiler filter, let's build new list and continue
                CheckFilter(OldBasePath,OldVars,wxStringTokenize(Filter.Value,_T("| \t")),Config,Set,WhichFilter+1);
            }
            else
            {
                // We've set compiler list before, leave only the intersection
                // of previous and current list
                wxArrayString Compilers;
                wxStringTokenizer Tokenizer(Filter.Value,_T("| \t"));
                while ( Tokenizer.HasMoreTokens() )
                {
                    wxString Comp = Tokenizer.GetNextToken();
                    if ( OldCompilers.Index(Comp) != wxNOT_FOUND )
                    {
                        Compilers.Add(Comp);
                    }
                }

                if ( !Compilers.IsEmpty() )
                {
                    CheckFilter(OldBasePath,OldVars,Compilers,Config,Set,WhichFilter+1);
                }
            }
            break;
        }

        case LibraryDetectionFilter::None:
        {
            CheckFilter(OldBasePath,OldVars,OldCompilers,Config,Set,WhichFilter+1);
            break;
        }
    }
}
コード例 #30
0
ファイル: Mapping.cpp プロジェクト: jaabell/gmESSI
void Mapping::mapFile() {

    fstream mapFile(this->FileName, fstream::in);
    string line;

    while(getline(mapFile,line)) {

        Tokenizer str = Tokenizer(line,"#  \t\v\n\r\f");
        if(!delSpaces(str.nextToken()).compare("ELEMENT_ID"))
            break;
    }

    while(getline(mapFile,line)) {

        string strLine = delSpaces(line);
        Tokenizer str = Tokenizer(line,"#  \t\v\n\r\f\"");

        if(!str.nextToken().compare("ENDELEMENT_ID"))
            break;
        if(!str.currToken().substr(0,2).compare("//"))
            continue;
        if(delSpaces(str.currToken()).length()==0)
            continue;

        string elementDes="";
        string elementId = "";

        elementId = elementId + str.currToken();
        elementDes= elementDes + str.nextToken();
        str.setDelimiter("\"");
        elementDes= elementDes + str.nextToken();

        this->ElementMap.insert(pair<string,string>(elementId,elementDes));
    }

    while(getline(mapFile,line)) {

        Tokenizer str = Tokenizer(line,"#  \t\v\n\r\f");
        if(!delSpaces(str.nextToken()).compare("ESSI_TAGS"))
            break;
    }

    while(getline(mapFile,line)) {

        Tokenizer str = Tokenizer(line,"#  \t\v\n\r\f");
        if(!delSpaces(str.nextToken()).compare("ENDESSI_TAGS"))
            break;
        if(!delSpaces(str.currToken()).substr(0,2).compare("//"))
            continue;
        if(delSpaces(str.currToken()).length()==0)
            continue;

        this->EssiTagList.insert(str.currToken());
    }

    while(getline(mapFile,line)) {

        string Id, GmshCommandList, EssiCommand="";
        Tokenizer str = Tokenizer(line,"!  \t\v\n\r\f");

        if(!delSpaces(str.nextToken()).substr(0,2).compare("//"))
            continue;
        if(delSpaces(str.currToken()).length()==0)
            continue;

        Id = str.currToken();
        str.setDelimiter("<>");

        if(delSpaces(str.nextToken()).length()==0)
            GmshCommandList = delSpaces(str.nextToken());
        else
            GmshCommandList = delSpaces(str.currToken());

        str.setDelimiter("  \t\v\n\r\f");

        EssiCommand= EssiCommand + delSpaces(str.nextToken())+" ";
        str.setDelimiter("<>");
        EssiCommand= EssiCommand + str.nextToken();

        this->makeFunction(Id, GmshCommandList,EssiCommand);
    }

    mapFile.close();
}