示例#1
0
char *
eclipsehome(void)
{
    if (!eclipsehome_)
    {
	eclipsehome_ = whereami();
	if (!eclipsehome_)
	{
	    char buf1[MAX_PATH_LEN];
	    int size=MAX_PATH_LEN;
	    if (ec_env_lookup("ECLIPSEDIR", buf1, &size))
	    {
		(void) canonical_filename(buf1, buf);
		if (buf[0] != '/')
		{
		    char buf2[MAX_PATH_LEN];
		    strcpy(buf2, buf);
		    get_cwd(buf, MAX_PATH_LEN);
		    strcat(buf, buf2);
		}
		eclipsehome_ = buf;
	    }
	    else
	    {
#ifdef _WIN32
		eclipsehome_ = "//C/Eclipse";
#else
		eclipsehome_ = "/usr/local/eclipse";
#endif
	    }
	}
    }
    return eclipsehome_;
}
示例#2
0
//Process commands pointed by input pointer (STDIN or CMD ARGS) -> Parse, Execute
void processCommand(FILE *input_ptr)
{
char input_line[MAX_LINE];
struct commands_struct *command_line = NULL;
get_cwd();
	while(fgets(input_line, MAX_LINE, input_ptr) != NULL) {
	command_line = init_command();
	if (parse(input_line, command_line) == 0) 
	{
	        execute(command_line);
	}
	get_cwd();
	free(command_line);
	fflush(input_ptr);
	}
}
示例#3
0
文件: main.cpp 项目: AI0867/wesnoth
	wesnoth_global_fixture()
	{
		reporter.open("boost_test_result.xml");
		assert( reporter.is_open() );

		boost::unit_test::results_reporter::set_stream(reporter);
//		lg::set_log_domain_severity("all",3);
		game_config::path = get_cwd();


		// Initialize unit tests
		SDL_Init(SDL_INIT_TIMER);
		test_utils::get_fake_display(1024, 768);

		gui2::init();
		static const gui2::event::tmanager gui_event_manager;



		// Set more report as default
		if (boost::unit_test::runtime_config::log_level() == boost::unit_test::invalid_log_level)
			boost::unit_test::unit_test_log.set_threshold_level( boost::unit_test::log_messages );
		if (boost::unit_test::runtime_config::report_level() == boost::unit_test::INV_REPORT_LEVEL)
			boost::unit_test::results_reporter::set_level(boost::unit_test::SHORT_REPORT);
		boost::unit_test::unit_test_monitor.register_exception_translator<game::error>(&exception_translator_game);
		boost::unit_test::unit_test_monitor.register_exception_translator<network::error>(&exception_translator_network);
		boost::unit_test::unit_test_monitor.register_exception_translator<config::error>(&exception_translator_config);
	}
示例#4
0
bool 
Path::set_directory (symbol directory_s)
{ 
  const std::string& directory = directory_s.name ();
  const char *const dir = directory.c_str ();
  const bool result 
    = chdir (dir) == 0 || (mkdir (dir, 0777) == 0 && chdir (dir) == 0); 
  
  if (!result)
    /* Do nothing */;
  else if (directory[0] == '/'
#ifndef __unix__
           || directory[0] == '\\' || directory[1] == ':'
#endif
           )
    // Already absolute.
    current_directory = directory;
  else
    // Make it absolute.
    current_directory = get_cwd ();

  std::ostringstream tmp;
  tmp << "Changing directory to '" << directory << "' " 
      << (result ? "success" : "failure");
  Assertion::debug (tmp.str ());

  return result;
}
示例#5
0
int do_ls0(char *argv[])
{
    init_ls();
    int retval = hw3_ops.readdir(get_cwd(), NULL, filler, 0, NULL);
    print_ls();
    return retval;
}
示例#6
0
int
to_canonic_path(const char path[], char buf[], size_t buf_len)
{
	if(!is_path_absolute(path))
	{
		char cwd[PATH_MAX];
		char full_path[PATH_MAX];

		if(get_cwd(cwd, sizeof(cwd)) == NULL)
		{
			/* getcwd() failed, we can't use relative path, so fail. */
			LOG_SERROR_MSG(errno, "Can't get CWD");
			return 1;
		}

		snprintf(full_path, sizeof(full_path), "%s/%s", cwd, path);
		canonicalize_path(full_path, buf, buf_len);
	}
	else
	{
		canonicalize_path(path, buf, buf_len);
	}

	chosp(buf);
	return 0;
}
示例#7
0
文件: commands.c 项目: acklinr/vifm
SETUP_ONCE()
{
	assert_non_null(get_cwd(cwd, sizeof(cwd)));

	make_abs_path(sandbox, sizeof(sandbox), SANDBOX_PATH, "", cwd);
	make_abs_path(test_data, sizeof(test_data), TEST_DATA_PATH, "", cwd);
}
std::string show_wesnothd_server_search(display& disp)
{
	// Showing file_chooser so user can search the wesnothd
	std::string old_path = preferences::get_mp_server_program_name();
	size_t offset = old_path.rfind("/");
	if (offset != std::string::npos)
	{
		old_path = old_path.substr(0, offset);
	}
	else
	{
		old_path = "";
	}
#ifndef _WIN32

#ifndef WESNOTH_PREFIX
#define WESNOTH_PREFIX "/usr"
#endif
	const std::string filename = "wesnothd";
	std::string path = WESNOTH_PREFIX + std::string("/bin");
	if (!is_directory(path))
		path = get_cwd();

#else
	const std::string filename = "wesnothd.exe";
	std::string path = get_cwd();
#endif
	if (!old_path.empty()
			&& is_directory(old_path))
	{
		path = old_path;
	}

	utils::string_map symbols;

	symbols["filename"] = filename;

	const std::string title = utils::interpolate_variables_into_string(
			  _("Find $filename server binary to host networked games")
			, &symbols);

	int res = dialogs::show_file_chooser_dialog(disp, path, title, false, filename);
	if (res == 0)
		return path;
	else
		return "";
}
示例#9
0
int pwd(int argc, char **argv)
{
    char *cwd = get_cwd();
    kprintf("%s\n", cwd);
    free(cwd);

    return EOK;
}
示例#10
0
int do_ls1(char *argv[])
{
    char path[128];
    sprintf(path, "%s/%s", get_cwd(), argv[0]);
    init_ls();
    int retval = hw3_ops.readdir(fix_path(path), NULL, filler, 0, NULL);
    print_ls();
    return retval;
}
示例#11
0
//Signal handler for the interrupt - Ctrl + C
void signal_handler(int signo)
{
	if (pid != 0) {
	printf("\n  [%u] interrupted\n", pid );
	//If ^C then stop any foreground process
	}
	fflush(stdout);
	get_cwd();
}
示例#12
0
std::string get_intl_dir()
{
#ifdef _WIN32
	return get_cwd() + "/translations";
#else

#ifdef USE_INTERNAL_DATA
	return get_cwd() + "/" LOCALEDIR;
#endif

#if HAS_RELATIVE_LOCALEDIR
	std::string res = game_config::path + "/" LOCALEDIR;
#else
	std::string res = LOCALEDIR;
#endif

	return res;
#endif
}
示例#13
0
SETUP()
{
	saved_cwd = save_cwd();
	assert_success(chdir(SANDBOX_PATH));

	view_setup(&lwin);
	assert_non_null(get_cwd(lwin.curr_dir, sizeof(lwin.curr_dir)));

	cfg.use_trash = 0;
}
示例#14
0
void
Path::reset ()
{
  // Find path.
  path = get_daisy_path ();
  current_directory = get_cwd ();

  std::ostringstream tmp;
  tmp << "Reseting current directory to '" << current_directory << "'";
  Assertion::debug (tmp.str ());
}
示例#15
0
bool extract_archive(const std::string &filename, const std::string &target)
{
    autoclose::archive in(archive_read_new(), archive_read_free);
    autoclose::archive out(archive_write_disk_new(), archive_write_free);

    if (!in || !out) {
        LOGE("Out of memory");
        return false;
    }

    archive_entry *entry;
    int ret;
    std::string cwd = get_cwd();

    if (cwd.empty()) {
        return false;
    }

    if (!set_up_input(in.get(), filename)) {
        return false;
    }

    set_up_output(out.get());

    if (!mkdir_recursive(target, S_IRWXU | S_IRWXG | S_IRWXO)) {
        LOGE("%s: Failed to create directory: %s",
             target.c_str(), strerror(errno));
        return false;
    }

    if (chdir(target.c_str()) < 0) {
        LOGE("%s: Failed to change to target directory: %s",
             target.c_str(), strerror(errno));
        return false;
    }

    auto chdir_back = finally([&] {
        chdir(cwd.c_str());
    });

    while ((ret = archive_read_next_header(in.get(), &entry)) == ARCHIVE_OK) {
        if (libarchive_copy_header_and_data(in.get(), out.get(), entry) != ARCHIVE_OK) {
            return false;
        }
    }

    if (ret != ARCHIVE_EOF) {
        LOGE("Archive extraction ended without reaching EOF: %s",
             archive_error_string(in.get()));
        return false;
    }

    return true;
}
示例#16
0
static char *
get_root(void)
{
#ifndef _WIN32
	return x_strdup("/");
#else
	char volume[4]; // "C:\"
	GetVolumePathName(get_cwd(), volume, sizeof(volume));
	return x_strdup(volume);
#endif
}
示例#17
0
/* Arguements: None
   Returns (void)
*/
void print_prompt()
{
  char *hostname = get_hostname();
  char *username = get_username();
  char *cwd = get_cwd();

  printf("%s@%s:%s$ ", username, hostname, cwd);

  free(hostname);
  free(username);
  free(cwd);
}
示例#18
0
SETUP()
{
	view_setup(&lwin);

	assert_success(chdir(TEST_DATA_PATH "/read"));
	assert_non_null(get_cwd(lwin.curr_dir, sizeof(lwin.curr_dir)));

	lwin.sort[0] = SK_BY_NAME;
	memset(&lwin.sort[1], SK_NONE, sizeof(lwin.sort) - 1);

	populate_dir_list(&lwin, 0);
}
示例#19
0
文件: cd.c 项目: rdavid42/ft_p
int						cd(char *root, int *cs, char *cmd, int *id)
{
	char				**arg;
	char const			*cur = get_cwd();

	(void)id;
	arg = ssplit(cmd, ' ');
	if (scmp(root, cur, slen(root)) != 0)
		return (afree(arg), sc(cs, -2), error(CWD_DENIED), 0);
	go_dir(cs, root, cur, arg[1]);
	return (afree(arg), 1);
}
示例#20
0
static void update_completion( GtkEntry* entry,
                               GtkEntryCompletion* completion )
{
    char* new_dir, *fn;
    const char* old_dir;
    GtkListStore* list;
    const char *sep;

    sep = strrchr( gtk_entry_get_text(entry), '/' );
    if( sep )
        fn = (char*)sep + 1;
    else
        fn = (char*)gtk_entry_get_text(entry);
    g_object_set_data_full( G_OBJECT(completion), "fn", g_strdup(fn), (GDestroyNotify)g_free );

    new_dir = get_cwd( entry );
    old_dir = (const char*)g_object_get_data( (GObject*)completion, "cwd" );
    if( old_dir && new_dir && 0 == g_ascii_strcasecmp( old_dir, new_dir ) )
    {
        g_free( new_dir );
        return;
    }
    g_object_set_data_full( (GObject*)completion, "cwd",
                             new_dir, g_free );
    list = (GtkListStore*)gtk_entry_completion_get_model( completion );
    gtk_list_store_clear( list );
    if( new_dir )
    {
        GDir* dir;
        if( (dir = g_dir_open( new_dir, 0, NULL )) )
        {
            const char* name;
            while( (name = g_dir_read_name( dir )) )
            {
                char* full_path = g_build_filename( new_dir, name, NULL );
                if( g_file_test( full_path, G_FILE_TEST_IS_DIR ) )
                {
                    GtkTreeIter it;
                    char* disp_name = g_filename_display_basename( full_path );
                    gtk_list_store_append( list, &it );
                    gtk_list_store_set( list, &it, COL_NAME, disp_name, COL_PATH, full_path, -1 );
                    g_free( disp_name );
                }
                g_free( full_path );
            }
            g_dir_close( dir );

            gtk_entry_completion_set_match_func( completion, match_func, new_dir, NULL );
        }
        else
            gtk_entry_completion_set_match_func( completion, NULL, NULL, NULL );
    }
}
示例#21
0
文件: cmd.c 项目: julien-f/shelldon
int
cmd_pwd (Shell *shell, void *args)
{
	char *cwd = get_cwd ();
	if (!cwd)
	{
		fprintf (stderr, "Failed to get current working directory.\n");
		return -1;
	}
	printf ("%s\n", cwd);
	free (cwd);
	return 0;
}
示例#22
0
std::string get_exe_dir()
{
#ifndef _WIN32
	char buf[1024];
	size_t path_size = readlink("/proc/self/exe", buf, sizeof(buf)-1);
	if(path_size == static_cast<size_t>(-1))
		return std::string();
	buf[path_size] = 0;
	return std::string(dirname(buf));
#else
	return get_cwd();
#endif
}
示例#23
0
/* Opens the file with the given NAME.
   Returns the new file if successful or a null pointer
   otherwise.
   Fails if no file named NAME exists,
   or if an internal memory allocation fails. */
struct inode *
filesys_open (const char *name)
{
  struct dir *search_dir = get_cwd(name);

  if (search_dir == NULL) {
    return NULL;
  }

  struct inode *inode = NULL;

  if (name[0] == '/') {
    inode = dir_get_inode(search_dir);
  }

  char *part = malloc(NAME_MAX + 1);
  if (part == NULL) {
    return false;
  }
  memset(part, 0, NAME_MAX + 1);
  int retrieved_next_part;
  for (retrieved_next_part = get_next_part(part, &name); retrieved_next_part > 0;
       retrieved_next_part = get_next_part(part, &name)) {
    if (dir_lookup (search_dir, part, &inode)) {
      if (!inode_is_dir(inode)) {
        break;
      } else {
        dir_close(search_dir);
        search_dir = dir_open(inode);
        if (search_dir == NULL) {
          free(part);
          return false;
        }
      }
    } else {
      inode = NULL;
      break;
    }
  }
  if (inode != NULL && inode_is_dir(inode) && get_next_part(part, &name) == 0) {
    inode = inode_reopen(inode);
  }
  dir_close(search_dir);
  
  if (inode != NULL && get_next_part(part, &name) != 0) {
    inode_close(inode);
    inode = NULL;
  }
  free(part);
  return inode;
}
示例#24
0
static value_t fl_path_cwd(value_t *args, uint32_t nargs)
{
    if (nargs > 1)
        argcount("path.cwd", nargs, 1);
    if (nargs == 0) {
        char buf[1024];
        get_cwd(buf, sizeof(buf));
        return string_from_cstr(buf);
    }
    char *ptr = tostring(args[0], "path.cwd");
    if (set_cwd(ptr))
        lerrorf(IOError, "path.cwd: could not cd to %s", ptr);
    return FL_T;
}
示例#25
0
restorePage::restorePage(int conn) : Pages()
{
   Dmsg1(dbglvl, "Construcing restorePage Instance connection %i\n", conn);
   m_conn = conn;
   QStringList titles;

   setupUi(this);
   m_name = tr("Restore Select");
   pgInitialize();
   QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
   thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/restore.png")));

   m_console->notify(m_conn, false);          /* this should already be off */

   connect(fileWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)),
           this, SLOT(fileDoubleClicked(QTreeWidgetItem *, int)));
   connect(directoryWidget, SIGNAL(
           currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
           this, SLOT(directoryItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
   connect(upButton, SIGNAL(pressed()), this, SLOT(upButtonPushed()));
   connect(markButton, SIGNAL(pressed()), this, SLOT(markButtonPushed()));
   connect(unmarkButton, SIGNAL(pressed()), this, SLOT(unmarkButtonPushed()));
   connect(okButton, SIGNAL(pressed()), this, SLOT(okButtonPushed()));
   connect(cancelButton, SIGNAL(pressed()), this, SLOT(cancelButtonPushed()));

   fileWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
   fileWidget->addAction(actionMark);
   fileWidget->addAction(actionUnMark);
   connect(actionMark, SIGNAL(triggered()), this, SLOT(markButtonPushed()));
   connect(actionUnMark, SIGNAL(triggered()), this, SLOT(unmarkButtonPushed()));

   setFont(m_console->get_font());
   m_console->displayToPrompt(m_conn);

   titles << tr("Mark") << tr("File") << tr("Mode") << tr("User")
          << tr("Group") << tr("Size") << tr("Date");
   fileWidget->setHeaderLabels(titles);

   get_cwd();

   readSettings();
   /* wait was entered from pre-restore
    * will exit, but will reenter in fillDirectory */
   mainWin->waitExit();
   fillDirectory();
   dockPage();
   setCurrent();
   this->show();
   if (mainWin->m_miscDebug) Pmsg0(000, "Leave restorePage\n");
}
示例#26
0
std::string get_intl_dir()
{
#ifdef _WIN32
	// return get_cwd() + "/translations";
	if (!game_config::path.empty()) {
		return game_config::path + "/translations";
	} else {
		return get_cwd() + "/translations";
	}
#else

	return game_config::path + "/" LOCALEDIR;
#endif
}
示例#27
0
SETUP_ONCE()
{
	char cwd[PATH_MAX];
	assert_non_null(get_cwd(cwd, sizeof(cwd)));

	if(is_path_absolute(TEST_DATA_PATH))
	{
		snprintf(test_data, sizeof(test_data), "%s", TEST_DATA_PATH);
	}
	else
	{
		snprintf(test_data, sizeof(test_data), "%s/%s", cwd, TEST_DATA_PATH);
	}
}
示例#28
0
文件: utils.c 项目: acklinr/vifm
void
set_to_sandbox_path(char buf[], size_t buf_len)
{
	if(is_path_absolute(SANDBOX_PATH))
	{
		strcpy(buf, SANDBOX_PATH);
	}
	else
	{
		char cwd[PATH_MAX + 1];
		assert_non_null(get_cwd(cwd, sizeof(cwd)));
		snprintf(buf, buf_len, "%s/%s", cwd, SANDBOX_PATH);
	}
}
示例#29
0
//Initializes the prompt
static void init_prompt()
{
	//Sets the username, homedir, and hostname, and colors
	if(!got_username || !got_homedir)
		get_username_homedir();
	//Sets the hostname if we don't already have it
	if(!got_hostname)
		get_hostname();
	//Sets the prompt colors if we don't already have it
	if(!got_di_color || !got_ex_color)
		get_colors();
	//Sets the current working dir and the short version
	if(dir_changed)
		get_cwd();
}
示例#30
0
文件: util.c 项目: AlexsJones/dnoted
void delete_message(void)
{
  char *cwd = get_cwd();
  char *write_path = file_path();
  kvp_node *head = pull_kvp_from_file(write_path);	
  char buffer[1024];
  bzero(buffer,1024);
  char *homedir = getenv("HOME");
  strncpy(buffer,homedir,strlen(homedir));
  strcat(buffer,"/.dnoted/dnoted.temp");
  while(head)
  {
    if(strcmp(head->key,cwd) != 0)
    {
      //add it to our new file
      FILE *fp;
      if((fp = fopen(buffer,"w")) == NULL)
      {
        perror("delete_message: ");
        exit(1);
      }
      //Create a payload similar to write_message	
      char payload[2048];
      strncpy(payload,head->key,strlen(head->key));
      strncat(payload,"=",1);
      strncat(payload,head->value,strlen(head->value));		

      int size = strlen(payload);
      fwrite(payload,size,1,fp);
      //Adding end of line
      fwrite("\n",1,1,fp);
      fclose(fp);
    }
    head = head->next; 
  }
  FILE *file;
  if((file = fopen(buffer,"r")) != NULL)
  {
    system("mv $HOME/.dnoted/dnoted.temp $HOME/.dnoted/dnoted.conf");
    fclose(file);
  }
  else
  {
    system("rm $HOME/.dnoted/dnoted.conf; touch $HOME/.dnoted/dnoted.conf");
  }
  free(write_path);
  free(cwd);
}