mirror of
https://github.com/KeyZox71/ft_minipowershell.git
synced 2025-05-11 23:18:46 +02:00
「✏️」 norm: Normed heredoc
This commit is contained in:
@ -6,24 +6,23 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/20 09:19:39 by mmoussou #+# #+# */
|
||||
/* Updated: 2024/07/03 10:08:18 by mmoussou ### ########.fr */
|
||||
/* Updated: 2024/07/09 11:05:31 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
/*
|
||||
# mode
|
||||
0: ouvre un nouveau fichier
|
||||
1: réouvre le fichier pour la lecture
|
||||
-1: pour signifier qu'il faut decrémenter la static
|
||||
* # mode
|
||||
* 0: ouvre un nouveau fichier
|
||||
* 1: réouvre le fichier pour la lecture
|
||||
* -1: pour signifier qu'il faut decrémenter la static
|
||||
*/
|
||||
int fd_manager(int mode)
|
||||
{
|
||||
static int index = 0;
|
||||
char *index_itoa;
|
||||
char *path;
|
||||
int fd;
|
||||
|
||||
if (mode < 0)
|
||||
index--;
|
||||
@ -42,10 +41,9 @@ int fd_manager(int mode)
|
||||
ft_strlcat(path, index_itoa, ft_strlen(index_itoa));
|
||||
free(index_itoa);
|
||||
if (mode > 0)
|
||||
fd = open(path, O_RDONLY);
|
||||
return (open(path, O_RDONLY));
|
||||
else
|
||||
fd = open(path, O_WRONLY | O_TRUNC | O_CREAT, 0644);
|
||||
return (fd);
|
||||
return (open(path, O_WRONLY | O_TRUNC | O_CREAT, 0644));
|
||||
}
|
||||
|
||||
static int get_input(char *delimiter, int fd)
|
||||
@ -60,12 +58,12 @@ static int get_input(char *delimiter, int fd)
|
||||
if (status == -1)
|
||||
fd_manager(fd);
|
||||
if (status == -1)
|
||||
return (-1);
|
||||
break ;
|
||||
status = write(fd, "\n", 1);
|
||||
if (status == -1)
|
||||
fd_manager(fd);
|
||||
if (status == -1)
|
||||
return (-1);
|
||||
break ;
|
||||
free(line);
|
||||
line = readline("heredoc> ");
|
||||
}
|
||||
|
35
src/main.c
35
src/main.c
@ -6,23 +6,11 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/24 11:18:04 by adjoly #+# #+# */
|
||||
/* Updated: 2024/07/06 18:07:24 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/07/07 14:50:45 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <readline/readline.h>
|
||||
#include "error_msg.h"
|
||||
#include <readline/history.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <fcntl.h>
|
||||
#include "libft.h"
|
||||
#include "builtins.h"
|
||||
#include "minishell.h"
|
||||
#include "parsing.h"
|
||||
#include "prompt.h"
|
||||
|
||||
void sig_c(int code)
|
||||
{
|
||||
@ -33,6 +21,19 @@ void sig_c(int code)
|
||||
rl_redisplay();
|
||||
}
|
||||
|
||||
bool run_checks(char *rl)
|
||||
{
|
||||
if (!*rl)
|
||||
return (true);
|
||||
if (check_syntax(rl))
|
||||
return (true);
|
||||
if (check_quote(rl))
|
||||
return (true);
|
||||
if (check_pipe(rl))
|
||||
return (true);
|
||||
return (false);
|
||||
}
|
||||
|
||||
int main(int ac, char **av, char **env)
|
||||
{
|
||||
char *rl;
|
||||
@ -53,13 +54,7 @@ int main(int ac, char **av, char **env)
|
||||
free(prompt);
|
||||
if (!rl)
|
||||
exit(727);
|
||||
if (!*rl)
|
||||
continue ;
|
||||
if (check_syntax(rl))
|
||||
continue ;
|
||||
if (check_quote(rl))
|
||||
continue ;
|
||||
if (check_pipe(rl))
|
||||
if (run_checks(rl))
|
||||
continue ;
|
||||
piped = tokenizer(rl);
|
||||
if (check_argv(piped))
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/30 10:48:41 by adjoly #+# #+# */
|
||||
/* Updated: 2024/07/06 18:06:14 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/07/07 14:57:54 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
Reference in New Issue
Block a user