-
Notifications
You must be signed in to change notification settings - Fork 0
/
builtin.c
63 lines (59 loc) · 884 Bytes
/
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
#include "builtin.h"
#include "parse.h"
#include "extern.h"
#include<stdlib.h>
#include<stdio.h>
typedef void(*CMD_HANDLER)(void);
typedef struct builtin_cmd
{
char *name;
CMD_HANDLER handler;
}BUILTIN_CMD;
void do_exit(void);
void do_cd(void);
void do_type(void);
BUILTIN_CMD builtins[]=
{
{"exit",do_exit},
{"cd",do_cd},
{"type",do_type},
{NULL,NULL}
};
//内部命令解析,返回1表示为内部命令
int builtin(void)
{
/*
if(check("exit"))
do_exit();
else if(check("cd"))
do_cd();
else
return 0;
return 1;
*/
int i=0;
int found=0;
while(builtins[i].name!=NULL)
{
if(check(builtins[i].name))
{
builtins[i].handler();
found=1;
break;
}
++i;
}
return found;
}
void do_exit(void)
{
exit(EXIT_SUCCESS);
}
void do_cd(void)
{
printf("cd..\n");
}
void do_type(void)
{
printf("type..\n");
}