forked from cassianokc/gcshell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
builtin.c
51 lines (49 loc) · 1.26 KB
/
builtin.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
45
46
47
48
49
50
51
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "common.h"
int check_builtin(char **arg, size_t size) {
if (strcmp(arg[0], "cd") == 0 && size >= 2) {
chdir(arg[1]);
free_pointer_to_pointers(arg, size);
return SUCESS;
}
if (strcmp(arg[0], "exit") == 0) {
free_pointer_to_pointers(arg, size);
exit(EXIT_SUCCESS);
}
if (strcmp(arg[0], "help") == 0) {
help();
free_pointer_to_pointers(arg, size);
return SUCESS;
}
if (strcmp(arg[0], "jobs") == 0) {
help();
free_pointer_to_pointers(arg, size);
return SUCESS;
}
if (strcmp(arg[0], "bg") == 0) {
help();
free_pointer_to_pointers(arg, size);
return SUCESS;
}
if (strcmp(arg[0], "fg") == 0) {
help();
free_pointer_to_pointers(arg, size);
return SUCESS;
}
return FAILURE;
}
void help(void) {
FILE *readme = fopen("README", "r");
char *read_string = NULL;
size_t input_lenght;
if (readme != NULL) {
while (getline(&read_string, &input_lenght, readme) != FAILURE)
printf("%s", read_string);
fclose(readme);
} else
printf("Couldn't find README.\n");
return;
}