Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
mysh-0
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jung June Pyo
mysh-0
Commits
0f7560ff
Commit
0f7560ff
authored
Apr 9, 2018
by
Jung June Pyo
Browse files
Options
Downloads
Patches
Plain Diff
final
parent
b91da7f5
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
mysh
+0
-0
0 additions, 0 deletions
mysh
src/commands.c
+26
-6
26 additions, 6 deletions
src/commands.c
src/utils.c
+38
-1
38 additions, 1 deletion
src/utils.c
with
64 additions
and
7 deletions
mysh
0 → 100755
+
0
−
0
View file @
0f7560ff
File added
This diff is collapsed.
Click to expand it.
src/commands.c
+
26
−
6
View file @
0f7560ff
#include
<string.h>
#include
<string.h>
#include
<stdio.h>
#include
"commands.h"
#include
"commands.h"
#include
<unistd.h>
int
do_cd
(
int
argc
,
char
**
argv
)
{
int
do_cd
(
int
argc
,
char
**
argv
)
{
if
(
!
validate_cd_argv
(
argc
,
argv
))
if
(
!
validate_cd_argv
(
argc
,
argv
))
return
-
1
;
return
-
1
;
// TODO: Fill it!
int
i
=
chdir
(
argv
[
1
]);
if
(
i
==
0
)
{
return
0
;
return
0
;
}
}
else
return
-
1
;
}
int
do_pwd
(
int
argc
,
char
**
argv
)
{
int
do_pwd
(
int
argc
,
char
**
argv
)
{
if
(
!
validate_pwd_argv
(
argc
,
argv
))
if
(
!
validate_pwd_argv
(
argc
,
argv
))
...
@@ -16,17 +23,30 @@ int do_pwd(int argc, char** argv) {
...
@@ -16,17 +23,30 @@ int do_pwd(int argc, char** argv) {
// TODO: Fill it!
// TODO: Fill it!
char
buf
[
1000
];
getcwd
(
buf
,
1000
);
printf
(
"%s
\n
"
,
buf
);
return
0
;
return
0
;
}
}
int
validate_cd_argv
(
int
argc
,
char
**
argv
)
{
int
validate_cd_argv
(
int
argc
,
char
**
argv
)
{
// TODO: Fill it!
// TODO: Fill it!
if
(
strcmp
(
argv
[
0
],
"cd"
)
==
0
&&
argc
==
2
)
return
1
;
return
1
;
else
return
0
;
}
}
int
validate_pwd_argv
(
int
argc
,
char
**
argv
)
{
int
validate_pwd_argv
(
int
argc
,
char
**
argv
)
{
// TODO: Fill it!
// TODO: Fill it!
if
(
strcmp
(
argv
[
0
],
"pwd"
)
==
0
&&
argc
==
1
)
return
1
;
return
1
;
else
return
0
;
}
}
This diff is collapsed.
Click to expand it.
src/utils.c
+
38
−
1
View file @
0f7560ff
#include
<stdlib.h>
#include
<stdio.h>
#include
<string.h>
#include
"utils.h"
#include
"utils.h"
void
mysh_parse_command
(
const
char
*
command
,
void
mysh_parse_command
(
const
char
*
command
,
int
*
argc
,
char
***
argv
)
int
*
argc
,
char
***
argv
)
{
{
// TODO: Fill this!
// TODO: Fill this!
int
n
=
0
;
char
*
t
;
char
tmp
[
100
];
*
argc
=
0
;
strcpy
(
tmp
,
command
);
*
argv
=
(
char
**
)
malloc
(
sizeof
(
char
*
)
*
50
);
(
*
argv
)[
n
]
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
50
);
t
=
strtok
(
tmp
,
"
\n\t
"
);
if
(
t
==
NULL
)
{
strcpy
((
*
argv
)[
n
],
""
);
*
argc
=
1
;
return
;
}
while
(
t
!=
NULL
)
{
strcpy
((
*
argv
)[
n
++
],
t
);
(
*
argv
)[
n
]
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
50
);
t
=
strtok
(
NULL
,
"
\n\t
"
);
(
*
argc
)
++
;
}
}
}
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