Exemple #1
0
//----------------------------------------------------------------------------------
// Find out if a command lives in m_sGNUPlotPath or in PATH
bool Gnuplot::get_program_path()
{
    // first look in m_sGNUPlotPath for Gnuplot
    std::string tmp = Gnuplot::m_sGNUPlotPath + "/" + Gnuplot::m_sGNUPlotNomeArquivo;

#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__TOS_WIN__)
    if ( Gnuplot::file_exists(tmp,0) ) // check existence
#elif defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
    if ( Gnuplot::file_exists(tmp,1) ) // check existence and execution permission
#endif
    {
        return true;
    }

    // second look in PATH for Gnuplot
    char *path;
    // Retrieves a C string containing the value of the environment variable PATH
    path = getenv("PATH");

		if (path == nullptr)
    {
        throw GnuplotException("Path is not set");
        return false;
    }
    else
    {
        std::list<std::string> ls;
        //split path (one long string) into list ls of strings
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__TOS_WIN__)
        stringtok(ls,path,";");
#elif defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
        stringtok(ls,path,":");
#endif
        // scan list for Gnuplot program files
        for (std::list<std::string>::const_iterator i = ls.begin(); i != ls.end(); ++i)
        {
            tmp = (*i) + "/" + Gnuplot::m_sGNUPlotNomeArquivo;
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__TOS_WIN__)
            if ( Gnuplot::file_exists(tmp,0) ) // check existence
#elif defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
            if ( Gnuplot::file_exists(tmp,1) ) // check existence and execution permission
#endif
            {
                Gnuplot::m_sGNUPlotPath = *i; // set m_sGNUPlotPath
                return true;
            }
        }

        tmp = "Can't find gnuplot neither in PATH nor in \"" + Gnuplot::m_sGNUPlotPath + "\"";
        throw GnuplotException(tmp);

        Gnuplot::m_sGNUPlotPath = "";
        return false;
    }
}
int main(int argc, char** argv)
{
	if(argc < 2)
	{
		std::cout << "Usage: " << argv[0] << " listen_port [boostrap_host:port]" << std::endl;
		return EXIT_FAILURE;
	}

	srand((unsigned)time(NULL));

	Key me(StrToTyp<uint32_t>(argv[1]));

	Arbore* arbore = new Arbore(StrToTyp<uint16_t>(argv[1]));

	pf_log.SetLoggedFlags("DESYNCH WARNING ERR INFO DHT FILE", false);
	Scheduler::StartSchedulers(5);

	if(argc > 2)
	{
		Host host = hosts_list.DecodeHost(argv[2]);
		pf_log[W_INFO] << "Connecting to " << host;
		arbore->GetDHT()->GetChimera()->Join(host);
	}

	std::string s;
	while(std::getline(std::cin, s))
	{
		std::string command_str = stringtok(s, " ");
		Key k;

		if(command_str.length() == 0)
			continue;

		switch(command_str[0])
		{
			case 's':
			case 'S':
			{
				pf_log[W_FILE] << "Try to create a chunk";
				char chaine[10]={ 'B', 'o', 'n', 'j', 'o', 'u', 'r', '\0' };
				char *data = (char*) &chaine;
				FileChunk* fc = new FileChunk(data, 0, sizeof(chaine));
				k = s;
				pf_log[W_FILE] << "Try to send the chunk" << " with key " << k;
				arbore->Send(k, *fc);
				break;
			}
			case 'q':
			case 'Q':
				return EXIT_SUCCESS;
			default:
				pf_log[W_ERR] << "Command not recognized.";
		}
	}


	return EXIT_SUCCESS;
}
Exemple #3
0
bool DesktopFile::not_show_in(list<String>& lst) {
	E_RETURN_VAL_IF_FAIL(errcode == DESK_FILE_SUCCESS, false);

	char buff[256];
	if(!Config::get(ENTRY_SECT, "NotShowIn", buff, sizeof(buff)-1))
		return false;

	stringtok(lst, buff, ";");
	return true;
}
Exemple #4
0
static int _dirs_get(const char* env, const char* fallback, StringList& lst) {
	E_ASSERT(fallback != NULL);

	char* path = getenv(env);
	if(!path)
		path = (char*)fallback;

	stringtok(lst, path, ":");
	return lst.size();
}
void TokenizerParser::getStringArray(string Str_Arr[], const string &exp, size_t MAX, size_t &count)
{
    list<string> TokenList;
    stringtok(TokenList, exp);
    list<string>::const_iterator it = TokenList.begin();
    size_t index = 0;
    count = 0;
    for (; it != TokenList.end() && index < MAX; ++it)
    {
        Str_Arr[index++] = *it;
        count++;
    }
}
Exemple #6
0
static std::wstring SanitizeSearchPaths(const std::wstring& searchpath)
{
    std::vector<std::wstring> container;
    stringtok(container, searchpath, true);
    std::wstring sResult;
    for (const auto& path : container)
    {
        if (!sResult.empty())
            sResult += L"|";
        sResult += CPathUtils::GetLongPathname(path);
    }
    return sResult;
}
Exemple #7
0
Message Message::parse(string line)
{
	string s;
	Message m;
	while((s = stringtok(line, " ")).empty() == false)
	{
		if(m.getCommand().empty())
			m.setCommand(strupper(s));
		else if(s[0] == ':')
		{
			m.addArg(s.substr(1) + (line.empty() ? "" : " " + line));
			break;
		}
		else
			m.addArg(s);
	}
	return m;
}
/** Get any additional attributes that may be appended to the node's name 
 *
 *  A 3D model file usually contains several independent objects.
 *  Each object appears as a distinct node in the scenegraph. Most
 *  modelling tools allow to assign an arbitrary name to an object.
 *  CRRCsim decomposes this string into two parts: everything up
 *  to the first blank character is interpreted as the real name
 *  of a node, while the rest of the string is parsed for some
 *  known attributes that may describe the node's appearance or
 *  behaviour.
 *
 *  This method extracts all known attributes from the object's name
 *  string.
 *
 *  \param  node  pointer to a node in the scenegraph
 *  \return struct with attribute values
 */
SSGUtil::NodeAttributes SSGUtil::getNodeAttributes(ssgEntity* node)
{
  std::string NodeName;
  SSGUtil::NodeAttributes attribs;

  if (node->getName() != NULL)
  {
     NodeName = node->getName();
  }
  
  std::string::size_type posn = NodeName.find(' ');

  if (posn != std::string::npos)
  {
    // node name contains attributes, only evaluate text after the blank
    NodeName = NodeName.substr(posn);

    // break remaining text into tokens
    stringtok(attribs.rawAttributes, NodeName, " ");
  }

  return attribs;
}
FileEntry* CacheBase::Path2File(std::string path, unsigned int flags, std::string* filename)
{
	BlockLockMutex lock(this);
	DirEntry* current_dir = tree;

	std::string name;

	while((name = stringtok(path, "/")).empty() == false)
	{
		FileEntry* child_file = current_dir->GetFile(name);
		if(!child_file || child_file->IsRemoved())
		{
			if(path.empty())
			{
				/* we are in last dir, but this file doesn't exist */
				if(child_file && (flags & (RESTORE_REMOVED_FILE|GET_REMOVED_FILE)))
				{
					if(flags & RESTORE_REMOVED_FILE)
						child_file->ClearRemoved();
					return child_file;
				}
				else if(filename)
				{
					*filename = name;
					return current_dir;
				}
				else
					return NULL;
			}

			/* we aren't in last dir, so the path isn't found. */
			if(flags & CREATE_UNKNOWN_DIRS)
			{
				if(child_file && !dynamic_cast<DirEntry*>(child_file))
				{
					current_dir->RemFile(child_file);
					child_file = NULL;
				}

				if(!child_file)
				{
					pf_stat stat;
					stat.uid = 0;
					stat.gid = 0;
					child_file = new DirEntry(name, stat, current_dir);
					current_dir->AddFile(child_file);
				}
				if(flags & RESTORE_REMOVED_FILE)
					child_file->ClearRemoved();
			}
			else if(!(flags & GET_REMOVED_FILE) || !child_file)
				return NULL;
		}

		if(!(current_dir = dynamic_cast<DirEntry*>(child_file)))
		{
			/* This isn't a directory. */
			if(path.empty())
			{
				/* We are on last dir, so it is the requested file. */
				return child_file;
			}
			/* it isn't a file in path, so the path isn't found. */

			return NULL;
		}
	}

	return current_dir;
}
Exemple #10
0
int main(int argc, char** argv)
{
	if(argc < 2)
	{
		std::cout << "Usage: " << argv[0] << " listen_port [boostrap_host:port]" << std::endl;
		return EXIT_FAILURE;
	}

	srand(time(NULL));

	DHT* dht = new DHT(NULL, StrToTyp<uint16_t>(argv[1]));

	pf_log.SetLoggedFlags("DESYNCH WARNING ERR INFO DHT", false);
	Scheduler::StartSchedulers(5);

	if(argc > 2)
	{
		Host host = hosts_list.DecodeHost(argv[2]);
		pf_log[W_INFO] << "Connecting to " << host;
		dht->GetChimera()->Join(host);
	}

	std::string s;
	while(std::getline(std::cin, s))
	{
		std::string command_str = stringtok(s, " ");
		Key k;

		if(command_str.length() == 0)
			continue;

		switch(command_str[0])
		{
			case 's':
			case 'S':
				pf_log[W_DHT] << dht->GetStorage()->GetStr();
				break;
			case 'l':
			case 'L':
				pf_log[W_DHT] << dht->GetChimera()->GetRouting()->GetLeafset()->GetStr();
				break;
			case 'r':
			case 'R':
				pf_log[W_DHT] << dht->GetChimera()->GetRouting()->GetRoutingTable()->GetStr();
				break;
			case 'p':
			case 'P':
				k.MakeHash(s);
				pf_log[W_DHT] << "Publish " << s << " with key " << k;
				dht->Publish(k, s);
				break;
			case 'u':
			case 'U':
				k = stringtok(s, " ");
				pf_log[W_DHT] << "Unublish " << s << " with key " << k;
				dht->Unpublish(k, s);
				break;
			case 'g':
			case 'G':
				k = s;
				pf_log[W_DHT] << "Request data with key " << k;
				if(!dht->RequestData(k))
					if(dht->GetStorage()->hasKey(k))
						pf_log[W_DHT] << dht->GetStorage()->getInfo(k)->GetStr();
				break;
			case 'q':
			case 'Q':
				return EXIT_SUCCESS;
			default:
				pf_log[W_ERR] << "Command not recognized.";
		}
	}

	return EXIT_SUCCESS;
}