/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* collect_redirs.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: dkaiser next != NULL) { if (cur->type == REDIR_TOKEN && cur->next->type == STRING_TOKEN) cur = collect_redir(tokens, result, cur); else if (cur->type == REDIR_TOKEN) { printf("Parsing error.\n"); return (free(result), NULL); } else cur = cur->next; } if (cur && cur->type == REDIR_TOKEN) { printf("Parsing error.\n"); return (free(result), NULL); } return (result); } static t_token *collect_redir(t_token **tokens, t_redirection *result, t_token *cur) { set_redir(&result[is_output_redir(cur->content.redir_type)], cur->content.redir_type, cur->next->content.string); cur = cur->next; free_token_and_connect(cur->previous); if (cur->next != NULL) { if (cur->previous == NULL) *tokens = cur->next; cur = cur->next; free_token_and_connect(cur->previous); } else { free_token(cur); return (NULL); } return (cur); } static void set_redir(t_redirection *redir, int type, char *specifier) { redir->type = type; redir->specifier = specifier; } static int is_output_redir(int i) { if (i & (INPUT_FILE | INPUT_LIMITER)) return (0); else if (i & (OUTPUT_APPEND | OUTPUT_OVERRIDE)) return (1); else { panic(UNREACHABLE); return (-1); } }