-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbasic_shell2.c
More file actions
60 lines (57 loc) · 1.12 KB
/
basic_shell2.c
File metadata and controls
60 lines (57 loc) · 1.12 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
#include "shell.h"
/**
*signalc - no ctrl c
*@a: not used
**/
void signalc(int a)
{
(void) a;
write(STDOUT_FILENO, "\nGhost-in-the-shell-3 ", 22);
fflush(stdout);
}
/**
* main - shell starting
* @ac: number of arguments
* @argvex: arguments
* Return: Always (0);
**/
int main(int ac, char *argvex[])
{
char *line = NULL;
bus_t bus0 = {0, 0, NULL};
bus_t *bus;
char **argv;
int confg, aux;
unsigned int i = 1;
(void) ac;
aux = cp_env();
if (aux == -1)
return (-1);
bus = &bus0;
if (isatty(STDIN_FILENO))
write(STDOUT_FILENO, "Ghost-in-the-shell-1 ", 21);
signal(SIGINT, signalc);
while ((confg = getstdin(&line)) != -1)
{
ignore_comments(line);
bus->count++;
argv = create_argv(line, confg);
bus->arg0 = argvex[0];
if (argv && argv[0])
{
aux = check_bltin(argv, line, bus);
if (aux != 0)
bus->stat = check_argv(argv, argvex, bus, line);
}
if (isatty(STDIN_FILENO))
write(STDOUT_FILENO, "Ghost-in-the-shell-2 ", 21);
free(line);
for (i = 1; argv && argv[i]; i++)
free(argv[i]);
free(argv);
}
if (isatty(STDIN_FILENO))
printf("\n");
free(line);
return (bus->stat);
}