-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay.c
80 lines (60 loc) · 1.42 KB
/
display.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
68
69
70
71
72
73
74
75
76
77
78
79
#include "functions.h"
void display()
{
char *username = (char*)malloc(1024*sizeof(char));
forn(i) username[i] = '\0';
char *hostname = (char*)malloc(1024*sizeof(char));
forn(i) hostname[i] = '\0';
gethostname(hostname,1024);
getlogin_r(username,1024);
char *dir = (char*)malloc(1024*sizeof(char));
forn(i) dir[i] = '\0';
getcwd(dir,1024);
if(strcmp(dir,root_dir) == 0)
{
printf("\033[1;36m");
printf("%s<%s@%s:",smiley,username,hostname);
printf("\033[0m");
printf("\033[01;33m");
printf("~");
printf("\033[0m");
printf("\033[1;36m");
printf(">");
printf("\033[0m");
}
else if( (strncmp(dir,root_dir,(strlen(root_dir))) == 0) && ((strlen(dir)) > strlen(root_dir)) )
{
char *temp = (char*)malloc(1024*sizeof(char)); forn(i) temp[i] = '\0';
int j = 0;
for(int i=(strlen(root_dir)+1);i<(strlen(dir));i++)
{
temp[j] = dir[i];
// printf("op: %c\n",(char)temp[j]);
j++;
}
printf("\033[1;36m");
printf("%s<%s@%s:",smiley,username,hostname);
printf("\033[0m");
printf("\033[01;33m");
printf("~/%s",temp);
printf("\033[0m");
printf("\033[1;36m");
printf(">");
printf("\033[0m");
}
else
{
printf("\033[1;36m");
printf("%s<%s@%s:",smiley,username,hostname);
printf("\033[0m");
printf("\033[01;33m");
printf("%s",dir);
printf("\033[0m");
printf("\033[1;36m");
printf(">");
printf("\033[0m");
}
free(username);
free(hostname);
free(dir);
}