Skip to content

Commit 801ee56

Browse files
committed
Testing in progress
1 parent d2870aa commit 801ee56

File tree

6 files changed

+49
-42
lines changed

6 files changed

+49
-42
lines changed

lib/libft/src/ft_printcharpp.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ void print_charpp(char **cmd)
1919
i = 0;
2020
while (cmd[i])
2121
{
22-
ft_printf("%s\n", cmd[i]);
22+
ft_printf("-%s-\n", cmd[i]);
2323
i++;
2424
}
2525
}

src/ft_parser.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ char **ft_parser(char *prompt)
4646
char **cmd;
4747

4848
cmd = ft_cmdtrim(prompt);
49-
if (prompt[0] && prompt[ft_strlen(prompt) - 1] == ' ')
49+
if (prompt[ft_strlen(prompt) - 1] == ' ')
5050
cmd = ft_charpp_del_back(cmd);
5151
cmd = ft_expand_vars(cmd);
5252
return (cmd);
@@ -69,7 +69,7 @@ char **ft_cmdtrim(char *prompt)
6969

7070
i = 0;
7171
ret = NULL;
72-
while (i < (int)ft_strlen(prompt))
72+
while (prompt[i] != '\0')
7373
{
7474
while (prompt[0] && prompt[i] == ' ')
7575
i++;

src/main.c

+4-5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ int main(int argc, char **argv __attribute__((unused)), char **envp)
1616
{
1717
char *line;
1818
char **cmds;
19+
int check;
1920

2021
if (argc != 1)
2122
exit(0);
@@ -25,18 +26,16 @@ int main(int argc, char **argv __attribute__((unused)), char **envp)
2526
while (1)
2627
{
2728
line = ft_readline();
28-
if (ft_check_cmd(line))
29+
check = ft_check_cmd(line);
30+
if (check == 1)
2931
{
3032
cmds = ft_parser(line);
3133
ft_executer(cmds, g_global.path);
3234
ft_charppfree(cmds);
3335
free(line);
3436
}
35-
else
36-
{
37+
else if (check == 0)
3738
ft_error("minishell syntax error\n", line);
38-
g_global.exit_status = 258;
39-
}
4039
}
4140
}
4241

src/parser_utils.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ int ft_check_cmd(char *prompt)
8686
if (state != NO && state != SQC && state != DQC)
8787
{
8888
ft_printf("Quote Error\n");
89-
return (0);
89+
return (-1);
9090
}
9191
__qs('\0', 1);
9292
if (!ft_locate_firstpipe(prompt))

src/prints.c

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ void ft_error(char *str, char *line)
1616
{
1717
free(line);
1818
ft_putstr_fd(str, 2);
19+
g_global.exit_status = 258;
1920
}
2021

2122
char *ft_readline(void)

src/quote.c

+40-33
Original file line numberDiff line numberDiff line change
@@ -34,50 +34,48 @@ char *ft_add_quote(char *str)
3434

3535
char *ft_dq(char *prompt, int i)
3636
{
37+
char *aux;
38+
int j;
3739
int len;
38-
char *ret;
3940

4041
len = ft_strclen(prompt, DQ, i + 1);
41-
if (prompt[i + len] != ' ')
42+
aux = ft_calloc(len + 2, sizeof(char));
43+
j = 1;
44+
i++;
45+
aux[0] = DQ;
46+
while (prompt[i] != DQ)
4247
{
43-
if (prompt[len + 1])
44-
{
45-
if (prompt[i + len] == DQ)
46-
len += ft_strclen(prompt, DQ, len + 2);
47-
else if (prompt[i + len] == SQ)
48-
len += ft_strclen(prompt, SQ, len + 2);
49-
else
50-
len += wordlen_perso(prompt, len + i);
51-
ret = ft_substr(prompt, i, len + 2);
52-
return (ret);
53-
}
48+
aux[j] = prompt[i];
49+
if (prompt[i] == '\0')
50+
return (aux);
51+
i++;
52+
j++;
5453
}
55-
ret = ft_substr(prompt, i, len + 1);
56-
return (ret);
54+
aux[j] = DQ;
55+
return (aux);
5756
}
5857

5958
char *ft_sq(char *prompt, int i)
6059
{
60+
char *aux;
61+
int j;
6162
int len;
62-
char *ret;
6363

6464
len = ft_strclen(prompt, SQ, i + 1);
65-
if (prompt[i + len + 1] != ' ')
65+
aux = ft_calloc(len + 2, sizeof(char));
66+
j = 1;
67+
i++;
68+
aux[0] = SQ;
69+
while (prompt[i] != SQ)
6670
{
67-
if (prompt[len + 1])
68-
{
69-
if (prompt[i + len + 1] == DQ)
70-
len += ft_strclen(prompt, DQ, len + 2);
71-
else if (prompt[i + len + 1] == SQ)
72-
len += ft_strclen(prompt, SQ, len + 2);
73-
else
74-
len += wordlen_perso(prompt, len + i);
75-
ret = ft_substr(prompt, i, len + 2);
76-
return (ret);
77-
}
71+
aux[j] = prompt[i];
72+
if (prompt[i] == '\0')
73+
return (aux);
74+
i++;
75+
j++;
7876
}
79-
ret = ft_substr(prompt, i, len + 1);
80-
return (ret);
77+
aux[j] = SQ;
78+
return (aux);
8179
}
8280

8381
int wordlen_perso(char *prompt, int i)
@@ -96,10 +94,19 @@ int wordlen_perso(char *prompt, int i)
9694

9795
char *ft_noq(char *prompt, int i)
9896
{
97+
char *aux;
98+
int j;
9999
int len;
100-
char *ret;
101100

102101
len = wordlen_perso(prompt, i);
103-
ret = ft_substr(prompt, i, len);
104-
return (ret);
102+
aux = ft_calloc(len + 2, sizeof(char));
103+
j = 0;
104+
while (prompt[i] != ' ' && prompt[i] != '"'
105+
&& prompt[i] != '\'' && prompt[i] != '\0')
106+
{
107+
aux[j] = prompt[i];
108+
i++;
109+
j++;
110+
}
111+
return (aux);
105112
}

0 commit comments

Comments
 (0)