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
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* b_alias_register.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */
/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
#ifdef __linux__
# include <linux/limits.h>
#else
# include <limits.h>
#endif
#include "d_define.h"
#include "s_struct.h"
#include "u_alias.h"
static void b_cpy_alias(char name[], char *ptr, char value[])
{
char *rptr;
char tmp;
rptr = ptr;
while (*rptr != C_NUL && ft_iswhitespace(*rptr) == TRUE)
rptr++;
tmp = *(rptr + ft_strlen(name));
*(rptr + ft_strlen(name)) = C_NUL;
if (ft_strncmp(rptr, name, ft_strlen(name) + 1) == 0) {
*(rptr + ft_strlen(name)) = tmp;
ft_strlcpy(value, ptr, ARG_MAX);
ft_memmove(value + (rptr - ptr) + 1, value + (rptr - ptr),
ft_strlen(value + (rptr - ptr)) + 1);
*(value + (rptr - ptr)) = C_BACKS;
}
else {
*(rptr + ft_strlen(name)) = tmp;
ft_strlcpy(value, ptr, ARG_MAX);
}
}
void b_register_arg(const char arg[], t_msh *msh)
{
char name[255];
char *ptr;
char value[ARG_MAX];
ptr = (char*)arg;
while (*ptr != C_NUL && *ptr != C_EQUALS)
{
ptr++;
}
if (*ptr == C_EQUALS)
{
ft_strlcpy(name, arg, (ptr - arg < 255) ? ((ptr - arg) + 1) : (255));
ptr += 1;
b_cpy_alias(name, ptr, value);
u_set_alias_value(name, value, msh);
}
}
|