void ft_parse_input(t_shun **shell) { if (*(*shell)->input) { (*shell)->argv = ft_parse_get_args((*shell)->input); (*shell)->argc = ft_tablen((*shell)->argv); if ((*shell)->argc != 0) { if (ft_strcmp(ft_strtolower((*shell)->argv[0]), "exit") == 0) ft_exit(&(*shell)); else if (ft_strcmp(ft_strtolower((*shell)->argv[0]), "env") == 0) ft_print_environ(*shell); else if (ft_strcmp(ft_strtolower((*shell)->argv[0]), "setenv") == 0) ft_setenv(&(*shell)); else if (ft_strcmp(ft_strtolower((*shell)->argv[0]), "unsetenv") == 0) ft_unsetenv(&(*shell)); else if (ft_strcmp(ft_strtolower((*shell)->argv[0]), "cd") == 0) ft_cd(&(*shell)); else if (ft_strcmp(ft_strtolower((*shell)->argv[0]), "prompt") == 0) ft_chg_prompt(&(*shell)); else if (ft_strcmp(ft_strtolower((*shell)->argv[0]), "pwd") == 0) ft_putendl(ft_get_pwd()); else ft_exec_bin(&(*shell)); } } }
t_magic *ft_cd_return(t_magic *magic) { char *oldpwd; int pwd; pwd = ft_wline(magic->env, "PWD"); oldpwd = magic->oldpwd; if (oldpwd) { if ((ft_check_access_cd(oldpwd, "")) == 0) { if (chdir(oldpwd) == 0) { magic = ft_set_oldpwd(magic); if (pwd >= 0) { free(magic->env[pwd]); magic->env[pwd] = ft_strjoin("PWD=", getcwd(NULL, 0)); } } free(magic->pwd); magic->pwd = ft_get_pwd(); } else ft_parse_error_cd(ft_check_access_cd(oldpwd, ""), oldpwd); } return (magic); }
t_magic *ft_go_from_home(t_magic *magic, char **info) { int pwd; char *path; int access; pwd = ft_wline(magic->env, "PWD"); path = ft_get_home(magic->env); if ((access = ft_check_access_cd(path, &info[1][1])) == 0) { if (chdir(ft_strjoin(path, &info[1][1])) == 0) { magic = ft_set_oldpwd(magic); if (pwd >= 0) { free(magic->env[pwd]); magic->env[pwd] = ft_strjoin("PWD=", getcwd(NULL, 0)); } } free(magic->pwd); magic->pwd = ft_get_pwd(); } else ft_parse_error_cd(access, info[1]); return (magic); }
t_magic *ft_go_home(t_magic *magic) { char *home; int pwd; int access; pwd = ft_wline(magic->env, "PWD"); home = ft_get_home(magic->env); if ((access = ft_check_access_cd(home, "")) == 0) { if (chdir(home) == 0) { magic = ft_set_oldpwd(magic); if (pwd >= 0) { free(magic->env[pwd]); magic->env[pwd] = ft_strjoin("PWD=", getcwd(NULL, 0)); } } free(magic->pwd); magic->pwd = ft_get_pwd(); } else if (ft_strlen(home) > 0) ft_parse_error_cd(access, home); return (magic); }
char *ft_set_relpwd(char *path) { char *pwd; pwd = NULL; pwd = ft_get_pwd(); if (pwd != NULL) { pwd = ft_strjoin(pwd, "/"); pwd = ft_strjoin(pwd, path); } return (pwd); }