-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalysis_quote.c
More file actions
119 lines (108 loc) · 2.63 KB
/
analysis_quote.c
File metadata and controls
119 lines (108 loc) · 2.63 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* analysis_quote.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hyeyeom <hyeyeom@42student.gyeongsan.kr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/23 16:59:38 by yuhyoon #+# #+# */
/* Updated: 2025/04/14 00:38:35 by hyeyeom ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int set_char_state(char *s, t_char_state *char_state)
{
char q;
int len;
q = is_quote(*s);
len = 0;
if (q != 0)
{
len = valid_quote(s, q);
if (len > 0)
{
char_state->quote = q;
}
}
return (len);
}
int putchar_quote_state_zero(char *current, int fd)
{
int size;
size = 0;
if ((is_whitespace(*(current))))
ft_putchar_fd(NONE, fd);
else if (ft_ismeta((current)))
ft_putchar_fd(ft_ismeta((current)), fd);
else
ft_putchar_fd(TEXT, fd);
size++;
return (size);
}
int read_store_fd(int replace_fd, int quote_fd)
{
int i;
struct stat st;
int size;
char *buf;
i = 0;
fstat(quote_fd, &st);
size = st.st_size;
close(quote_fd);
quote_fd = open("quote_fd", O_RDONLY, 0644);
buf = malloc(sizeof(char) * size);
read(quote_fd, buf, size);
while (i < size)
{
ft_putchar_fd(buf[i], replace_fd);
i++;
}
close(quote_fd);
free(buf);
unlink("quote_fd");
return (size);
}
int store_quote_seq(t_char_state *char_state, int len)
{
int quote_fd;
int i;
i = 0;
quote_fd = open("quote_fd", O_RDWR | O_CREAT | O_TRUNC, 0644);
while (i < len)
{
if (char_state->quote > 0)
{
if (char_state->quote == '\"' \
&& ft_ismeta(&(char_state->current[i])) == DOLLAR)
ft_putchar_fd(DOLLAR, quote_fd);
else if (char_state->current[i] == char_state->quote)
ft_putchar_fd(QUOTE, quote_fd);
else
ft_putchar_fd(TEXT, quote_fd);
}
i++;
}
return (quote_fd);
}
int valid_quote(char *s, int quote)
{
t_stack stack;
char *ss;
int i;
init_stack(&stack, NULL, 0);
ss = s;
push(&stack, ss);
i = 1;
while (is_emthy(&stack) == false && ss[i] != '\0')
{
if (is_quote(ss[i]) == quote)
pop(&stack);
i++;
}
if (is_emthy(&stack) == false && ss[i] == '\0')
{
pop(&stack);
i = i * -1;
}
return (i);
}