forked from mwanyambu/simple_shell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_input.c
More file actions
47 lines (44 loc) · 709 Bytes
/
get_input.c
File metadata and controls
47 lines (44 loc) · 709 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
#include "main.h"
/**
* get_input - gets user input from a file and executes commands
* @filename: name of the file
* Return: 0 if successful, 1 if an error occurs
*/
int get_input(char *filename)
{
FILE *f = fopen(filename, "r");
char *rd = NULL;
int check = 0;
size_t size = 0;
if (f != NULL)
{
while (_getline(&rd, &size, f) != -1)
{
char **argv = split_input(rd);
if (argv[0] != NULL)
{
if (_strcmp(argv[0], "exit") == 0)
{
check = status(argv);
}
else
{
check = run_builtins(argv);
}
}
free(argv);
if (check != 0)
{
break;
}
}
free(rd);
fclose(f);
}
else
{
perror("get_input");
return (1);
}
return (check);
}