예제 #1
0
파일: System.cpp 프로젝트: starand/cpp
sizeint GetIpAddrList(string_v& vsOutIpAddrList)
{
	START_FUNCTION();
	string_v vsIpAddrList;

	string sHostName;
	if (!GetHostName(sHostName)) {
		break;
	}

	struct hostent *pheHostEntry = gethostbyname(sHostName.c_str());
	if (!pheHostEntry) {
		break;
	}

	struct in_addr addr;
	for (int idx = 0; pheHostEntry->h_addr_list[idx] != 0; ++idx) 
	{
		memcpy(&addr, pheHostEntry->h_addr_list[idx], sizeof(struct in_addr));
		vsIpAddrList.push_back(inet_ntoa(addr));
	}

	vsOutIpAddrList.swap(vsIpAddrList);
	END_FUNCTION_RET(vsOutIpAddrList.size());
}
예제 #2
0
bool try_to_recognize_tokens(const string &str, string_v &tokens)
{
  int len = str.length();

  if (len == 0)
    return true;

  for (int l = len ; l > 0 ; l--)
  {
    string s = str.substr(0, l);
    
    if (token_type(s) != invalid)
    {
      tokens.push_back(s);

      if (try_to_recognize_tokens(str.substr(l, len-l), tokens))
        return true;

      tokens.pop_back();
      return false;
    }
  }

  return false;
}
예제 #3
0
type TypeRef::clone_and_bind_params(string_v &formal, type_v &actual)
{
  assert(real_type.is_null());

  for (unsigned int i=0 ; i < formal.size() ; i++)
    if (formal[i] == type_name)
      return actual[i];

  return type(new TypeRef(type_name));
}
예제 #4
0
파일: stdutils.cpp 프로젝트: starand/cpp
void CreateCommandLineParamsVactor(int argc, char *argv[], string_v &vsOutParams)
{
	ASSERTE(argv && argc);
	string_v vsParams;

	for (int idx = 0; idx < argc; ++idx)
	{
		vsParams.push_back(argv[idx]);
	}

	vsOutParams.swap(vsParams);
}
예제 #5
0
파일: stdutils.cpp 프로젝트: starand/cpp
void CreateCommandLineParamsVactor(char *szCommandLine, string_v &vsOutParams)
{
	ASSERTE(szCommandLine);
	string_v vsParams;

	bool bInQuotes = false;

	sizeint siCommandLineLen = strlen(szCommandLine);
	char *pszStartPos = const_cast<char *>(szCommandLine);

	for (sizeint siIndex = 0; siIndex < siCommandLineLen; ++siIndex)
	{
		if (szCommandLine[siIndex] == QUOTE)
		{
			bInQuotes = !bInQuotes;
		}

		if (!bInQuotes && (szCommandLine[siIndex] == SPACE || szCommandLine[siIndex] == TAB))
		{
			if (pszStartPos == szCommandLine + siIndex)
			{
				++pszStartPos;
			}
			else
			{
				szCommandLine[siIndex] = 0;

				vsParams.push_back(pszStartPos);
				pszStartPos = szCommandLine + siIndex + 1;
			}
		}
	}

	if (strlen(pszStartPos))
	{
		vsParams.push_back(pszStartPos);
	}

	vsOutParams.swap(vsParams);
}