/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* minishell.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: sede-san history_file); while (1) { if (line) free(line); char *prompt = NULL; char *hostname = get_hostname(); if (hostname) { free(hostname); } if (prompt) { line = readline(prompt); free(prompt); } else line = readline("minishell> "); if (!line) { write_history(minishell->history_file); cmd = parse_cmd("exit", minishell); exit_code = exit_builtin(cmd.argc, (const char **)cmd.argv); if (exit_code != -1) break ; } if (*line) { add_history(line); cmd = parse_cmd(line, minishell); free(line); line = NULL; if (ft_strncmp(cmd.argv[0], "exit\0", 5) == 0) { exit_code = exit_builtin(cmd.argc, (const char **)cmd.argv); write_history(minishell->history_file); if (exit_code != -1) break ; } else if (is_builtin(&cmd)) exec_builtin(&cmd, minishell->envp); else exec_cmd(&cmd, minishell->envp); } } write_history(minishell->history_file); rl_clear_history(); if (line) free(line); return (exit_code); } /** * @brief Clears and frees resources associated with a t_minishell instance. * * This function performs the following actions: * - Zeroes out the contents of the history_file string. * - Frees the memory allocated for the history_file. * - Frees the memory allocated for the path array using ft_free_split. * - Zeroes out the entire t_minishell structure. * * @param minishell Pointer to the t_minishell structure to be cleared and * freed. */ static void clear_minishell( t_minishell *minishell ) { ft_bzero(minishell->history_file, ft_strlen(minishell->history_file) * sizeof(char)); free(minishell->history_file); ft_bzero(minishell, sizeof(t_minishell)); }