blob: a107950a0dcd4d4796d0587c3a233d25d755b8f2 (
plain)
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
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
#include "lsh_main_func.c"
#include "lsh_builtins.c"
typedef struct{
char *prompt;
} SHELL_OB;
void lsh_loop(SHELL_OB *shell_obj)
{
char *line;
char **args;
int status;
do {
printf("%s",shell_obj->prompt);
line = lsh_read_line();
args = lsh_split_line(line);
status = lsh_execute(args);
free(line);
free(args);
} while (status);
}
int main(int argc, char **argv){
SHELL_OB shell_obj;
//get the hostname
char *hostname = (char *)malloc(sizeof(char) * 1024);
gethostname(hostname,sizeof(char) * 1024);
shell_obj.prompt=strcat(strcat(strcat(getenv("USER"), "@"), (char *)hostname), "> ");
lsh_loop(&shell_obj);
free(hostname);
return EXIT_SUCCESS;
}
|