-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcall_cd.c
More file actions
90 lines (75 loc) · 1.5 KB
/
call_cd.c
File metadata and controls
90 lines (75 loc) · 1.5 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include"global.h"
void call_cd(char **karsh,char *dir,int time,int freq)
{
int y;
if(time==-1 || freq==-1)
{
time=0;
freq=0;
y=1;
}
else
{
y = (freq/time);
}
int ii=0;
while(ii<y)
{sleep(time);
if(karsh[1]!=NULL)
{
char temp[1000];
if(strcmp(karsh[1],"-")==0)
{
strcpy(temp,prev1);
getcwd(prev1,1000);
chdir(temp);
return ;
}
}
getcwd(prev1,1000);
if(karsh[1]==NULL)
{
if(chdir(dir)==0)
{
}
else
{
perror("Cannot access");
}
}
else if(karsh[1][0]=='~')
{
int len2 = strlen(karsh[1]);
char d[100];
strcpy(d,dir);
int len3 = strlen(d);
for(int i=1;i<len2;i++)
{
len3++;
d[len3-1]=karsh[1][i];
}
if(chdir(d)!=0)
{
perror("Cannot access");
}
}
else if(strcmp(karsh[1],"~")==0)
{
if(chdir(dir)!=0)
{
perror("Cannot access");
}
}
else
{
if(chdir(karsh[1])!=0)
{
perror("Cannot access");
}
}
int xxx=freq-(time*(ii+1));
if(xxx<time)
sleep(xxx);
ii++;
}
}