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
Alexandru BRĂSLAŞU
Assignment Mini Shell
Commits
2c9f9573
Commit
2c9f9573
authored
1 year ago
by
Alexandru
Browse files
Options
Downloads
Patches
Plain Diff
Tema4 update words
parent
b625baf5
No related branches found
No related tags found
No related merge requests found
Pipeline
#50367
passed
1 year ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/cmd.c
+17
-54
17 additions, 54 deletions
src/cmd.c
with
17 additions
and
54 deletions
src/cmd.c
+
17
−
54
View file @
2c9f9573
...
...
@@ -61,19 +61,10 @@ static int parse_simple(simple_command_t *s, int level, command_t *father)
// in final returnez ceva (0 sau 1) si trec la urmatoarea comanda
if
(
s
->
verb
&&
s
->
verb
->
next_part
&&
!
strcmp
(
s
->
verb
->
next_part
->
string
,
"="
))
{
word_t
*
p
=
s
->
verb
->
next_part
->
next_part
;
char
str
[
300
],
*
strc
;
while
(
p
)
{
strc
=
str
;
if
(
p
->
expand
)
snprintf
(
str
,
sizeof
(
str
),
"%s%s"
,
strc
,
getenv
(
p
->
string
));
else
snprintf
(
str
,
sizeof
(
str
),
"%s%s"
,
strc
,
p
->
string
);
p
=
p
->
next_part
;
}
char
*
str
=
get_word
(
p
);
int
ret
=
setenv
(
s
->
verb
->
string
,
str
,
1
);
free
(
str
);
if
(
ret
<
0
)
return
1
;
return
0
;
...
...
@@ -96,6 +87,7 @@ static int parse_simple(simple_command_t *s, int level, command_t *father)
return
1
;
if
(
path
[
0
]
==
'\0'
&&
strcmp
(
s
->
verb
->
string
,
"cd"
))
return
1
;
fclose
(
fc
);
/* TODO: If builtin command, execute the command. */
if
(
!
strcmp
(
s
->
verb
->
string
,
"true"
))
...
...
@@ -109,7 +101,6 @@ static int parse_simple(simple_command_t *s, int level, command_t *father)
return
1
;
}
/* TODO: If external command:
* 1. Fork new process
* 2c. Perform redirections in child
...
...
@@ -149,27 +140,13 @@ static int parse_simple(simple_command_t *s, int level, command_t *father)
}
// verific daca iesirea este redirectata
if
(
s
->
out
)
{
char
strOut
[
300
],
*
strcOut
;
// consider si cazul in care fisierul de iesire are variabile de mediu
for
(
word_t
*
pOut
=
s
->
out
;
pOut
;
pOut
=
pOut
->
next_part
)
{
if
(
pOut
->
expand
)
{
char
*
x
=
NULL
;
x
=
getenv
(
pOut
->
string
);
if
(
x
)
{
strcOut
=
strOut
;
snprintf
(
strOut
,
sizeof
(
strOut
),
"%s%s"
,
strcOut
,
x
);
}
}
else
{
strcOut
=
strOut
;
snprintf
(
strOut
,
sizeof
(
strOut
),
"%s%s"
,
strcOut
,
pOut
->
string
);
}
}
char
*
strOut
=
get_word
(
s
->
out
);
if
(
s
->
io_flags
==
IO_OUT_APPEND
||
s
->
err
)
fd_out
=
open
(
strOut
,
O_WRONLY
|
O_CREAT
|
O_APPEND
,
0644
);
else
fd_out
=
open
(
strOut
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
,
0644
);
free
(
strOut
);
if
(
fd_out
<
0
)
exit
(
1
);
dup2
(
fd_out
,
1
);
...
...
@@ -184,55 +161,41 @@ static int parse_simple(simple_command_t *s, int level, command_t *father)
if
(
s
->
err
)
{
dup2
(
fd_stderr
,
2
);
close
(
fd_err
);
close
(
fd_stderr
);
}
if
(
s
->
in
)
{
dup2
(
fd_stdin
,
0
);
close
(
fd_in
);
close
(
fd_stderr
);
}
if
(
s
->
out
)
{
dup2
(
fd_stdout
,
1
);
close
(
fd_out
);
close
(
fd_stdout
);
}
exit
(
ret
);
}
// execut comanda
char
*
args
[
300
],
*
argsc
;
int
i
=
0
;
args
[
i
++
]
=
(
char
*
)
s
->
verb
->
string
;
for
(
word_t
*
p
=
s
->
params
;
p
;
p
=
p
->
next_part
)
{
for
(
word_t
*
q
=
p
;
q
;
q
=
q
->
next_word
)
{
if
(
q
->
expand
)
{
char
*
x
=
NULL
;
x
=
getenv
(
q
->
string
);
args
[
i
++
]
=
x
;
}
else
{
const
char
*
t
=
q
->
string
;
if
(
*
t
==
'\t'
&&
i
>
1
)
{
argsc
=
args
[
i
-
1
];
snprintf
(
args
[
i
-
1
],
sizeof
(
args
),
"%s%s"
,
argsc
,
t
);
}
else
{
args
[
i
++
]
=
(
char
*
)
t
;
}
}
}
}
args
[
i
]
=
NULL
;
execvp
(
s
->
verb
->
string
,
args
);
int
i
;
char
**
argv
=
get_argv
(
s
,
&
i
);
execvp
(
s
->
verb
->
string
,
argv
);
free
(
argv
);
//redirectez stdin, stdout si stderr unde erau initial
if
(
s
->
err
)
{
dup2
(
fd_stderr
,
2
);
close
(
fd_err
);
close
(
fd_stderr
);
}
if
(
s
->
in
)
{
dup2
(
fd_stdin
,
0
);
close
(
fd_in
);
close
(
fd_stderr
);
}
if
(
s
->
out
)
{
dup2
(
fd_stdout
,
1
);
close
(
fd_out
);
close
(
fd_stdout
);
}
if
(
rc
==
false
)
exit
(
1
);
...
...
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