-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsh_api.c
44 lines (39 loc) · 1002 Bytes
/
jsh_api.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//
// Created by Jerry Zhang on 2020-06-29.
//
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "jsh_api.h"
#include "utils.h"
#include "jsh_config.h"
#include "builtins.h"
#include "SimpleFileSystem/FileSystemAPI.h"
int jsh_read_line(char *buffer, int size) {
return getLine(get_prompt(), buffer, size);
}
char **jsh_split_line(char *line) {
char *separator = " ";
int num_of_token = count_orrurrence(line, separator[0]) + 2;
char **res = malloc(sizeof(char *) * num_of_token);
char *token = strtok(line, separator);
int index = 0;
while (token != NULL) {
res[index++] = token;
token = strtok(NULL, separator);
}
res[index] = NULL;
return res;
}
int jsh_execute(char **args) {
if (args == NULL || args[0] == NULL)
return true;
if (is_builtin(args)) {
return exec_builtin(args);
}
if (is_file_system_api(args)) {
return exec_api(args);
}
return true;
}