Skip to content
Snippets Groups Projects
Commit d3ab5dad authored by Jaewon Choi's avatar Jaewon Choi
Browse files

WIP: Support single_command for pipe

parent d82ac2c4
No related branches found
No related tags found
No related merge requests found
#ifndef MYSH_COMMANDS_H_
#define MYSH_COMMANDS_H_
struct single_command
{
int argc;
char** argv;
};
/**
do_cd(argc, argv)
......
#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_
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment