-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexport_utils.c
More file actions
70 lines (65 loc) · 2.18 KB
/
export_utils.c
File metadata and controls
70 lines (65 loc) · 2.18 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* export_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: astein <astein@student.42lisboa.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/05 14:44:15 by anshovah #+# #+# */
/* Updated: 2023/12/15 14:16:57 by astein ### ########.fr */
/* */
/* ************************************************************************** */
#include "frankenshell.h"
// check if first char is alpha or _
// check if all other chars are alphanum including _
/**
* @brief checks if the 'key' is valid
* - can't be NULL
* - the first char has to be alpha or '_'
* - the rest has to alphanum or '_'
*
* @param key
* @return t_bool
*/
static t_bool validate_key(char *key)
{
if (!key)
return (ft_false);
if (key[0] != '_' && !ft_isalpha(key[0]))
return (ft_false);
key++;
while (*key)
{
if (*key != '_' && !ft_isalnum(*key))
return (ft_false);
key++;
}
return (ft_true);
}
void case_equal_sign(t_mbox *mbox, t_ast *arg_node,
t_bool *fnd_err, char *equal_sign)
{
char *key;
char *value;
key = ft_substr(arg_node->content, 0,
ft_strlen(arg_node->content) - ft_strlen(equal_sign));
value = ft_substr(equal_sign, 1, ft_strlen(equal_sign) - 1);
if (validate_key(key))
set_var_value(mbox, key, value);
else
{
err_msg(mbox, NO_EXIT_STATUS, "nnnnnn", ERR_P, "export: `",
arg_node->content, SQ, CS, NO_VI);
*fnd_err = ft_false;
}
free_whatever("pp", key, value);
}
void case_no_equal_sign(t_mbox *mbox, t_ast *arg_node, t_bool *fnd_err)
{
if (!validate_key(arg_node->content))
{
err_msg(mbox, NO_EXIT_STATUS, "nnnnnn", ERR_P, "export: `",
arg_node->content, SQ, CS, NO_VI);
*fnd_err = ft_false;
}
}