-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtilda.c
41 lines (41 loc) · 1.23 KB
/
tilda.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
void Tilda_or_not(){
char dir[MAX];
if(getcwd(dir,sizeof(dir))==NULL){ // man doc: getcwd returns the abssolute directory path. Returns NULL if error.
return 1;
}
else{
int i;
int match=1;
char curr[]=".";
char * path=realpath(curr,NULL);
for(int k=strlen(path);k>=0;k--){
if(path[k]=='/'){
path[k]='\0';
break;
}
}
if(path==NULL){ // unable to find curr , i.e "./main.c"
printf("Error! Main file has been misplaced -- configuration disturbed !\n");
}
else{
for(i=0;i<strlen(dir) && i<strlen(path);i++){
if(dir[i]!=path[i]){
match=0;
break;
}
}
if(i>=strlen(path) && match){ // match has definitely taken place completely...dir is equal or more than path of main
char new[MAX];
new[0]='~';
for(int j=0;dir[i+j];j++){
new[j+1]=dir[i+j];
}
printf("%s\n",new);
}
else{
printf("%s\n",dir);
}
}
return 0;
}
}