loop read again if script modifierd
This commit is contained in:
parent
c0977b20ff
commit
46ccf47755
11 changed files with 63 additions and 29 deletions
BIN
42sh/a.out
Executable file
BIN
42sh/a.out
Executable file
Binary file not shown.
|
|
@ -0,0 +1 @@
|
|||
/Users/ariard/Projects/42sh
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/06 18:33:10 by ariard ### ########.fr */
|
||||
/* Updated: 2017/02/06 21:23:44 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -51,6 +51,7 @@ struct s_comp
|
|||
struct s_script
|
||||
{
|
||||
char *buffer;
|
||||
int fd;
|
||||
int size;
|
||||
int lc;
|
||||
};
|
||||
|
|
@ -84,7 +85,7 @@ int shell_single_command(char *command);
|
|||
|
||||
int read_script(char *file);
|
||||
int shell_script(void);
|
||||
t_list **shell_get_ast(char *command);
|
||||
int get_script_content(t_script *script);
|
||||
|
||||
void ft_expand_dollar(char **av, char **env);
|
||||
char *ft_findexec(char *path, char *file);
|
||||
|
|
|
|||
3
42sh/infinite.sh
Normal file
3
42sh/infinite.sh
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
echo hello >> infinite.sh
|
||||
hello
|
||||
hello
|
||||
|
|
@ -1 +1,3 @@
|
|||
ls ; pwd > file1 ; ls | cat
|
||||
ls ; pwd > file1
|
||||
ls | cat
|
||||
echo hello world
|
||||
|
|
|
|||
1
42sh/sample/infinite.sh
Normal file
1
42sh/sample/infinite.sh
Normal file
|
|
@ -0,0 +1 @@
|
|||
echo "echo hello" >> sample/infinite.sh
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/30 17:33:53 by ariard #+# #+# */
|
||||
/* Updated: 2017/02/06 18:12:10 by ariard ### ########.fr */
|
||||
/* Updated: 2017/02/06 22:03:38 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/06 20:38:07 by ariard ### ########.fr */
|
||||
/* Updated: 2017/02/06 21:03:47 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,29 +6,34 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/21 22:49:31 by ariard #+# #+# */
|
||||
/* Updated: 2017/02/03 19:55:38 by ariard ### ########.fr */
|
||||
/* Updated: 2017/02/06 21:58:44 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
static int rs_loop(char *file, t_script *script)
|
||||
int get_script_content(t_script *script)
|
||||
{
|
||||
int fd;
|
||||
char *line;
|
||||
|
||||
line = NULL;
|
||||
if ((fd = open(file, O_RDONLY)) == -1)
|
||||
return (0);
|
||||
while ((get_next_line(fd, &line)) > 0)
|
||||
while (((get_next_line(script->fd, &line))) > 0)
|
||||
{
|
||||
ft_strappend(&script->buffer, line);
|
||||
ft_strappend(&script->buffer, "\n");
|
||||
ft_strdel(&line);
|
||||
script->size += ft_strlen(script->buffer);
|
||||
}
|
||||
if (script->size)
|
||||
script->buffer[ft_strlen(script->buffer) - 1] = 0;
|
||||
close(fd);
|
||||
return (script->size);
|
||||
}
|
||||
|
||||
static int rs_read(char *file, t_script *script)
|
||||
{
|
||||
if ((script->fd = open(file, O_RDONLY)) == -1)
|
||||
return (0);
|
||||
get_script_content(script);
|
||||
if (script->size > 0)
|
||||
{
|
||||
data_singleton()->opts &= ~SHELL_MODE_MASK;
|
||||
|
|
@ -42,6 +47,7 @@ static int rs_setup(t_script *script)
|
|||
ft_bzero(script, sizeof(script));
|
||||
script->buffer = NULL;
|
||||
script->size = 0;
|
||||
script->fd = -1;
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
|
@ -54,7 +60,7 @@ int read_script(char *file)
|
|||
return (0);
|
||||
if (rs_setup(script) < 0)
|
||||
return (-1);
|
||||
if (rs_loop(file, script) < 0)
|
||||
if (rs_read(file, script) < 0)
|
||||
return (-1);
|
||||
DG("{inv}{bol}{gre}read of script{eoc} script detected");
|
||||
return (1);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/22 23:06:34 by ariard #+# #+# */
|
||||
/* Updated: 2017/02/06 20:58:54 by ariard ### ########.fr */
|
||||
/* Updated: 2017/02/06 22:03:30 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -17,10 +17,14 @@ int shell_script()
|
|||
t_list *token;
|
||||
t_btree *ast;
|
||||
t_list *list_ast;
|
||||
t_script *script;
|
||||
|
||||
token = NULL;
|
||||
ast = NULL;
|
||||
list_ast = NULL;
|
||||
script = &data_singleton()->script;
|
||||
while (script->size)
|
||||
{
|
||||
if (ft_lexer(&token, &data_singleton()->script.buffer) || !token)
|
||||
return (1);
|
||||
DG("after post_tokenize");
|
||||
|
|
@ -35,5 +39,9 @@ int shell_script()
|
|||
return (1);
|
||||
ast = NULL;
|
||||
}
|
||||
script->size = 0;
|
||||
get_script_content(script);
|
||||
}
|
||||
close(script->fd);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
12
42sh/test.c
Normal file
12
42sh/test.c
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int loop;
|
||||
|
||||
loop = 1;
|
||||
printf("hello world");
|
||||
if (loop)
|
||||
main();
|
||||
return (0);
|
||||
}
|
||||
Loading…
Reference in a new issue