char *ft_readline(char *prompt, t_hist *hist, int settings) { t_rl rl; char *line; if (rl_init(&rl, hist, settings, prompt) < 0) //Init readline return (NULL); cur_cwrite(rl.prompt, rl.promptsize, ft_strlen(rl.prompt)); //Cwrite the prompt if (readline_loop(&rl) < 0) //Launch the main readline loop until \n, \0 or error occured return (NULL); line = NULL; if (ISIN(rl.bitset, RL_BS_FLUSH) && rl.dyn.used) { line = ft_strjoin(rl.dyn.str, rl.dyn.strend - rl.dyn.post); //Get the line wth the concatenate of the ante cursor buffer and the post cursor buffer if (ISIN(settings, RL_HISTORY)) { if (!(hist->cursor = ft_dlstnew(line, rl.dyn.used + 1))) ft_memdel((void **)&line); else ft_dlstaddn(&hist->list, hist->cursor); //If history handled, add this new entry to it } } rl_destroy(&rl); write(1, "\n", 1); return (line); }
char *ft_readline(char *prompt, t_hist *hist, int settings) { t_rl rl; char *line; if (rl_init(&rl, hist, settings, prompt) < 0) return (NULL); cur_cwrite(rl.prompt, rl.promptsize, ft_strlen(rl.prompt)); if (readline_loop(&rl) < 0) return (NULL); line = NULL; if (ISIN(rl.bitset, RL_BS_FLUSH) && rl.dyn.used) { line = ft_strjoin(rl.dyn.str, rl.dyn.strend - rl.dyn.post); if (ISIN(settings, RL_HISTORY)) { if (!(hist->cursor = ft_dlstnew(line, rl.dyn.used + 1))) ft_memdel((void **)&line); else ft_dlstaddn(&hist->list, hist->cursor); } } rl_destroy(&rl); write(1, "\n", 1); return (line); }
static void add_sprite(t_dlist **list, int sprite, double x, double y) { t_sprite content; content.y = y; content.x = x; content.texture = sprite; ft_dlstadd_end(list, ft_dlstnew(&content, sizeof(t_sprite))); }
static void display_screamer(t_mega *all) { t_sprite content; content.x = 4; content.y = 33.5; content.texture = SCREAM; ft_dlstadd_end(&all->sprites, ft_dlstnew(&content, sizeof(t_sprite))); all->e.refresh = 1; }
int hist_copy(t_hist *hist, t_hist *hist_cp) { hist->cursor = hist->list; while (hist->cursor) { hist_cp->cursor = ft_dlstnew(hist->cursor->content,\ hist->cursor->content_size); if (!hist_cp->cursor) { ft_dlstdel(&hist_cp->list, NULL); return (-1); } ft_dlstaddn(&hist_cp->list, hist_cp->cursor); hist->cursor = hist->cursor->n; } if (!(hist_cp->cursor = ft_dlstnew(NULL, 0))) { ft_dlstdel(&hist_cp->list, NULL); return (-1); } ft_dlstaddn(&hist_cp->list, hist_cp->cursor); return (0); }
static t_dlist *init_list(int ac, char **av) { int i; t_select box; t_dlist *list; i = 1; list = NULL; while (i < ac) { box.str = ft_strdup(av[i]); box.flags = NO_FLAG; ft_dlstadd_end(&list, ft_dlstnew(&box, sizeof(t_select))); i++; } return (list); }
int parse_room(t_lemin_var *var, char **split, t_parser_info *pi) { int len; t_vertex *room; t_dlist *el; len = ft_strarray_len(split); if (!is_room_name_correct(split[0]) && !are_rcoord_correct(split, len)) return (0); if (!(room = create_room())) return (-1); room->n = sumstring(split, len); get_room_coord(split, len, room->rcoord); if (does_room_exist_already(var, room)) return (0); el = ft_dlstnew((void *)room, sizeof(t_vertex)); manage_start_end(var, pi, room, el); ft_dlstadd_last(&(var->rooms), el); var->room_nb++; return (1); }
void insert_sort(char *da_file, t_dlist **files, t_mega *all) { int len; t_dlist *nav; struct stat sb; len = ft_dlstlen(*files); nav = ft_dlstlast(*files); da_file = ft_strjoin(all->p.file, da_file); if (stat(da_file, &sb) != -1 && !(S_ISREG(sb.st_mode) || S_ISDIR(sb.st_mode))) { return ; } while (len > 0) { if (ft_strcmp(nav->content, da_file) < 0) break ; nav = nav->before; len--; } ft_dlstadd_i(files, ft_dlstnew(da_file, (ft_strlen(da_file) + 1)), len); }
t_dlist *makelst(char *path) { char *start; t_dlist *lst; t_dlist *elem; lst = NULL; start = ++path; while (*path) { if (*path == '/') { if (*start != '/') { if (!(elem = ft_dlstnew((void *)start, sizeof(char) * (path - start)))) return (NULL); ft_dlstaddn(&lst, elem); } start = path + 1; } path++; } return (lst); }
void insert_sort(char *da_file, t_dlist **files, char *path) { int len; t_dlist *nav; t_file data; len = ft_dlstlen(*files); nav = ft_dlstlast(*files); data.filename = ft_strdup(da_file); if (path == NULL) data.path = data.filename; else data.path = path_file(path, da_file, 0); if (lstat(data.path, &data.sb) == -1) error(BAD_PATH, data.path); while (len > 0) { if (ft_strcmp(((t_file *)nav->content)->filename, da_file) < 0) break ; nav = nav->before; len--; } ft_dlstadd_i(files, ft_dlstnew(&data, sizeof(t_file)), len); }
t_dlist *cleanlst(t_dlist *e) { if (e->content_size == 1 && *(char *)e->content == '.') return (ft_dlstnew(NULL, 0)); return (ft_dlstnew(e->content, e->content_size)); }