mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
refactor: put parsing of command and debugging out of main loop
This commit is contained in:
parent
36c1b72eff
commit
0584757446
1 changed files with 30 additions and 11 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/06 13:44:06 by kcolin #+# #+# */
|
||||
/* Updated: 2025/03/19 12:12:39 by khais ### ########.fr */
|
||||
/* Updated: 2025/03/19 16:30:32 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -17,12 +17,37 @@
|
|||
#include "parser/wordsplit/wordsplit.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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[], char **envp)
|
||||
{
|
||||
char *line;
|
||||
t_cmdgroup *cmd;
|
||||
t_wordlist *words;
|
||||
t_buffer *indent;
|
||||
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
|
@ -30,14 +55,8 @@ int main(int argc, char *argv[], char **envp)
|
|||
line = get_command();
|
||||
while (line != NULL)
|
||||
{
|
||||
words = minishell_wordsplit(line);
|
||||
free(line);
|
||||
cmd = cmdgroup_from_wordlist(words);
|
||||
wordlist_destroy(words);
|
||||
indent = ft_buffer_new();
|
||||
cmdgroup_debug(cmd, indent, true);
|
||||
ft_buffer_free(indent);
|
||||
cmdgroup_destroy(cmd);
|
||||
cmd = parse_command(line);
|
||||
debug_command(cmd);
|
||||
line = get_command();
|
||||
}
|
||||
return (0);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue