예제 #1
0
file_detection_context_t::file_detection_context_t(history_t *hist, const wcstring &cmd) :
    history(hist),
    command(cmd),
    when(time(NULL)),
    working_directory(get_working_directory())
{
}
예제 #2
0
std::string source_locationt::as_string(bool print_cwd) const
{
  std::string dest;

  const irep_idt &file=get_file();
  const irep_idt &line=get_line();
  const irep_idt &column=get_column();
  const irep_idt &function=get_function();

  if(!file.empty())
  {
    if(dest!="") dest+=' ';
    dest+="file ";
    if(print_cwd)
      dest+=concat_dir_file(id2string(get_working_directory()),
                            id2string(file));
    else
      dest+=id2string(file);
  }
  if(!line.empty())     { if(dest!="") dest+=' '; dest+="line "+id2string(line); }
  if(!column.empty())   { if(dest!="") dest+=' '; dest+="column "+id2string(column); }
  if(!function.empty()) { if(dest!="") dest+=' '; dest+="function "+id2string(function); }

  return dest;
}
예제 #3
0
std::string get_path_from_user( const std::vector<std::string>& executables ) {
	auto strTitle = std::string{ "Where is " };

	if( executables.empty() ) {
		std::cout << "No filter specified.\n";
		return "";
	}
	else if( executables.size() == 1 ) {
		strTitle += executables.front();
	}
	else {
		auto end = std::end( executables );
		for( auto iter = std::begin( executables ); ; ) {
			strTitle += *iter;

			++iter;

			if( iter != end ) {
				strTitle += " or ";
			}
			else {
				break;
			}
		}
	}

	strTitle += "?";

	auto strFilter = std::string{ "" };

	for( const auto& e : executables ) {
		strFilter += e + '\0' + e + '\0';
	}

	auto filename = create_zeroed<TCHAR, 65536>();
	auto open_filename = create_zeroed<OPENFILENAME>();

	open_filename.lStructSize = sizeof( OPENFILENAME );
	open_filename.lpstrFilter = strFilter.c_str();
	open_filename.lpstrFile = filename.data();
	open_filename.nMaxFile = filename.size();
	open_filename.lpstrTitle = strTitle.c_str();
	open_filename.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST;

	auto working_directory = get_working_directory();

	auto result = GetOpenFileName( &open_filename );

	set_working_directory( working_directory );

	if( !result ) {
		return "";
	}

	return std::string( filename.data() );
}
예제 #4
0
    int RunEnvironment::
    setFileNames(std::string& fullpath, std::string& meshFileName, std::string& errString)
    {
      int err=0;
      fullpath = get_working_directory() + meshFileName;
      if (meshFileName[0] == '/')
        {
          // already absolute
          fullpath = meshFileName;
        }
      else if (meshFileName.length() >= 3 && (meshFileName[0] != '.' && meshFileName[1] != '/'))
        {
          // make it a relative path
          fullpath = get_working_directory() + meshFileName;
          meshFileName = "./"+meshFileName;
          //fullpath = get_working_directory() + meshFileName.substr(2,meshFileName.length()-2);
        }
      else if (meshFileName.length() >= 3 && (meshFileName[0] == '.' && meshFileName[1] == '/'))
        {
          fullpath = get_working_directory() + meshFileName.substr(2,meshFileName.length()-2);
        }
      else
        {
          err = 1;
          errString = "RunEnvironment::setFileNames: bad format for input file name, name= "+meshFileName;
          return err;
        }

      size_t found = 0;
      // strip off the basename + extension
      found = fullpath.find_last_of("/");
      if (found != std::string::npos)
        {
          fullpath = fullpath.substr(0,found);
        }
      if(fullpath == ".") 
        fullpath = "./";
      else
        fullpath += "/";

      return err;
    }
예제 #5
0
파일: cwd.cpp 프로젝트: Giessen/qibuild
int main(int argc, char* argv[])
{
  if (argc < 2) {
    std::cerr << "Usage: cwd EXPECTED" << std::endl;
    return 2;
  }

  std::string actual = get_working_directory();
  std::string expected = argv[1];
  if (actual != expected) {
    std::cerr << "Expecting:" << std::endl
              << expected << std::endl
              << "Got:"
              << actual;
    return 1;
  }
  return 0;

}
예제 #6
0
  void Forwarder::write_to_directory(const std::string &directory) const {
    std::string wd = get_working_directory();
    std::string absolute_dir_name;
    if(!directory[0] != '/')
      absolute_dir_name = wd + "/" + directory;
    else
      absolute_dir_name = directory;
    std::string data_structure_filename = absolute_dir_name + "/data_structure";
    std::string nStates2seq_absolute_dir_name = absolute_dir_name + "/nStates2seq";
    
    // create directory
    mk_dir(absolute_dir_name);
    mk_dir(nStates2seq_absolute_dir_name);

    // write basic data structure
    write_data_structure(data_structure_filename);

    // write nStates2seq
    write_seqs(nStates2seq_absolute_dir_name);
  }
예제 #7
0
// PCA This function does I/O, (calls is_potential_path, path_get_path, maybe others) and so ought to only run on a background thread
void highlight_shell( const wcstring &buff, std::vector<int> &color, int pos, wcstring_list_t *error, const env_vars_snapshot_t &vars )
{
    ASSERT_IS_BACKGROUND_THREAD();
    
    const size_t length = buff.size();
    assert(buff.size() == color.size());


	if( length == 0 )
		return;
	
    std::fill(color.begin(), color.end(), -1);

    /* Do something sucky and get the current working directory on this background thread. This should really be passed in. Note that we also need this as a vector (of one directory). */
    const wcstring working_directory = get_working_directory();

    /* Tokenize the string */
    tokenize(buff.c_str(), color, pos, error, working_directory, vars);

	/*
	  Locate and syntax highlight cmdsubsts recursively
	*/

	wchar_t * const subbuff = wcsdup(buff.c_str());
    wchar_t * subpos = subbuff;
	int done=0;
	
	while( 1 )
	{
		wchar_t *begin, *end;
    
		if( parse_util_locate_cmdsubst(subpos, &begin, &end, 1) <= 0)
		{
			break;
		}
		
		if( !*end )
			done=1;
		else
			*end=0;
		
        //our subcolors start at color + (begin-subbuff)+1
        size_t start = begin - subbuff + 1, len = wcslen(begin + 1);
        std::vector<int> subcolors(len, -1);
        
		highlight_shell( begin+1, subcolors, -1, error, vars );
        
        // insert subcolors
        std::copy(subcolors.begin(), subcolors.end(), color.begin() + start);
        
        // highlight the end of the subcommand
        assert(end >= subbuff);
        if ((size_t)(end - subbuff) < length) {
            color.at(end-subbuff)=HIGHLIGHT_OPERATOR;
        }
		
		if( done )
			break;
		
		subpos = end+1;
	}
    free(subbuff);

	/*
	  The highlighting code only changes the first element when the
	  color changes. This fills in the rest.
	*/
	int last_val=0;
	for( size_t i=0; i < buff.size(); i++ )
	{
		if( color.at(i) >= 0 )
			last_val = color.at(i);
		else
			color.at(i) = last_val;
	}
    
	/*
	  Color potentially valid paths in a special path color if they
	  are the current token.
      For reasons that I don't yet understand, it's required that pos be allowed to be length (e.g. when backspacing).
	*/
	if( pos >= 0 && (size_t)pos <= length )
	{
		
        const wchar_t *cbuff = buff.c_str();
		const wchar_t *tok_begin, *tok_end;
		parse_util_token_extent( cbuff, pos, &tok_begin, &tok_end, 0, 0 );
		if( tok_begin && tok_end )
		{
			wcstring token(tok_begin, tok_end-tok_begin);
			const wcstring_list_t working_directory_list(1, working_directory);
			if (unescape_string(token, 1) && is_potential_path(token, working_directory_list, PATH_EXPAND_TILDE))
			{
				for( ptrdiff_t i=tok_begin-cbuff; i < (tok_end-cbuff); i++ )
				{
                    // Don't color HIGHLIGHT_ERROR because it looks dorky. For example, trying to cd into a non-directory would show an underline and also red.
                    if (! (color.at(i) & HIGHLIGHT_ERROR)) {
                        color.at(i) |= HIGHLIGHT_VALID_PATH;
                    }
				}
			}
		}
	}
	

	highlight_universal_internal( buff, color, pos );

	/*
	  Spaces should not be highlighted at all, since it makes cursor look funky in some terminals
	*/
	for( size_t i=0; i < buff.size(); i++ )
	{
		if( iswspace(buff.at(i)) )
		{
			color.at(i)=0;
		}
	}
}
예제 #8
0
    void RunEnvironment::
    doLoadBalance(stk_classic::ParallelMachine comm, std::string meshFileName)
    {

      if (meshFileName.length() == 0) return;

      unsigned p_size = stk_classic::parallel_machine_size(comm);
      unsigned p_rank = stk_classic::parallel_machine_rank(comm);
      int err=0;
      std::string errString;

      if (p_size > 1 && !p_rank)
        {
          std::string fullpath = meshFileName;

          std::cout << "tmp get_working_directory= " << get_working_directory() << std::endl;
          std::cout << "tmp fullpath before= " << fullpath << std::endl;

          err = setFileNames(fullpath, meshFileName, errString);

          if (!err)
            {
              std::cout << "tmp fullpath= " << fullpath << std::endl;
              std::cout << "tmp meshFileName= " << meshFileName << std::endl;

              //std::string fullpath = meshFileName;

              //
              //  file.exo
              //  file.e
              unsigned extension_length = 1;

              size_t found = meshFileName.find_last_of(".");
              if (found == std::string::npos) {
                //throw std::runtime_error("RunEnvironment::doLoadBalance input file name must have an extension");
                err = 2;
                errString = "RunEnvironment::doLoadBalance input file name must have an extension";
              }
              extension_length = meshFileName.length() - found - 1;
              std::string base_name = meshFileName.substr(0, meshFileName.length()-(extension_length+1));

              std::string extension = meshFileName.substr(meshFileName.length()-extension_length, meshFileName.length());

              std::cout << "tmp: extension= " << extension << " meshFileName= " << meshFileName << " fullpath= " << fullpath << " base_name= " << base_name << std::endl;

              std::string command="loadbal -No_subdirectory -spread -suffix_mesh " + extension+" -suffix_spread "+extension+" -p "+toString(p_size)+ " ";
              command += "-R " +fullpath+" " + base_name;
              //command += "-R ./ "  + base_name;

              command="decomp -p "+toString(p_size)+ " -R " +fullpath+" " + meshFileName;

              std::cout << "RunEnvironment::doLoadBalance: command= " << command << std::endl;

              runCommand(command);
            }
        }

      stk_classic::all_reduce( comm, stk_classic::ReduceSum<1>( &err ) );

      if (err && !p_rank)
        {
          std::cout << "ERROR in RunEnvironment::doLoadBalance: " << errString << std::endl;
        }
      if (err)
        throw std::runtime_error("ERROR in RunEnvironment::doLoadBalance: " + errString );

#if defined(STK_HAS_MPI)
      MPI_Barrier( comm );
#endif
    }