int main(int argc, char **argv) { t_screen screen; screen = (t_screen){1000, 800}; if (argc == 1) ft_exec("wolf3d.42", "Wolf3d.42", 0, screen); else if (argc == 2) ft_exec(argv[1], argv[1], 1, screen); else ft_putstr("Veuillez saisir aucun parametre ou bien le fichier map\n"); return (0); }
void ft_env(t_s *s, int nbenv) { if (nbenv > 0) { ft_enva(s, nbenv); ft_exec(s, (nbenv + 1), s->tempenv); freetab(s->tempenv); s->tempenv = NULL; } else { s->tempenv = NULL; ft_exec(s, 1, s->myenv); } }
static void ft_simple_exec(char **av) { char **new_av; int i; int len; int k; len = 0; i = 1; k = 0; while (ft_strchr(av[i], '=')) i++; while (av[i] && len++ >= 0) i++; new_av = (char**) malloc(sizeof(*new_av) * len + 1); i = 1; while (ft_strchr(av[i], '=')) i++; while (av[i]) { new_av[k] = ft_strdup(av[i]); i++; k++; } new_av[k] = '\0'; ft_exec(new_av, g_env.env); }
void exec_opc(t_proc_list **lst, t_proc_list **exec_proc, t_vm *vm) { if (vm->cycles != 0 && vm->cycles == (*lst)->proc->wex) { if (ft_codage_erase(vm->mem, (*lst)->proc) || ft_param_erase(vm->mem, (*lst)->proc)) { if ((*lst)->proc->opc == 1 || (*lst)->proc->opc == 9 || (*lst)->proc->opc == 12 || (*lst)->proc->opc == 15) (*lst)->proc->codage = read_value(vm->mem, (*lst)->proc->prevpc + 1, 1); else (*lst)->proc->codage = read_value(vm->mem, (*lst)->proc->prevpc + 2, 1); reset_param(&((*lst)->proc->par_list)); (*lst)->proc->exec = 1; (*lst)->proc->pc = (*lst)->proc->prevpc; get_opc(lst, vm); } ft_exec(lst, exec_proc, vm); (*lst)->proc->exec = 1; reset_param(&((*lst)->proc->par_list)); (*lst)->proc->opc = 0; (*lst)->proc->wex = 0; (*lst)->proc->codage = 0; } }
int main(int argc, char **argv, char **envp) { if (argc && argv && envp) { envp = get_envp(envp); ft_exec(&envp); } return (0); }
void ft_exec(char ***envp) { char *line; t_list *tokens; char *trim; line = NULL; tokens = NULL; ft_prompt(*envp); line = ft_get_cmd(*envp); if (!line) return (ft_exec(envp)); trim = ft_strtrim(line); if (trim && !ft_strequ(trim, "")) { tokens = ft_tokenize(trim); free(trim); if (tokens) parse_cmd(tokens, envp); } return (ft_exec(envp)); }
void ft_envi(t_s *s, int nbenv) { int i; i = 0; if (nbenv > 0) { s->tempenv = (char **)malloc(sizeof(char *) * (nbenv + 1)); while (i < nbenv) { s->tempenv[i] = ft_strdup(s->in[i + 2]); i++; } s->tempenv[i] = NULL; ft_exec(s, (nbenv + 2), s->tempenv); freetab(s->tempenv); s->tempenv = NULL; } else { s->tempenv = NULL; ft_exec(s, 2, s->tempenv); } }
int ft_exec_cmd(t_data *data) { data->fdes1 = open(data->infile, O_RDONLY); data->fdes2 = open(data->outfile, O_RDWR | O_CREAT | O_TRUNC, 0644); pipe(data->fd1); data->pid = fork(); if (data->pid == 0) { close(data->fd1[0]); dup2(data->fd1[1], 1); dup2(data->fdes1, 0); ft_exec(data, data->name1, data->av1); close(data->fd1[0]); } if (data->pid > 0) { close(data->fd1[1]); dup2(data->fd1[0], 0); dup2(data->fdes2, 1); ft_exec(data, data->name2, data->av2); close(data->fd1[1]); } return (0); }
int check_builtin(t_env *e) { int ret; if (!e->av[0]) return (0); ret = (ft_strequ(e->av[0], "env") && !(e->av[1])) ? display_env(e) : 0; if (ret != 2) ret = (ft_strequ(e->av[0], "cd")) ? ft_cd(e) : 0; if (ret != 2) ret = (ft_strequ(e->av[0], "setenv")) ? ft_setenv(e) : 0; if (ret != 2) ret = (ft_strequ(e->av[0], "unsetenv")) ? ft_unsetenv(e) : 0; if (ret != 2) ret = (!(ft_strncmp(e->av[0], "./", 2))) ? ft_exec(e) : 0; if (ret != 2) ret = (ft_strcmp(e->av[0], "exit")) ? 0 : 1; return (ret); }
void ft_go(char ***env) { char *tmp; char **path; t_list *arg; t_tree *tree; if (!(tmp = ft_getenv("PATH", *env))) path = ft_path(); else path = ft_strsplit(tmp, ':'); if ((arg = ft_parser(g_e.buff)) && (tree = ft_make_tree(arg))) { ft_exec(tree, path, env); ft_del_tree(tree); } ft_tabdel(path); free(path); }
void ft_launch(char **av, int ac) { t_stack *pa; t_stack *pb; char *opt; int a; opt = ft_strdup("00000"); if ((a = ft_check(av, ac, opt)) > 0) { if ((ac - a + 1) < 1) exit (write(1, "\n", 1)); pa = ft_create_stack(av, ac - a + 1, "stack a", opt); pb = ft_create_stack(NULL, ac - a + 1, "stack b", opt); ft_exec(*pa, *pb); } else ft_putendl("Error"); free(opt); }
int ft_cmd(char **line, t_env *var) { int i; i = 0; if (!line || !line[0]) return (0); else if (ft_strcmp(line[0], "env") == 0) ft_show_env(var); else if (ft_strcmp(line[0], "unsetenv") == 0) ft_del_env(var, line[1]); else if (ft_strcmp(line[0], "setenv") == 0) var = ft_set_env(var, line[1]); else if (ft_strcmp(line[0], "cd") == 0) ft_change_directory(var, line[1]); else if (ft_strcmp(line[0], "exit") == 0) return (1); else ft_exec(line[0], line, var); return (0); }
void ft_pid1(int fd1, int *piped, char *cmd1) { char **command1; command1 = ft_strsplit(cmd1, ' '); dup2(fd1, 0); dup2(piped[1], 1); close(fd1); close(piped[0]); close(piped[1]); if (command1[0][0] == '/') { if (execve(command1[0], command1, environ) == -1) ft_error_handling("No such command, try removing the /\n"); } else ft_exec(command1); close(fd1); close(piped[0]); close(piped[1]); }
void ft_process(t_data *d, char *str) { int i; char **tab; char *tmp; i = 0; tmp = ft_tilde(str, d); tab = ft_strsplit_shell(tmp); ft_strdel(&tmp); if (tab && tab[0]) { ft_search_alias(d, &tab); ft_builtin(d, tab, &i); if (i == 0) { if (ft_exec(ft_convert_ltt(d->my_env), tab, d->fork) == 0) ft_printf("42sh: command not found: %s\n", tab[0]); } } ft_free_tab(&tab); }
void ft_pid2(int fd2, int *piped, char *cmd2) { char **command2; wait (NULL); command2 = ft_strsplit(cmd2, ' '); dup2(piped[0], 0); dup2(fd2, 1); close(piped[0]); close(piped[1]); close(fd2); if (command2[0][0] == '/') { if (execve(command2[0], command2, environ) == -1) ft_error_handling("No such command, try removing the /\n"); } else ft_exec(command2); close(fd2); close(piped[0]); close(piped[1]); }