forked from kevin-gatimu/simple_shell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprompt.c
More file actions
47 lines (45 loc) · 1.1 KB
/
prompt.c
File metadata and controls
47 lines (45 loc) · 1.1 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
46
47
#include "holberton.h"
/**
* prompt - call prompt from another function (prompt)
*
**/
void prompt(void)
{
for (;;)
{
char *text = NULL, **environ;
pid_t child_pid;
int status, lenbuf;
size_t bufsize = 0;
place("$ ");
lenbuf = getline(&text, &bufsize, stdin);
if (lenbuf == -1)
exit(98);
if (compareExit(text, "exit") == 0)
exit(0);
if (compareEnv(text, "env") == 0)
{
while (*environ != NULL)
{
if (!(_strcmpdir(*environ, "USER")) ||
!(_strcmpdir(*environ, "LANGUAGE")) ||
!(_strcmpdir(*environ, "SESSION")) ||
!(_strcmpdir(*environ, "COMPIZ_CONFIG_PROFILE")) ||
!(_strcmpdir(*environ, "SHLV")) ||
!(_strcmpdir(*environ, "HOME")) ||
!(_strcmpdir(*environ, "C_IS")) ||
!(_strcmpdir(*environ, "DESKTOP_SESSION")) ||
!(_strcmpdir(*environ, "LOGNAME")) ||
!(_strcmpdir(*environ, "TERM")) ||
!(_strcmpdir(*environ, "PATH")))
{
place(*environ), place("\n"); }
environ++; }}
child_pid = fork();
if (child_pid < 0)
perror("Error");
if (child_pid == 0)
identify_string(text);
else
wait(&status);
}}