mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
command list parse: different operators
This commit is contained in:
parent
1c00020c86
commit
659c9f57ff
3 changed files with 79 additions and 9 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/24 17:49:46 by khais #+# #+# */
|
||||
/* Updated: 2025/02/25 14:57:20 by khais ### ########.fr */
|
||||
/* Updated: 2025/02/25 15:08:48 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -74,6 +74,10 @@ static t_command_list *allocate_command_list(t_wordlist *words)
|
|||
= ft_calloc(output->num_pipelines, sizeof(t_pipeline *));
|
||||
if (output->pipelines == NULL)
|
||||
return (free(output), NULL);
|
||||
output->operators
|
||||
= ft_calloc(output->num_pipelines, sizeof(t_operator));
|
||||
if (output->operators == NULL)
|
||||
return (free(output->pipelines), free(output), NULL);
|
||||
return (output);
|
||||
}
|
||||
|
||||
|
|
@ -103,7 +107,7 @@ t_command_list *command_list_from_wordlist(t_wordlist *words)
|
|||
else
|
||||
{
|
||||
output->pipelines[idx] = pipeline_from_wordlist(current_wordlist);
|
||||
output->operator = match_op(current_word->word);
|
||||
output->operators[idx] = match_op(current_word->word);
|
||||
current_wordlist = NULL;
|
||||
worddesc_destroy(current_word);
|
||||
current_word = wordlist_pop(&words);
|
||||
|
|
@ -111,7 +115,10 @@ t_command_list *command_list_from_wordlist(t_wordlist *words)
|
|||
}
|
||||
}
|
||||
if (current_wordlist != NULL)
|
||||
{
|
||||
output->pipelines[idx] = pipeline_from_wordlist(current_wordlist);
|
||||
output->operators[idx] = OP_END;
|
||||
}
|
||||
return (output);
|
||||
}
|
||||
|
||||
|
|
@ -131,5 +138,6 @@ void command_list_destroy(t_command_list *cmd)
|
|||
i++;
|
||||
}
|
||||
free(cmd->pipelines);
|
||||
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/02/25 12:43:52 by khais ### ########.fr */
|
||||
/* Updated: 2025/02/25 15:06:23 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -18,9 +18,22 @@
|
|||
|
||||
typedef enum e_operator
|
||||
{
|
||||
/*
|
||||
** Not a valid operator
|
||||
*/
|
||||
OP_INVALID,
|
||||
/*
|
||||
** &&
|
||||
*/
|
||||
OP_AND,
|
||||
/*
|
||||
** ||
|
||||
*/
|
||||
OP_OR,
|
||||
/*
|
||||
** End of operator list
|
||||
*/
|
||||
OP_END,
|
||||
} t_operator;
|
||||
|
||||
/*
|
||||
|
|
@ -67,9 +80,26 @@ typedef enum e_operator
|
|||
*/
|
||||
typedef struct s_command_list
|
||||
{
|
||||
/*
|
||||
** List of pipelines contained in this command list.
|
||||
**
|
||||
** These should be executed left to right.
|
||||
*/
|
||||
t_pipeline **pipelines;
|
||||
/*
|
||||
** Number of pipelines in this command list.
|
||||
*/
|
||||
int num_pipelines;
|
||||
t_operator operator;
|
||||
/*
|
||||
** Operators that separate the pipelines.
|
||||
**
|
||||
** pipelines[0] operators[0] pipelines[1] operators[1]
|
||||
**
|
||||
** Terminated by OP_END
|
||||
**
|
||||
** In example above, operators[1] == OP_END
|
||||
*/
|
||||
t_operator *operators;
|
||||
} t_command_list;
|
||||
|
||||
t_command_list *command_list_from_wordlist(t_wordlist *words);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue