#include #include #include #include #include "libft.h" #include "minishell.h" // /** // * @brief Prints the prompt for the Minishell. // * // * This function prints the prompt for the Minishell, which is the current working directory followed by a dollar sign. // * // * @param void // * @return void // */ typedef struct s_enviroment { char *name; char *value; struct s_enviroment *next; } t_enviroment; void add_enviroment(t_enviroment **enviroment, char *name, char *value) { t_enviroment *new_enviroment = malloc(sizeof(t_enviroment)); if (new_enviroment == NULL) { perror("malloc"); return; } new_enviroment->name = name; new_enviroment->value = value; new_enviroment->next = *enviroment; *enviroment = new_enviroment; } void print_enviroment(t_enviroment *enviroment) { while (enviroment != NULL) { printf("%s=%s\n", enviroment->name, enviroment->value); enviroment = enviroment->next; } } char *get_enviroment(t_enviroment *enviroment, char *name) { while (enviroment != NULL) { if (ft_strcmp(enviroment->name, name) == 0) { return enviroment->value; } enviroment = enviroment->next; } return NULL; } void print_prompt(void) { char *cwd = getcwd(NULL, 0); if (cwd == NULL) { perror("getcwd"); return; } printf("%s$ ", cwd); free(cwd); } void print_list(void *content) { t_token *token; token = (t_token *)content; ft_printf("%s\n", token->value); } int main(int argc, char **argv, char **envp) { (void)argc; (void)envp; // char **env; // t_enviroment *enviroment = NULL; t_lexer *lexer; t_list *list; // while (*envp != NULL) // { // env = ft_split(*envp, '='); // add_enviroment(&enviroment, env[0], env[1]); // envp++; // } lexer = ft_lexer_new(argv[1]); list = ft_parse_input(lexer); ft_lstiter(list, print_list); ft_lstclear(&list, ft_clear_tokenlist); ft_lexer_free(lexer); // print_enviroment(enviroment); return 0; }