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
choi-jun-yong
mysh-0
Commits
f510d5a8
Commit
f510d5a8
authored
7 years ago
by
choi-jun-yong
Browse files
Options
Downloads
Patches
Plain Diff
thank you
parent
f2c8d615
Branches
master
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
+33
-5
33 additions, 5 deletions
src/commands.c
src/utils.c
+30
-3
30 additions, 3 deletions
src/utils.c
with
63 additions
and
8 deletions
mysh
0 → 100755
+
0
−
0
View file @
f510d5a8
File added
This diff is collapsed.
Click to expand it.
src/commands.c
+
33
−
5
View file @
f510d5a8
#include
<string.h>
#include
<string.h>
#include
<stdio.h>
#include
"commands.h"
#include
"commands.h"
#include
<unistd.h>
#define MAX_SIZE 300
char
buf
[
MAX_SIZE
];
int
ch
;
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!
else
if
((
ch
=
chdir
(
argv
[
1
]))
==
0
)
{
return
0
;
return
0
;
}
}
else
{
return
-
1
;
}
// TODO: Fill it!
}
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
))
return
-
1
;
return
-
1
;
getcwd
(
buf
,
MAX_SIZE
);
printf
(
"%s
\n
"
,
buf
);
// TODO: Fill it!
// TODO: Fill it!
return
0
;
return
0
;
...
@@ -22,11 +34,27 @@ int do_pwd(int argc, char** argv) {
...
@@ -22,11 +34,27 @@ int do_pwd(int argc, char** argv) {
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
)
{
if
(
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
)
{
if
(
argc
==
1
)
{
return
1
;
return
1
;
}
}
}
else
return
0
;
}
This diff is collapsed.
Click to expand it.
src/utils.c
+
30
−
3
View file @
f510d5a8
#include
"utils.h"
#include
"utils.h"
#include
<string.h>
#include
<stdlib.h>
void
mysh_parse_command
(
const
char
*
command
,
int
*
argc
,
char
***
argv
)
{
char
*
tmp
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
60
);
char
*
token
;
*
argv
=
(
char
**
)
malloc
(
sizeof
(
char
)
*
60
);
int
c
=
0
;
*
argc
=
0
;
(
*
argv
)[
c
]
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
60
);
strcpy
(
tmp
,
command
);
token
=
strtok
(
tmp
,
"' '
\t\n\0
"
);
void
mysh_parse_command
(
const
char
*
command
,
if
(
token
==
NULL
)
int
*
argc
,
char
***
argv
)
{
strcpy
((
*
argv
)[
c
],
""
);
c
=
c
+
1
;
}
while
(
1
)
{
{
// TODO: Fill this!
if
(
token
==
NULL
)
break
;
strcpy
((
*
argv
)[
c
],
token
);
c
=
c
+
1
;
(
*
argv
)[
c
]
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
60
);
token
=
strtok
(
NULL
,
"' '
\n\t\0
"
);
}
*
argc
=
c
;
}
}
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