-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnon_interactive.c
More file actions
62 lines (54 loc) · 998 Bytes
/
non_interactive.c
File metadata and controls
62 lines (54 loc) · 998 Bytes
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
#include "shell.h"
/**
* s_ignore - ignores spaces and newlines
* @str: string
* Return: new string
*/
char *s_ignore(char *str)
{
while (*str == ' ' || *str == '\n')
{
str++;
}
return (str);
}
/**
* non_interactive - handles non interactive shell
* @env: env variables
*/
void non_interactive(list_t *env)
{
size_t i = 0, n = 0;
int line_no = 0, exit_stat = 0;
char *command = NULL, *new = NULL, **com_lines = NULL, **toks = NULL;
i = _getline(&command);
if (i == 0)
{
free(command);
exit(0);
}
new = command;
command = s_ignore(command);
com_lines = _strtok(command, "\n");
if (new != NULL)
free(new);
n = 0;
while (com_lines[n] != NULL)
{
line_no++;
toks = NULL;
toks = _strtok(com_lines[n], " ");
exit_stat = 0;
exit_stat = builtin_c(toks, env, line_no, com_lines);
if (exit_stat)
{
n++;
continue;
}
exit_stat = execute(toks, env, line_no);
n++;
}
sh_free_double_ptr(com_lines);
free_linked(env);
exit(exit_stat);
}