Archived
1
0

[] feat: parsing working but free does not

This commit is contained in:
2024-03-30 16:43:00 +01:00
parent e57a2cc78b
commit 9c1f172983
15 changed files with 93 additions and 13 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -14,8 +14,46 @@
"src/main.c",
"-c",
"-o",
"obj/main.o"
"obj/src/main.o"
],
"file": "src/main.c"
},
{
"directory": "/nfs/homes/adjoly/Documents/pipex",
"arguments": [
"cc",
"-I",
"include/",
"-I",
"libft/",
"-Werror",
"-Wall",
"-Wextra",
"-g",
"src/parsing/parsing.c",
"-c",
"-o",
"obj/src/parsing/parsing.o"
],
"file": "src/parsing/parsing.c"
},
{
"directory": "/nfs/homes/adjoly/Documents/pipex",
"arguments": [
"cc",
"-I",
"include/",
"-I",
"libft/",
"-Werror",
"-Wall",
"-Wextra",
"-g",
"src/utils/ft_freetab.c",
"-c",
"-o",
"obj/src/utils/ft_freetab.o"
],
"file": "src/utils/ft_freetab.c"
}
]

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/28 16:54:40 by adjoly #+# #+# */
/* Updated: 2024/03/28 22:37:29 by adjoly ### ########.fr */
/* Updated: 2024/03/29 10:41:40 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -20,5 +20,7 @@ typedef struct s_pcmd
} t_pcmd;
void ft_freearr(char **arr);
t_pcmd split_cmd(char *cmd_av);
t_pcmd *parse_cmd(int ac, char **av);
#endif

Binary file not shown.

BIN
obj/src/parsing/parsing.o Normal file

Binary file not shown.

BIN
obj/src/utils/ft_freetab.o Normal file

Binary file not shown.

BIN
pipex

Binary file not shown.

View File

@ -6,14 +6,40 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/21 10:03:04 by adjoly #+# #+# */
/* Updated: 2024/03/28 23:04:32 by adjoly ### ########.fr */
/* Updated: 2024/03/30 13:22:17 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include "parsing.h"
int main(int ac, char **av)
{
ft_putstr_fd(*av, 1);
return (ac);
t_pcmd *cmd;
t_pcmd *tmp;
char **option_tmp;
cmd = parse_cmd(ac, av);
tmp = cmd;
while (tmp && (*tmp).cmd)
{
ft_printf("cmd : %s\n", (*tmp).cmd);
option_tmp = (*tmp).option;
while (*option_tmp)
{
ft_printf("%s\n", *option_tmp);
option_tmp++;
}
tmp++;
}
tmp = cmd;
while (tmp && (*tmp).cmd)
{
if (tmp->option)
ft_freearr(tmp->option);
free(tmp->cmd);
tmp++;
}
free(cmd);
return (EXIT_SUCCESS);
}

View File

@ -6,29 +6,42 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/22 21:13:26 by adjoly #+# #+# */
/* Updated: 2024/03/28 22:37:50 by adjoly ### ########.fr */
/* Updated: 2024/03/30 12:01:17 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "parsing.h"
#include "libft.h"
t_pcmd split_cmd(char *cmd)
t_pcmd split_cmd(char *cmd_av)
{
char **split;
char **tmp_split;
t_pcmd cmd;
split = ft_split(cmd, 32);
split = ft_split(cmd_av, 32);
tmp_split = split;
cmd.cmd = *tmp_split;
tmp_split++;
cmd.option = tmp_split;
return (cmd);
}
t_pcmd *parse_cmd(int ac, char **av)
{
char **tmp;
tmp = av + 1;
t_pcmd *cmd_arr;
t_pcmd *cmd_tmp;
(void)ac;
cmd_arr = ft_calloc(10000, 1);
cmd_tmp = cmd_arr;
tmp = av + 2;
while (*tmp)
{
*cmd_tmp = split_cmd(*tmp);
cmd_tmp++;
tmp++;
}
return (cmd_arr);
}

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/28 22:34:09 by adjoly #+# #+# */
/* Updated: 2024/03/28 22:36:50 by adjoly ### ########.fr */
/* Updated: 2024/03/30 11:58:39 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,9 +17,10 @@ void ft_freearr(char **arr)
char **tmp;
tmp = arr;
while(*tmp)
while(tmp && *tmp)
{
free(*tmp);
tmp++;
}
free(arr);
}