-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
57 lines (48 loc) · 917 Bytes
/
main.c
File metadata and controls
57 lines (48 loc) · 917 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
46
47
48
49
50
51
52
53
54
55
56
57
#include "header.h"
char *dir;//current working directory
char username[80],host[40];
void loop(void){
char *line;
int status;
do{
printf("<%s@%s:%s>",username,host,dir);
line=read_line();
char *myline;
status=split_command(line);//this function also executes command
free(line);
//signal handling
signal(SIGINT,ctrlC);
signal(SIGQUIT,ctrlD);
}while(status);
}
void getdirectory(){
char thishome[20]="myshell";
char Dir[200];
getcwd(Dir,200);
dir=strstr(Dir,thishome);
//if dir=home
if(strcmp(dir,thishome)==0)
dir="~";
else{
char *temp=strtok(dir,thishome);
strcpy(dir,"~");
strcat(dir,temp);
}
}
void prompt(){
//username
struct passwd *p=getpwuid(getuid());
strcpy(username,p->pw_name);
//hostname
gethostname(host,40);
//get current working directory
getdirectory();
}
int main(int argc, char **argv)
{
//prompt
prompt();
//command loop
loop();
return 0;
}