-
Notifications
You must be signed in to change notification settings - Fork 0
/
print_home.c
43 lines (43 loc) · 1.27 KB
/
print_home.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
#include"header.h"
#include"variables.h"
void printhome()
{
char pwd[2000], host_name[2000], *username;
gethostname(host_name,sizeof(host_name));
username = (char *)malloc(200*sizeof(char));
cuserid(username);
getcwd(pwd,sizeof(pwd));
printf(KGRN "%s@%s:" RESET,username,host_name);
int i=0, count = 0;
i = 0;
char *home = HOME;char pwd2[2000];
count = strlen(home);home[count] = '\0'; // This had to be written as \0 was not present at last.
strcpy(pwd2, pwd);pwd2[count] = '\0';
if(string_compare(pwd2, home)){
if(strlen(home) == strlen(pwd)){
printf(KBLU "[~]> " RESET);
}
else{
printf(KBLU "[~/");
while (pwd[i])
{
if (i > count)
printf("%c",pwd[i]);
i++;
}
printf("]> " RESET);
}
}
else{
printf(KBLU "[");
printf("%s", pwd);
printf("]> "RESET);
}
/*This piece of code needs to run every time to check which job quits*/
for(i = 0;i < background_jobs; i++){
if(kill(job[i].pid, 0) == 0)
job[i].flag = 1; // means it is running
else
job[i].flag = 0; // means it is stopped
}
}