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

WIP: move to another machine

parent d3ab5dad
No related branches found
No related tags found
No related merge requests found
......@@ -5,7 +5,7 @@
void mysh_parse_command(const char* command,
int* n_commands,
struct single_command** commands);
struct single_command (*commands)[]);
void parse_single_command(const char* command,
int *argc, char*** argv);
......
......@@ -10,13 +10,25 @@ static void release_argv(int argc, char*** argv);
int main()
{
char buf[8096];
int argc;
char** argv;
while (1) {
fgets(buf, 8096, stdin);
mysh_parse_command(buf, &argc, &argv);
struct single_command commands[512];
int n_commands = 0;
mysh_parse_command(buf, &n_commands, &commands);
for (int i = 0; i < n_commands; ++i) {
struct single_command* com = commands + i;
int argc = com->argc;
char** argv = com->argv;
for (int j = 0; j < argc; ++j) {
printf("%s ", argv[j]);
}
printf("\n");
}
/*
if (strcmp(argv[0], "") == 0) {
goto release_and_continue;
......@@ -39,6 +51,7 @@ release_and_continue:
release_and_exit:
release_argv(argc, &argv);
break;
*/
}
return 0;
......
#include "utils.h"
#define _GNU_SOURCE
#include <stdlib.h>
#include <string.h>
void mysh_parse_command(const char* command,
int* n_commands,
struct single_command** 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);
......@@ -19,6 +17,12 @@ void mysh_parse_command(const char* command,
int ti = 0;
while (tok != NULL) {
struct single_command* com = *commands + ti;
parse_single_command(tok, &com->argc, &com->argv);
++ti;
tok = strtok_r(buf, "|", &saveptr);
}
*n_commands = ti;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment