int get_next_line(int const fd, char ** line) { int ret_read; char *buff; static char *rest = NULL; int ifretline; ret_read = 0; ifretline = 0; if ((buff = (char*)malloc(512)) == NULL || (*line = ft_memalloc(1)) == NULL) return (-1); if (!rest) rest = ft_memalloc(1); if (*rest != '\0' && ft_strchr(rest, '\n')) { manager_buffer(&buff, &rest, line, &ifretline); return (1); } while (ifretline == 0 && (ret_read = read(fd, buff, 512))) { buff[ret_read] = '\0'; manager_read(&buff, &rest, line, &ifretline); } if (buff[0] == '\0' && rest[0] != '\0' && ret_read == 0) return (last_tring(&rest, &buff)); return (ret_read = (*line[0] == '\0' ? 0 : 1)); }
void main_process(t_struct *st, char *txt, va_list *list) { int old_pos; int new_pos; int size_str; init_buf(st, txt); size_str = my_strlen(txt); for (old_pos = 0; old_pos < size_str; old_pos = new_pos) { new_pos = get_pos_substring(st, txt, old_pos); manager_buffer(st, txt + old_pos, new_pos - old_pos); call_select_var(st, list, txt, &new_pos); } }