-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlexer.c
More file actions
71 lines (64 loc) · 1.82 KB
/
lexer.c
File metadata and controls
71 lines (64 loc) · 1.82 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* lexer.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mbani <mbani@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/12/03 10:55:54 by mbani #+# #+# */
/* Updated: 2020/12/11 17:59:35 by mbani ### ########.fr */
/* */
/* ************************************************************************** */
#include "shell.h"
int add_string(char *line, enum e_quotes *sngl, enum e_quotes *dbl)
{
int i;
int j;
int sep;
char *tmp;
char *op;
i = 0;
tmp = ft_strdup(line);
while (tmp[i])
{
j = 0;
quote_check(sngl, dbl, tmp, i);
if (*sngl == 1 || *dbl == 1)
i += quoted_str(tmp + i, sngl, dbl);
sep = separators_check(&tmp, &i, &op, &j);
if (sep == 1)
continue ;
else if (sep == 0)
break ;
i++;
}
return (add_to_list_bulk(&tmp, &op, &i, &j));
}
void line_split(char *line)
{
int i;
enum e_quotes sngl;
enum e_quotes dbl;
i = 0;
sngl = 0;
dbl = 0;
while (line[i])
{
while (line[i] == ' ' || line[i] == '\t')
i++;
if (line[i])
i += add_string(line + i, &sngl, &dbl);
}
red_file_cmd(g_cmd_head);
}
void quote_removal_free(char **str, char **tmp, char **temp)
{
free(str[0]);
str[0] = tmp[0];
free(temp[0]);
}
void search_and_replace_help(char **str, int i, int j)
{
str[0][i - j] = 127;
str[0][i - j + 1] = 127;
}