-
Notifications
You must be signed in to change notification settings - Fork 0
/
built_in.c
67 lines (66 loc) · 1.11 KB
/
built_in.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
65
66
67
#include "all.h"
int cd(char ** args)
{
if(args[1]==NULL)
{
chdir(home);
}
else
{
if(!strcmp(args[1],"~")) chdir(home);
else
{
if(chdir(args[1])) perror("err");
}
}
return 1;
}
int pwd()
{
char* buff = (char*)malloc(200*sizeof(char));
getcwd(buff,200);
printf("%s\n",buff);
free(buff);
return 1;
}
int echo(char** args)
{
for (int i = 1; args[i] != NULL; i++)
{
printf("%s ",args[i]);
}
printf("\n");
return 1;
}
int execute(char **args)
{
if(args[0]==NULL)
{
return 1;
}
if(!strcmp(args[0],"cd"))
{
return cd(args);
}
if(!strcmp(args[0],"pwd"))
{
return pwd();
}
if(!strcmp(args[0],"echo"))
{
return echo(args);
}
else if (!strcmp("pinfo", args[0]))
{
return pinfo(args);
}
else if (!strcmp("ls", args[0]) || !strcmp("l", args[0]))
{
return ls(args);
}
else if (!strcmp("exit", args[0]) || !strcmp("EXIT", args[0]))
{
return 0;
}
return proc_launch(args);
}