-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathms_print_errors_utils.c
135 lines (128 loc) · 3.62 KB
/
ms_print_errors_utils.c
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ms_print_errors_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dlana <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/11 18:22:14 by obeedril #+# #+# */
/* Updated: 2022/03/14 16:08:16 by dlana ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int ms_print_errors_chfa(char *str, int flag)
{
if (flag == 1 || flag == ERR_CMD)
{
ft_putstr_fd("MiMishell: ", 2);
ft_putstr_fd(str, 2);
ft_putstr_fd(": command not found\n", 2);
}
if (flag == 2)
{
ft_putstr_fd("MiMishell: ", 2);
ft_putstr_fd(str, 2);
ft_putstr_fd(": is a directory\n", 2);
}
if (flag == 3)
{
ft_putstr_fd("MiMishell: ", 2);
ft_putstr_fd(str, 2);
ft_putstr_fd(": permission denied\n", 2);
}
if (flag == 4)
{
ft_putstr_fd("MiMishell: ", 2);
ft_putstr_fd(str, 2);
ft_putstr_fd(": no such file or directory\n", 2);
}
return (-1);
}
void ms_print_error_builtin(char *str, int flag)
{
if (flag == 1)
ft_putstr_fd("Mimishell: cd: OLDPWD not set\n", 2);
if (flag == 2)
{
ft_putstr_fd("Mimishell: cd: -", 2);
ft_putstr_fd(str, 2);
ft_putstr_fd(": invalid option\n", 2);
ft_putstr_fd("cd: usage: cd [-L|-P] [dir]\n", 2);
}
if (flag == 3)
{
ft_putstr_fd("Mimishell: cd: ", 2);
ft_putstr_fd(str, 2);
ft_putstr_fd(": no such file or directory\n", 2);
}
if (flag == 4)
{
ft_putstr_fd("\bexit\n", 2);
ft_putstr_fd("Mimishell: exit: ", 2);
ft_putstr_fd(str, 2);
ft_putstr_fd(": numeric argument required\n", 2);
}
if (flag == 5)
ft_putstr_fd("\bexit\nMimishell: exit: too many arguments\n", 2);
}
int ms_error(int error, char *str)
{
if (error == ERR_TOKEN && (str[0] == 34 || str[0] == 39))
{
ft_putstr_fd("Mimishell: unexpected EOF while ", 2);
ft_putstr_fd("looking for matching '", 2);
ft_putstr_fd(str, 2);
ft_putstr_fd("'\n", 2);
}
else if (error == ERR_TOKEN)
{
ft_putstr_fd("Mimishell: syntax error near unexpected token '", 2);
ft_putstr_fd(str, 2);
ft_putstr_fd("'\n", 2);
}
else if (error == ERR_Q_MARK)
write(2, "Mimisell: skipped quotation_marks\n", 35);
else if (error == ERR_NUM_ONE && str[0] == '!')
{
ft_putstr_fd("Mimishell: ", 2);
ft_putstr_fd(str, 2);
ft_putstr_fd(": event not found\n", 2);
}
return (-1);
}
int ms_error_2(int error, int qm)
{
char a;
a = qm;
if (error == ERR_TOKEN && qm == 34)
{
ft_putstr_fd("Mimishell: unexpected EOF while ", 2);
ft_putstr_fd("looking for matching '", 2);
write(2, &a, 1);
ft_putstr_fd("'\n", 2);
}
if (error == ERR_TOKEN && qm == 39)
{
ft_putstr_fd("Mimishell: unexpected EOF while ", 2);
ft_putstr_fd("looking for matching '", 2);
write(2, &a, 1);
ft_putstr_fd("'\n", 2);
}
return (-1);
}
int ms_err_export(int error, char *str, char *cmd)
{
if (error == ERR_NUM_ONE && cmd[0] == 'e')
{
ft_putstr_fd("Mimishell: export: '", 2);
ft_putstr_fd(str, 2);
ft_putstr_fd("': not a valid identifier\n", 2);
}
if (error == ERR_NUM_ONE && cmd[0] == 'u')
{
ft_putstr_fd("Mimishell: unset: '", 2);
ft_putstr_fd(str, 2);
ft_putstr_fd("': not a valid identifier\n", 2);
}
return (-1);
}