others shebang ok
This commit is contained in:
parent
e4682de358
commit
f81a51cdd8
21 changed files with 104 additions and 18 deletions
Binary file not shown.
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/19 21:03:13 by ariard ### ########.fr */
|
||||
/* Updated: 2017/01/22 22:42:30 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/22 00:37:20 by ariard ### ########.fr */
|
||||
/* Updated: 2017/01/22 22:50:22 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -41,8 +41,9 @@ struct s_comp
|
|||
# define SHELL_OPTS_LC (1 << 1)
|
||||
# define SHELL_MODE_INPUT (1 << 2)
|
||||
# define SHELL_MODE_EXEC (1 << 3)
|
||||
# define SHELL_MODE_SCRIPT (1 << 4)
|
||||
|
||||
# define SHELL_MODE_MASK (SHELL_MODE_INPUT | SHELL_MODE_EXEC)
|
||||
# define SHELL_MODE_MASK (SHELL_MODE_INPUT | SHELL_MODE_EXEC | SHELL_MODE_SCRIPT)
|
||||
# define SHELL_HAS_JOBC(b) (b & SHELL_OPTS_JOBC)
|
||||
|
||||
# define SHELL_MSG_NOJOBC "no job-control"
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/21 22:50:22 by ariard #+# #+# */
|
||||
/* Updated: 2017/01/22 21:24:47 by ariard ### ########.fr */
|
||||
/* Updated: 2017/01/22 22:19:32 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -37,4 +37,6 @@ typedef struct s_script t_script;
|
|||
|
||||
int ft_read_script(char *file);
|
||||
|
||||
int rs_shebang_check(char *file, t_script *script);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#!/bin/sh
|
||||
#!/bin/yolosh
|
||||
while [ 1 ]; do
|
||||
sleep 1
|
||||
echo "a"
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/10 16:01:30 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/11 14:41:54 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/01/22 22:08:34 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/12 13:14:35 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/01/22 22:16:06 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/21 22:56:51 by ariard ### ########.fr */
|
||||
/* Updated: 2017/01/22 22:08:22 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/13 14:20:45 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/20 00:12:56 by ariard ### ########.fr */
|
||||
/* Updated: 2017/01/22 22:11:35 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/13 17:07:10 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/11 18:01:36 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/01/22 22:16:52 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/08 18:03:48 by sbenning #+# #+# */
|
||||
/* Updated: 2017/01/22 21:06:24 by ariard ### ########.fr */
|
||||
/* Updated: 2017/01/22 21:43:48 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/09 01:25:03 by sbenning #+# #+# */
|
||||
/* Updated: 2017/01/21 22:34:25 by ariard ### ########.fr */
|
||||
/* Updated: 2017/01/22 21:56:30 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/08 18:07:47 by sbenning #+# #+# */
|
||||
/* Updated: 2017/01/22 21:25:10 by ariard ### ########.fr */
|
||||
/* Updated: 2017/01/22 22:46:09 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/22 21:18:37 by ariard ### ########.fr */
|
||||
/* Updated: 2017/01/22 22:52:41 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -50,7 +50,10 @@ int main(int ac, char **av)
|
|||
return (0);
|
||||
}
|
||||
if (ft_read_script(av[1]))
|
||||
{
|
||||
shell_single_command(data_singleton()->line.input);
|
||||
return (0);
|
||||
}
|
||||
while (1)
|
||||
{
|
||||
if (ft_readline())
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/11 14:04:48 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/19 21:23:17 by ariard ### ########.fr */
|
||||
/* Updated: 2017/01/22 22:18:56 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/12 17:23:59 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/22 20:56:35 by ariard ### ########.fr */
|
||||
/* Updated: 2017/01/22 21:58:53 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/21 22:49:31 by ariard #+# #+# */
|
||||
/* Updated: 2017/01/22 21:39:49 by ariard ### ########.fr */
|
||||
/* Updated: 2017/01/22 22:19:42 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -48,6 +48,8 @@ int ft_read_script(char *file)
|
|||
return (-1);
|
||||
if (rs_loop(file, script) < 0)
|
||||
return (-1);
|
||||
if (rs_shebang_check(file, script) < 0)
|
||||
return (-1);
|
||||
script->buffer = NULL;
|
||||
DG("{inv}{bol}{gre}read of script{eoc} script detected");
|
||||
return (1);
|
||||
|
|
|
|||
78
42sh/src/read-script/rs_shebang.c
Normal file
78
42sh/src/read-script/rs_shebang.c
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* rs_shebang.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/22 21:42:27 by ariard #+# #+# */
|
||||
/* Updated: 2017/01/22 22:53:34 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
static char *rs_shebang_parse_interpreter(char *shebang)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = ft_strlen(shebang) - 1;
|
||||
while (shebang[i])
|
||||
{
|
||||
if (shebang[i] == '/')
|
||||
return (&shebang[++i]);
|
||||
i--;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
static int rs_valid_interpreter(char *interpreter)
|
||||
{
|
||||
if (ft_strncmp(interpreter, "bash", ft_strlen("bash")) == 0)
|
||||
return (1);
|
||||
if (ft_strncmp(interpreter, "csh", ft_strlen("csh")) == 0)
|
||||
return (1);
|
||||
if (ft_strncmp(interpreter, "ksh", ft_strlen("bash")) == 0)
|
||||
return (1);
|
||||
if (ft_strncmp(interpreter, "sh", ft_strlen("bash")) == 0)
|
||||
return (1);
|
||||
if (ft_strncmp(interpreter, "tcsh", ft_strlen("bash")) == 0)
|
||||
return (1);
|
||||
if (ft_strncmp(interpreter, "tcsh", ft_strlen("bash")) == 0)
|
||||
return (1);
|
||||
if (ft_strncmp(interpreter, "minishell", ft_strlen("minishell")) == 0)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void rs_set_line_input(char *interpreter, char *file)
|
||||
{
|
||||
char *buffer;
|
||||
|
||||
buffer = ft_strnew(1024);
|
||||
ft_strncpy(buffer, interpreter, ft_strlen(interpreter));
|
||||
ft_strncat(buffer, " ", 1);
|
||||
ft_strncat(buffer, file, ft_strlen(file));
|
||||
data_singleton()->line.input = buffer;
|
||||
data_singleton()->opts &= ~SHELL_MODE_MASK;
|
||||
data_singleton()->opts |= SHELL_MODE_INPUT;
|
||||
}
|
||||
|
||||
int rs_shebang_check(char *file, t_script *script)
|
||||
{
|
||||
char *interpreter;
|
||||
|
||||
if (!script || !script->queue || !script->queue->next)
|
||||
return (0);
|
||||
interpreter = rs_shebang_parse_interpreter(script->queue->next->content);
|
||||
if (interpreter == NULL || rs_valid_interpreter(interpreter) == 0)
|
||||
rs_set_line_input("sh", file);
|
||||
else if (ft_strncmp(interpreter, "minishell", ft_strlen("minishell")) != 0)
|
||||
rs_set_line_input(interpreter, file);
|
||||
else if (ft_strncmp(interpreter, "minishell", ft_strlen("minishell")) == 0)
|
||||
{
|
||||
data_singleton()->opts &= ~SHELL_MODE_MASK;
|
||||
data_singleton()->opts |= SHELL_MODE_EXEC;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
Loading…
Reference in a new issue