int set_pwd(char ***env, char *path) { char *final_pwd; char **command; int i; i = (strncmp(path, "~/", 2) == 0) ? 1 : 0; if (i == 1 || (strncmp(path, "~\0", 2) == 0)) { if (!(final_pwd = my_strdog(my_getenv(*env, "HOME"), "/"))) return (1); } else if (path[0] == '/') { if (!(final_pwd = strdup("/"))) return (-1); } else if (!(final_pwd = my_strdog(my_getenv(*env, "PWD"), "/"))) return (1); if (!(command = my_str_to_wordtab2(path, "/"))) return (1); final_pwd = set_pwd_loop(command, final_pwd, i); builtin_setenv(env, "PWD", final_pwd); free(final_pwd); return (1); }
void minishell2(char **env) { char *bufpath[2]; char **tab; char **cmd; while (42) { bufpath[0] = prompt(); check_exit(bufpath[0]); bufpath[1] = get_path(env); tab = my_str_to_wordtab(bufpath[1]); cmd = my_str_to_wordtab2(bufpath[0]); process(bufpath, tab, cmd, env); } }
/* ** Retourne le path adequate a a partir de la chaine path */ char *recup_goodpath(char **cmd, char *pathline) { char **path_tab; int i; char *full_path; i = 0; path_tab = my_str_to_wordtab2(del_label(pathline, "PATH"), ':'); while (path_tab[i]) { full_path = mk_fullpath(path_tab[i], cmd[0]); if (access(full_path, F_OK) == 0) { my_free_tab(path_tab); return (full_path); } i++; free(full_path); } my_free_tab(path_tab); return (NULL); }
void ftrace_fork(ptraceData *data) { pid_t pid; char **tab; printf("Running %s\n", data->command); tab = my_str_to_wordtab2(data->command); pid = xfork(); if (!pid) { ptrace(PT_TRACE_ME, 0, NULL, 0); perror("ptrace fork"); errno = 0; execvpe(tab[0], tab, environ); perror(data->command); puts(tab[0]); printf("==\n"); } else { loop(data, pid, 0); } }