-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuiltin.c
64 lines (54 loc) · 1.21 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
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "builtin.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "basics.h"
/*
* builtin function as char array , for show in help and get by name
*/
char *builtin_str[] = {
"cd",
"help",
"exit"
};
/*
* List of builtin commands, followed by their corresponding functions.
*/
int (*builtin_func[])(char **) = {
&lash_cd,
&lash_help,
&lash_exit
};
int lash_num_builtins() {
return sizeof(builtin_str) / sizeof(char *);
}
/*
* Builtin function implementations.
*/
int lash_cd(char **args) {
if (args[1] == NULL) {
fprintf(stderr, "lash: expected argument to \"cd\"\n");
} else {
if (chdir(args[1]) != 0) {
perror("lash");
}
}
return 1;
}
int lash_help(char **args) {
int i;
printl(
"author : \n\tpms (parsa mahmoudy sahebi || parsa011)\nContributors : \n\tAli (alichraghi)\n"
"Type program names and arguments, and hit enter.\n"
"The following are built in:"
);
for (i = 0; i < lash_num_builtins(); i++) {
printl(builtin_str[i]);
}
printl("Use the man command for information on other programs.");
return 1;
}
int lash_exit(char **args) {
exit(0);
return 0;
}