mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
cmdlist: use new architecture (STUB)
I fixed the tests, and the basic functionallity of detecting pipelines works, but detecting nested cmdgroups is not yet implemented
This commit is contained in:
parent
8f7e7f7dfe
commit
56fe943efc
13 changed files with 116 additions and 69 deletions
|
|
@ -6,15 +6,16 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/24 17:49:46 by khais #+# #+# */
|
||||
/* Updated: 2025/03/04 15:23:00 by khais ### ########.fr */
|
||||
/* Updated: 2025/03/18 14:43:39 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "command_list.h"
|
||||
#include "command_list_item.h"
|
||||
#include "command_list_builder.h"
|
||||
#include "command_list_item_type.h"
|
||||
#include "operator.h"
|
||||
#include "libft.h"
|
||||
#include "../../ft_errno.h"
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
|
@ -45,9 +46,11 @@ static void cmdlist_builder_delimit(
|
|||
t_cmdlist_builder *builder,
|
||||
t_wordlist **words)
|
||||
{
|
||||
builder->cmdlist->pipelines[builder->idx]
|
||||
builder->cmdlist->cmds[builder->idx] = cmdlist_item_create();
|
||||
builder->cmdlist->cmds[builder->idx]->inner.pipeline
|
||||
= pipeline_from_wordlist(builder->current_wordlist);
|
||||
if (builder->cmdlist->pipelines[builder->idx] == NULL)
|
||||
builder->cmdlist->cmds[builder->idx]->type = TYPE_PIPELINE;
|
||||
if (builder->cmdlist->cmds[builder->idx]->inner.pipeline == NULL)
|
||||
{
|
||||
cmdlist_builder_error(builder);
|
||||
wordlist_destroy(*words);
|
||||
|
|
@ -104,12 +107,12 @@ void cmdlist_destroy(t_cmdlist *cmd)
|
|||
if (cmd == NULL)
|
||||
return ;
|
||||
i = 0;
|
||||
while (i < cmd->num_pipelines)
|
||||
while (i < cmd->num_cmds)
|
||||
{
|
||||
pipeline_destroy(cmd->pipelines[i]);
|
||||
cmdlist_item_destroy(cmd->cmds[i]);
|
||||
i++;
|
||||
}
|
||||
free(cmd->pipelines);
|
||||
free(cmd->cmds);
|
||||
free(cmd->operators);
|
||||
free(cmd);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/24 17:45:01 by khais #+# #+# */
|
||||
/* Updated: 2025/03/09 14:22:19 by khais ### ########.fr */
|
||||
/* Updated: 2025/03/18 12:59:56 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -16,6 +16,7 @@
|
|||
# include "../wordlist/wordlist.h"
|
||||
# include "../pipeline/pipeline.h"
|
||||
# include "operator.h"
|
||||
# include "../../buffer/buffer.h"
|
||||
|
||||
/*
|
||||
** cf. 3.2.4 Lists of Commands
|
||||
|
|
@ -62,15 +63,15 @@
|
|||
typedef struct s_cmdlist
|
||||
{
|
||||
/*
|
||||
** Array of pipelines contained in this command list.
|
||||
** Array of pointers to commands in this command list
|
||||
**
|
||||
** These should be executed left to right.
|
||||
*/
|
||||
t_pipeline **pipelines;
|
||||
struct s_cmdlist_item **cmds;
|
||||
/*
|
||||
** Number of pipelines in this command list.
|
||||
** Number of commands in this command list.
|
||||
*/
|
||||
int num_pipelines;
|
||||
int num_cmds;
|
||||
/*
|
||||
** Operators that separate the pipelines.
|
||||
**
|
||||
|
|
@ -85,5 +86,6 @@ typedef struct s_cmdlist
|
|||
|
||||
t_cmdlist *cmdlist_from_wordlist(const t_wordlist *wordlist);
|
||||
void cmdlist_destroy(t_cmdlist *cmd);
|
||||
void cmdlist_debug(t_cmdlist *cmd, t_buffer **indent, bool is_last);
|
||||
|
||||
#endif // COMMAND_LIST_H
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/26 13:51:18 by khais #+# #+# */
|
||||
/* Updated: 2025/03/09 14:24:05 by khais ### ########.fr */
|
||||
/* Updated: 2025/03/18 13:31:57 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -53,15 +53,15 @@ static t_cmdlist *allocate_command_list(t_wordlist *words)
|
|||
output = ft_calloc(1, sizeof(t_cmdlist));
|
||||
if (output == NULL)
|
||||
return (NULL);
|
||||
output->num_pipelines = command_list_count_pipelines(words);
|
||||
output->pipelines
|
||||
= ft_calloc(output->num_pipelines, sizeof(t_pipeline *));
|
||||
if (output->pipelines == NULL)
|
||||
output->num_cmds = command_list_count_pipelines(words);
|
||||
output->cmds
|
||||
= ft_calloc(output->num_cmds, sizeof(struct s_cmdlist_item **));
|
||||
if (output->cmds == NULL)
|
||||
return (free(output), NULL);
|
||||
output->operators
|
||||
= ft_calloc(output->num_pipelines, sizeof(t_operator));
|
||||
= ft_calloc(output->num_cmds, sizeof(t_operator));
|
||||
if (output->operators == NULL)
|
||||
return (free(output->pipelines), free(output), NULL);
|
||||
return (free(output->cmds), free(output), NULL);
|
||||
return (output);
|
||||
}
|
||||
|
||||
|
|
@ -100,5 +100,5 @@ void cmdlist_builder_next_word(
|
|||
*/
|
||||
bool cmdlist_builder_at_last_pipeline(t_cmdlist_builder *builder)
|
||||
{
|
||||
return (builder->idx == builder->cmdlist->num_pipelines - 1);
|
||||
return (builder->idx == builder->cmdlist->num_cmds - 1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/26 13:50:25 by khais #+# #+# */
|
||||
/* Updated: 2025/03/04 15:23:55 by khais ### ########.fr */
|
||||
/* Updated: 2025/03/18 12:59:57 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
36
src/parser/command_list/command_list_item.c
Normal file
36
src/parser/command_list/command_list_item.c
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* command_list_item.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/18 13:02:02 by khais #+# #+# */
|
||||
/* Updated: 2025/03/18 13:35:25 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "command_list_item.h"
|
||||
#include "libft.h"
|
||||
|
||||
void cmdlist_item_destroy(t_cmdlist_item *cmd)
|
||||
{
|
||||
if (cmd == NULL)
|
||||
return ;
|
||||
if (cmd->type == TYPE_CMDGROUP)
|
||||
cmdgroup_destroy(cmd->inner.cmdgroup);
|
||||
if (cmd->type == TYPE_PIPELINE)
|
||||
pipeline_destroy(cmd->inner.pipeline);
|
||||
free(cmd);
|
||||
}
|
||||
|
||||
t_cmdlist_item *cmdlist_item_create(void)
|
||||
{
|
||||
t_cmdlist_item *item;
|
||||
|
||||
item = ft_calloc(1, sizeof(t_cmdlist_item));
|
||||
if (item == NULL)
|
||||
return (NULL);
|
||||
item->type = TYPE_INVALID;
|
||||
return (item);
|
||||
}
|
||||
|
|
@ -1,30 +1,32 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* cmdgroup_item.h :+: :+: :+: */
|
||||
/* command_list_item.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/11 15:43:15 by khais #+# #+# */
|
||||
/* Updated: 2025/03/11 18:10:24 by khais ### ########.fr */
|
||||
/* Created: 2025/03/18 12:54:31 by khais #+# #+# */
|
||||
/* Updated: 2025/03/18 13:34:14 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef CMDGROUP_ITEM_H
|
||||
# define CMDGROUP_ITEM_H
|
||||
#ifndef COMMAND_LIST_ITEM_H
|
||||
# define COMMAND_LIST_ITEM_H
|
||||
|
||||
# include "cmdgroup_item_type.h"
|
||||
# include "../command_list/command_list.h"
|
||||
# include "cmdgroup.h"
|
||||
# include "../cmdgroup/cmdgroup.h"
|
||||
# include "command_list_item_type.h"
|
||||
|
||||
typedef struct s_cmdgroup_item
|
||||
typedef struct s_cmdlist_item
|
||||
{
|
||||
enum e_cmdgroup_item_type type;
|
||||
union u_cmdgroup_item_inner
|
||||
enum e_cmdlist_item_type type;
|
||||
union u_cmdlist_item_inner
|
||||
{
|
||||
t_cmdgroup *cmdgroup;
|
||||
struct s_cmdlist *cmdlist;
|
||||
struct s_pipeline *pipeline;
|
||||
} inner;
|
||||
} t_cmdgroup_item;
|
||||
} t_cmdlist_item;
|
||||
|
||||
#endif // CMDGROUP_ITEM_H
|
||||
void cmdlist_item_destroy(t_cmdlist_item *cmd);
|
||||
t_cmdlist_item *cmdlist_item_create(void);
|
||||
|
||||
#endif // COMMAND_LIST_ITEM_H
|
||||
|
|
@ -1,23 +1,23 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* cmdgroup_item_type.h :+: :+: :+: */
|
||||
/* command_list_item_type.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/11 15:45:33 by khais #+# #+# */
|
||||
/* Updated: 2025/03/11 15:46:25 by khais ### ########.fr */
|
||||
/* Created: 2025/03/18 12:56:30 by khais #+# #+# */
|
||||
/* Updated: 2025/03/18 12:58:38 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef CMDGROUP_ITEM_TYPE_H
|
||||
# define CMDGROUP_ITEM_TYPE_H
|
||||
#ifndef COMMAND_LIST_ITEM_TYPE_H
|
||||
# define COMMAND_LIST_ITEM_TYPE_H
|
||||
|
||||
typedef enum e_cmdgroup_item_type
|
||||
typedef enum e_cmdlist_item_type
|
||||
{
|
||||
TYPE_INVALID = 0,
|
||||
TYPE_GROUP,
|
||||
TYPE_LIST,
|
||||
} t_cmdgroup_item_type;
|
||||
TYPE_INVALID,
|
||||
TYPE_CMDGROUP,
|
||||
TYPE_PIPELINE,
|
||||
} t_cmdlist_item_type;
|
||||
|
||||
#endif // CMDGROUP_ITEM_TYPE_H
|
||||
#endif // COMMAND_LIST_ITEM_TYPE_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue