mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
cmdgroup parsing: start implementing the new architecture
This commit is contained in:
parent
d6bb24df54
commit
f9aa614ef2
4 changed files with 18 additions and 30 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/03/11 15:18:02 by khais #+# #+# */
|
/* Created: 2025/03/11 15:18:02 by khais #+# #+# */
|
||||||
/* Updated: 2025/03/11 18:14:24 by khais ### ########.fr */
|
/* Updated: 2025/03/18 11:48:33 by khais ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -25,12 +25,6 @@ t_cmdgroup *cmdgroup_from_wordlist(t_wordlist *words)
|
||||||
cmd = ft_calloc(1, sizeof(t_cmdgroup));
|
cmd = ft_calloc(1, sizeof(t_cmdgroup));
|
||||||
if (cmd == NULL)
|
if (cmd == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
cmd->item_num = 1;
|
|
||||||
cmd->items = ft_calloc(1, sizeof(t_cmdgroup_item));
|
|
||||||
if (cmd->items == NULL)
|
|
||||||
return (free(cmd), NULL);
|
|
||||||
cmd->items[0].type = TYPE_LIST;
|
|
||||||
cmd->items[0].inner.cmdlist = cmdlist_from_wordlist(words);
|
|
||||||
return (cmd);
|
return (cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/03/11 15:11:57 by khais #+# #+# */
|
/* Created: 2025/03/11 15:11:57 by khais #+# #+# */
|
||||||
/* Updated: 2025/03/11 18:14:33 by khais ### ########.fr */
|
/* Updated: 2025/03/18 12:07:29 by khais ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,19 +14,23 @@
|
||||||
# define CMDGROUP_H
|
# define CMDGROUP_H
|
||||||
|
|
||||||
# include "../wordlist/wordlist.h"
|
# include "../wordlist/wordlist.h"
|
||||||
|
# include "../command_list/command_list.h"
|
||||||
|
|
||||||
struct s_cmdgroup_item;
|
/*
|
||||||
|
** A grouping of commands, surrounded by parentheses.
|
||||||
|
**
|
||||||
|
** A top-level cmdgroup is modeled as having an implicit set of parentheses.
|
||||||
|
*/
|
||||||
typedef struct s_cmdgroup
|
typedef struct s_cmdgroup
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
** Number of items in this cmdgroup
|
** list of the commands inside this group
|
||||||
*/
|
*/
|
||||||
int item_num;
|
struct s_cmdlist item;
|
||||||
/*
|
/*
|
||||||
** array of items in this cmdgroup
|
** redirections to apply to the whole group
|
||||||
*/
|
*/
|
||||||
struct s_cmdgroup_item *items;
|
struct s_redirection_list *redirections;
|
||||||
} t_cmdgroup;
|
} t_cmdgroup;
|
||||||
|
|
||||||
t_cmdgroup *cmdgroup_from_wordlist(t_wordlist *words);
|
t_cmdgroup *cmdgroup_from_wordlist(t_wordlist *words);
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/03/18 11:43/36 by khais #+# #+# */
|
/* Created: 2025/03/18 11:49/19 by khais #+# #+# */
|
||||||
/* Updated: 2025/03/18 11:43:36 by khais ### ########.fr */
|
/* Updated: 2025/03/18 11:49:19 by khais ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -39,9 +39,7 @@ static void test_cmdgroup_parsing_single_cmdlist(void)
|
||||||
cmd = parse_cmdgroup("echo this | cat -e && echo works | wc -c");
|
cmd = parse_cmdgroup("echo this | cat -e && echo works | wc -c");
|
||||||
// assert
|
// assert
|
||||||
assert(NULL != cmd);
|
assert(NULL != cmd);
|
||||||
assert(1 == cmd->item_num);
|
// TODO
|
||||||
assert(TYPE_LIST == cmd->items[0].type);
|
|
||||||
assert_cmdgroup_itemlistequal("echo this | cat -e && echo works | wc -c", cmd, 0);
|
|
||||||
// cleanup
|
// cleanup
|
||||||
cmdgroup_destroy(cmd);
|
cmdgroup_destroy(cmd);
|
||||||
do_leak_check();
|
do_leak_check();
|
||||||
|
|
@ -55,9 +53,8 @@ static void test_cmdgroup_parsing_two_cmdlist(void)
|
||||||
ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__);
|
ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__);
|
||||||
cmd = parse_cmdgroup("echo this | cat -e && echo works | wc -c");
|
cmd = parse_cmdgroup("echo this | cat -e && echo works | wc -c");
|
||||||
// assert
|
// assert
|
||||||
|
// TODO
|
||||||
assert(NULL != cmd);
|
assert(NULL != cmd);
|
||||||
assert(1 == cmd->item_num);
|
|
||||||
assert(TYPE_LIST == cmd->items[0].type);
|
|
||||||
assert_cmdgroup_itemlistequal("echo this | cat -e && echo works | wc -c", cmd, 0);
|
assert_cmdgroup_itemlistequal("echo this | cat -e && echo works | wc -c", cmd, 0);
|
||||||
// cleanup
|
// cleanup
|
||||||
cmdgroup_destroy(cmd);
|
cmdgroup_destroy(cmd);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/02/13 15:21:09 by khais #+# #+# */
|
/* Created: 2025/02/13 15:21:09 by khais #+# #+# */
|
||||||
/* Updated: 2025/03/11 18:12:05 by khais ### ########.fr */
|
/* Updated: 2025/03/18 11:50:23 by khais ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -128,24 +128,17 @@ t_cmdgroup *parse_cmdgroup(char *input)
|
||||||
void assert_cmdgroup_itemlistequal(char *expected_str, t_cmdgroup *got_cmd, int item_number)
|
void assert_cmdgroup_itemlistequal(char *expected_str, t_cmdgroup *got_cmd, int item_number)
|
||||||
{
|
{
|
||||||
ft_dprintf(STDERR_FILENO, "checking that item %d of cmdlist %p matches [%s]\n", item_number, got_cmd, expected_str);
|
ft_dprintf(STDERR_FILENO, "checking that item %d of cmdlist %p matches [%s]\n", item_number, got_cmd, expected_str);
|
||||||
ft_dprintf(STDERR_FILENO, "expecteing to have at least %d items, and got %d\n", item_number + 1, got_cmd->item_num);
|
|
||||||
assert(got_cmd->item_num > item_number);
|
|
||||||
ft_dprintf(STDERR_FILENO, "expecteing item %p to be of type list got %d\n", got_cmd->items[item_number], got_cmd->items[item_number].type);
|
|
||||||
t_cmdlist *expected = parse_command_list(expected_str);
|
t_cmdlist *expected = parse_command_list(expected_str);
|
||||||
t_cmdlist *got = got_cmd->items[item_number].inner.cmdlist;
|
|
||||||
if (expected == NULL)
|
if (expected == NULL)
|
||||||
{
|
{
|
||||||
ft_dprintf(STDERR_FILENO, "expecting the list to be null\n");
|
ft_dprintf(STDERR_FILENO, "expecting the list to be null\n");
|
||||||
assert(expected == got);
|
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
ft_dprintf(STDERR_FILENO, "checking if the list matches...\n");
|
ft_dprintf(STDERR_FILENO, "checking if the list matches...\n");
|
||||||
assert(expected->num_pipelines == got->num_pipelines);
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (i < expected->num_pipelines)
|
while (i < expected->num_pipelines)
|
||||||
{
|
{
|
||||||
assert_pipelineequal_raw(expected->pipelines[i], got->pipelines[i]);
|
|
||||||
assert(expected->operators[i] == got->operators[i]);
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
assert(false && "not yet implemented");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue