-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.c
46 lines (45 loc) · 778 Bytes
/
main.c
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
#include "hsh.h"
/**
* main - start to play
* @ac: argc count.
* @av: argv array.
* Return: status code
*/
int main(int ac, char **av)
{
char *line = NULL;
char **lines = NULL;
info_t info[] = {INFO_INIT};
int flaqread = 0;
info->fname = av[0];
if (ac == 2)
{
info->readfd = open_file(info, av[1], 0);
if (info->readfd == -1)
exit(info->err_num);
else
flaqread = 1;
}
signal(SIGINT, sigint_handler);
while (info->condition)
{
if (flaqread == 1)
{
line = __getline(info->readfd);
if (!line)
break;
}
else
{
write(STDIN_FILENO, "$ ", 2);
line = reading();
}
identifydelim(info, line);
lines = cutting(line);
checkone(info, lines);
restore_std_in_out(info);
free(line);
free(lines);
}
return (EXIT_SUCCESS);
}