Add semicolumn split
This commit is contained in:
parent
53fc85a9e6
commit
e088bfbac0
17
src/main.c
17
src/main.c
|
@ -7,7 +7,7 @@
|
||||||
int position = 0;
|
int position = 0;
|
||||||
char pwd[128]; // FIXME: change to PATH_MAX
|
char pwd[128]; // FIXME: change to PATH_MAX
|
||||||
|
|
||||||
char **split_line(char *line) {
|
char **split_line(char *line, char *delim) {
|
||||||
int bufsize = 64;
|
int bufsize = 64;
|
||||||
position = 0;
|
position = 0;
|
||||||
char **tokens = malloc(bufsize * sizeof(char*));
|
char **tokens = malloc(bufsize * sizeof(char*));
|
||||||
|
@ -18,11 +18,11 @@ char **split_line(char *line) {
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
token = strtok(line, " ");
|
token = strtok(line, delim);
|
||||||
while (token != NULL) {
|
while (token != NULL) {
|
||||||
tokens[position] = token;
|
tokens[position] = token;
|
||||||
position++;
|
position++;
|
||||||
token = strtok(NULL, " ");
|
token = strtok(NULL, delim);
|
||||||
}
|
}
|
||||||
tokens[position] = NULL;
|
tokens[position] = NULL;
|
||||||
return tokens;
|
return tokens;
|
||||||
|
@ -85,7 +85,7 @@ int parse_command(char **command) {
|
||||||
printf("exit\n");
|
printf("exit\n");
|
||||||
exit(0);
|
exit(0);
|
||||||
} else if (!strcmp(command[0], "echo")) {
|
} else if (!strcmp(command[0], "echo")) {
|
||||||
for (int i = 1; i <= position - 1; i++)
|
for (int i = 1; i <= position - 1; i++)
|
||||||
printf("%s ", command[i]);
|
printf("%s ", command[i]);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -109,6 +109,7 @@ int parse_command(char **command) {
|
||||||
int main() {//int argc, char *argv[]) {
|
int main() {//int argc, char *argv[]) {
|
||||||
char *line = NULL;
|
char *line = NULL;
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
|
char** commands;
|
||||||
char** args;
|
char** args;
|
||||||
int status = 0; // FIXME
|
int status = 0; // FIXME
|
||||||
int command_status = 0; // FIXME
|
int command_status = 0; // FIXME
|
||||||
|
@ -121,9 +122,13 @@ int main() {//int argc, char *argv[]) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
line[strlen(line) - 1] = '\0';
|
line[strlen(line) - 1] = '\0';
|
||||||
args = split_line(line);
|
commands = split_line(line, ";");
|
||||||
|
int after_parse_position = position; // To know where we in ; list FIXME
|
||||||
|
for (int i = 0; i <= after_parse_position - 1; i++) {
|
||||||
|
args = split_line(commands[i], " ");
|
||||||
|
|
||||||
command_status = parse_command(args);
|
command_status = parse_command(args);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return command_status;
|
return command_status;
|
||||||
|
|
Loading…
Reference in New Issue