-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdisplay.c
More file actions
45 lines (44 loc) · 1.13 KB
/
display.c
File metadata and controls
45 lines (44 loc) · 1.13 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
#include "custom_header.h"
char * dirName()
{
char *path = (char *)malloc(1000);
getcwd(path,1000);
char *home = getenv("PWD");
if(strlen(path) == strlen(home))
return "~";
else if(strlen(path) >= strlen(home))
{
char *relativePath = (char *)malloc(sizeof(path)+1);
int lenHome = strlen(home);
int lenPath = strlen(path);
relativePath[0]='~';
for(int i=lenHome;i<=lenPath;i++)
relativePath[i-lenHome+1] = path[i];
return relativePath;
}
return path;
}
void display()
{
struct utsname userInfo;
uname(&userInfo);
checkBackgroud();
const char *sys_name = userInfo.sysname;
const char *user_name = getenv("USER");
printf("%s@%s:",user_name,sys_name);
printf("%s",dirName());
printf("%c",'>');
char ** cmd;
CURR_FOREGROUND = -1;
CURR_FOREGROUND_NAME = NULL;
//Signal Handling see signal.h
signal(SIGINT,CtrlCHandler);
signal(SIGTSTP,CtrlZHandler);
cmd = input();
for(int i=0;cmd[i]!=NULL;i++)
{
cmd[i]=parseCommand(cmd[i]);
//execCmd(cmd[i]);
pipeExec(cmd[i]);
}
}