-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathroutine_v5.c
More file actions
74 lines (65 loc) · 1.72 KB
/
routine_v5.c
File metadata and controls
74 lines (65 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* routine_v5.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bguzel <bguzel@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/09 18:48:23 by bguzel #+# #+# */
/* Updated: 2023/09/10 12:37:18 by bguzel ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void ft_exit(int i)
{
if (g_var.cmds[i]->str[1] == NULL)
{
printf("exit\n");
leaks_destroyer();
free(g_var.path);
exit(0);
}
else if (str_is_digit(g_var.cmds[i]->str[1])
&& g_var.cmds[i]->str[2] == NULL)
{
printf("exit\n");
g_var.exit_code = ft_atoi(g_var.cmds[i]->str[1]);
leaks_destroyer();
free(g_var.path);
exit(g_var.exit_code);
}
exit_helper(i);
}
void ft_env(void)
{
int i;
i = 0;
while (g_var.env[i])
{
printf("%s\n", g_var.env[i]);
i++;
}
}
void ft_pwd(void)
{
char p[256];
getcwd(p, sizeof(p));
printf("%s\n", p);
}
void ft_cd(int k)
{
char str[128];
getcwd(str, sizeof(str));
if (g_var.cmds[k]->str[1])
cd_helper_v3(k, str);
else
{
cd_helper(str);
cd_tilde(str);
}
}
void print_error(char *str)
{
printf("minishell: %s: command not found\n", str);
g_var.exit_code = 127;
}