-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxtools.c
109 lines (95 loc) · 1.53 KB
/
xtools.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include "main.h"
/**
* _getenv - gets the path
* @data: a pointer to the struct of data
* @path_name: a path_name
*
* Return: (Success) a positive number
* ------- (Fail) a negative number
*/
char *_getenv(char *path_name, sh_t *data)
{
int i = 0;
char *token;
char *env;
while (environ[i])
{
env = _strdup(environ[i]);
token = strtok(env, "=");
while (token)
{
if (_strcmp(token, path_name) == 0)
{
token = strtok(NULL, "=");
data->env = env;
return (token);
}
token = strtok(NULL, "=");
}
free(env);
i++;
}
return (NULL);
}
/**
* signal_handler - handle the process interrept signal
* @signo: the signal identifier
*
* Return: void
*/
void signal_handler(int signo)
{
if (signo == SIGINT)
{
PRINT("\n");
PRINT(PROMPT);
}
}
/**
* fill_an_array - fill an array with elements
* @a: the given array
* @el: the given element
* @len: the length of the array
*
* Return: pointer to filled array
*/
void *fill_an_array(void *a, int el, unsigned int len)
{
char *p = a;
unsigned int i = 0;
while (i < len)
{
*p = el;
p++;
i++;
}
return (a);
}
/**
* array_rev - reverse array
* @arr: the given array
* @len: the array length
*
* Return: void
*/
void array_rev(char *arr, int len)
{
int i;
char tmp;
for (i = 0; i < (len / 2); i++)
{
tmp = arr[i];
arr[i] = arr[(len - 1) - i];
arr[(len - 1) - i] = tmp;
}
}
/**
* index_cmd - indexed command
* @data: a pointer to the data structure
*
* Return: void
*/
void index_cmd(sh_t *data)
{
data->index += 1;
}