Minishell 1.0
42 School Minishell Project - A simple shell implementation
Yüklüyor...
Arıyor...
Eşleşme Yok
error_handling.c
Bu dosyanın dokümantasyonuna git.
2#include <stdlib.h>
3
4int handle_syntax_error(t_shell *shell, char *unexpected_token)
5{
6 ft_putstr_fd("minishell: syntax error near unexpected token `", 2);
7 ft_putstr_fd(unexpected_token, 2);
8 ft_putstr_fd("'\n", 2);
9 shell->exit_status = 2;
10 return (0);
11}
12
13static char *join_free(char *s1, char *s2)
14{
15 char *result;
16
17 if (!s1)
18 return (NULL);
19 result = ft_strjoin(s1, s2);
20 free(s1);
21 return (result);
22}
23
24static char *build_error_msg(char *cmd, char *arg, char *msg)
25{
26 char *buf;
27
28 buf = ft_strdup("minishell: ");
29 if (cmd)
30 {
31 buf = join_free(buf, cmd);
32 buf = join_free(buf, ": ");
33 }
34 if (arg)
35 {
36 buf = join_free(buf, "`");
37 buf = join_free(buf, arg);
38 buf = join_free(buf, "': ");
39 }
40 buf = join_free(buf, msg);
41 buf = join_free(buf, "\n");
42 return (buf);
43}
44
45void shell_error(char *cmd, char *arg, char *msg)
46{
47 char *buf;
48
49 buf = build_error_msg(cmd, arg, msg);
50 if (buf)
51 {
52 ft_putstr_fd(buf, 2);
53 free(buf);
54 }
55}
static char * build_error_msg(char *cmd, char *arg, char *msg)
static char * join_free(char *s1, char *s2)
int handle_syntax_error(t_shell *shell, char *unexpected_token)
void shell_error(char *cmd, char *arg, char *msg)
Minishell ana header dosyası
struct s_shell t_shell
int exit_status
Definition minishell.h:153