Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Assignment Mini Shell
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
George-Constantin SIMION
Assignment Mini Shell
Commits
716d5459
Commit
716d5459
authored
3 months ago
by
Simion George
Browse files
Options
Downloads
Patches
Plain Diff
DONE
parent
1b332926
No related branches found
No related tags found
No related merge requests found
Pipeline
#98993
passed
3 months ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/cmd.c
+12
-0
12 additions, 0 deletions
src/cmd.c
with
12 additions
and
0 deletions
src/cmd.c
+
12
−
0
View file @
716d5459
...
@@ -68,6 +68,7 @@ static int parse_simple(simple_command_t *s, int level, command_t *father)
...
@@ -68,6 +68,7 @@ static int parse_simple(simple_command_t *s, int level, command_t *father)
shell_exit
();
shell_exit
();
}
else
if
(
strcmp
(
command
,
"cd"
)
==
0
)
{
}
else
if
(
strcmp
(
command
,
"cd"
)
==
0
)
{
/* Saving the old output, redirecting if the case, readjusting the ouput to the old one */
int
save
=
dup
(
STDOUT_FILENO
);
int
save
=
dup
(
STDOUT_FILENO
);
char
*
out
=
get_word
(
s
->
out
);
char
*
out
=
get_word
(
s
->
out
);
int
out_fd
=
open
(
out
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
,
0644
);
int
out_fd
=
open
(
out
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
,
0644
);
...
@@ -83,6 +84,7 @@ static int parse_simple(simple_command_t *s, int level, command_t *father)
...
@@ -83,6 +84,7 @@ static int parse_simple(simple_command_t *s, int level, command_t *father)
return
status
;
return
status
;
}
else
{
}
else
{
/* Getting the environment variable and modifying */
char
*
envir_var
=
get_word
(
s
->
verb
);
char
*
envir_var
=
get_word
(
s
->
verb
);
if
(
strchr
(
envir_var
,
'='
)
!=
NULL
)
{
if
(
strchr
(
envir_var
,
'='
)
!=
NULL
)
{
...
@@ -110,6 +112,7 @@ static int parse_simple(simple_command_t *s, int level, command_t *father)
...
@@ -110,6 +112,7 @@ static int parse_simple(simple_command_t *s, int level, command_t *father)
return
-
1
;
return
-
1
;
}
else
if
(
pid
==
0
)
{
}
else
if
(
pid
==
0
)
{
/* Saving the in */
char
*
in
=
get_word
(
s
->
in
);
char
*
in
=
get_word
(
s
->
in
);
int
in_fd
=
open
(
in
,
O_RDONLY
);
int
in_fd
=
open
(
in
,
O_RDONLY
);
...
@@ -117,6 +120,7 @@ static int parse_simple(simple_command_t *s, int level, command_t *father)
...
@@ -117,6 +120,7 @@ static int parse_simple(simple_command_t *s, int level, command_t *father)
free
(
in
);
free
(
in
);
if
(
s
->
out
!=
NULL
&&
s
->
err
!=
NULL
&&
strcmp
(
get_word
(
s
->
out
),
get_word
(
s
->
err
))
==
0
)
{
if
(
s
->
out
!=
NULL
&&
s
->
err
!=
NULL
&&
strcmp
(
get_word
(
s
->
out
),
get_word
(
s
->
err
))
==
0
)
{
/* For the &> redirection */
char
*
out
=
get_word
(
s
->
out
);
char
*
out
=
get_word
(
s
->
out
);
int
out_fd
;
int
out_fd
;
...
@@ -130,6 +134,7 @@ static int parse_simple(simple_command_t *s, int level, command_t *father)
...
@@ -130,6 +134,7 @@ static int parse_simple(simple_command_t *s, int level, command_t *father)
free
(
out
);
free
(
out
);
}
else
{
}
else
{
/* Opening the out and error if they exists */
if
(
s
->
out
!=
NULL
)
{
if
(
s
->
out
!=
NULL
)
{
char
*
out
=
get_word
(
s
->
out
);
char
*
out
=
get_word
(
s
->
out
);
int
out_fd
;
int
out_fd
;
...
@@ -157,6 +162,7 @@ static int parse_simple(simple_command_t *s, int level, command_t *father)
...
@@ -157,6 +162,7 @@ static int parse_simple(simple_command_t *s, int level, command_t *father)
}
}
}
}
/* Getting the commmand and executing it. If error, exit */
int
argc
=
0
;
int
argc
=
0
;
char
**
argv
=
get_argv
(
s
,
&
argc
);
char
**
argv
=
get_argv
(
s
,
&
argc
);
...
@@ -187,6 +193,7 @@ static bool run_in_parallel(command_t *cmd1, command_t *cmd2, int level,
...
@@ -187,6 +193,7 @@ static bool run_in_parallel(command_t *cmd1, command_t *cmd2, int level,
command_t
*
father
)
command_t
*
father
)
{
{
/* TODO: Execute cmd1 and cmd2 simultaneously. */
/* TODO: Execute cmd1 and cmd2 simultaneously. */
/* Two kids, both executing down the tree command */
pid_t
pid1
=
fork
();
pid_t
pid1
=
fork
();
...
@@ -221,8 +228,11 @@ static bool run_on_pipe(command_t *cmd1, command_t *cmd2, int level,
...
@@ -221,8 +228,11 @@ static bool run_on_pipe(command_t *cmd1, command_t *cmd2, int level,
int
pipefd
[
2
];
int
pipefd
[
2
];
/* Pipe for in - out functionality */
pipe
(
pipefd
);
pipe
(
pipefd
);
/* The first end. Closing the end we do not use, */
/* Pointing the output of the first process to the in of the second */
pid_t
pid1
=
fork
();
pid_t
pid1
=
fork
();
if
(
pid1
==
0
)
{
if
(
pid1
==
0
)
{
...
@@ -235,6 +245,8 @@ static bool run_on_pipe(command_t *cmd1, command_t *cmd2, int level,
...
@@ -235,6 +245,8 @@ static bool run_on_pipe(command_t *cmd1, command_t *cmd2, int level,
exit
(
stat
);
exit
(
stat
);
}
}
/* Second end. */
/* Taking the input from the ouput end of the pipe (reading one) */
pid_t
pid2
=
fork
();
pid_t
pid2
=
fork
();
if
(
pid2
==
0
)
{
if
(
pid2
==
0
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment