Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
mysh-1
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
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
NamHwaSu
mysh-1
Commits
d3ab5dad
Commit
d3ab5dad
authored
7 years ago
by
Jaewon Choi
Browse files
Options
Downloads
Patches
Plain Diff
WIP: Support single_command for pipe
parent
d82ac2c4
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/commands.h
+6
-0
6 additions, 0 deletions
include/commands.h
include/utils.h
+7
-1
7 additions, 1 deletion
include/utils.h
src/utils.c
+26
-4
26 additions, 4 deletions
src/utils.c
with
39 additions
and
5 deletions
include/commands.h
+
6
−
0
View file @
d3ab5dad
#ifndef MYSH_COMMANDS_H_
#define MYSH_COMMANDS_H_
struct
single_command
{
int
argc
;
char
**
argv
;
};
/**
do_cd(argc, argv)
...
...
This diff is collapsed.
Click to expand it.
include/utils.h
+
7
−
1
View file @
d3ab5dad
#ifndef MYSH_UTILS_H_
#define MYSH_UTILS_H_
#include
"commands.h"
void
mysh_parse_command
(
const
char
*
command
,
int
*
n_commands
,
struct
single_command
**
commands
);
void
parse_single_command
(
const
char
*
command
,
int
*
argc
,
char
***
argv
);
#endif // MYSH_UTILS_H_
This diff is collapsed.
Click to expand it.
src/utils.c
+
26
−
4
View file @
d3ab5dad
...
...
@@ -4,15 +4,37 @@
#include
<string.h>
void
mysh_parse_command
(
const
char
*
command
,
int
*
n_commands
,
struct
single_command
**
commands
)
{
const
int
kMaxPipes
=
512
;
*
commands
=
(
struct
single_command
*
)
malloc
(
sizeof
(
struct
single_command
)
*
kMaxPipes
);
char
buf
[
4096
];
strcpy
(
buf
,
command
);
char
*
saveptr
=
NULL
;
char
*
tok
=
strtok_r
(
buf
,
"|"
,
&
saveptr
);
int
ti
=
0
;
while
(
tok
!=
NULL
)
{
}
*
n_commands
=
ti
;
}
void
parse_single_command
(
const
char
*
command
,
int
*
argc
,
char
***
argv
)
{
const
int
kMaxArgc
=
512
;
*
argv
=
(
char
**
)
malloc
(
kMaxArgc
);
*
argv
=
(
char
**
)
malloc
(
kMaxArgc
*
sizeof
(
char
*
)
);
char
buf
[
4096
];
strcpy
(
buf
,
command
);
char
*
tok
=
strtok
(
buf
,
"
\n\t
"
);
char
*
saveptr
=
NULL
;
char
*
tok
=
strtok_r
(
buf
,
"
\n\t
"
,
&
saveptr
);
int
ti
=
0
;
...
...
@@ -22,7 +44,7 @@ void mysh_parse_command(const char* command,
++
ti
;
tok
=
strtok
(
NULL
,
"
\n\t
"
);
tok
=
strtok
_r
(
NULL
,
"
\n\t
"
,
&
saveptr
);
}
*
argc
=
ti
;
...
...
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