static int *line_filler(char *line, int *mapline) { char **tab; int i; int nb_int; if (!(tab = ft_strsplit(line, ' '))) return (NULL); nb_int = 0; while (tab[nb_int] != NULL) nb_int++; if (!(mapline = (int *)ft_memalloc(sizeof(int) * (nb_int + 1)))) { ft_tabdel((void ***)&tab); return (NULL); } mapline[0] = nb_int; i = 0; while (tab[i]) { mapline[i + 1] = ft_atoi(tab[i]); i++; } ft_tabdel((void ***)&tab); return (mapline); }
static void ft_realloc_alias(char *value, char ***tab) { char **cmd; char **tmp; int len; int i; int j; tmp = ft_tabdup(*tab); ft_tabdel(tab); cmd = ft_strsplit_space(value); i = ft_tablen(tmp) - 1; j = ft_tablen(cmd); len = i + j; *tab = (char **)malloc(sizeof(char *) * (len + 1)); (*tab)[len] = NULL; while (--len >= 0) { if (i > 0) (*tab)[len] = ft_strdup(tmp[i--]); else (*tab)[len] = ft_strdup(cmd[--j]); } ft_tabdel(&cmd); ft_tabdel(&tmp); }
static void sh_clear_context(t_info *context) { free(context->line); if (context->args) ft_tabdel(&context->args); if (context->env) ft_tabdel(&context->env); free(context->cursdir); }
void ft_get_materials(t_data *d, char *file_mat, char *file_obj) { int fd; char *line; char **tab; int i; size_t j; i = -1; fd = ft_open_file_mat(file_mat, file_obj); while (get_next_line(fd, &line) > 0 && !(j = 0)) { tab = ft_strsplit_space(line); if (tab[0] && tab[0][0] != '#') { while (j < sizeof(g_parse) / sizeof(*g_parse)) { if (!ft_strcasecmp(tab[0], g_parse[j].cmp)) g_parse[j].func(d, &i, tab); j++; } } ft_tabdel(&tab); ft_strdel(&line); } close(fd); }
int sh_loop(t_info *info) { int ret; int multi; ret = 1; sh_get_path(info); ft_printf("\033[31m%s\033[39m $> ", info->cursdir); while ((ret = get_next_line(0, &info->line)) > 0) { UNSET(info->sig, BIT_A); UNSET(info->opt, OPT_A); if (!(multi = sh_multi(info))) { sh_parse(info); info->status = sh_exec(info, info->env, &info->args[1]); } sh_get_path(info); ft_printf("\033[31m%s\033[39m $> ", info->cursdir); ft_tabdel(&info->args); free(info->line); } if (ret == -1) return (EXIT_FAILURE); return (EXIT_SUCCESS); }
int ft_tab(t_data *d) { char *path; DIR *dirp; char **result; char *name; char *tmp; if (!d->line->str || !(path = ft_search_path(d->line->str, d->line->index))) return (1); tmp = ft_preg_replace("\\", "", path); if (!(dirp = opendir(tmp))) { ft_strdel(&path); return (1); } ft_strdel(&tmp); name = ft_get_name(d->line->str, d->line->index); result = ft_search_files(dirp, name); ft_bubble_sort_str(result); ft_completion(d, result, name); closedir(dirp); ft_strdel(&path); ft_strdel(&name); ft_tabdel(&result); return (1); }
void prend(t_env *e, t_clients *player) { char **tab; char msg[4]; char tmp[BUF_SIZE]; tab = ft_strsplit(player->arg[0], ' '); ft_strcpy(msg, "ok\n"); prend2(e, player, msg, tab); sprintf(tmp, "inv %d %d %d %d %d %d %d %d %s\n", player->nb , player->life, player->linemate , player->deraumere, player->sibur, player->mendiane , player->phiras, player->thystame, player->name); sprintf(tmp + strlen(tmp), "inside %d %d %d %d %d %d %d %d %d\n" , player->X, player->Y, e->map[player->Y][player->X].nourriture , e->map[player->Y][player->X].linemate , e->map[player->Y][player->X].deraumere , e->map[player->Y][player->X].sibur , e->map[player->Y][player->X].mendiane , e->map[player->Y][player->X].phiras , e->map[player->Y][player->X].thystame); maj_gfx(e, tmp); next_action(player); ft_strcat(player->buf_write, msg); ft_tabdel(&tab); }
void exec_get_request(char *entry, int sock) { char **cmd; char *ret; int fd; long size; cmd = split_entry(entry); if ((fd = open(cmd[1], O_RDONLY)) == -1) { ret = ft_strjoin_tw("\033[31mERROR\033[0m get server: can't open " , cmd[1], "\n"); send_ret(ret, sock); } else { ret = ft_strdup("OK"); send_ret(ret, sock); size = get_file_size(fd); exec_get_command(sock, fd, size); close(fd); } free(ret); ft_tabdel(&cmd); }
int do_exec(t_av av, t_list *g_env, t_list *l_env) { char **env; char **path; char *str; env = convert_env(g_env, l_env); str = get_path(g_env, l_env); if (av.arg == NULL) av.arg = (char *[]){"", NULL}; if (execve(av.cmd, av.arg, env) == -1) { path = get_allpath(av.cmd, str); exec_path(av.arg, path, env); ft_tabdel(path); } ft_tabdel(env); return (bi_exit(AV_INIT(NULL, NULL, NULL, 1), NULL, NULL)); }
static void ft_cmd2(t_env *e, char cmd[], int fd) { char **tab; ft_strtrimbadass(cmd); ft_printf("__CMD : %s__ ->%d\n", cmd, e->clients[fd].nb); tab = ft_strsplit(cmd, ' '); ft_cmd3(e, cmd, fd, tab); ft_tabdel(&tab); }
int ft_obj_parse_angle(t_obj *obj, char const *line, size_t *count) { char **p; double a; double b; double c; p = ft_strsplit_func(line, &ft_isspace); if (ft_tablen(p) == 5) { a = ft_get_double_value(p[1]); b = ft_get_double_value(p[2]); c = ft_get_double_value(p[3]); obj->ang = M_POINT(a, b, c); ft_tabdel(&p); return (P_ANGLE); } P_ERROR("ANGLE", *count); obj->ang = M_POINT(0, 0, 0); ft_tabdel(&p); return (0); }
int ft_parse_light(t_env **env, int fd) { t_llst *add; char **tab; if (!(add = ft_llistnew())) return (-1); if (!(tab = ft_parse_tab(fd, 4, "origin"))) return (-1); add->light.origin.x = (double)ft_atoi(tab[1]); add->light.origin.y = (double)ft_atoi(tab[2]); add->light.origin.z = (double)ft_atoi(tab[3]); ft_tabdel(tab); if (!(tab = ft_parse_tab(fd, 4, "color"))) return (-1); add->light.color.r = (double)ft_atoi(tab[1]); add->light.color.g = (double)ft_atoi(tab[2]); add->light.color.b = (double)ft_atoi(tab[3]); ft_tabdel(tab); (*env)->light = ft_llistadd((*env)->light, add); return (0); }
int ft_eye_parse_position(t_cam *cam, char const *line, size_t *count) { char **p; double a; double b; double c; p = ft_strsplit_func(line, &ft_isspace); if (ft_tablen(p) == 5) { a = ft_get_double_value(p[1]); b = ft_get_double_value(p[2]); c = ft_get_double_value(p[3]); cam->position = M_POINT(a, b, c); ft_tabdel(&p); return (P_POSITION); } P_ERROR("POSITION", *count); cam->position = M_POINT(0, 0, 0); ft_tabdel(&p); return (0); }
void ft_great(t_parser *parser, t_data *d) { int fd; char **tab; char *tmp; tmp = ft_bquote(d, parser->left->str); tab = ft_strsplit_shell(tmp); ft_strdel(&tmp); fd = open(tab[0], O_CREAT | O_TRUNC | O_RDWR, 0644); if (ft_check_error(tab, fd)) { ft_tabdel(&tab); return ; } ft_tabdel(&tab); if (d->pipe == 0) dup2(fd, 1); ft_process_tree(parser->right, d); if (d->pipe == 0) dup2(d->save_fd[1], 1); close(fd); }
int ft_obj_parse_negatif(t_obj *obj, char const *line, size_t *count) { char **p; int tmp; p = ft_strsplit_func(line, &ft_isspace); if (ft_tablen(p) == 3) { tmp = 0; if (ft_strlen(p[1]) == ft_strlen_func(p[1], &ft_isdigit)) tmp = ft_atoi(p[1]); if (ft_strequ(p[1], "true") || tmp == 1) obj->param.negatif = true; else obj->param.negatif = false; ft_tabdel(&p); return (P_NEGATIF); } P_ERROR("NEGATIF", *count); obj->param.negatif = 0; ft_tabdel(&p); return (0); }
int ft_parse_cam(t_env **env, int fd) { char **tab; if (!(tab = ft_parse_tab(fd, 4, "origin"))) return (-1); (*env)->cam->origin.x = (double)ft_atoi(tab[1]); (*env)->cam->origin.y = (double)ft_atoi(tab[2]); (*env)->cam->origin.z = (double)ft_atoi(tab[3]); ft_tabdel(tab); if (!(tab = ft_parse_tab(fd, 4, "dir"))) return (-1); (*env)->cam->dir.x = (double)ft_atoi(tab[1]); (*env)->cam->dir.y = (double)ft_atoi(tab[2]); (*env)->cam->dir.z = (double)ft_atoi(tab[3]); ft_tabdel(tab); if (!(tab = ft_parse_tab(fd, 4, "up"))) return (-1); (*env)->cam->upvec.x = (double)ft_atoi(tab[1]); (*env)->cam->upvec.y = (double)ft_atoi(tab[2]); (*env)->cam->upvec.z = (double)ft_atoi(tab[3]); ft_tabdel(tab); return (0); }
static int test_size(int ***map) { int i; int size; i = 1; size = *map[0][0]; while ((*map)[i]) { if (size != (*map)[i][0]) { ft_tabdel((void ***)&(*map)); return (0); } i++; } return (1); }
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_dless(t_parser *parser, t_data *d) { char **tab; int fd; tab = ft_strsplit_shell(parser->left->str); if (!tab || !tab[0]) { ft_putendl_fd("parser error", 2); return ; } ft_heredoc(tab); ft_tabdel(&tab); fd = open("/tmp/.less", O_RDONLY); dup2(fd, 0); d->redirect = 0; ft_process_tree(parser->right, d); d->redirect = 1; dup2(d->save_fd[0], 0); close(fd); }
void exec_put_request(char *entry, int sock) { char **cmd; char *ret; int fd; cmd = split_entry(entry); if ((fd = open(cmd[1], O_WRONLY | O_TRUNC | O_CREAT, 0644)) == -1) { ret = ft_strjoin_tw("\033[31mERROR\033[0m get server: can't create " , cmd[1], "\n"); send_ret(ret, sock); } else { ret = ft_strdup("OK"); send_ret(ret, sock); exec_put_command(sock, fd); close(fd); } free(ret); ft_tabdel(&cmd); }