-
Notifications
You must be signed in to change notification settings - Fork 0
/
mode.c
76 lines (62 loc) · 1.49 KB
/
mode.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "shell.h"
char **_strtokr(char *str, char *delim);
/**
* interactive - prints prompt ($ ).
*
* Return: void.
*/
void interactive(void)
{
char *stream = NULL;
char *terminal = NULL;/* Interactive command one to tokenize to command two */
char **str = NULL; /* Interactive command two to pass to execve */
int control;
/* char delim[] = {' ', '\n'}; */
do {
prompt();
stream = _getline(); /* command from keyboard */
terminal = strtok(stream, ";"); /* terminal = "ls -l /tmp" */
while (terminal)
{
/* str = {"ls", */
str = _strtok(terminal, " \n"); /* Return an array of strings */
control = executeBuiltins(str);
terminal = strtok(NULL, ";");
}
free(stream);
free_tokens(str);
if (control >= 0)
exit(control);
} while (1);
}
/**
* non_interactive - prints prompt ($ ).
*
* Return: void.
*/
void non_interactive(void)
{
char *stream = NULL;
char *terminal = NULL; /* Non interactive command to tokenize */
char **str = NULL; /* Non interactive command to pass to execve */
int control = -1;
/* char delim[] = {' ', '\n'}; */
do {
prompt();
stream = get_input();
/* printf("Input is %s\n", stream); */
terminal = strtok(stream, ";");
/* printf("First token is %s\n", terminal); */
while (terminal)
{
str = _strtokr(terminal, " \n");
control = executeBuiltins(str);
terminal = strtok(NULL, ";");
}
/* printf(" I is %d\n", i); */
free(stream);
free_tokens(str);
if (control >= 0)
exit(control);
} while (1);
}