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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* p_line_next.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>
#include <stdlib.h>
#include <stdint.h>
#include "d_enum.h"
#include "s_destroy.h"
#include "f_fail.h"
#include "s_struct.h"
#include "u_vars.h"
#include "u_vars_next.h"
#include "p_lcom_vars.h"
/* TODO: norme : 2 fonctions + de 35l*/
static void
p_register_word(char word[],
t_msh *msh)
{
char name[255];
char val[255];
char *ptr;
size_t i;
name[0] = '$';
ptr = word;
i = 1;
while (*ptr != '=' && *ptr != '\0')
{
name[i] = *ptr;
i++;
ptr++;
}
name[i] = '\0';
ptr++;
i = 0;
while (*ptr != '\0')
{
val[i] = *ptr;
i++;
ptr++;
}
val[i] = '\0';
u_subst_var_value(name, val, msh);
}
static char
**p_add_to_variables_and_delete(char *words[],
t_bool reg,
int64_t i,
t_msh *msh)
{
int64_t j;
int64_t k;
char **rewords;
j = 0;
if (reg == TRUE)
while (words[j] && j < i)
{
p_register_word(words[j], msh);
j++;
}
j = 0;
while (words[i + j] != NULL)
j++;
if (!(rewords = (char**)malloc((j + 1) * sizeof(char*))))
{
ft_delwords(words);
f_alloc_and_destroy_msh(msh);
}
k = i;
while (i - k < j)
{
if (!(rewords[i - k] = ft_strdup(words[i])))
{
ft_delwords(words);
f_alloc_and_destroy_msh(msh);
}
i++;
}
rewords[i - k] = 0;
ft_delwords(words);
return (rewords);
}
char
**p_check_args_equals(char *words[],
t_msh *msh)
{
char *ptr;
t_bool reg;
t_bool isvar;
int64_t i;
i = 0;
reg = FALSE;
isvar = FALSE;
while (words[i])
{
ptr = words[i];
while (*ptr != '\0' && *ptr != '=')
ptr++;
reg = (*ptr == '=') ? TRUE : FALSE;
isvar = (*ptr == '=') ? TRUE : FALSE;
if (*ptr == '\0' || words[i][0] == '=' ||
ft_isdigit(words[i][0]) == TRUE)
{
reg = FALSE;
if (i == 0)
isvar = FALSE;
if (isvar == TRUE)
p_add_to_env_fork(i, words, msh);
else
msh->env_fork_tmp[0][0] = '\0';
break ;
}
i++;
}
if (isvar == TRUE)
return (p_add_to_variables_and_delete(words, reg, i, msh));
return (words);
}
|