-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandle_s_sep.c
executable file
·58 lines (53 loc) · 1.08 KB
/
handle_s_sep.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
47
48
49
50
51
52
53
54
55
56
57
#include "shell.h"
/**
* handle_s_sep - handle ; separator
* @line: string
* @line_len: integer
* @argv: array of arguments
* @built: struct to handle builtin functions
* @status: integer
*
* Return: 1 if there is the ; separator or 0 if not
*/
int handle_s_sep(char *line, int line_len, char **argv,
Built_fun *built, int *status)
{
int found = 0, i, arg2_0_len;
char **args = NULL, **args2 = NULL;
for (i = 0; i < line_len; i++)
{
if (line[i] == ';')
{
found = 1;
args = split_str(line, ";");
free(line);
if (!args)
exit(EXIT_FAILURE);
i = 0;
while (args[i])
{
args2 = split_str(args[i], " \t");
if (!args2)
{
_free(args);
exit(EXIT_FAILURE);
}
handle_hash(args2);
arg2_0_len = _strlen(args2[0]);
if (_strcmp_(args2[0], "exit") == 0 &&
arg2_0_len == _strlen("exit"))
_free(args);
if (!check_builtin(argv, args2, built, status))
check_command(argv, args2, status);
if (args2)
_free(args2);
i++;
args2 = NULL;
}
if (args)
_free(args);
break;
}
}
return (found);
}