int main(int argc, char **argv) { int line_number; int fd; char *line; t_list *tokens; if (argc < 2) fatal_error(RAYTRACER, ERR_TOO_FEW_ARGS, 0); if (argc > 2) fatal_error(RAYTRACER, ERR_TOO_MANY_ARGS, 0); line_number = 1; fd = access_file(argv[1]); while (get_next_line(fd, &line)) { ft_lstappend(&tokens, tokenize(line, line_number)); line_number++; free(line); } if (parse_exp(&tokens) && tokens == NULL) ft_putendl("PARSE WIN"); else { WRITE(2, "Parse fail near : '"); ft_putstr_fd(get_token(&tokens)->lexeme, 2); WRITE(2, "' at line "); ft_putnbr_fd(get_token(&tokens)->line, 2); ft_putchar('\n'); } return (0); }
int ftls_add_entry(t_list **alst, t_env *e, char *name, char *prefix) { struct stat statbuf; char *path; t_entry entry; t_list *lst_ptr; path = (prefix) ? ft_strjoin(prefix, name) : ft_strdup(name); if (ftls_get_file_status(e, &statbuf, &path)) return (1); ftls_copy_details(&entry, &statbuf, name, prefix); if (e->showlist) ftls_copy_details_sub2(e, &entry, &statbuf); ftls_manage_time_ptr(e, &entry); if (ftls_is_entry_showable(e, &entry) && (e->atleastonetoshow = 1)) e->totalblocks += entry.st_blocks; if (e->showlist && ftls_is_entry_showable(e, &entry)) ftls_get_column_metadata(e, &entry); if ((entry.st_mode & S_IFLNK) == S_IFLNK) ftls_get_linktarget(&entry, path); ft_strdel(&path); lst_ptr = ft_lstnew(&entry, sizeof(t_entry)); *alst ? ft_lstappend(alst, lst_ptr) : (*alst = lst_ptr); e->col_len = ft_getmax(e->col_len, ft_getmin(ft_strlen(name), e->termwidth)); return (0); }
int read_line(t_info *info, char *line, int line_nbr) { int i; int valid_label; t_label *temp; i = 0; valid_label = 0; while (line[i] != '\0' && line[i] != COMMENT_CHAR) { if (line[i] == LABEL_CHAR) { temp = check_label(line, i, &valid_label, line_nbr); if (valid_label == -1) return (-1); if (valid_label == 1) { info->num_labels++; ft_lstappend(&info->labels, ft_lstnew((void *)temp)); } } i++; } return (0); }
void rrb(t_algo *algo) { if (algo->stack_b != NULL && algo->stack_b->next != NULL) { ft_lstrotrev(&algo->stack_b, algo->elem_b); ft_lstappend(&algo->operations, ft_lstnew(ft_strdup("rra"))); algo->op_count++; } else ft_putendl_fd("Error : Not enough elements to rev-rotate stack b", 2); }
t_list *tokenize_prompt(t_context *context, char *format) { t_token token; int ret; t_list *tokens; tokens = 0; while ((ret = read_token(&format, &token)) == 1) ft_lstappend(&tokens, ft_lstnew(&token, sizeof(t_token))); if (ret == -1) ft_lstdel(&tokens, free_token); post_process(context, tokens); return (tokens); }
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem)) { t_list *it; t_list *mapped; t_list *res; it = lst; mapped = 0; while (it) { res = f(it); ft_lstappend(&mapped, ft_lstnew(res->content, res->content_size)); it = it->next; } return (mapped); }