Minishell 1.0
42 School Minishell Project - A simple shell implementation
Yüklüyor...
Arıyor...
Eşleşme Yok
cleanup.c
Bu dosyanın dokümantasyonuna git.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* cleanup.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: hgenc <hgenc@student.42kocaeli.com.tr> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2026/02/19 14:22:00 by hgenc #+# #+# */
9/* Updated: 2026/02/19 14:22:00 by hgenc ### ########.fr */
10/* */
11/* ************************************************************************** */
12
13/**
14 * @file cleanup.c
15 * @brief Merkezi temizlik sistemi
16 *
17 * Tüm t_shell kaynaklarını serbest bırakır ve temiz çıkış sağlar.
18 * Projedeki tüm exit noktaları shell_exit() üzerinden geçer.
19 */
20
22#include <readline/history.h>
23#include <readline/readline.h>
24#include <stdlib.h>
25
26/**
27 * @brief NULL-terminated string dizisini serbest bırakır
28 * @param arr NULL-terminated string dizisi
29 */
30void free_str_array(char **arr)
31{
32 int i;
33
34 if (!arr)
35 return ;
36 i = 0;
37 while (arr[i])
38 {
39 free(arr[i]);
40 i++;
41 }
42 free(arr);
43}
44
45/**
46 * @brief Tüm t_shell kaynaklarını serbest bırakır
47 * @param shell Shell yapısı pointer'ı
48 *
49 * env_list, token_list, ast_root ve cmd_line temizlenir.
50 */
52{
53 if (!shell)
54 return ;
55 if (shell->env_list)
56 ft_lstclear(&shell->env_list, &free_env_node);
57 if (shell->token_list)
58 ft_lstclear(&shell->token_list, &free_token_content);
59 if (shell->ast_root)
60 {
61 clean_ast(shell->ast_root);
62 shell->ast_root = NULL;
63 }
64 if (shell->cmd_line && shell->cmd_line[0] != '\0')
65 free(shell->cmd_line);
66 shell->cmd_line = NULL;
67}
68
69/**
70 * @brief Shell'i temizleyip programdan çıkar
71 * @param shell Shell yapısı pointer'ı
72 * @param exit_code Çıkış kodu
73 *
74 * cleanup_shell çağırır, readline history'yi temizler ve exit yapar.
75 */
76void shell_exit(t_shell *shell, int exit_code)
77{
78 cleanup_shell(shell);
79 rl_clear_history();
80 exit(exit_code);
81}
void shell_exit(t_shell *shell, int exit_code)
Shell'i temizleyip programdan çıkar.
Definition cleanup.c:76
void free_str_array(char **arr)
NULL-terminated string dizisini serbest bırakır.
Definition cleanup.c:30
void cleanup_shell(t_shell *shell)
Tüm t_shell kaynaklarını serbest bırakır.
Definition cleanup.c:51
void free_env_node(void *content)
Ortam değişkeni node'unu serbest bırakır.
Minishell ana header dosyası
struct s_shell t_shell
void clean_ast(t_ast *node)
AST ağacını recursive olarak temizler.
t_ast * ast_root
Definition minishell.h:150
t_list * token_list
Definition minishell.h:148
char * cmd_line
Definition minishell.h:152
t_list * env_list
Definition minishell.h:149
void free_token_content(void *content)
Definition utils.c:36