-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtokens.c
More file actions
83 lines (73 loc) · 1.98 KB
/
tokens.c
File metadata and controls
83 lines (73 loc) · 1.98 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tokens.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fnagy <fnagy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/17 08:20:08 by elavrich #+# #+# */
/* Updated: 2025/07/31 16:17:23 by fnagy ### ########.fr */
/* */
/* ************************************************************************** */
#include "Minishell.h"
t_token *new_token(char *word, int quoted)
{
t_token *tokens;
tokens = malloc(sizeof(t_token));
if (!tokens)
return (NULL);
tokens->com = ft_strdup(word);
if (!tokens->com)
{
free(word);
return (free(tokens), NULL);
}
tokens->next = NULL;
tokens->quoted = quoted;
return (tokens);
}
void add_token(t_token **head, char *word, int quoted)
{
t_token *new;
t_token *tmp;
new = new_token(word, quoted);
if (!new)
return ;
if (!*head)
*head = new;
else
{
tmp = *head;
while (tmp->next)
tmp = tmp->next;
tmp->next = new;
}
return ;
}
char *handle_var_exit_status(char *cmd, t_shell *shell,
int i, char **suf)
{
char *value;
value = ft_itoa(shell->exit_stat);
*suf = ft_strdup(cmd + (i + 2));
return (value);
}
char *handle_invalid_env(char c)
{
if (c != ' ')
return (ft_strdup(""));
return (ft_strdup("$"));
}
char *handle_valid_env(t_shell *shell, char *prefix)
{
char *env;
char *value;
env = shell->env_var[shell->env_idx];
value = ft_strchr(env, '=');
if (!value)
{
free(prefix);
return (ft_strdup(""));
}
return (ft_strdup(value + 1));
}