forked from denistillwaters/simple_shell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
72 lines (65 loc) · 1.04 KB
/
main.c
File metadata and controls
72 lines (65 loc) · 1.04 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "shell.h"
/**
* spacehandler - This function handles white spaces
* @buf: buffer
* Return: 0 (success)
*/
int spacehandler(char *buf)
{
int i;
for (i = 0; buf[i] != '\0'; i++)
{
if (buf[i] != ' ' && buf[i] != '\t')
{
return (0);
}
}
return (1);
}
/**
* main - SIMPLE SHELL
* @ac: argument count
* @av: argument vector
* Return: returns 0 success
*/
int main(int __attribute__ ((unused)) ac, char **av)
{
ssize_t read;
size_t size = 0;
int count = 0;
char *buf = NULL;
signal(SIGINT, handler);
while (1)
{
if (isatty(STDIN_FILENO))
{
write(STDOUT_FILENO, PROMPT, 4);
fflush(stdout);
}
read = getline(&buf, &size, stdin);
if (read == -1)
{
break;
}
count++;
removechar(buf, '\n');
if (spacehandler(buf) == 1)
continue;
if (_strlen(buf) == 0)
continue;
if (_strcmp(ENVV, buf) == 0)
{
printenv();
continue;
}
analyze(buf, count, av);
size = 0, free(buf);
buf = NULL;
}
if (isatty(STDIN_FILENO))
{
_putchar('\n');
}
free(buf);
return (EXIT_SUCCESS);
}