forked from kevin-gatimu/simple_shell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathengine.c
More file actions
99 lines (86 loc) · 1.45 KB
/
engine.c
File metadata and controls
99 lines (86 loc) · 1.45 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "holberton.h"
/**
* lookforslash - identifies if first char is a slash.
* @cmd: first string
* Return: 1 if yes 0 if no.
*/
int lookforslash(char *cmd)
{
int cont = 0;
while (cmd[cont])
{
if (cmd[0] == '/')
{
printf("%c\n", cmd[0]);
return (1);
}
cont++;
}
return (0);
}
/**
* compareExit - identifies if first char is a slash.
* @s1: first string
* @s2: exit string
* Return: 1 if yes 0 if no.
*/
int compareExit(char *s1, char *s2)
{
int i = 0;
for (; (*s2 != '\0' && *s1 != '\0') && *s1 == *s2; s1++)
{
if (i == 3)
break;
i++;
s2++;
}
return (*s1 - *s2);
}
/**
* compareEnv - identifies if first char is a slash.
* @s1: first string
* @s2: exit string
* Return: 1 if yes 0 if no.
*/
int compareEnv(char *s1, char *s2)
{
int i = 0;
for (; (*s2 != '\0' && *s1 != '\0') && *s1 == *s2; s1++)
{
if (i == 2)
break;
i++;
s2++;
}
return (*s1 - *s2);
}
/**
* identify_string - identyfy keyboard input.
* @parameter: call prompt from another function (prompt)
* Return: str
**/
char **identify_string(char *parameter)
{
char **buf = malloc(1024 * sizeof(char *));
char *split;
int i = 0;
char *delim = " \t\n";
split = strtok(parameter, delim);
while (split != NULL)
{
buf[i] = split;
i++;
split = strtok(NULL, delim);
}
execute_proc(buf);
return (buf);
}
/**
* controlC - avoid close the shell
* @sig: keep going shell
**/
void controlC(int sig)
{
(void) sig;
write(1, "\n$ ", 3);
}