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
74ae5b70
Commit
74ae5b70
authored
Jan 21, 2021
by
abenoit
Browse files
Merge branch 'master' of
https://framagit.org/abenoit/minishell
parents
07f02763
ad56770d
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/execution/launch_command.c
View file @
74ae5b70
...
...
@@ -186,7 +186,7 @@ int execute_cmd(char **args, char **redir_paths, enum e_redir_op *redir_types,
if
(
cmd_code
==
M_ERROR
)
return
(
MALLOC_ERR
);
ret
=
command
[
cmd_code
](
args
,
xe
);
if
(
ret
>
GNL_ERR
)
if
(
ret
>
=
HOME_NOT_SET
)
return
(
exec_error
(
ret
-
7
));
free_str_array
(
args
);
return
(
ret
);
...
...
src/main.c
View file @
74ae5b70
...
...
@@ -6,6 +6,7 @@
#include
<sys/types.h>
// waitpid
#include
<sys/wait.h>
// waitpid
#include
<fcntl.h>
static
int
handle_eof
(
char
**
line
,
int
ret
)
{
...
...
@@ -81,6 +82,20 @@ int exec_env_init(t_xe *xe, char **env_source)
return
(
SUCCESS
);
}
int
read_from_file
(
t_xe
*
xe
,
char
**
argv
)
{
int
fd
;
int
flags
;
flags
=
O_RDONLY
;
fd
=
open
(
argv
[
1
],
flags
);
if
(
fd
<
0
)
return
(
-
1
);
dup2
(
fd
,
STDIN_FILENO
);
xe
->
backup_stdin
=
dup
(
STDIN_FILENO
);
return
(
SUCCESS
);
}
int
main
(
int
argc
,
char
**
argv
,
char
**
env_source
)
{
int
ret
;
...
...
@@ -94,8 +109,17 @@ int main(int argc, char **argv, char **env_source)
ft_bzero
(
xe
,
sizeof
(
t_xe
));
if
(
xe
==
NULL
)
ret
=
MALLOC_ERR
;
else
if
(
argc
!=
1
)
else
if
(
argc
>
2
)
ret
=
ARG_ERR
;
else
if
(
argc
==
2
)
{
ret
=
exec_env_init
(
xe
,
env_source
);
ret
=
read_from_file
(
xe
,
argv
);
if
(
ret
!=
SUCCESS
)
return
(
ft_exit
(
ret
,
xe
));
while
(
ret
==
SUCCESS
)
ret
=
main_loop
(
xe
);
}
else
{
signal_handler
();
// err?
...
...
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