-
Notifications
You must be signed in to change notification settings - Fork 0
/
_main_old
48 lines (45 loc) · 1.39 KB
/
_main_old
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
#include "main.h"
/**
*main - Write a program that prints all the arguments, without using ac.
*@argv: is a NULL terminated array of strings
*@argc: is the number of items in av
*Return: Always 0.
*/
/*int main(int argc __attribute__((unused)), char *argv[])*/
char **array_Of_Words = NULL, *line = NULL, *delim = "\n\t\r\a ";
size_t len = 0;
ssize_t nread;
int file_stat; /*int status, file_stat; */
if (isatty(STDIN_FILENO))
{
_puts("$ ");
while ((nread = getline(&line, &len, stdin)) != -1)
{
if (nread != 1) /*Handle enter pressing*/
{
array_Of_Words = _stringTok(line, delim);
if (_strcmp(array_Of_Words[0], "exit") == 0)
exit_b(array_Of_Words, line);
if (isEnv(array_Of_Words[0]))
{
printf("$ ");
continue; }
file_stat = _stat(array_Of_Words[0]); /*fstat=0? fork:error*/
file_stat == 0 ? _fork(array_Of_Words, argv) :
printf("%s: No such file or directory\n", argv[0]); }
printf("$ "); } }
else
{ /*non interactive mode*/
while (getline(&line, &len, stdin) != -1)
{
array_Of_Words = _stringTok(line, delim);
if (_strcmp(array_Of_Words[0], "exit") == 0)
exit_b(array_Of_Words, line);
if (isEnv(array_Of_Words[0]))
{
printf("$ ");
continue; }
file_stat = _stat(array_Of_Words[0]);
file_stat == 0 ? _fork(array_Of_Words, argv) :
printf("%s:command not found\n", argv[0]); } }
exit_b(array_Of_Words, line);