int get_next_line(int fd, char **line) { static t_gnldata *data = NULL; t_gnldata *tmp; if (data == NULL) { data = (t_gnldata *)malloc(sizeof(t_gnldata)); ft_bzero(data, sizeof(t_gnldata)); data->fd = fd; return (ft_gnl(fd, line, data)); } else { tmp = data; while (tmp->next != NULL && tmp->fd == fd) tmp = tmp->next; if (tmp->next == NULL && tmp->fd != fd) { tmp->next = (t_gnldata *)malloc(sizeof(t_gnldata)); tmp = tmp->next; } return (ft_gnl(fd, line, tmp)); } }
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 void ft_get_alias_list(void) { int i; int fd; char *tmp; char *path; tmp = ft_strjoin(ft_getenv(g_env.env, "HOME"), "/"); path = ft_strjoin(tmp, ".bashrc"); fd = open(path, O_RDONLY); free(tmp); tmp = NULL; while (ft_gnl(fd, &tmp) > 0) { i = 0; while (*(tmp + i) == ' ' || *(tmp + i) == '\t') i++; if (!ft_strncmp(tmp + i, "alias ", 6)) ft_add_node(tmp + i); } if (g_env.alias_lst) g_env.alias_lst = g_env.alias_lst->start; free(path); free(tmp); }
int ft_get_data(t_hall **hall) { char *note; char *line; int ret; ret = 0; note = NULL; line = NULL; while ((ret = ft_gnl(0, &line)) > 0 && ft_strchr(line, '-') == 0) { if ((ret = get_hall(hall, &line, ¬e)) < 0) return (ret); ft_putstr_double(line, '\n'); ft_clean_str(&line); } if (ret < 1) { if (ret == 0) ret = -2; return (ret); } if (note) ft_clean_str(¬e); if ((ret = get_connect(hall, &line)) < 0) return (ret); return (0); }
static void ft_get_alias_list(void) { int fd; char *tmp; char *path; tmp = ft_strjoin(ft_getenv(g_env.env, "HOME"), "/"); path = ft_strjoin(tmp, ".zshrc"); free(tmp); fd = open(path, O_RDONLY); tmp = NULL; while (ft_gnl(fd, &tmp) > 0) { if (ft_strstr(tmp, "alias")) ft_add_node(tmp); } if (g_env.alias_lst) g_env.alias_lst = g_env.alias_lst->start; }
void get_material_attributes(t_env *e, int fd) { t_split_string attr; char *temp_line; attr.words = 0; e->material[e->materials] = (t_material *)malloc(sizeof(t_material)); init_material(e->material[e->materials]); while (ft_gnl(fd, &temp_line)) { if (temp_line[0] == '\0') break ; attr = ft_nstrsplit(temp_line, '\t'); ft_strdel(&temp_line); if (attr.words < 2) err(FILE_FORMAT_ERROR, "Material attributes", e); set_material_values(e, attr.strings[0], attr.strings[1]); ft_free_split(&attr); } ft_strdel(&temp_line); ++e->materials; }
static void ft_get_history(void) { char *str; int i; str = NULL; while (ft_gnl(g_env.histo_fd, &str) > 0) { i = 0; if (str[i] == ':' && str[i + 1] == ' ' && ft_isdigit(str[i + 2])) { while (ft_strncmp(str + i, ":0;", 3) && str + i) i++; if (str + i == '\0') ft_update_history(str, 1); else ft_update_history(str + i + 3, 1); } else ft_update_history(str, 1); } free(str); }