mirror of
https://github.com/KeyZox71/ft_minipowershell.git
synced 2025-03-15 11:26:51 +01:00
「✨」 feat(quotes_parsing): quotes are now correctly parsed ! :D
This commit is contained in:
@ -6,87 +6,17 @@
|
|||||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/03 10:50:52 by mmoussou #+# #+# */
|
/* Created: 2024/07/03 10:50:52 by mmoussou #+# #+# */
|
||||||
/* Updated: 2024/07/04 12:08:01 by mmoussou ### ########.fr */
|
/* Updated: 2024/07/06 17:47:53 by mmoussou ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
uint formated_string_size(char *cmd)
|
|
||||||
{
|
|
||||||
uint i;
|
|
||||||
uint c;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
c = 0;
|
|
||||||
while (cmd[i])
|
|
||||||
{
|
|
||||||
if (cmd[i] == SINGLE)
|
|
||||||
{
|
|
||||||
c--;
|
|
||||||
while (cmd[i] && cmd[i] != SINGLE)
|
|
||||||
{
|
|
||||||
i++;
|
|
||||||
c++;
|
|
||||||
}
|
|
||||||
if (!cmd)
|
|
||||||
return (c + 1);
|
|
||||||
c--;
|
|
||||||
}
|
|
||||||
if (cmd[i] == DOUBLE)
|
|
||||||
{
|
|
||||||
c--;
|
|
||||||
while (cmd[i] && cmd[i] != DOUBLE)
|
|
||||||
{
|
|
||||||
i++;
|
|
||||||
c++;
|
|
||||||
}
|
|
||||||
if (!cmd)
|
|
||||||
return (c + 1);
|
|
||||||
c--;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
c++;
|
|
||||||
}
|
|
||||||
return (c);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *format_quotes_string(char *cmd)
|
char *format_quotes_string(char *cmd)
|
||||||
{
|
{
|
||||||
//char *new_cmd;
|
|
||||||
uint i;
|
uint i;
|
||||||
uint i_offset;
|
uint i_offset;
|
||||||
|
|
||||||
i = formated_string_size(cmd);
|
|
||||||
if (i == ft_strlen(cmd))
|
|
||||||
return (ft_strdup(cmd));
|
|
||||||
/*new_cmd = ft_calloc(sizeof(char), i);
|
|
||||||
if (!new_cmd)
|
|
||||||
return (NULL);
|
|
||||||
i = 0;
|
|
||||||
while (cmd[i])
|
|
||||||
{
|
|
||||||
if (cmd[i] == SINGLE)
|
|
||||||
{
|
|
||||||
i++;
|
|
||||||
last_i = i;
|
|
||||||
while (cmd[i] && cmd[i] != SINGLE)
|
|
||||||
i++;
|
|
||||||
ft_strlcat(new_cmd, cmd + last_i, i);
|
|
||||||
last_i = i;
|
|
||||||
}
|
|
||||||
else if (cmd[i] == DOUBLE)
|
|
||||||
{
|
|
||||||
i++;
|
|
||||||
last_i = i;
|
|
||||||
while (cmd[i] && cmd[i] != DOUBLE)
|
|
||||||
i++;
|
|
||||||
ft_strlcat(new_cmd, cmd + last_i, i);
|
|
||||||
last_i = i;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
ft_strlcat(new_cmd, cmd + last_i, formated_string_size(cmd) + 1);*/
|
|
||||||
i = 0;
|
i = 0;
|
||||||
i_offset = 0;
|
i_offset = 0;
|
||||||
while (cmd[i])
|
while (cmd[i])
|
||||||
@ -94,49 +24,42 @@ char *format_quotes_string(char *cmd)
|
|||||||
if (cmd[i] == SINGLE)
|
if (cmd[i] == SINGLE)
|
||||||
{
|
{
|
||||||
i_offset++;
|
i_offset++;
|
||||||
|
i++;
|
||||||
while (cmd[i] && cmd[i] != SINGLE)
|
while (cmd[i] && cmd[i] != SINGLE)
|
||||||
{
|
{
|
||||||
cmd[i - i_offset] = cmd[i];
|
cmd[i - i_offset] = cmd[i];
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
if (!cmd[i])
|
i_offset++;
|
||||||
|
}
|
||||||
|
else if (cmd[i] == DOUBLE)
|
||||||
{
|
{
|
||||||
// CANCEL THE OFFSET AND RETURN
|
i_offset++;
|
||||||
return (cmd);
|
i++;
|
||||||
}
|
while (cmd[i] && cmd[i] != DOUBLE)
|
||||||
}
|
|
||||||
else if (cmd[i])
|
|
||||||
{
|
{
|
||||||
|
cmd[i - i_offset] = cmd[i];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
i_offset++;
|
i_offset++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
cmd[i - i_offset] = cmd[i];
|
cmd[i - i_offset] = cmd[i];
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
cmd[i - i_offset] = 0;
|
||||||
return (cmd);
|
return (cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
int format_quotes_cmd(t_cmd *cmd)
|
int format_quotes_cmd(t_cmd *cmd)
|
||||||
{
|
{
|
||||||
char *new_cmd;
|
|
||||||
uint i;
|
uint i;
|
||||||
|
|
||||||
//printf("before : %s\n", cmd->cmd);
|
format_quotes_string(cmd->cmd);
|
||||||
new_cmd = format_quotes_string(cmd->cmd);
|
|
||||||
if (!new_cmd)
|
|
||||||
return (-1);
|
|
||||||
free(cmd->cmd);
|
|
||||||
cmd->cmd = new_cmd;
|
|
||||||
//printf("after : %s\n", cmd->cmd);
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (cmd->argv[i])
|
while (cmd->argv[i])
|
||||||
{
|
{
|
||||||
//printf("before : %s\n", cmd->argv[i]);
|
format_quotes_string(cmd->argv[i]);
|
||||||
new_cmd = format_quotes_string(cmd->argv[i]);
|
|
||||||
if (!new_cmd)
|
|
||||||
return (-1);
|
|
||||||
free(cmd->argv[i]);
|
|
||||||
cmd->argv[i] = new_cmd;
|
|
||||||
//printf("after : %s\n", cmd->argv[i]);
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
@ -144,7 +67,6 @@ int format_quotes_cmd(t_cmd *cmd)
|
|||||||
|
|
||||||
int format_quotes(t_list *list_cmd)
|
int format_quotes(t_list *list_cmd)
|
||||||
{
|
{
|
||||||
//printf("aled\n");
|
|
||||||
if (!list_cmd)
|
if (!list_cmd)
|
||||||
return (0);
|
return (0);
|
||||||
while (list_cmd)
|
while (list_cmd)
|
||||||
|
Reference in New Issue
Block a user