From e4682de358917913093d2b2e47be392e76dbd4b1 Mon Sep 17 00:00:00 2001 From: "ariard@student.42.fr" Date: Sun, 22 Jan 2017 21:40:30 +0100 Subject: [PATCH] read script queue ok --- 42sh/includes/.readscript.h.swp | Bin 0 -> 12288 bytes 42sh/includes/readscript.h | 9 ++--- 42sh/src/job-control/sigint_handler.c | 2 +- 42sh/src/job-control/sigtstp_handler.c | 2 +- 42sh/src/job-control/sigttin_handler.c | 2 +- 42sh/src/line-editing/.ft_readline.c.swp | Bin 0 -> 12288 bytes 42sh/src/line-editing/ft_readline.c | 2 +- 42sh/src/line-editing/rl_dynamic_buffer.c | 2 +- 42sh/src/line-editing/rl_setup.c | 2 +- 42sh/src/main/.main.c.swo | Bin 0 -> 12288 bytes 42sh/src/main/data_exit.c | 2 +- 42sh/src/main/data_init.c | 2 +- 42sh/src/main/main.c | 14 ++++---- 42sh/src/main/shell_init.c | 2 +- 42sh/src/read-script/.ft_read_script.c.swp | Bin 0 -> 12288 bytes 42sh/src/read-script/ft_read_script.c | 39 ++++++++++++++++++--- 42sh/src/read-script/rs_setup.c | 23 ------------ 17 files changed, 53 insertions(+), 50 deletions(-) create mode 100644 42sh/includes/.readscript.h.swp create mode 100644 42sh/src/line-editing/.ft_readline.c.swp create mode 100644 42sh/src/main/.main.c.swo create mode 100644 42sh/src/read-script/.ft_read_script.c.swp delete mode 100644 42sh/src/read-script/rs_setup.c diff --git a/42sh/includes/.readscript.h.swp b/42sh/includes/.readscript.h.swp new file mode 100644 index 0000000000000000000000000000000000000000..69ba5059fb6607f965696b954f5b50cda8caa519 GIT binary patch literal 12288 zcmeI2KX21O7{=dr3s8zc3?LyLL_nLMIB|mlEj&L(m`8^b`6HeS@o;*g@#a@SK>QnZBdzPY!}KKU!$YKqtzMT#&vB zh35;^mdQe$8->zArrnB^-AN){VU~w|w#xHu<#m0Ll&2RZb?arFPPb(%Sj3BPAZ@<+ zBG2zd3Trl*)mZbGaB&`D?#9*YccrS|qLt)i7Arh}x*47cYokY!n!B}Teo{+|p7{Npe& M+_eV<51m1O0d?(L>Hq)$ literal 0 HcmV?d00001 diff --git a/42sh/includes/readscript.h b/42sh/includes/readscript.h index 2334db34..11228a50 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 00:37:21 by ariard ### ########.fr */ +/* Updated: 2017/01/22 21:24:47 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,7 +25,6 @@ struct s_script { char *buffer; int b_size; - int used; int q_size; t_list *queue; }; @@ -35,9 +34,7 @@ typedef struct s_script t_script; /* * Read_script setup/cleanup */ - -int rs_setup(t_script *script); - -int ft_read_script(); + +int ft_read_script(char *file); #endif diff --git a/42sh/src/job-control/sigint_handler.c b/42sh/src/job-control/sigint_handler.c index de5ec7dd..93e6c4cf 100644 --- a/42sh/src/job-control/sigint_handler.c +++ b/42sh/src/job-control/sigint_handler.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/10 15:14:47 by jhalford #+# #+# */ -/* Updated: 2017/01/10 17:24:06 by jhalford ### ########.fr */ +/* Updated: 2017/01/22 20:56:45 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/sigtstp_handler.c b/42sh/src/job-control/sigtstp_handler.c index ecae88cb..6fd5a311 100644 --- a/42sh/src/job-control/sigtstp_handler.c +++ b/42sh/src/job-control/sigtstp_handler.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/10 15:14:53 by jhalford #+# #+# */ -/* Updated: 2017/01/11 14:51:27 by jhalford ### ########.fr */ +/* Updated: 2017/01/22 19:03:32 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/sigttin_handler.c b/42sh/src/job-control/sigttin_handler.c index 1b424bf5..b28e84be 100644 --- a/42sh/src/job-control/sigttin_handler.c +++ b/42sh/src/job-control/sigttin_handler.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/10 15:14:53 by jhalford #+# #+# */ -/* Updated: 2017/01/09 16:37:32 by jhalford ### ########.fr */ +/* Updated: 2017/01/22 17:22:10 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line-editing/.ft_readline.c.swp b/42sh/src/line-editing/.ft_readline.c.swp new file mode 100644 index 0000000000000000000000000000000000000000..b02632a54ad7b7248e527143145e2f36f058d0f7 GIT binary patch literal 12288 zcmeI2Piz!b9LFDs;wmVh7fp;$n!s-V?Vna?7K&oK0;aTe+gjw`W;^?~9lFe{GqaY` zR1b&}Z+a5(CWtY-}n9A z_r00jrZbm$?a*PmyMKUS+d{~3;$ z$W?Fwlt4FF2d*aw`4lXIQLq)sz@dT@IKAwPldz!%^$cpqEo^#0665AWp)b(BEX`v~e86H<7=~@5m(rZ+p&T)mUMd1f zBl5ZCHk9VhpBLZ+I!$fqx+56=B9y z;m=aSuq`~r)L_j*L}NNUEaoO5k9b}DA*UoC8fIc?!K^Ww9L%9UoI>BFx?`WN`$L2X zlO>}=I%rd~t$FIdB`o)l72s`1fq$_ z*P|-CzT7UGDvT9IrqTC-!sx{8xNL#GT~@=Rc_?9?@w-KP%a$fsJG|gd>QFy3ld7(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 literal 0 HcmV?d00001 diff --git a/42sh/src/line-editing/ft_readline.c b/42sh/src/line-editing/ft_readline.c index 85b96e20..e7b4a105 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 00:37:17 by ariard ### ########.fr */ +/* Updated: 2017/01/22 21:06:24 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line-editing/rl_dynamic_buffer.c b/42sh/src/line-editing/rl_dynamic_buffer.c index 932db10b..c52ea08c 100644 --- a/42sh/src/line-editing/rl_dynamic_buffer.c +++ b/42sh/src/line-editing/rl_dynamic_buffer.c @@ -6,7 +6,7 @@ /* By: sbenning +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/08 18:42:31 by sbenning #+# #+# */ -/* Updated: 2017/01/21 22:41:19 by ariard ### ########.fr */ +/* Updated: 2017/01/22 21:24:09 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line-editing/rl_setup.c b/42sh/src/line-editing/rl_setup.c index ead0b93e..c505c991 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/21 23:27:14 by ariard ### ########.fr */ +/* Updated: 2017/01/22 21:25:10 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/.main.c.swo b/42sh/src/main/.main.c.swo new file mode 100644 index 0000000000000000000000000000000000000000..457e93ebd7784e760e2fe818b783dd64267e4b6a GIT binary patch literal 12288 zcmeI2&2QsG7{+Ij*u_8r?Fu9~O&zv%(=?9L(nenBZa;Sm*>*)+b|ngy>o|#9$2Rt~ zv_t_3v3K|bkoXHg0&zgvBNxsqIC0~^azf(3nP>cwq#tyvrI$rB)h`~;%=^4=9*?6` z@n-3rrJHoBI8M-BAmqzSckf*L^=0zycZ8UsV}><8adNZA!%9%riWB8xJv?FQ$BCeN zEA+Q)i$&^0Iclm=XsIpJ@#2@Fbwa$D5)KFl9?^jvRv)Vjknyrs;tDx=kY2jD{)l2C zOgJDM5Do|jgag6>;ec>JI3OH&935c6Ir0e#e z;ec>JI3OGl4hRQ?1HysF&;b*_@5>hmnS2VxJOKB==ipPY0~+8e(7=m;fZv`bd z5jkGNwGGQ}wM?(3)J$fkW6bxIk+Esl@$91G1v_kH1d-iRdO~$(gtl4Z3l+YmEfML% zrsLW?8$$Yu#|%%MMi`M5IssG6-FLP3cqA(CUyZY4i%bR^HZ#m!UNExaO|=v4qwl~E zSVV{D>WzhJ)mXW;wrW)8kStMgJO>3>1#0eck@@S2+;+U(PJ7dLJMBhjcOqtnjQVvN z2efV9>d-BJ6P9@_^j+#i^l~H@=xGwaxiULPuTptsS*AJ;i;FU{wu$30N#f60D(F#O zj@2|nn$M#uLJnWhu1E1TNDa03Y)ct3qxdqZd8%r8y2(P@Hq0P!_YKFZJ9`S|3v>wn z<9ecB9=SsEno9F3k`PudB1uAcNV`F1 zxlGHNu2uB$DZ05&lgFF;66bO`oZ&TYcsM$p%LM1}p_U0ws#;ksO;V^$l=RmsTyU#t zx^+LS^(1qnT#=@S?sz8H9XL&A6e{T-mZR4flnKu6>%A&o-!iT3YgTA_QPB?@(|zmH zZY(mYXG(pVnc&fwhm3Hwo+9c@)iXi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/07 18:07:50 by jhalford #+# #+# */ -/* Updated: 2017/01/19 21:06:33 by ariard ### ########.fr */ +/* Updated: 2017/01/22 17:20:29 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/data_init.c b/42sh/src/main/data_init.c index c303d707..2b77bc85 100644 --- a/42sh/src/main/data_init.c +++ b/42sh/src/main/data_init.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */ -/* Updated: 2017/01/21 23:28:31 by ariard ### ########.fr */ +/* Updated: 2017/01/22 17:20:04 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index cd8b64f7..98bf0967 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 00:37:15 by ariard ### ########.fr */ +/* Updated: 2017/01/22 21:18:37 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -49,14 +49,14 @@ int main(int ac, char **av) shell_single_command(shell_get_avdata()); return (0); } + if (ft_read_script(av[1])) + return (0); while (1) { -// if (ft_read_script()) -// return (1); -// else if (ft_readline()) -// return (1); -// if (shell_single_command(data_singleton()->line.input)) -// return (1); + if (ft_readline()) + return (1); + if (shell_single_command(data_singleton()->line.input)) + return (1); } return (0); } diff --git a/42sh/src/main/shell_init.c b/42sh/src/main/shell_init.c index 461d8736..eca82051 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/21 22:02:05 by ariard ### ########.fr */ +/* Updated: 2017/01/22 20:56:35 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 new file mode 100644 index 0000000000000000000000000000000000000000..cfd7b8e5e470c64de7e8ab8484431ba649b44bc1 GIT binary patch literal 12288 zcmeI2&2QX97{;fZ>Oug)r9}cwcTw?vdeju$%)U9yBhjkdEDMi3#P> zS^D^6JIl@0QQ86RfObGTpdHW-Xa}?d+5zpr|H1)2JV8D{B@YzUJX>5(%w3DFzGw%u z1KI)YfObGTpdHW-Xa}?d+5zo=c0fCDA3EUT|NC#BBxKt_^7#M1`u_jbBZOQ5E8x3_ z33(Sh0e)B^ zzfk)<@H_Y!=%yXe4rm9o1KI)Y!2RpMgcvE~qco;wyRuGIdILA5RjEy;9Lv|0 za~s`jSmqYPnyqOs4t+Rh5LWBoVrf#82SXr~1gcsTHzpZ(dFWA*9?X+&sQhV>e}yb0 z=S4}z%)l20A#qVy##5g~<~fzOd|e_SAC58}v+Kp$>SflcoEWiqZlqGlXJQx=u~Ga3 z;cFu{Vs&DSiE({^_d?BG#(Oclf!Ht>S=H%$7POo1fxw54$q=i_9kShf{o?l4=9^+I zm3JHvQVYfV{5c(3BhA*N^ob0?azFN+O76^tJSt_o7!!sv*xU>(f&;;k2g;(TrQW< z!|%M|aC9-I1YgA8f?2^fwQZ<5o%W%Ev|JO4>Qczje^+u1V#N=HaJMgaAo#*fN0qf9 z%X>cKc!M#Qr@gyVbCgKUQA$&qs^r=DC3-^bKoNNs>Pis%b>_JE5|U2Mkx|8syePpX c1QtUaM@iyNG=%&o!Nnz%;IVyB@S(HF-}}G+z5oCK literal 0 HcmV?d00001 diff --git a/42sh/src/read-script/ft_read_script.c b/42sh/src/read-script/ft_read_script.c index 71bbc46b..4e674620 100644 --- a/42sh/src/read-script/ft_read_script.c +++ b/42sh/src/read-script/ft_read_script.c @@ -6,20 +6,49 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/21 22:49:31 by ariard #+# #+# */ -/* Updated: 2017/01/22 00:33:09 by ariard ### ########.fr */ +/* Updated: 2017/01/22 21:39:49 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -int ft_read_script() +static int rs_loop(char *file, t_script *script) +{ + int fd; + + script->queue = ft_memalloc(sizeof(t_list)); + fd = open(file, O_RDONLY); + while (get_next_line(fd, &script->buffer) > 0) + { + ft_lsteadd(&script->queue, + ft_lstnew(script->buffer, ft_strlen(script->buffer))); + ft_strdel(&script->buffer); + } + close(fd); + return (0); +} + +static int rs_setup(t_script *script) +{ + ft_bzero(script, sizeof(script)); + script->buffer = NULL; + script->b_size = 0; + script->q_size = 0; + return (0); +} + +int ft_read_script(char *file) { t_script *script; script = &data_singleton()->script; + if (!file) + return (0); if (rs_setup(script) < 0) return (-1); -// if (rs_loop(script) < 0) -// return (-1); - return (0); + if (rs_loop(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_setup.c b/42sh/src/read-script/rs_setup.c deleted file mode 100644 index 4d735c14..00000000 --- a/42sh/src/read-script/rs_setup.c +++ /dev/null @@ -1,23 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* rs_setup.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: ariard +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2017/01/21 23:08:04 by ariard #+# #+# */ -/* Updated: 2017/01/22 00:33:27 by ariard ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -int rs_setup(t_script *script) -{ - ft_bzero(script, sizeof(script)); - script->buffer = 0; - script->b_size = 0; - script->used = 0; - script->q_size = 0; - return (0); -}