void parsing_objects(int fd, char *object, t_env *rt) { char *line; char **tab; int tmp; tmp = 0; init_name(rt, object); while (get_next_line(fd, &line) > 0 && line[0]) { tmp = 1; tab = ft_strsplit(line, ' '); if ((ft_strcmp(tab[0], "radius") && ft_strcmp(tab[0], "pos") && ft_strcmp(tab[0], "color") && ft_strcmp(tab[0], "angle") && ft_strcmp(tab[0], "a") && ft_strcmp(tab[0], "b") && ft_strcmp(tab[0], "c") && ft_strcmp(tab[0], "material") && ft_strcmp(tab[0], "separation")) || !tab[2]) ft_exit("\033[31mMissing parameter for an object\n"); parsing_options(tab, rt, rt->i_obj); parsing_options2(tab, rt, rt->i_obj); tab_free(tab); ft_strdel(&line); } if (tmp) ft_strdel(&line); rt->i_obj++; }
void arg_to_tab(int argc, char *argv[]) { t_argtab tab; int i; tab_init(&tab, argc); tab_fill(&tab, argc, argv); tab_sort(&tab); print_error(tab); printfilelist(tab.file.ptr, tab.file.size, ""); if (!tab.dir.size) return ; if (tab.file.size) ft_putchar('\n'); if (tab.dir.size != 1 || (tab.error.size && !tab.file.size)) ft_putstr(tab.dir.ptr[0]->name), ft_putendl(":"); i = 0; while (i < (tab.dir.size)) { ls_mult_arg(tab.dir.ptr[i]->name, i); if (i != (tab.dir.size - 1)) ft_putchar('\n'); i++; } tab_free(&tab); exit(0); }
t_input *shift_or_input(t_execution *exec, t_input *input) { t_input *tmp; tmp = input; if (!exec->r_value) { while (tmp->flag == 3 || tmp->flag == 2) { tmp = tmp->next; input_free(tmp); } } if (!tmp->flag) { tab_free(tmp->text); free(tmp); return (NULL); } else { tmp = tmp->next; input_free(tmp); exec->input = tmp; } set_ids((input = tmp)); return (input); }
void parsing_light(int fd, t_env *rt) { char *line; char **tab; int tmp; tmp = 0; while (get_next_line(fd, &line) > 0 && line[0] != '\0') { tab = split_tab(line); if (!ft_strcmp(tab[0], "pos")) rt->light[rt->i_light].center = new_vector(ft_atof(tab[2]), ft_atof(tab[3]), ft_atof(tab[4])); else if (!ft_strcmp(tab[0], "color")) { check_color(ft_atof(tab[2]), ft_atof(tab[3]), ft_atof(tab[4])); rt->light[rt->i_light].color.r = ft_atof(tab[2]); rt->light[rt->i_light].color.g = ft_atof(tab[3]); rt->light[rt->i_light].color.b = ft_atof(tab[4]); } else if (!ft_strcmp(tab[0], "parallel")) rt->light[rt->i_light].parallel = ft_atoi(tab[2]); tab_free(tab); ft_strdel(&line); } (tmp) ? (ft_strdel(&line)) : (0); rt->i_light++; }
void parsing_camera(int fd, t_env *rt) { char *line; char **tab; int tmp; tmp = 0; while (get_next_line(fd, &line) > 0 && line[0] != '\0') { tmp = 1; tab = split_tab(line); if (!ft_strcmp(tab[0], "pos")) { rt->eye.x = ft_atof(tab[2]); rt->eye.y = ft_atof(tab[3]); rt->eye.z = ft_atof(tab[4]); } else if (!ft_strcmp(tab[0], "angle")) rt->cam_angle = new_vector(ft_atof(tab[2]), ft_atof(tab[3]), ft_atof(tab[4])); tab_free(tab); ft_strdel(&line); } if (tmp) ft_strdel(&line); }
void get_points(t_co *c, int *fd, char *line, int *v) { int x; int y; char **split; x = 0; y = 0; while (get_next_line(*fd, &line) > 0) { split = ft_strsplit(line, ' '); while (x < c->coord->x_point) { c->coord->vert[*v] = (t_point *)malloc(sizeof(t_point)); c->coord->vert[*v]->h = ft_atoi(split[x]); c->coord->vert[*v]->x = ((x * c->gap) - (y * c->gap)) + ORIGIN_X; c->coord->vert[*v]->y = ((x * c->gap) + (y * c->gap)) / c->div + ORIGIN_Y - (c->coord->vert[*v]->h * c->c_height); *v += 1; x++; } tab_free(split); free(line); x = 0; y++; } }
void init_coord(char *file_name, t_co *c) { char *line; int i; int fd; int x_len; char **split; i = 0; c->coord = (t_coord *)malloc(sizeof(t_coord)); fd = open(file_name, O_RDONLY); while (get_next_line(fd, &line) > 0) { split = ft_strsplit(line, ' '); if (i++ == 0) x_len = tab_len(split); c->coord->x_point = tab_len(split); tab_free(split); check_len_map(x_len, c->coord); free(line); } check_ret_gnl(&fd, line); c->coord->to_pts = x_len * i; c->coord->y_point = i; close(fd); }
void get_new_map(t_event *event) { int i; char *tmp; tab_free(event->data->map); free(event->data->initial); wait(&i); event->data->name[my_strlen(event->data->name) - 1]++; tmp = event->data->name; free(event->data); if ((event->data = get_the_map(tmp)) == NULL) { my_printf("Congratulation\n"); exit(1); } back_ground(event->window); }
t_input *shift_sc_input(t_execution *exec, t_input *input) { t_input *tmp; tmp = input; if (!tmp->flag) { tab_free(tmp->text); free(tmp); return (NULL); } else { tmp = tmp->next; input_free(input); exec->input = tmp; } set_ids((input = tmp)); return (input); }