Exemple #1
0
//-------------------------------------------------------------------
bool UnRegisterPath(const char* path)
{
    TCHAR szPath[MAX_PATH];
    char  pmbbuf[MAX_PATH];

    DWORD length = GetModuleFileName(nullptr, szPath, sizeof(szPath));

    if (!path || length == 0) {
        return false;
    }

    wcstombs(pmbbuf, szPath, MAX_PATH);

    std::string exec_path(pmbbuf);

    std::string::size_type pos = exec_path.rfind("bin");

    std::string new_path = exec_path.substr(0, pos) + path;

    std::vector<std::string>::iterator IterFind = std::find(gPathStr.begin(), gPathStr.end(), new_path);

    if (IterFind != gPathStr.end()) {
        gPathStr.erase(IterFind);
    }

    return false;
}
Exemple #2
0
//----------------------------------------------------------------------------------
bool RegisterPath(const char *path)
{
    TCHAR szPath[MAX_PATH];
    char  pmbbuf[MAX_PATH];

    bool bResult = false;

    if (path)
    {
        DWORD length = GetModuleFileName(nullptr, szPath, sizeof(szPath));

        if (length > 0)
        {
            wcstombs(pmbbuf, szPath, MAX_PATH);

            std::string exec_path(pmbbuf);

            std::string::size_type pos = exec_path.find_last_of("/\\", exec_path.find_last_of("/\\") - 1);

            assert(pos != std::string::npos);

            std::string new_path = exec_path.substr(0, pos) + '\\' + path;

            std::vector<std::string>::const_iterator IterFind = std::find(gPathStr.begin(), gPathStr.end(), new_path);

            if (IterFind == gPathStr.end()) {
                gPathStr.push_back(new_path);
            }

            bResult = true;
        }
    }
    return bResult;
}
Exemple #3
0
void		exec_cmd(char *str)
{
	char **cmd;

	str = ft_strdup(parse_vars(str));
	if (!(cmd = split_cmd(str)) || !cmd[0])
	{
		free_tab(cmd);
		return ;
	}
	if (!exec_file(cmd) && !exec_builtin(cmd))
		exec_path(cmd);
	free(str);
	free_tab(cmd);
}
Exemple #4
0
int			do_exec(t_av av, t_list *g_env, t_list *l_env)
{
	char	**env;
	char	**path;
	char	*str;

	env = convert_env(g_env, l_env);
	str = get_path(g_env, l_env);
	if (av.arg == NULL)
		av.arg = (char *[]){"", NULL};
	if (execve(av.cmd, av.arg, env) == -1)
	{
		path = get_allpath(av.cmd, str);
		exec_path(av.arg, path, env);
		ft_tabdel(path);
	}
	ft_tabdel(env);
	return (bi_exit(AV_INIT(NULL, NULL, NULL, 1), NULL, NULL));
}
Exemple #5
0
//----------------------------------------------------------------------------------
std::wstring BuildFolderPath(const wchar_t *folder)
{
    std::wstring outPath;

    TCHAR szPath[MAX_PATH];

    if (folder)
    {
        DWORD length = GetModuleFileName(nullptr, szPath, sizeof(szPath));

        if (length > 0)
        {
            std::wstring exec_path(szPath);

            std::wstring::size_type pos = exec_path.find_last_of(L"/\\", exec_path.find_last_of(L"/\\") - 1);

            assert(pos != std::wstring::npos);

            outPath = exec_path.substr(0, pos) + L'\\' + folder;
        }
    }

    return outPath;
}
Exemple #6
0
/* hashed command search routine
 * ----------------------------------------------------------------------- */
union command exec_hash(char *name, enum hash_id *idptr) {
  enum hash_id id;
  union command cmd;

  /* name contains slashes, its a path */
  if(name[str_chr(name, '/')]) {
    /* do not hash this... */
    id = H_PROGRAM;
    cmd.path = name;

    /* ...but validate the path */
    if(access(cmd.path, X_OK) != 0)
      cmd.path = NULL;
  }
  /* otherwise try to find hashed entry */
  else {
    struct exechash *entry;
    unsigned long hash;

    /* hash the name for possible re-use on exechash_create() */
    hash = exec_hashstr(name);
  
    /* do we have a cache hit? */
    if((entry = exec_search(name, hash))) {
      entry->hits++;
      id = entry->id;
      cmd = entry->cmd;
    }
    /* if we don't have a cache hit we're gonna search, special builtins first */
    else {
      id = H_EXEC;
      cmd.builtin = builtin_search(name, B_EXEC);

      /* then search for functions */
      if(cmd.builtin == NULL) {
        id = H_SBUILTIN;
        cmd.builtin = builtin_search(name, B_SPECIAL);
      }
      
      /* then search for functions */
      if(cmd.builtin == NULL) {
        id = H_FUNCTION;
        cmd.fn = /* FIXME */ NULL;
      }
      
      /* then search for normal builtins */
      if(cmd.fn == NULL) {
        id = H_BUILTIN;
        cmd.builtin = builtin_search(name, B_DEFAULT);
      }
      
      /* then search for external commands */
      if(cmd.builtin == NULL) {
        id = H_PROGRAM;
        cmd.path = exec_path(name);
      }
      
      /* if we found something then create a new cache entry */
      if(cmd.ptr) {
        entry = exec_create(name, hash);
        entry->hits++;
        entry->id = id;
        entry->cmd = cmd;
      }
    }
  }
  
  /* we have a command, set the id */
  if(cmd.ptr && idptr)
    *idptr = id;

  return cmd;
}