mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
81 lines
2.2 KiB
C
81 lines
2.2 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* minishell.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2025/02/06 13:44:06 by kcolin #+# #+# */
|
|
/* Updated: 2025/03/19 16:38:42 by khais ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "buffer/buffer.h"
|
|
#include "get_command.h"
|
|
#include "parser/cmdgroup/cmdgroup.h"
|
|
#include "parser/wordlist/wordlist.h"
|
|
#include "parser/wordsplit/wordsplit.h"
|
|
#include "postprocess/redirections/redirection_parsing.h"
|
|
#include <stdlib.h>
|
|
|
|
/*
|
|
** Parse shell commands from line.
|
|
**
|
|
** Frees line before exiting
|
|
*/
|
|
static t_cmdgroup *parse_command(char *line)
|
|
{
|
|
t_wordlist *words;
|
|
t_cmdgroup *cmd;
|
|
|
|
words = minishell_wordsplit(line);
|
|
free(line);
|
|
cmd = cmdgroup_from_wordlist(words);
|
|
wordlist_destroy(words);
|
|
return (cmd);
|
|
}
|
|
|
|
/*
|
|
** debug-print a cmdgroup
|
|
*/
|
|
static void debug_command(t_cmdgroup *cmd)
|
|
{
|
|
t_buffer *indent;
|
|
|
|
indent = ft_buffer_new();
|
|
cmdgroup_debug(cmd, indent, true);
|
|
ft_buffer_free(indent);
|
|
cmdgroup_destroy(cmd);
|
|
}
|
|
|
|
/*
|
|
** Do all the post-processing steps relating to a command.
|
|
**
|
|
** Currently, this is the following:
|
|
** 1. redirection parsing
|
|
*/
|
|
static t_cmdgroup *post_process_command(t_cmdgroup *cmd)
|
|
{
|
|
if (cmdgroup_parse_redirections(cmd) == NULL)
|
|
return (cmdgroup_destroy(cmd), NULL);
|
|
return (cmd);
|
|
}
|
|
|
|
int main(int argc, char *argv[], char **envp)
|
|
{
|
|
char *line;
|
|
t_cmdgroup *cmd;
|
|
|
|
(void)argc;
|
|
(void)argv;
|
|
(void)envp;
|
|
line = get_command();
|
|
while (line != NULL)
|
|
{
|
|
cmd = parse_command(line);
|
|
cmd = post_process_command(cmd);
|
|
debug_command(cmd);
|
|
line = get_command();
|
|
}
|
|
return (0);
|
|
}
|