Ejemplo n.º 1
0
void	find_cd(char *str, t_struct *pile)
{
  int	n;
  int	flag;
  char	*tmp;
  char	**path;

  n = 0;
  flag = 0;
  tmp = my_strdup(str);
  path = my_str_towordtab_cd(tmp, '/');
  while (path[n] != 0)
    {
      if (path[n + 1] == 0)
	flag = 1;
      if (my_strncmp(path[n], "..", 2) == 0)
	my_cd_back(pile, flag);
      else if ((n == 0) && (path[n][0] == '-'))
	my_cd_minus(path[n], pile);
      else
	my_cd_opendir(path[n], pile, flag);
      n++;
    }
  my_free_tab(path);
  free(path);
  free(tmp);
}
Ejemplo n.º 2
0
static char     *my_cd_realpath(char *path, char **env)
{
  char          *tmp;

  tmp = NULL;
  if (my_strcmp(path, "-") == 0 || my_strcmp(path, "--") == 0)
    tmp = my_cd_back(path, env);
  else if (my_strcmp(path, "~") == 0)
    tmp = my_strdup(my_getenv(env, "HOME"));
  else if (my_strichr(path, '~') == 0 && my_strichr(path, '/') == 1)
    tmp = my_strjoin(my_getenv(env, "HOME"), my_strchr(path, '/'));
  else if (my_strichr(path, '/') == 0)
    tmp = my_strdup(path);
  else
    {
      tmp = my_strjoin(my_getenv(env, "PWD"), "/");
      tmp = my_strfjoin(tmp, my_strdup(path));
    }
  if (tmp != NULL)
    tmp = my_realpath(tmp);
  return (tmp);
}