-
Notifications
You must be signed in to change notification settings - Fork 0
/
dollarexport.c
92 lines (85 loc) · 1.82 KB
/
dollarexport.c
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* dollarexport.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fvieira <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/28 22:09:06 by fvieira #+# #+# */
/* Updated: 2023/03/28 22:09:10 by fvieira ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int between2(const char *str, int pos)
{
int temp;
int flag;
int c;
temp = -1;
flag = 1;
c = -1;
while (str[++c] && c <= pos)
{
if (temp >= 0 && str[c] == str[temp])
{
temp = -1;
flag = 1;
continue ;
}
if (str[c] == 39 && temp == -1)
{
temp = c;
flag = 0;
}
}
if (flag == 1)
return (1);
return (0);
}
int count_words2(char const *s, char *c)
{
int words;
int i;
int j;
words = 1;
i = 0;
while (s[i])
{
j = 0;
while (j < 3)
{
if (s[i] == c[j] && i > 0 && s[i - 1] != c[0]
&& s[i - 1] != c[1] && s[i - 1] != c[2])
{
if (between2(s, i) == 1)
{
words++;
break ;
}
}
j++;
}
i++;
}
return (words);
}
int validate_variables(char *str, int flag)
{
int i;
i = 0;
if (!str)
return (1);
while (str[i])
{
if (!ft_isalpha(str[i]) && str[i] != '_')
{
if (flag)
free(str);
return (0);
}
i++;
}
if (flag)
free(str);
return (1);
}