Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Benoit
minishell
Commits
805d63a5
Commit
805d63a5
authored
Jan 21, 2021
by
abenoit
Browse files
move error functions to ft_exit.c
parent
e9aa85a3
Changes
7
Hide whitespace changes
Inline
Side-by-side
Makefile
View file @
805d63a5
...
...
@@ -10,7 +10,6 @@ SRC += parse_input.c
SRC
+=
check_syntax.c
SRC
+=
parse_utils.c
SRC
+=
exec_handler.c
SRC
+=
exec_error.c
#SRC += prepare_args.c
#SRC += test.c #alternative to prepare_args.c
...
...
inc/parsing.h
View file @
805d63a5
...
...
@@ -31,8 +31,7 @@ enum e_state
enum
e_parsing_error
{
NO_ERROR
,
SQUOTE_MISSING
,
SQUOTE_MISSING
=
9
,
DQUOTE_MISSING
,
ESCAPE_NL
,
REDIR_PATH_INVALID
,
...
...
@@ -62,7 +61,7 @@ typedef char *(*t_parse)(t_state_machine *, char *);
/*
** check_syntax.c
*/
int
parsing_error
(
int
err_code
,
int
*
stat_loc
);
int
parsing_error
(
int
err_code
,
t_xe
*
xe
);
int
check_syntax
(
char
*
line
);
/*
...
...
src/execution/exec_error.c
deleted
100644 → 0
View file @
e9aa85a3
#include
"execution.h"
int
exec_error
(
int
err_code
,
t_xe
*
xe
)
{
const
char
*
err_msg
[]
=
{
"HOME not set"
,
"No such file or directory"
};
(
void
)
err_msg
;
ft_putstr_fd
(
"minishell: command error: "
,
STDERR_FILENO
);
ft_putstr_fd
(
err_msg
[
err_code
-
7
],
STDERR_FILENO
);
ft_putchar_fd
(
'\n'
,
STDERR_FILENO
);
// have to set stat_loc as well !!!
if
(
err_code
==
HOME_NOT_SET
)
xe
->
stat_loc
=
1
;
if
(
err_code
==
NO_SUCH_FILE
)
xe
->
stat_loc
=
127
;
if
(
xe
->
child
==
1
)
return
(
CLEAN_EXIT
);
else
return
(
SUCCESS
);
}
src/execution/launch_command.c
View file @
805d63a5
...
...
@@ -188,7 +188,7 @@ int execute_cmd(char **args, char **redir_paths, enum e_redir_op *redir_types,
return
(
MALLOC_ERR
);
ret
=
command
[
cmd_code
](
args
,
xe
);
if
(
ret
>=
HOME_NOT_SET
)
return
(
exec_error
(
ret
,
xe
)
);
return
(
ret
);
free_str_array
(
args
);
return
(
ret
);
}
src/ft_exit.c
View file @
805d63a5
#include
"minishell.h"
#include
"execution.h"
#include
"parsing.h"
#include
<stdio.h>
// perror
void
putstr_stderr
(
const
char
*
str
)
...
...
@@ -10,6 +12,46 @@ void putstr_stderr(const char *str)
}
}
int
parsing_error
(
int
err_code
,
t_xe
*
xe
)
{
const
char
*
err_msg
[
NB_PARSING_ERRORS
]
=
{
"No matching single quote"
,
"No matching double quote"
,
"Multiline inputs are currently not supported"
,
"Redirection path invalid"
,
"No redirection path specified"
,
"Empty command before ; or |"
};
(
void
)
err_msg
;
ft_putstr_fd
(
"minishell: syntax error: "
,
STDERR_FILENO
);
ft_putstr_fd
(
err_msg
[
err_code
],
STDERR_FILENO
);
ft_putchar_fd
(
'\n'
,
STDERR_FILENO
);
xe
->
stat_loc
=
2
;
return
(
SUCCESS
);
}
int
exec_error
(
int
err_code
,
t_xe
*
xe
)
{
const
char
*
err_msg
[]
=
{
"HOME not set"
,
"No such file or directory"
};
(
void
)
err_msg
;
ft_putstr_fd
(
"minishell: command error: "
,
STDERR_FILENO
);
ft_putstr_fd
(
err_msg
[
err_code
-
7
],
STDERR_FILENO
);
ft_putchar_fd
(
'\n'
,
STDERR_FILENO
);
// have to set stat_loc as well !!!
if
(
err_code
==
HOME_NOT_SET
)
xe
->
stat_loc
=
1
;
if
(
err_code
==
NO_SUCH_FILE
)
xe
->
stat_loc
=
127
;
if
(
xe
->
child
==
1
)
return
(
CLEAN_EXIT
);
else
return
(
SUCCESS
);
}
static
const
char
*
err_msg
(
int
err_code
)
{
const
char
*
msg
[]
=
{
...
...
@@ -21,25 +63,29 @@ static const char *err_msg(int err_code)
return
(
msg
[
err_code
]);
}
static
int
err_output
(
enum
e_retcode
err_code
)
static
int
err_output
(
int
err_code
)
{
putstr_stderr
(
"Error
\n
"
);
if
(
err_code
<
=
ARG_ERR
)
if
(
err_code
=
=
ARG_ERR
)
{
putstr_stderr
(
err_msg
(
err_code
-
3
));
putstr_stderr
(
"
\n
"
);
}
else
else
if
(
err_code
<
HOME_NOT_SET
)
perror
(
err_msg
(
err_code
-
3
));
write
(
1
,
"exit
1
\n
"
,
7
);
write
(
1
,
"exit
\n
"
,
7
);
exit
(
EXIT_FAILURE
);
}
int
ft_exit
(
enum
e_retcode
ret
,
t_xe
*
xe
)
{
if
(
ret
>
CLEAN_EXIT
)
if
(
ret
>=
SQUOTE_MISSING
)
// temp
return
(
parsing_error
(
ret
-
9
,
xe
));
else
if
(
ret
>=
HOME_NOT_SET
)
return
(
exec_error
(
ret
-
7
,
xe
));
else
if
(
ret
>
CLEAN_EXIT
)
err_output
(
ret
);
else
if
(
ret
<
CLEAN_EXIT
)
// temp
else
putstr_stderr
(
"ERROR CODE ERROR"
);
// temp
free_str_array
(
xe
->
exported
);
// besoin de free?
free_str_array
(
xe
->
env
);
// besoin de free?
...
...
src/main.c
View file @
805d63a5
...
...
@@ -53,7 +53,7 @@ static int main_loop(t_xe *xe)
if
(
ret
==
SUCCESS
)
{
if
((
ret
=
check_syntax
(
line
))
!=
SUCCESS
)
return
(
parsing_error
(
ret
,
&
(
xe
->
stat_loc
))
);
// necessitates SUCCESS to avoid exiting but needs further error management
return
(
ret
);
// necessitates SUCCESS to avoid exiting but needs further error management
ret
=
handle_execution
(
xe
,
STDIN_FILENO
,
0
);
//printf("ret = %d\n", ret);
free
(
line
);
...
...
@@ -127,7 +127,7 @@ int main(int argc, char **argv, char **env_source)
ret
=
exec_env_init
(
xe
,
env_source
);
if
(
ret
!=
SUCCESS
)
return
(
ft_exit
(
ret
,
xe
));
while
(
ret
=
=
SUCCESS
)
while
(
ret
!
=
CLEAN_EXIT
)
ret
=
main_loop
(
xe
);
}
return
(
ft_exit
(
ret
,
xe
));
...
...
src/parsing/check_syntax.c
View file @
805d63a5
#include
"parsing.h"
int
parsing_error
(
int
err_code
,
int
*
stat_loc
)
{
const
char
*
err_msg
[
NB_PARSING_ERRORS
]
=
{
"=== no error (here for padding) ==="
,
"No matching single quote"
,
"No matching double quote"
,
"Multiline inputs are currently not supported"
,
"Redirection path invalid"
,
"No redirection path specified"
,
"Empty command before ; or |"
};
(
void
)
err_msg
;
ft_putstr_fd
(
"minishell: syntax error: "
,
STDERR_FILENO
);
ft_putstr_fd
(
err_msg
[
err_code
],
STDERR_FILENO
);
ft_putchar_fd
(
'\n'
,
STDERR_FILENO
);
*
stat_loc
=
2
;
return
(
SUCCESS
);
}
void
check_others
(
t_byte
*
flags
,
char
c
)
{
if
(
!
(
ft_isspace
(
c
)))
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment