t_lst_col *list_calc_cols(t_lst_item *items, t_lst_col *cols) { t_lst_col *col; int height; if ((height = ft_trmheight() - 1) <= 0) { ft_lstdel((t_lst **)&cols, NULL); return (NULL); } col = cols; while (items) { if (!col && (!(col = (t_lst_col *)ft_lstpushback__(sizeof(t_lst_col), (t_lst **)&cols)))) return (NULL); items = calc_col(col, items, height); if (!items && col->next) { ft_lstdel((t_lst **)&col->next, NULL); col->next = NULL; } col = col->next; } return (cols); }
void clean_env(t_env *e) { if (e->list_obj != NULL) ft_lstdel(&(e->list_obj), clean_elem); if (e->list_spot != NULL) ft_lstdel(&(e->list_spot), clean_elem); }
static void free_arg(t_list **lst_f, t_list **lst_d) { if (*lst_f) ft_lstdel(lst_f, (void(*)(void*, size_t))free_content); if (*lst_d) ft_lstdel(lst_d, (void(*)(void*, size_t))free_content); }
int ft_env(t_list *cmd_l, t_list *env_l) { t_list *env_c; char **arg; t_list *unset; int i; int illegal; i = 1; illegal = 0; if (!(start_env(env_l, &env_c, &arg, cmd_l))) return (1); if (!(no_arg_env(arg, &env_c, i))) return (help_env(&env_c)); unset = checkout(arg, &i, env_c, &illegal); if (!(unset_it(unset, &env_c))) return (help_env(&env_c)); get_set(arg, &i, &env_c); if (arg[i]) execute(arg + i, &env_c); else if (!illegal) print_lst(env_c); ft_lstdel(&unset, (void(*)(void*, size_t))del_content); free_tab2d(arg); ft_lstdel(&env_c, (void(*)(void*, size_t))del_content); return (1); }
static int check_list(t_fdf *e, t_list **list) { int i; int j; t_list *tmp; if (!(tmp = my_first_init(e, list, &i))) return (0); while ((j = -1) && tmp) { if (!(e->p[--i] = (t_3d *)malloc((e->npw + 1) * sizeof(t_3d)))) { ft_lstdel(list, &my_lstdel); return (0); } while (((char **)tmp->content)[++j]) { e->p[i][j].z = ft_atoi(((char **)tmp->content)[j]); e->mia = FT_MIN(e->mia, e->p[i][j].z); e->maa = FT_MAX(e->maa, e->p[i][j].z); } while (j < e->npw) e->p[i][j++].z = 0; tmp = tmp->next; } ft_lstdel(list, &my_lstdel); return (1); }
void piles_delete(t_piles **piles) { if (piles && *piles) { ft_lstdel(&(*piles)->a, del); ft_lstdel(&(*piles)->b, del); free(*piles); *piles = NULL; } }
void delete_all(t_list **map, t_room **room, t_chain **network, t_list **cp) { if (map) ft_lstdel(map); if (room) ft_delete_room(room); if (network) ft_delet_network(network); if (cp) ft_lstdel(cp); }
static int minishell(t_sh *sh) { char **cmds; char *cmd; int res; res = 0; ft_putstr("$>"); while (get_next_line(0, &cmd)) { sh->last_res = res; cmd = ft_strfjoin(cmd, " "); cmds = ft_str_to_tab(cmd); res = minishell_boot(sh, sh->env_list, cmds); if (cmd) free(cmd); if (cmds) ft_free_tab(cmds); cmds = NULL; ft_putstr("$>"); } if (sh->env_list) { ft_lstdel(&sh->env_list, &minishell_builtins_unsetenv_free); free(sh->env_list); } return (res); }
int bi_exit(t_av av, t_list **g_env, t_list **g_lenv) { if (*av.arg != NULL && !ft_strisnum(*av.arg)) { if (ft_isdigit(*av.arg[0])) print_error(av, 11); else print_error(av, 10); return (0); } ft_lstdel(g_env, free_env); ft_lstdel(g_lenv, free_env); ret_exit(SET, (av.argv[1] != NULL) ? ft_atoi(av.argv[1]) : 0); *g_exit = (av.argv[1] != NULL) ? (unsigned char)ft_atoi(av.argv[1]) : 0; return (0); }
void ft_lstdel(t_list_libft **alst, void (*del)(void*, size_t)) { if (!alst || !*alst) return ; ft_lstdel(&((*alst)->next), del); ft_lstdelone(alst, del); }
void fill_tab(t_dir *dir) { t_list *cur; int i; i = 0; if (!(dir->tab = (char***)ft_memalloc(sizeof(char**) * dir->filenum + 1))) print_error(NULL); cur = dir->lst_dirent; while (cur && i < dir->filenum + 1) { if (!(dir->tab[i] = (char**)ft_memalloc(sizeof(char*) * 11))) print_error(NULL); if (!(dir->tab[i][0] = ft_strdup(((t_dirent*)cur->content)->d_name))) print_error(NULL); if ((dir->tab[i] = fill_list(dir->tab[i], dir->name, dir))) i++; else { free(dir->tab[i]); dir->filenum--; } cur = cur->next; } ft_lstdel(&dir->lst_dirent, ft_lstdelcontent); }
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_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); }
static int sort_argv(t_list **list, t_arg *arg_list) { t_list *reg_list; bool first; bool alone; first = 1; if (*list != NULL) print_fakelist(list); if (*list != NULL) { reg_list = get_reglist(list); if (reg_list != NULL) { print_ls(reg_list, arg_list); ft_lstdel(®_list, free_list); first = 0; } } alone = 0; if ((*list) != NULL && (*list)->next == NULL) alone = 1; if (*list != NULL) return (base_list(*list, arg_list, alone, first)); else return (0); }
static int my_filllist(t_list **list, int fd) { int i; t_list *tmp; char **ret; char *line; line = NULL; *list = NULL; while ((i = ft_gnl(fd, &line)) > 0) { ret = ft_strsplit(line, ' '); if (!(tmp = (t_list *)malloc(sizeof(t_list)))) { ft_memdel((void **)&ret); ft_lstdel(list, &my_lstdel); return (-2); } tmp->content = ret; tmp->content_size = sizeof(char **); ft_lstadd(list, tmp); } ft_memdel((void **)&line); return (i); }
static t_list *my_first_init(t_fdf *e, t_list **list, int *size) { int i; t_list *tmp; e->nph = 0; tmp = *list; while (tmp) { i = 0; while (((char **)(tmp->content))[i]) i++; e->npw = FT_MAX(e->npw, i); tmp = tmp->next; e->nph++; } if (!(e->p = (t_3d **)malloc((e->nph + 1) * sizeof(t_3d *)))) { ft_lstdel(list, &my_lstdel); return (NULL); } i = 0; *size = e->nph; while (i <= *size) e->p[i++] = NULL; return (*list); }
void ft_lstdel(t_list **alst, void (*del)(void*, size_t)) { if (*alst == NULL || !del) return ; ft_lstdel(&((*alst)->next), del); ft_lstdelone(alst, del); }
void msh_loop(t_config *conf) { int status; char *cmd; t_list **lcmd; t_list *tmp; status = 1; while (1) { ft_putstr("$>"); cmd = msh_read_cmd(); if (!(lcmd = ft_memalloc(sizeof(t_list*)))) exit(msh_error(NULL, NULL, MSH_ERR_MEM)); lcmd = msh_parse(cmd, conf, lcmd); tmp = *lcmd; while (tmp) { status = msh_exec(tmp->content, conf); tmp = tmp->next; } ft_lstdel(lcmd, &msh_lstarray_free); free(lcmd); } }
int tok_list_cons(char *str, t_list **list, t_token *toktab) { int i; int ret; t_token token; i = 0; while (str[i] != '\0') { if (lexer_tab(str + i, toktab, &token) == 1) ; else if ((ret = lexer_isnumber(str + i, &token)) == 1) ; else if ((ret = lexer_isalpha(str + i, &token)) == 1) ; else if (tok_error(str + i, list, &token) == 0) { ft_lstdel(list, NULL); return (0); } if (tokenlst(list, &token) == NULL) return (0); i += token.size; } return (1); }
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem)) { t_list *begin; t_list *add; t_list *tmp; if (!f) return (NULL); add = NULL; begin = lst; while (lst) { tmp = lst; lst = lst->next; if (!(tmp = (*f)(tmp))) { if (begin) ft_lstdel(&begin, &del); break ; } (!add) ? (begin = tmp) : 0; (add) ? (add->next = tmp) : 0; add = tmp; } return (begin); }
void ft_lstdel(t_list **link, void (*del)(void *, size_t)) { if (*link && del) { ft_lstdel(&(*link)->next, (*del)); ft_lstdelone(link, del); } }
void ft_lstdel(t_list **alst, void (*del)(void *, size_t)) { del((*alst)->content, (*alst)->content_size); if ((*alst)->next) ft_lstdel(&(*alst)->next, del); free(*alst); *alst = NULL; }
void ft_lstdel(t_list **alst, void (*del)(void *, size_t)) { if ((**alst).next != NULL) ft_lstdel(&((**alst).next), (*del)); (*del)((**alst).content, (**alst).content_size); free(*alst); *alst = NULL; }
static int reset_buf(t_buffer *buf, char **junk) { ft_lstdel(&buf->chunks, ft_lstfree); if (junk) ft_strdel(junk); buf->size = 0; return (-1); }
void my_lstdel(t_list **alst, void (*del)(void *, size_t)) { if (*alst && del) { ft_lstdel(&(*alst)->next, del); ft_lstdelone(alst, del); } }
void ft_lstdel(t_list **alst, void (*del)(void *, size_t)) { if (*alst) { ft_lstdel(&((*alst)->next), del); ft_lstdelone(alst, del); } }
void ls_file(t_lsprop *prop, t_list **il, int print_title) { if (prop->first_time == 1) ls_first_time(prop, il, print_title); else ls_next_times(prop, il, print_title); ft_lstdel(il, del_t_file_list); }
void ft_lstdel(t_list **alst, void (*del)(void *, size_t)) { if ((*alst)->next != NULL) { ft_lstdel(&(*alst)->next, del); } ft_lstdelone(alst, del); }
void ft_lstdel(t_list **alst, void (*del)(void *, size_t)) { t_list *node; node = (*alst)->next; if (node != NULL) ft_lstdel(&node, del); ft_lstdelone(alst, del); }
void ft_lstdel(t_list **lst, void (*del)(void *, size_t)) { if (!lst) return ; if (!*lst) return ; ft_lstdel(&(*lst)->next, del); ft_lstdelone(lst, del); }