Repository navigation
Expand file tree
/
Copy pathutils.c
More file actions
94 lines (85 loc) · 2.06 KB
/
Copy pathutils.c
File metadata and controls
94 lines (85 loc) · 2.06 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
84
85
86
87
88
89
90
91
92
93
94
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bmachado <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/14 15:54:29 by bmachado #+# #+# */
/* Updated: 2022/02/23 15:43:22 by bmachado ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int is_whitespace(int c)
{
if (c == '\t' || c == '\n' || c == '\r'
|| c == '\v' || c == '\f' || c == ' ')
return (1);
return (0);
}
int get_input(t_shell *shell, char **buff)
{
char *tbuff;
input_signal();
*buff = readline("Minishell %% ");
if (*buff)
{
tbuff = ft_strtrim(*buff, " ");
ft_strcpy(*buff, tbuff);
if (ft_isfilled(tbuff))
add_history(tbuff);
free(tbuff);
return (1);
}
else
{
printf("exit\n");
shell->running = 0;
}
return (0);
}
void send_to_cmd(char **cmds, int i, char *joined_cmd, t_token *tk)
{
if (joined_cmd)
cmds[i] = joined_cmd;
else if (tk->value)
cmds[i] = tk->value;
}
int is_number(char *num)
{
int i;
i = 0;
while (num[i])
{
if (!ft_isdigit(num[i]) && num[i] != '-' && num[i] != '+')
return (0);
i++;
}
return (1);
}
int valid_quote(char *input)
{
int dq;
int q;
int count;
int i;
i = -1;
dq = 0;
q = 0;
count = 0;
while (input[++i])
{
if (input[i] == '\'' && !q && !dq)
q = 1;
else if (input[i] == '\"' && !q && !dq)
dq = 1;
else if (!dq && q && input[i] == '\'')
q = 0;
else if (!q && dq && input[i] == '\"')
dq = 0;
else
continue ;
count++;
}
return (count % 2 == 0);
}