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 parsing(char *argv, t_map *map, t_param *param) { int fd; map->nb_line = 0; map->nb_col = 0; if ((fd = open(argv, O_RDONLY)) < 0) ft_exit(); map = count_line_col(fd, map); map->tab = (int **)malloc(sizeof(int *) * (map->nb_line)); map->tab[map->nb_line] = NULL; close(fd); fd = open(argv, O_RDONLY); map = split_tab(map, fd); define_start(param, map); check_border(map); close(fd); }
int sort(t_tetra *list, char **str, int pos, char c) { t_tab i; i.tab = split_tab(list->minos, i.tab, i.cd); i.y = pos % 100; i.x = pos / 100; i.len = i.cd[1]; i.init = i.y; i.sharp = 0; if (list->nb[0] + i.x > ln(*str) + 1) return (-1); if ((i.y - list->nb[2]) + 1 < 0) return (-1); if (i.y + ((list->nb[2] - list->nb[1]) * -1) > ln(*str)) return (-1); if (rc(i, str, c) == -1) return (-1); else return (0); }
static int add_comp_single(char *prefix, char *all_possible, char **completed) { int ret = -1; size_t len = 0; size_t pre_len = 0; size_t comp_len = 0; size_t tail_len = 0; char *p = NULL; char *buf = NULL; char *endp = NULL; char *pre_word = NULL; char *comp_word = NULL; char *tails = NULL; dbg("%s\nprefix:(%s)\nall_possible:\n--\n%s\n--\n", __FUNCTION__, prefix, all_possible); //get last partial-word for tab-completion buf = split_tab(prefix, &pre_word,&tails); if (pre_word != NULL) pre_len = strlen(pre_word); else pre_len = 0; if (tails != NULL) tail_len = strlen(tails); else tail_len = 0; //merge <comp_word> + <p> //TODO: make sure all_possible contains only one word. //p = strtok(all_possible, " \t\n"); p = strtok(all_possible, "\t\n"); //remain 'space' if (p == NULL) return -1; len = strlen(p); dbg("\npremerge:\npre_word(%d)", (int)pre_len); if (pre_len != 0) dbg(":(%s)\n", pre_word); dbg("p(%d):(%s)\n", (int)len, p); if (tail_len != 0) dbg("tails(%d):(%s)\n", (int)tail_len, tails); if ((buf = malloc(pre_len+len+tail_len+1)) == NULL) { fprintf(stderr, "func(%s), line(%d): malloc failed.\n", __FUNCTION__, (int)__LINE__); return -1; } if (pre_len != 0) snprintf(buf, (pre_len+1), "%s", pre_word); snprintf(buf+pre_len, (len+1), "%s", p); if (tail_len != 0) snprintf(buf+pre_len+len, (tail_len+1), "%s", tails); buf[pre_len+tail_len+len] = '\0'; ret = do_add_comp(buf+pre_len); (*completed) = buf; myfree((void **)&pre_word); myfree((void **)&comp_word); myfree((void **)&tails); return ret; }