t_list *completion_search_in_env(t_comp *comp) { t_env_list *env; t_list *match[2]; char *str; int ret; match[0] = init_variables(&env, &str, comp, &ret); while (env) { if (!(ret = ft_strncmp(str, env->name, ft_strlen(str))) && !match[0]) { if (!(match[0] = ft_lstnew(env->name, ft_strlen(env->name) + 1))) return (clear_matches_and_dir(comp, match[0], NULL)); match[1] = match[0]; } else if (!ret) { if (!(match[1]->next = ft_lstnew(env->name, ft_strlen(env->name) + 1))) return (clear_matches_and_dir(comp, match[0], NULL)); match[1] = match[1]->next; } env = env->next; (ret == 0) ? comp->nb_matches++ : 0; } return (match[0]); }
int save_file(int const fd, t_list **file) { int ret; char buf[BUFF_SIZE]; t_list *beggin; while ((ret = read(fd, buf, BUFF_SIZE)) > 0) { if ((*file)->content) { (*file)->next = ft_lstnew(buf, ret + 1); *file = (*file)->next; } else { *file = ft_lstnew(buf, ret + 1); beggin = *file; } if (buf[ret - 1] == '\n') return (*file = beggin, 1); } if (ret < 0) return (-1); *file = beggin; return (1); }
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem)) { t_list *nlst; t_list *alst; t_list *tmp; t_list *tmp1; if (lst == NULL || f == NULL) return (NULL); tmp = lst; tmp1 = f(tmp); alst = ft_lstnew(tmp1->content, tmp1->content_size); if (alst == NULL) return (NULL); nlst = alst; tmp = tmp->next; while (tmp) { tmp1 = f(tmp); nlst->next = ft_lstnew(tmp1->content, tmp1->content_size); tmp = tmp->next; nlst = nlst->next; } return (alst); }
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem)) { t_list *newlst; t_list *tmp; t_list *newlst2; if (lst == NULL || f == NULL) return (NULL); while (lst != NULL) { tmp = f(lst); if (newlst == NULL) { if (!(newlst = ft_lstnew(tmp->content, tmp->content_size))) return (NULL); lst = lst->next; newlst2 = newlst; } else { if (!(newlst->next = ft_lstnew(tmp->content, tmp->content_size))) return (NULL); newlst = newlst->next; lst = lst->next; } } return (newlst2); }
t_list *map_wires(t_env *e) { t_dot *c; t_list *wires; wires = NULL; c = dot(0, 0, 0); while (c->y < e->max->y) { c->x = 0; while (c->x < e->max->x) { if (c->y + 1 < e->max->y) ft_lstadd(&wires, ft_lstnew(wire(e->map[c->y][c->x], e->map[c->y + 1][c->x]), sizeof(t_wire))); if (c->x + 1 < e->max->x) ft_lstadd(&wires, ft_lstnew(wire(e->map[c->y][c->x], e->map[c->y][c->x + 1]), sizeof(t_wire))); c->x++; } c->y++; } return (wires); }
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem)) { t_list *map; t_list *tmp; t_list *map2; if (lst == NULL) return (NULL); tmp = lst; tmp = f(tmp); if (!(map = ft_lstnew(tmp->content, tmp->content_size))) return (NULL); map2 = map; lst = lst->next; while (lst != NULL) { tmp = lst; tmp = f(tmp); if (!(map->next = ft_lstnew(tmp->content, tmp->content_size))) return (NULL); map = map->next; lst = lst->next; } return (map2); }
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem)) { t_list *srch; t_list *start; t_list *new_lst; if (lst && f) { srch = lst; if ((new_lst = ft_lstnew(f(lst)->content, f(srch)->content_size))) start = new_lst; while (srch->next) { if (srch->next) new_lst->next = ft_lstnew(f(srch->next)->content, f(srch->next)->content_size); else new_lst->next = NULL; new_lst = new_lst->next; if (new_lst == NULL) return (NULL); srch = srch->next; } return (start); } return (NULL); }
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem)) { t_list *result; t_list *tmpresult; t_list *tmplst; if (lst == NULL || f == NULL) return (NULL); tmplst = f(lst); if ((result = ft_lstnew(tmplst->content, tmplst->content_size))) { tmpresult = result; lst = lst->next; while (lst != NULL) { tmplst = (*f)(lst); if (!(tmpresult->next = ft_lstnew(tmplst->content, tmplst->content_size))) return (NULL); tmpresult = tmpresult->next; lst = lst->next; } } return (result); }
int main(int argc, char **argv ) { ls_type lst; t_list *tmp; name_stat *namestat; lst.arg_files = ft_lstnew(0, 0); lst.arg_dir = ft_lstnew(0, 0); if (argc == 1) argv = 0; // ft_display(&sd, &dir); else ft_ls_type(&lst, argc, argv); if (lst.arg_dir->content == NULL && lst.arg_files->content == NULL) readdirectory(&lst, "."); tmp = lst.arg_dir; while (tmp->next != NULL) { namestat = (name_stat*)tmp->content; ft_putendl(namestat->name); tmp = tmp->next; } tmp = lst.arg_files; while (tmp->next != NULL) { namestat = (name_stat*)tmp->content; ft_putendl(namestat->name); tmp = tmp->next; } return (1); }
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); }
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem)) { t_list *result; t_list *ptr; t_list *ptr2; result = NULL; if (lst == NULL || (*f) == NULL) return (NULL); ptr2 = (*f)(lst); if ((result = ft_lstnew(ptr2->content, ptr2->content_size)) != NULL) { ptr = result; lst = lst->next; while (lst != NULL) { ptr2 = (*f)(lst); if (!(ptr->next = ft_lstnew(ptr2->content, ptr2->content_size))) return (NULL); ptr = ptr->next; lst = lst->next; } } return (result); }
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem)) { t_list *new_lst; t_list *tmp; t_list *stock; new_lst = NULL; if (!lst || !f) return (NULL); tmp = f(lst); if ((new_lst = ft_lstnew(tmp->content, tmp->content_size))) { stock = new_lst; lst = lst->next; while (lst) { tmp = f(lst); if (!(stock->next = ft_lstnew(tmp->content, tmp->content_size))) return (NULL); stock = stock->next; lst = lst->next; } } return (new_lst); }
t_list *ft_lstfrom_btree_suffix(t_btree *root) { t_list *lst; t_list *last; if (!root) return (NULL); lst = NULL; if (root->left) lst = ft_lstfrom_btree_suffix(root->left); if (root->right) { if ((last = ft_lstlast(lst))) last->next = ft_lstfrom_btree_suffix(root->right); else { last = ft_lstfrom_btree_suffix(root->right); lst = last; } } if ((last = ft_lstlast(lst))) last->next = ft_lstnew(&root, sizeof(root)); else lst = ft_lstnew(&root, sizeof(root)); return (lst); }
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem)) { t_list *ret; t_list *ret_new; t_list *temp; t_list *lst_new; if (lst == NULL || f == NULL) return (NULL); lst_new = lst; temp = (*f)(lst_new); if ((ret_new = ft_lstnew(temp->content, temp->content_size)) == NULL) return (NULL); ret = ret_new; lst_new = lst_new->next; while (lst_new != NULL) { temp = (*f)(lst_new); ret_new->next = ft_lstnew(temp->content, temp->content_size); if (ret_new->next == NULL) return (NULL); ret_new = ret_new->next; lst_new = lst_new->next; } return (ret); }
t_list *ft_strsplit_to_lst(char const *s, char c) { int i; t_list *lst; int h; t_list *tmp; i = 0; if (!s || c < 0) return (NULL); lst = ft_lstnew(NULL, 0); tmp = lst; while (s[i]) { h = 0; while (s[i] == c) i++; if (!s[i]) break ; while (s[i + h] != c && s[i + h]) h++; lst->content = ft_strsub(s, i, h); lst->next = ft_lstnew(NULL, 0); lst = lst->next; i = i + h; } return (tmp); }
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem)) { t_list *make; t_list *t; t_list *head; if (!lst || !f) return (0); t = f(lst); if (!(make = ft_lstnew(t->content, t->content_size))) return (0); head = make; lst = lst->next; while (lst) { t = f(lst); if (!(make->next = ft_lstnew(t->content, t->content_size))) { ft_lstdel(&head, &f_lstdel); return (0); } make = make->next; lst = lst->next; } return (head); }
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem)) { t_list *buf; t_list *fresh_list; t_list *value; t_list *return_value; if (lst) { buf = f(lst); if (!(fresh_list = ft_lstnew(buf->content, buf->content_size))) return (NULL); return_value = fresh_list; lst = lst->next; while (lst) { buf = f(lst); if (!(value = ft_lstnew(buf->content, buf->content_size))) return (NULL); fresh_list->next = value; fresh_list = fresh_list->next; lst = lst->next; } return (return_value); } return (NULL); }
int uf_test_lstnew(void) { t_list *begin; size_t v; v = 1; begin = ft_lstnew(NULL, 36); if (begin != 0 && (begin->content_size != 0 || begin->content != NULL)) D_ERROR; free(begin); begin = ft_lstnew(&v, sizeof(size_t)); if (begin != NULL) { if (&v == begin->content) D_ERROR; if (*(size_t*)begin->content != 1) D_ERROR; if (begin->content_size != sizeof(size_t)) D_ERROR; if (begin->next != 0) D_ERROR; } free(begin); return (1); }
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem)) { t_list *newlist; t_list *tmp; t_list *next; t_list *tmp2; tmp = lst; newlist = ft_lstnew(tmp->content, tmp->content_size); f(newlist); if (tmp->next != NULL) { tmp = tmp->next; tmp2 = newlist; } while (tmp != NULL) { next = tmp->next; tmp2->next = ft_lstnew(tmp->content, tmp->content_size); tmp = next; f(tmp2->next); tmp2 = tmp2->next; } return (newlist); }
t_list *ft_lstdup(t_list *lst) { t_list *list_cpy; t_list *start; t_list *tmp; start = NULL; if (lst) { list_cpy = ft_lstnew(lst->content, lst->content_size); if (list_cpy) { start = list_cpy; lst = lst->next; while (lst) { tmp = ft_lstnew(lst->content, lst->content_size); if (!tmp) return (NULL); lst = lst->next; list_cpy->next = tmp; list_cpy = list_cpy->next; } } } return (start); }
t_list *ft_search_fd(t_list **begin, int fd) { t_list *next; next = *begin; if (!next) { next = ft_lstnew("\0", 1); next->content_size = fd; ft_lstadd(begin, next); return (next); } else { while (next) { if (next->content_size == (size_t)fd) return (next); next = next->next; } next = ft_lstnew("\0", 1); next->content_size = fd; ft_lstadd(begin, next); return (next); } }
t_list *ft_lstmap(t_list *lst, t_list *(*f) (t_list *elem)) { t_list *brand_new_list; t_list *the_beginning; t_list *tempo; if (f == NULL || lst == NULL) return (NULL); tempo = f(lst); brand_new_list = ft_lstnew(tempo->content, tempo->content_size); if (brand_new_list == NULL) return (NULL); the_beginning = brand_new_list; while (lst->next != NULL) { tempo = f(lst->next); brand_new_list->next = ft_lstnew(tempo->content, tempo->content_size); if (brand_new_list->next == NULL) { ft_lstdel(&the_beginning, &ft_bzero); return (NULL); } lst = lst->next; brand_new_list = brand_new_list->next; } return (the_beginning); }
t_list *ft_splittolst(const char *s, char c) { size_t i; size_t k; t_list *tab; char *tmp; i = 0; k = 0; tmp = NULL; tab = NULL; while (s != NULL && s[i]) { i = k; while (s[i] && k < ft_strlen(s) && s[k] != c) k++; tmp = ft_strsub(s, i, (k - i)); if (tmp != NULL && (k - i) > 0) { if (tab == NULL) tab = ft_lstnew(tmp, ft_strlen(tmp) + 1); else ft_lstpushback(&tab, ft_lstnew(tmp, ft_strlen(tmp) + 1)); } k++; } return (tab); }
int uf_test_lstdel(void) { t_list *begin; size_t v; v = 1; begin = ft_lstnew(&v, sizeof(void *)); begin->next = ft_lstnew(&v, sizeof(void *)); begin->next->next = ft_lstnew(&v, sizeof(void *)); ft_lstdel(&begin, uf_del_callback); if (begin != NULL) D_ERROR; return (1); }
void ft_lstpushback(t_list **list, void *content, size_t size) { t_list *node; node = *list; if (node) { while (node->next) node = node->next; node->next = ft_lstnew(content, size); } else *list = ft_lstnew(content, size); }
void ft_lstpushback(t_list **lst, void const *cont, size_t cont_size) { t_list *list; list = *lst; if (list) { while (list->next) list = list->next; list->next = ft_lstnew(cont, cont_size); } else *lst = ft_lstnew(cont, cont_size); }
void ft_lstpush(t_list **begin, void *content, size_t size) { t_list *list; list = *begin; if (list) { while (list->next) list = list->next; list->next = ft_lstnew(content, size); } else *begin = ft_lstnew(content, size); }
void ft_lstpushback(t_list **alst, char *content) { t_list *tmp; tmp = *alst; if (tmp == NULL) { *alst = ft_lstnew(content); return ; } while (tmp->next) tmp = tmp->next; tmp->next = ft_lstnew(content); }
void ft_lstend(t_list **list, void *content, size_t c_size) { t_list *new_list; new_list = *list; if (new_list) { while (new_list->next != NULL) new_list = new_list->next; new_list->next = ft_lstnew(content, c_size); } else *list = ft_lstnew(content, c_size); }
static void ft_list_push_back(t_list **begin_list, t_list *data) { t_list *tmp; tmp = *begin_list; if (tmp == NULL) *begin_list = ft_lstnew(data->content, data->content_size); else { while (tmp->next != NULL) tmp = tmp->next; tmp->next = ft_lstnew(data->content, data->content_size); } }