minishell: only parse simple commands

This commit is contained in:
Khaïs COLIN 2025-03-27 15:57:32 +01:00
parent f07a80c762
commit d8bc528c5a
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
4 changed files with 25 additions and 211 deletions

View file

@ -6,13 +6,14 @@
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/06 13:44:06 by kcolin #+# #+# */
/* Updated: 2025/03/20 17:36:58 by khais ### ########.fr */
/* Updated: 2025/03/27 15:58:27 by khais ### ########.fr */
/* */
/* ************************************************************************** */
#include "buffer/buffer.h"
#include "get_command.h"
#include "parser/cmdgroup/cmdgroup.h"
#include "parser/simple_cmd/simple_cmd.h"
#include "parser/wordlist/wordlist.h"
#include "parser/wordsplit/wordsplit.h"
#include "postprocess/redirections/redirection_parsing.h"
@ -24,29 +25,30 @@
**
** Frees line before exiting
*/
static t_cmdgroup *parse_command(char *line)
static t_simple_cmd *parse_command(char *line)
{
t_wordlist *words;
t_cmdgroup *cmd;
t_simple_cmd *cmd;
words = minishell_wordsplit(line);
free(line);
cmd = cmdgroup_from_wordlist(words);
wordlist_destroy(words);
if (words == NULL)
return (NULL);
cmd = simple_cmd_from_wordlist(words);
return (cmd);
}
/*
** debug-print a cmdgroup
*/
static void debug_command(t_cmdgroup *cmd)
static void debug_command(t_simple_cmd *cmd)
{
t_buffer *indent;
indent = ft_buffer_new();
cmdgroup_debug(cmd, indent, true);
simple_cmd_debug(cmd, indent, true);
ft_buffer_free(indent);
cmdgroup_destroy(cmd);
simple_cmd_destroy(cmd);
}
/*
@ -56,19 +58,19 @@ static void debug_command(t_cmdgroup *cmd)
** 1. redirection parsing
** 2. quote removal
*/
static t_cmdgroup *post_process_command(t_cmdgroup *cmd)
static t_simple_cmd *post_process_command(t_simple_cmd *cmd)
{
if (cmdgroup_parse_redirections(cmd) == NULL)
return (cmdgroup_destroy(cmd), NULL);
if (cmdgroup_remove_quotes(cmd) == NULL)
return (cmdgroup_destroy(cmd), NULL);
if (parse_redirections(cmd) == NULL)
return (simple_cmd_destroy(cmd), NULL);
if (simple_cmd_remove_quotes(cmd) == NULL)
return (simple_cmd_destroy(cmd), NULL);
return (cmd);
}
int main(int argc, char *argv[], char **envp)
{
char *line;
t_cmdgroup *cmd;
char *line;
t_simple_cmd *cmd;
(void)argc;
(void)argv;

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/20 17:36:20 by khais #+# #+# */
/* Updated: 2025/03/21 18:33:43 by khais ### ########.fr */
/* Updated: 2025/03/27 14:27:14 by khais ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,7 +16,7 @@
/*
** do quote removal on all words of this simple cmd
*/
static t_simple_cmd *simple_cmd_remove_quotes(t_simple_cmd *cmd)
t_simple_cmd *simple_cmd_remove_quotes(t_simple_cmd *cmd)
{
t_wordlist *new;
t_worddesc *result;

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/28 13:51:03 by khais #+# #+# */
/* Updated: 2025/03/20 17:36:11 by khais ### ########.fr */
/* Updated: 2025/03/27 14:27:27 by khais ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,7 +16,8 @@
# include "../worddesc/worddesc.h"
# include "../cmdgroup/cmdgroup.h"
t_worddesc *remove_quotes(t_worddesc *word);
t_cmdgroup *cmdgroup_remove_quotes(t_cmdgroup *cmd);
t_worddesc *remove_quotes(t_worddesc *word);
t_cmdgroup *cmdgroup_remove_quotes(t_cmdgroup *cmd);
t_simple_cmd *simple_cmd_remove_quotes(t_simple_cmd *cmd);
#endif // REMOVE_QUOTES_H