int ft_cd(t_env *shell) { char *path; int i; i = 0; if (shell->ac == 1 || (shell->ac == 2 && (shell->av[1][0] == '~' && !shell->av[1][1]))) return (ft_cd_home(shell)); if (shell->ac == 3) return (ft_cd_double(shell)); if (shell->ac == 2 && shell->av[1]) { if (shell->av[1][0] == '.' && !shell->av[1][1]) return (0); if (shell->av[1][0] == '-' && !shell->av[1][1]) return (ft_cd_less(shell)); path = (shell->av[1][0] && shell->av[1][0] != '/') ? ft_rel_pwd(shell, shell->av[1]) : ft_strdup(shell->av[1]); ft_cd_normal(shell, path); free(path); return (1); } else ft_putstr("cd : Invalid usage\n"); return (0); }
void ft_cd(t_term *term) { struct stat bufstat; ft_cd2(term); if (term->cmds[1] && term->cmds[1][0] == '~' && term->cmds[1][1]) { if (!ft_get_val_exists(term, "HOME")) return (ft_putendl("NO HOME")); term->cmds[1] = ft_strjoin(ft_get_val(term, "HOME"), &term->cmds[1][1]); } if (!term->cmds[1] || (term->cmds[1] && term->cmds[1][0] == '~')) return (ft_cd_home(term)); else { if (access(term->cmds[1], R_OK)) return (ft_cd_error(term->cmds[1])); if (lstat(term->cmds[1], &bufstat) == -1) { return (ft_putendl(ft_strjoin( "cd: no such file or directory: ", term->cmds[1]))); } } ft_cd_suite(term); }
int ft_check_cd(char *line, t_env *env) { char **cdtab; cdtab = ft_strsplit(line, ' '); if (ft_strcmp(line, "cd") == 0) ft_cd_home(env); else if (cdtab[1][0] == '-') ft_cd_minus(env, line); else if (cdtab[1][0] == '~') ft_cd_tilde(env, cdtab); else if (cdtab[0] && cdtab[1]) ft_cd(line, env); return (0); }
int ft_cd(char **tab) { if (ft_tablen((void **)tab) == 1) return (ft_cd_home()); else if (tab[1][0] == '~') return (ft_cd_tild(tab[1])); else if (tab[1][0] == '-') { if (tab[1][1] != '\0') return (st_check_option(&tab[1])); else return (ft_cd_least()); } else if (ft_tablen((void **)tab) > 2) return (ft_error_cd("cd", 4, NULL)); else return (ft_other_cd(tab[1], 0)); return (0); }
static int st_check_option(char **tab) { int y; int ret; int status; int fstatus; y = 0; status = 0; while (tab[y]) { fstatus = 0; ret = st_check_arg(tab[y], &status); if (ret == 0 && st_check_arg(tab[y + 1], &fstatus) != 0) return (ft_other_cd(tab[y + 1], status)); y++; } return (ft_cd_home()); }