From f81a51cdd8c216537b14289a335c965f4d91109f Mon Sep 17 00:00:00 2001 From: "ariard@student.42.fr" Date: Sun, 22 Jan 2017 22:55:34 +0100 Subject: [PATCH] others shebang ok --- 42sh/includes/.readscript.h.swp | Bin 12288 -> 12288 bytes 42sh/includes/exec.h | 2 +- 42sh/includes/minishell.h | 5 +- 42sh/includes/readscript.h | 4 +- 42sh/script.sh | 2 +- 42sh/src/exec/exec_ampersand.c | 2 +- 42sh/src/exec/exec_command.c | 2 +- 42sh/src/exec/ft_exec.c | 2 +- 42sh/src/exec/launch_process.c | 2 +- 42sh/src/exec/process_setexec.c | 2 +- 42sh/src/line-editing/ft_readline.c | 2 +- 42sh/src/line-editing/rl_merge_line.c | 2 +- 42sh/src/line-editing/rl_setup.c | 2 +- 42sh/src/main/.main.c.swo | Bin 12288 -> 12288 bytes 42sh/src/main/main.c | 7 +- 42sh/src/main/shell_get_opts.c | 2 +- 42sh/src/main/shell_init.c | 2 +- 42sh/src/read-script/.ft_read_script.c.swp | Bin 12288 -> 12288 bytes .../.rs_shebang.c.swp} | Bin 12288 -> 12288 bytes 42sh/src/read-script/ft_read_script.c | 4 +- 42sh/src/read-script/rs_shebang.c | 78 ++++++++++++++++++ 21 files changed, 104 insertions(+), 18 deletions(-) rename 42sh/src/{line-editing/.ft_readline.c.swp => read-script/.rs_shebang.c.swp} (69%) create mode 100644 42sh/src/read-script/rs_shebang.c diff --git a/42sh/includes/.readscript.h.swp b/42sh/includes/.readscript.h.swp index 69ba5059fb6607f965696b954f5b50cda8caa519..747c167aa887573d7bd2381b8b4521531f6f0ddd 100644 GIT binary patch delta 163 zcmZojXh;xCG6?hZRWR2xW&i>K28Jh!tr1x-H;P?mW-TpA)3wJrlZoBP%Fxov*l4qd?hYmZ DL%1&f delta 98 zcmZojXh;xCG6?hZRWR2xW&i>K1_pl7)`*q&H;P?mo|wS8`5m(o52MCrL4nWwyx%w( w7&dW1RB22WR9MUg;%(&G%*gVCb8@v7-{u2ajZEx@Rz@aPCgz(xbayZT00|HpYybcN diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index e9f22dc9..279d7450 100644 --- a/42sh/includes/exec.h +++ b/42sh/includes/exec.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 */ /* */ /* ************************************************************************** */ diff --git a/42sh/includes/minishell.h b/42sh/includes/minishell.h index 47191403..e0a4a1f4 100644 --- a/42sh/includes/minishell.h +++ b/42sh/includes/minishell.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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" diff --git a/42sh/includes/readscript.h b/42sh/includes/readscript.h index 11228a50..d12f2cc3 100644 --- a/42sh/includes/readscript.h +++ b/42sh/includes/readscript.h @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 diff --git a/42sh/script.sh b/42sh/script.sh index 8fb9fff0..4065c7cb 100755 --- a/42sh/script.sh +++ b/42sh/script.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/yolosh while [ 1 ]; do sleep 1 echo "a" diff --git a/42sh/src/exec/exec_ampersand.c b/42sh/src/exec/exec_ampersand.c index ad4123d8..a3ab0fa9 100644 --- a/42sh/src/exec/exec_ampersand.c +++ b/42sh/src/exec/exec_ampersand.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/exec_command.c b/42sh/src/exec/exec_command.c index 6b2c2562..17da9096 100644 --- a/42sh/src/exec/exec_command.c +++ b/42sh/src/exec/exec_command.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/ft_exec.c b/42sh/src/exec/ft_exec.c index b656db94..462674d4 100644 --- a/42sh/src/exec/ft_exec.c +++ b/42sh/src/exec/ft_exec.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/launch_process.c b/42sh/src/exec/launch_process.c index 9857891f..ca0b0bbe 100644 --- a/42sh/src/exec/launch_process.c +++ b/42sh/src/exec/launch_process.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/process_setexec.c b/42sh/src/exec/process_setexec.c index 2ce1d0a3..db7afc51 100644 --- a/42sh/src/exec/process_setexec.c +++ b/42sh/src/exec/process_setexec.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line-editing/ft_readline.c b/42sh/src/line-editing/ft_readline.c index e7b4a105..90f36e9e 100644 --- a/42sh/src/line-editing/ft_readline.c +++ b/42sh/src/line-editing/ft_readline.c @@ -6,7 +6,7 @@ /* By: sbenning +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line-editing/rl_merge_line.c b/42sh/src/line-editing/rl_merge_line.c index 50ee04af..91a3f8ff 100644 --- a/42sh/src/line-editing/rl_merge_line.c +++ b/42sh/src/line-editing/rl_merge_line.c @@ -6,7 +6,7 @@ /* By: sbenning +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line-editing/rl_setup.c b/42sh/src/line-editing/rl_setup.c index c505c991..4870c0a7 100644 --- a/42sh/src/line-editing/rl_setup.c +++ b/42sh/src/line-editing/rl_setup.c @@ -6,7 +6,7 @@ /* By: sbenning +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/.main.c.swo b/42sh/src/main/.main.c.swo index 457e93ebd7784e760e2fe818b783dd64267e4b6a..2ec104e90ca9acf3f0e70c01db2d7441b7d38cf5 100644 GIT binary patch delta 151 zcmZojXh;xCG6?hZRWR2xW&i>K28NZItr1J#ZWQ~)&*->WP~bB^?`<{)hTrTES;xtO z3fGM;a4;~;0^%MZ?gZjGAg%)9R3HumVi_Rj1!68B{tMLkn|(7Q%R{!wY#Kt7Jv3@3 jf6!2$T%;k(V$Hx=z4?+xJ`1~%m8p@HiQ#4s-5pE-e~2Sv delta 179 zcmZojXh;xCG6?hZRWR2xW&i>K28Ox9tq~4)Hj4e?XSCZaDDat|SBag0!HfeUYd2X? z;kw=tAa5rSZw2B7Ks*tM!-3cXh+To$0*FC6l!2IyV>2Vm2e!$-)rI8r^*K2?i&9HU ui}Gq2pbP~K15IlN&RT|Appt%GWKqt|mo)NO*bS`=Ev$^qH+$&rU;+T9#wmpW diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 98bf0967..e64ce801 100644 --- a/42sh/src/main/main.c +++ b/42sh/src/main/main.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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])) - return (0); + { + shell_single_command(data_singleton()->line.input); + return (0); + } while (1) { if (ft_readline()) diff --git a/42sh/src/main/shell_get_opts.c b/42sh/src/main/shell_get_opts.c index 04fb5a22..9096ee5e 100644 --- a/42sh/src/main/shell_get_opts.c +++ b/42sh/src/main/shell_get_opts.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/shell_init.c b/42sh/src/main/shell_init.c index eca82051..c6f549e0 100644 --- a/42sh/src/main/shell_init.c +++ b/42sh/src/main/shell_init.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/read-script/.ft_read_script.c.swp b/42sh/src/read-script/.ft_read_script.c.swp index cfd7b8e5e470c64de7e8ab8484431ba649b44bc1..48f63c7ad8edd66f56957b07b7e6718865e5f452 100644 GIT binary patch delta 205 zcmZojXh;xCG6?hZRWR2xW&i>K28MTvtr0mdH;Vn@XSCQXDDat|SDJ%?L7WpJYcW|+ z;k;f4kXH%Bi9oCd#F9V^QXvDxd_c?##5_R!4yf}6$7V*B{p^!(Xo#8QmDScVa2BPO zlosVFXc%f*GjO_K2)Jt~)q((2;bec!O5Wm()TG3`^!VhA)a2~RXEe1ppU|viW;e1j Ow6roY+U%jbg9!lmnle%V delta 216 zcmZojXh;xCG6?hZRWR2xW&i>K28O8;tr7Z9H;Vn@XEfU^DDat|H=2Wi!JiW%Yc^R> z;k@2VATJJx1A!PM;|IicK&%bKl0f_qsN**fzXReM9Ge+gPO(out05*(%fMNbT2fk+ zr=Ve|3FH6;B`vCxP=u`+I9=Q^MKpjy$fC8iAkC8vG!r(T(5z%;H?%Ugv@)^W?4i4Z F2>`VYH5mW^ diff --git a/42sh/src/line-editing/.ft_readline.c.swp b/42sh/src/read-script/.rs_shebang.c.swp similarity index 69% rename from 42sh/src/line-editing/.ft_readline.c.swp rename to 42sh/src/read-script/.rs_shebang.c.swp index b02632a54ad7b7248e527143145e2f36f058d0f7..7e751dc17c105905aa9072af6a2f21ece24025a8 100644 GIT binary patch literal 12288 zcmeI2Pi)&%9LIl!vEe}h!GS-g*Hl`aq=^%!sK}$yMpwi{+f6E+CZ-a(&dcJ}b%O0| ztJ)0-Q7%Z_nUD}j960TS;D7{25GN2qf&(Y6oW?lweR+1`wpr;$BsBCqeQNvp_rCtU zuYd1VQ{QUo-01~2U91p}Cy0K_ZlC|=k7vn#dW7u2wS&5Nu>Zj;!3%A(T%0nCjbNY9 z>r&7-8?-KQCkl-zGi(}R;1~h7>xIw>+;(IHVJ&R(RolN#R@ z)k!&^98eA@2b2TK0p);lKslfsP!1>ulmp6v`_KU!f8RfHi0HyYNFIOxPyYXZ^Kqg# zz$p0YF`_l_9QbaO=qi{1KR-&e4c-CkzylRf20EAkN5Nl@5Zwa5g0I1s;B)XP_yl|m zeBgm1VBq(o&<7uY_rMu&5Ix?}BYG531nSVWOMheQ*Li1HOk>-+~)p9b5t{KzR5%uz)(01ImH_ zjRV(63wYECeAd6xOWEV3HKJO(6NOQr*X_uzg|2_m<5A1kukDV+y|ybRTd20$QOLGt z*wQO=^YgWZGpFWibLZz~p?s&{V>9e}Dth7M(yNHxB#n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Fy3ld7(0 zH;sCHCxKpd5vP1dT`=!b7q2~7wpq9vlG?|<9L~Lo-H0a zaIiU@f%lSQ&M(AFYgEqz>7-O0j1^vv^RF>nvTdtoHmnxaFU1R`dxz>f6dzFw_YOko z9xf(`CcdDsR#?Z&Mqizo2wi1xt-R5&iVnpUP z>UF1GSS(EMF9u374`>0ULgMx5F6{$!|aM(?{Maaobb3*%P?6t{lhLTGKLWjS8dNL!bTq3)=}v zchl~Bw$bi1H@t_NGMuU7iw>*gX)cr9oz7&_xg5=9^O;@w+#sD>rvBs2p^m${x^RTw zV#CAH@|-dp!B+rfxGSB_r87e`JCx51Uq)iFprk!Kk>aUXeUg1^2#aXsSE?{8uz$c;D|b5GF+QSiz=U2me}JP&i^OF7JqT*8{V@E1s7eK{0lAUxtst1 diff --git a/42sh/src/read-script/ft_read_script.c b/42sh/src/read-script/ft_read_script.c index 4e674620..92a11f9d 100644 --- a/42sh/src/read-script/ft_read_script.c +++ b/42sh/src/read-script/ft_read_script.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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); diff --git a/42sh/src/read-script/rs_shebang.c b/42sh/src/read-script/rs_shebang.c new file mode 100644 index 00000000..090cb834 --- /dev/null +++ b/42sh/src/read-script/rs_shebang.c @@ -0,0 +1,78 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* rs_shebang.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ariard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +}