static void make_quadlink(t_list *lst_len) { int var; int len_1; int len_2; t_list *dble_1; t_list *dble_2; dble_1 = NULL; dble_2 = NULL; var = ((t_pile*)(lst_len->content))->val; if (var < 2) { cpy_link(lst_len); return ; } len_1 = var / 2; len_2 = var / 2 + var % 2; if (!(dble_1 = make_dblink(len_1)) || !(dble_2 = make_dblink(len_2))) { free(dble_1); free(dble_2); return ; } ft_lstadd_back(dble_1, dble_2); ft_lstadd_back(lst_len, dble_1); return ; }
char *ft_ftos(int fd, size_t buff_size) { t_list *lst; t_list *last; char *str; size_t read_oct; lst = NULL; if (!(str = (char *)malloc(buff_size * sizeof(char)))) return (NULL); read_oct = read(fd, str, buff_size); ft_lstadd_back(&lst, ft_lstnew(str, read_oct)); last = lst; if (read_oct == buff_size) { while ((read_oct = read(fd, str, buff_size)) == buff_size) { ft_lstadd_back(&last, ft_lstnew(str, read_oct)); last = last->next; } ft_lstadd_back(&last, ft_lstnew(str, read_oct)); } free(str); str = ft_lstcat(lst); ft_lstpdel(&lst); return (str); }
void add_face_to_model(t_obj obj, int obj_face[3][3], t_model *model) { t_list *tmp; int i; t_vertex vertex; float random_color[SIZE_RGBA]; i = -1; set_random_color(&random_color); while (++i < 3) { if ((tmp = ft_lstgetone(obj.v, obj_face[i][0] - 1))) ft_memcpy(&vertex.position, tmp->content, sizeof(float [3])); if ((tmp = ft_lstgetone(obj.color, obj_face[i][0] - 1))) ft_memcpy(&vertex.color, tmp->content, sizeof(float [4])); else ft_memcpy(&vertex.color, random_color, sizeof(float [4])); if ((tmp = ft_lstgetone(obj.vt, obj_face[i][1] - 1))) ft_memcpy(&vertex.tex_coord, tmp->content, sizeof(float [2])); else add_zy_vt_to_vertex(&vertex); tmp = ft_lstnew(&vertex, sizeof(t_vertex)); ft_lstadd_back(&model->vertices, tmp); model->v_size++; } }
t_cmd *shell_parser_exec(char **p_input, char *end, int *res) { char *new_cmd; char *new_cmd_end; int tok; t_exec_cmd *cmd; t_cmd *ret; ret = shell_parser_new_exec_cmd(); cmd = (t_exec_cmd *)ret; cmd->argv = NULL; ret = shell_parser_redirection(ret, p_input, end); while (*p_input < end) { if ((tok = tokenizer(p_input, end, &new_cmd, &new_cmd_end)) == 0) break ; if (tok != 'a' && (*res = 0)) return (NULL); ft_lstadd_back(&cmd->argv, ft_lstnew( ft_strndup(new_cmd, new_cmd_end - new_cmd), new_cmd_end - new_cmd + 1)); ret = shell_parser_redirection(ret, p_input, end); } return (ret); }
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *)) { t_list *map; map = NULL; while (lst) { ft_lstadd_back(&map, (*f)(lst)); lst = lst->next; } return (map); }
static void evo_duplicate(t_env *e, t_unit *unit) { t_list *elem; t_unit clone; clone = *unit; clone.pos = random_pos(clone.pos); if (evo_exist(e->pop, clone.pos)) return ; clone.pv = random_rank(PVPOPMIN, PVPOPMAX) + (clone.lv * (random_rank(LVUPDEATHMIN, LVUPDEATHMAX))); if (!(elem = ft_lstnew(&clone, sizeof(t_unit)))) return ; else ft_lstadd_back(&e->pop, elem); }
t_list *ft_lststrsplit(char const *str, char spliter) { t_list *splits; splits = *str == spliter ? NULL : ft_lstnew(str, splitsize(str, spliter)); while (*str) { if (*str == spliter && str[1] != spliter) { str++; ft_lstadd_back(&splits, ft_lstnew(str, splitsize(str, spliter))); } str++; } return (splits); }
void get_lstconf(t_tree *tr, t_list **lst) { t_pile data; t_list *tmp; if (!tr) return ; if (!tr->left && !tr->right) { data.val = ((t_pile*)(tr->content))->val; if (!(tmp = ft_lstnew(&data, sizeof(t_pile)))) return ; if (!*lst) ft_lstadd(lst, tmp); else ft_lstadd_back(*lst, tmp); } get_lstconf(tr->left, lst); get_lstconf(tr->right, lst); }
static t_list *make_dblink(int len) { t_list *link_1; t_list *link_2; t_pile pile_1; t_pile pile_2; link_1 = NULL; link_2 = NULL; pile_1.val = len / 2; pile_2.val = len / 2 + len % 2; if (!(link_1 = ft_lstnew(&pile_1, sizeof(t_pile))) || !(link_2 = ft_lstnew(&pile_2, sizeof(t_pile)))) { free(link_1); free(link_2); return (NULL); } ft_lstadd_back(link_1, link_2); return (link_1); }
t_list *get_op_lst(void) { char *line; t_list *op_lst; t_list *tmp; t_op content; op_lst = NULL; get_next_line(0, &line); content.op = line; if (!(op_lst = ft_lstnew(&content, sizeof(content)))) return (NULL); while (get_next_line(0, &line)) { content.op = line; if (!(tmp = ft_lstnew(&content, sizeof(content)))) return (NULL); ft_lstadd_back(op_lst, tmp); } free(line); return (op_lst); }
t_list *ft_lstsplit(char *s, char c) { t_list *alst; t_list *lst; char **split; int i; split = ft_strsplit(s, c); if (split == NULL) return (NULL); alst = NULL; i = 0; while (split[i] != NULL) { lst = ft_lstnew(split[i], ft_strlen(split[i]) + 1); if (lst == NULL) return (NULL); ft_lstadd_back(&alst, lst); i++; } ft_free_strsplit(split); return (alst); }
t_list *ft_lststrdsplit_int(char const *str) { t_list *splits; int value; if (isnumeric(*str)) { value = ft_atoi(str); splits = ft_lstnew(&value, sizeof(value)); } else splits = NULL; while (*str) { if (!isnumeric(*str) && isnumeric(str[1])) { str++; value = ft_atoi(str); ft_lstadd_back(&splits, ft_lstnew(&value, sizeof(value))); } str++; } return (splits); }