-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd_cd.c
More file actions
45 lines (45 loc) · 745 Bytes
/
cmd_cd.c
File metadata and controls
45 lines (45 loc) · 745 Bytes
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
#include "headerFiles.h"
void cmd_cd(){
char tempdir[10000];
strcpy(tempdir,currdir);
char* tok;
tok = strtok(s," ");
if(strcmp(tok,"cd")==0)
{
tok = strtok(0," ");
if(tok==NULL){
chdir(homedir);
}
else if(strcmp(tok,".")==0){
chdir(currdir);
}
else if(strcmp(tok,"..")==0){
chdir("..");
}
else if(strcmp(tok,"-")==0){
chdir(prevdir);
}
else if(tok[0]=='~')
{
char temp[10000];
strcpy(temp,homedir);
if(sizeof(tok)>1)
strcat(temp,&tok[1]);
if(chdir(temp)!=0) perror(temp);
}
else{
if(chdir(tok)!=0)
{
perror(tok);
}
}
stx=1;
}
getcwd(name,100*sizeof(char));
strcpy(currdir,name);
if(strcmp(currdir,tempdir)!=0)
{
strcpy(prevdir,tempdir);
}
strcpy(s,s_save);
}