-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfill_command_utils.c
More file actions
78 lines (70 loc) · 1.76 KB
/
fill_command_utils.c
File metadata and controls
78 lines (70 loc) · 1.76 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fill_command_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aoutifra <aoutifra@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/06/25 18:52:32 by srachdi #+# #+# */
/* Updated: 2023/07/13 11:38:00 by aoutifra ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int count_until_specials(char *s, int i)
{
while (s[i] && s[i] != ' ' && s[i] != '?' && \
s[i] != '?' && s[i] != '$' && s[i] != '\"' && s[i] != '\'')
i++;
return (i);
}
int letter_count(char *s)
{
int len;
len = 0;
len = ft_strlen(s);
if (!len)
return (1);
while (*s && ft_isspace(*s))
{
s++;
len--;
}
return (len);
}
char *skip_space(char *s)
{
int i;
char *str;
i = 0;
if (letter_count(s) == 0)
return (s);
while (s[i] && ft_isspace(s[i]))
i++;
str = ft_substr(s, i, ft_strlen(s) - i);
if (!str)
return (NULL);
free(s);
return (str);
}
void fill_err(t_cmd *cmd)
{
cmd->heredoc = 0;
if (cmd->in)
free (cmd->in);
cmd->in = NULL;
if (cmd->out)
free (cmd->out);
cmd->out = NULL;
cmd->next = NULL;
}
void free_stuff(char *a, char *b, char *c, char *d)
{
if (a)
free(a);
if (b)
free(b);
if (c)
free(c);
if (d)
free(d);
}