Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
Os Pa1temp
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
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
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Junho Choi
Os Pa1temp
Commits
88b5d051
Commit
88b5d051
authored
3 years ago
by
9659tig
Browse files
Options
Downloads
Patches
Plain Diff
Final
parent
cdd8c3a8
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
pa1.c
+29
-22
29 additions, 22 deletions
pa1.c
with
29 additions
and
22 deletions
pa1.c
+
29
−
22
View file @
88b5d051
...
...
@@ -46,24 +46,8 @@ typedef struct {
* Return 0 when user inputs "exit"
* Return <0 on error
*/
static
int
run_command
(
int
nr_tokens
,
char
*
tokens
[])
{
int
status
;
int
flag
=
0
,
pipe_index
;
pid_t
child
;
static
void
run_pipe
(
int
pipe_index
,
char
*
tokens
[]){
char
*
pipe1
[
TOKEN_LENGTH
],
*
pipe2
[
TOKEN_LENGTH
];
if
(
strcmp
(
tokens
[
0
],
"exit"
)
==
0
)
return
0
;
for
(
int
i
=
0
;
tokens
[
i
]
!=
NULL
;
i
++
)
{
if
(
!
strcmp
(
tokens
[
i
],
"|"
)){
tokens
[
i
]
=
NULL
;
pipe_index
=
i
;
flag
=
1
;
}
}
if
(
flag
){
for
(
int
i
=
0
;
i
<=
pipe_index
;
i
++
)
pipe1
[
i
]
=
tokens
[
i
];
...
...
@@ -96,7 +80,7 @@ static int run_command(int nr_tokens, char *tokens[])
wait
(
0
);
}
else
if
(
!
strcmp
(
"cd"
,
tokens
[
0
])
||
!
strcmp
(
"history"
,
tokens
[
0
])
||
!
strcmp
(
"!"
,
tokens
[
0
])
){
static
void
cd_history
(
int
nr_tokens
,
char
*
tokens
[
]
){
while
(
nr_tokens
--
){
if
(
!
strcmp
(
"cd"
,
tokens
[
0
])){
if
(
!
tokens
[
1
]
||
!
strcmp
(
"~"
,
tokens
[
1
]))
{
...
...
@@ -127,6 +111,29 @@ static int run_command(int nr_tokens, char *tokens[])
break
;
}
}
static
int
run_command
(
int
nr_tokens
,
char
*
tokens
[])
{
int
status
;
int
flag
=
0
,
pipe_index
;
pid_t
child
;
if
(
strcmp
(
tokens
[
0
],
"exit"
)
==
0
)
return
0
;
for
(
int
i
=
0
;
tokens
[
i
]
!=
NULL
;
i
++
)
{
if
(
!
strcmp
(
tokens
[
i
],
"|"
)){
tokens
[
i
]
=
NULL
;
pipe_index
=
i
;
flag
=
1
;
}
}
if
(
flag
)
run_pipe
(
pipe_index
,
tokens
);
else
if
(
!
strcmp
(
"cd"
,
tokens
[
0
])
||
!
strcmp
(
"history"
,
tokens
[
0
])
||
!
strcmp
(
"!"
,
tokens
[
0
]))
cd_history
(
nr_tokens
,
tokens
);
else
{
child
=
fork
();
while
(
nr_tokens
--
)
...
...
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