From f87832a6313745ca71e99ef98d74a121a46154c1 Mon Sep 17 00:00:00 2001 From: Manzovince Date: Sun, 14 Apr 2019 17:30:46 +0200 Subject: [PATCH 1/6] New version --- fillit | Bin 0 -> 9076 bytes includes/fillit.h | 6 +++--- srcs/handle_errors.c | 6 +++--- srcs/main.c | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) create mode 100755 fillit diff --git a/fillit b/fillit new file mode 100755 index 0000000000000000000000000000000000000000..142db180e567b25239047e66d5fba82aa0b0bc7e GIT binary patch literal 9076 zcmeHNU2GIp6uw)EmftCfVnK-uriw->AR*OgEXvC8r$q`@0u0;Tfv#+KoBfgU&`7gv z!Z@s1%{G~ofwG^t4we^Lpue&3xto7pKby!kRGx%Zs! z+;h)8_uM<3*?ar__1|vZDMVz35J#GX5E@GBOd-l53Q34XC_0K^bg$bG+ZB81MQR%< z(g<&f=;ucm8b(j7x2MrW_HS*}355}xKsd6{!Y~TvP=S(5L4W(^U@~ahg9(v{n_bbZ zo5c}7G>m+q*q5)Xg8oM5yZ+WH3lDo8T9m&#l*09A^qc8HGY4JJ-yh1~tID33d9Ty7 z_!9X-E|oc;41)glV!=4yovNMKPYu4&U>L>Bp;RVmq%!-n5;v~LDdmrAP9hHaa9iA( z>)I*Tb^W@Yb-os?ALH`YG03^DTq3nhh%1ve@`nfdvT0+mkORK8zxpOJ3 ziVWjG*0)Wj`D<12wJ3Yypg(M#IvGYf{$KI6DSuwxi2eRJ-??>f{^x4T#uqln)^GHl ziD)2iz@&n5Mn5vIQY*wVJhv+;M}^>ATEIKOJ?e_W0N@Px5IEPe4Mkrn!~*co;ouTD z=h}_pC+3vJp9gkt|Oi5>qs6>C!r(Vi^4b_`y%$v&RuIR ze>3v?N1OlrxoI_YQIrUZm_J(<%5wTM&P5)9jMUa?Ii^QHRey4U2|H2P#yLl>U&Eh) zh^WVcc(xzT7tDbb&#pjRsXiEi9z>!4&ZRDYSYhTXq%Z?v2Eq)483;3QyBXM_TfgX~ ziKuQ3Pw6&_H9YBL@izOGZzbI>PU_Y1>mpxT1~DZ7uy>H*utiqgS3@fS^wb=NP7C#jcI-t<`F!;fZGL_&oR;8J^%c z+ME87`6+`aP-Cncdg(%R&-to1U)8{@S;fiH@Klpl-VRGS7kjA1`IrFN(o0i9E7LE6 zcnhOD*3DWCsdk(*5ZEf`i`FVz4|=W3&}CfpJIGsSIFp_T55EDDS4_VS}$&kC};lV2JX66v}@lELS z^$}FoIr}uVdZjW*W_{;8MAI?rbT5r-FkV7qD4}(xz;vsu(^h7OA2j+{xgQEhV*D7Y zv2u@sc9~wRv!$~&t0EmTXOFW_LK?kse5M@Nc3mdkWzS=CTkWqXlrBarDU5#!q#*1KiBSJwMv-6!iL>MfNe^T5_^ueJXJKh=IzV*FQ( z*3Zwy@t-KQQ~H6@DoU3qJws`f(q>AhD7`}IQ%WYK6O{OKa{N6=1v6g|v0N^jdouc5 zwwO*vGuc8kXU3D!{i(FMVz$?~G4onHoeFBZ(`GzxM)SqKfm9(H_xd1qaUTlF&#|@S z@7*=vEc~rXqRfQN#rJP3ilVyUDg3-y{SKV3c$?zO6n|9lwTgEszDe;O#r-}*Im|$q zfiMGM2Eq)483;2FW+2Q!n1L_@VFtnsgcIlu+)5jBD_;Yu5{OD3>bGwTKw_-+-CMKtBdB z6UBmwyZ1Q5+#p>UVsoP3#H@JUVwgON$qS61%7`SrOTEbO=tMNhX0c12+N5TPs|#^# za^fCT)kTyRqq@47mI7^ElaXqqO9E7Mphb9A<=$N`lvs!pxIE=S3-1v%2)w5x?ogQj zpFsSS!ciQT66;>O!aVzgo=uW?*yP7U0sMLZmjjrG#s2 +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */ -/* Updated: 2019/04/14 12:34:30 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/14 17:29:58 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,7 +20,7 @@ #include // for debug printf #include // to use bool type -# define BUFFER_SIZE 1024 +# define BUFF_SIZE 1024 /* ** DELETE BEFORE EVALUATION @@ -33,7 +33,7 @@ void print_test(char *test); */ char *read_file(char *file); -void ft_display_error(char *s, int fd); +void print_error(char *s); int ft_file_errors(char *file); #endif diff --git a/srcs/handle_errors.c b/srcs/handle_errors.c index 09b7c72..66a0915 100644 --- a/srcs/handle_errors.c +++ b/srcs/handle_errors.c @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/01 13:29:05 by vmanzoni #+# #+# */ -/* Updated: 2019/04/14 14:16:01 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/14 17:30:30 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,9 +16,9 @@ ** Function that display error message *s on fd */ -void ft_display_error(char *s, int fd) +void print_error(char *s, int fd) { - write(fd, s, strlen(s)); + write(2, s, strlen(s)); } /* diff --git a/srcs/main.c b/srcs/main.c index cfb8a6a..f88adee 100644 --- a/srcs/main.c +++ b/srcs/main.c @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/02/12 13:20:48 by vmanzoni #+# #+# */ -/* Updated: 2019/04/14 14:17:22 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/14 17:30:14 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,9 +19,9 @@ int main(int argc, char **argv) if (argc == 2) { if (!(input = read_file(argv[1]))) - ft_display_error("Error: Could not read file.\n", 2); + ft_display_error("Error: Could not read file.\n"); if (ft_file_errors(input)) - ft_display_error("Error: Invalid file.\n", 2); + ft_display_error("Error: Invalid file.\n"); /* Check if every tetrimino is valid Transform input to tetriminos @@ -31,7 +31,7 @@ int main(int argc, char **argv) */ } else - ft_display_error("Error: Please submit a file.\n", 2); + ft_display_error("Error: Please submit a file.\n"); return (0); print_test(input); } From 451a07b7623ad6d5dbd3261eef45e69991dee215 Mon Sep 17 00:00:00 2001 From: Manzovince Date: Sun, 14 Apr 2019 17:47:13 +0200 Subject: [PATCH 2/6] READING FILE WORKING --- includes/fillit.h | 4 ++-- srcs/handle_errors.c | 18 ++++++++++-------- srcs/main.c | 10 +++++----- srcs/read_file.c | 11 ++++++----- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/includes/fillit.h b/includes/fillit.h index 803d391..3a3ea69 100644 --- a/includes/fillit.h +++ b/includes/fillit.h @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */ -/* Updated: 2019/04/14 17:29:58 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/14 17:43:41 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -34,6 +34,6 @@ void print_test(char *test); char *read_file(char *file); void print_error(char *s); -int ft_file_errors(char *file); +int check_file_errors(char *file); #endif diff --git a/srcs/handle_errors.c b/srcs/handle_errors.c index 66a0915..5553a00 100644 --- a/srcs/handle_errors.c +++ b/srcs/handle_errors.c @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/01 13:29:05 by vmanzoni #+# #+# */ -/* Updated: 2019/04/14 17:30:30 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/14 17:46:32 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,7 +16,7 @@ ** Function that display error message *s on fd */ -void print_error(char *s, int fd) +void print_error(char *s) { write(2, s, strlen(s)); } @@ -28,18 +28,20 @@ void print_error(char *s, int fd) ** - two \n in a row */ -int ft_file_errors(char *file) +int check_file_errors(char *file) { + int i; int line_nbr; + i = 0; line_nbr = 0; - while (*file) + while (file[i]) { - if (*file == '\n') + if (file[i] != '.' && file[i] != '#' && file[i] != '\n') + return (1); + if (file[i] == '\n') line_nbr++; - file++; - if (*file == '\n') - return (1); + i++; } if (line_nbr < 4 || line_nbr > 129) return (1); diff --git a/srcs/main.c b/srcs/main.c index f88adee..0896793 100644 --- a/srcs/main.c +++ b/srcs/main.c @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/02/12 13:20:48 by vmanzoni #+# #+# */ -/* Updated: 2019/04/14 17:30:14 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/14 17:44:38 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,9 +19,9 @@ int main(int argc, char **argv) if (argc == 2) { if (!(input = read_file(argv[1]))) - ft_display_error("Error: Could not read file.\n"); - if (ft_file_errors(input)) - ft_display_error("Error: Invalid file.\n"); + print_error("Error: Could not read file.\n"); + if (check_file_errors(input)) + print_error("Error: Invalid file.\n"); /* Check if every tetrimino is valid Transform input to tetriminos @@ -31,7 +31,7 @@ int main(int argc, char **argv) */ } else - ft_display_error("Error: Please submit a file.\n"); + print_error("Error: Please submit a file.\n"); return (0); print_test(input); } diff --git a/srcs/read_file.c b/srcs/read_file.c index 837ce68..954e52c 100644 --- a/srcs/read_file.c +++ b/srcs/read_file.c @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/13 12:09:46 by vmanzoni #+# #+# */ -/* Updated: 2019/04/14 14:23:24 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/14 17:44:18 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,23 +14,24 @@ char *read_file(char *file) { - char buf[BUFFER_SIZE]; + char buf[BUFF_SIZE]; int fd; int rv; int i; char *result; if (((fd = open(file, O_RDONLY)) < 0) \ - || ((rv = read(fd, &buf, BUFFER_SIZE)) < 0) \ - || !(result = malloc(sizeof(char)))) + || ((rv = read(fd, &buf, BUFF_SIZE)) < 0) \ + || !(result = malloc(sizeof(char) * rv))) return (NULL); buf[rv] = '\0'; i = 0; - while (rv--) + while (buf[i]) { result[i] = buf[i]; i++; } + result[i] = '\0'; close(fd); return (result); } From 1d244568dc78a72d7dd563354d3334938c9531c6 Mon Sep 17 00:00:00 2001 From: Manzovince Date: Sun, 14 Apr 2019 18:03:55 +0200 Subject: [PATCH 3/6] Adding v0 parse_input --- .gitignore | 2 ++ srcs/handle_errors.c | 11 +++-------- srcs/read_file.c | 29 ++++++++++++++++++++++++++++- 3 files changed, 33 insertions(+), 9 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c605b66 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ + +objs/ diff --git a/srcs/handle_errors.c b/srcs/handle_errors.c index 5553a00..a149b54 100644 --- a/srcs/handle_errors.c +++ b/srcs/handle_errors.c @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/01 13:29:05 by vmanzoni #+# #+# */ -/* Updated: 2019/04/14 17:46:32 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/14 17:53:24 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -41,16 +41,11 @@ int check_file_errors(char *file) return (1); if (file[i] == '\n') line_nbr++; + if (file[i] == '\n' && file[i+1] == '\n') + return (1); i++; } if (line_nbr < 4 || line_nbr > 129) return (1); return (0); } - -/* -int ft_tetri_errors() -{ - -} -*/ diff --git a/srcs/read_file.c b/srcs/read_file.c index 954e52c..6ed8b27 100644 --- a/srcs/read_file.c +++ b/srcs/read_file.c @@ -6,12 +6,16 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/13 12:09:46 by vmanzoni #+# #+# */ -/* Updated: 2019/04/14 17:44:18 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/14 18:03:20 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ #include "../includes/fillit.h" +/* +** Function that read and return a ptr to file +*/ + char *read_file(char *file) { char buf[BUFF_SIZE]; @@ -35,3 +39,26 @@ char *read_file(char *file) close(fd); return (result); } + +/* +** Function that parse a file and return each tetrimino +*/ + +int parse_input(char *input) +{ + int i; + int j; + int nl; + + i = 0; + nl = 0; + while (input[i]) + { + j = 0; + while (j != 4) + { + square[j][] = + j++; + } + } +} From 5d6b2b0db3d8a8c3e2095635a4043189d6c21af9 Mon Sep 17 00:00:00 2001 From: Manzovince Date: Sun, 14 Apr 2019 18:55:27 +0200 Subject: [PATCH 4/6] v0.1 parse_input Not tested --- srcs/handle_errors.c | 40 +++++++++++++++++++++++++++++++++++++++- srcs/read_file.c | 29 ++++++++++++++++++----------- 2 files changed, 57 insertions(+), 12 deletions(-) diff --git a/srcs/handle_errors.c b/srcs/handle_errors.c index a149b54..aa6652d 100644 --- a/srcs/handle_errors.c +++ b/srcs/handle_errors.c @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/01 13:29:05 by vmanzoni #+# #+# */ -/* Updated: 2019/04/14 17:53:24 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/14 18:40:49 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -49,3 +49,41 @@ int check_file_errors(char *file) return (1); return (0); } + +int check_tetri_errors(char *tetri) +{ + int i; + int htg; + int dot; + + i = 0; + htg = 0; + dot = 0; + while (tetri[i]) + { + if (tetri[i] = '#') + htg++; + else if (tetri[i] = '.') + dot++; + } + if (htg != 4 || dot != 12 || check_tetri_errors2(tetri)) + return (1); + return (0); +} + +/* +int check_tetri_errors2(char *tetri) +{ + int i; + + i = 0; + while (tetri[i]) + { + if (tetri[i] == '#') + { + + } + } + return (0); +} +*/ diff --git a/srcs/read_file.c b/srcs/read_file.c index 6ed8b27..b67d965 100644 --- a/srcs/read_file.c +++ b/srcs/read_file.c @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/13 12:09:46 by vmanzoni #+# #+# */ -/* Updated: 2019/04/14 18:03:20 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/14 18:54:53 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -46,19 +46,26 @@ char *read_file(char *file) int parse_input(char *input) { - int i; - int j; - int nl; + char /*NOM DE LA VARIABLE*/; + int c; + int i; + int j; - i = 0; - nl = 0; - while (input[i]) + c = 0; + while (input[c]) { - j = 0; - while (j != 4) + i = 0; + while (i < 4) { - square[j][] = - j++; + j = 0; + while (j < 4) + { + /*NOM DE LA VARIABLE[j]*/ = input[c++]; + j++; + } + c++; + i++; } + c++; } } From 9d8940e6a5bdad5aa71684a0e01647f6fc5ad937 Mon Sep 17 00:00:00 2001 From: Manzovince Date: Sun, 14 Apr 2019 21:39:40 +0200 Subject: [PATCH 5/6] Folders deleted --- fillit | Bin 9076 -> 8988 bytes includes/fillit.h => fillit.h | 0 ...smallest_square.c => get_smallest_square.c | 4 ++-- srcs/handle_errors.c => handle_errors.c | 4 ++-- srcs/main.c => main.c | 4 ++-- srcs/print_fillit.c => print_fillit.c | 4 ++-- srcs/read_file.c => read_file.c | 4 ++-- 7 files changed, 10 insertions(+), 10 deletions(-) rename includes/fillit.h => fillit.h (100%) rename srcs/get_smallest_square.c => get_smallest_square.c (90%) rename srcs/handle_errors.c => handle_errors.c (95%) rename srcs/main.c => main.c (93%) rename srcs/print_fillit.c => print_fillit.c (90%) rename srcs/read_file.c => read_file.c (94%) diff --git a/fillit b/fillit index 142db180e567b25239047e66d5fba82aa0b0bc7e..a41305e77673c73b54f47f6348541c3c96bbcfb5 100755 GIT binary patch delta 1279 zcmZWpUuaup6hB}7xU^0BC7ozpSDU1N*rv?ZX^CsM#fP+?&eDZ3^`+P@E3VktS}X3Q zCN;UZ>uoUI!8gG__@F2lEJ7dFbzMv2M1_G572MVr;Rf;$P^5EWJm=m!9T@n&@0{Q7 zoZmU;yZ7ezfe!`>TjH(7p9e!X8vz6W9H7O&o7f|cHTk5CK5v8IllZn65J|iy217-M zR1R6hi0ccn3x9A8_&KGUAEbkt_4`y%IOYL6an59v% zG%Dr(V69fm&Y2#$5FlcH&cq3S*f+9XuzvWSzxDL9j;=D!`%GlVx}6=cg;oB@B;B7m z@prAJj5*W%h>R?;);z?%!t8MZ%iIS6(+nIYpy!Hx$@p-frRgi0dzELu`yf8WoW1m)@4FNAU7g(Rsg110KLjTJ^!K40ZS|IvJe zLreO~76;cTxPwckH1^fnHtCnlI}GXCw*;jXD{B1asFG$9LKc)SvTrAC=De&8CG97N zC4$Y&C7Y1BLv}QS?=D!NGAwnKdY{1y{-E&<8`({vTSj@Ao(l)1300{)lbaqN*yEV| z%_$?#4Jtj)UFq5eJBHPwG6JJCrZVc3acW0Bb)AM;Cfb?9upBkN!FM~dZqmhqY^ZfU zK{>U~UTcq8`(Y7gsNZsqT6>)K=kl$$Dd*{vwa)TI*)9%YhwQ?XOyZKqF7z7bqS=aSXNZ#@6uAk#l2{lT#@uz)W{2{?gR+_^WKk$etM=JHvLI z?AK>!CT&KM_vXyR>^M zKaDW3M0V$6-WWgUU1cFn_O zY>*p2bFCVpx^mnis2s17;%2AQdZ8JOprq2MTcpSUBGL8wdBx`1aiQWutFP@kE}?$)jo)Hf zyyor9-9xkJZ`^cWMJI03WccmYM!|}kQh{q9Y7PAyF~wAiFQDej%Miv*bB$15D9n&D zzO@cfYS~yzP_m8WASD9?YHdStL+6w$+52;Zl=TT9uvldQqO6~8xTa2Rj16tWHVU#M zUCL3aNy?-vi*9+aS?`&ApDGtTe)9`5v^$C+jmj!K-b^Y`?2fC2VfY+O>s4xK7UWn) zfo3uE=OIx+4mZ7d5a8x+ZVqnqXEs4023*zUXKzY}=Wo+h4&Soyc`&uLXm_7Rk=;Ec zWkSlcQl67?M9R)lsos!s9P*_?&VQ~L4=W{cU+wX_8qb4|^y*&!52`B=X+I-eq4R^OxycMGvh-7d-q$aVO-)TF z$&108o=IIIyBGFMdh$}{Jb4^mIyE*<_A9VwGwG>%UIN}b>B&rr6~!l^H`|N*n3FAc zKs@NcbXX4_>8;_NI2b+xc_!Qy2;tuWUX0!?6~?GA!u^UaHp3^v9|8kJVY#kB?(|ng lAo8RejF?{>j~sI2ePpT_i)bB^Qj<)bMuUK;MIOT!{SOEL<(&Wk diff --git a/includes/fillit.h b/fillit.h similarity index 100% rename from includes/fillit.h rename to fillit.h diff --git a/srcs/get_smallest_square.c b/get_smallest_square.c similarity index 90% rename from srcs/get_smallest_square.c rename to get_smallest_square.c index 03893e4..ad03c58 100644 --- a/srcs/get_smallest_square.c +++ b/get_smallest_square.c @@ -6,11 +6,11 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/12 22:29:45 by vmanzoni #+# #+# */ -/* Updated: 2019/04/14 14:17:47 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/14 21:37:19 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ -#include "../includes/fillit.h" +#include "fillit.h" /* char *get_smallest_square() diff --git a/srcs/handle_errors.c b/handle_errors.c similarity index 95% rename from srcs/handle_errors.c rename to handle_errors.c index aa6652d..37ec9cc 100644 --- a/srcs/handle_errors.c +++ b/handle_errors.c @@ -6,11 +6,11 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/01 13:29:05 by vmanzoni #+# #+# */ -/* Updated: 2019/04/14 18:40:49 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/14 21:37:23 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ -#include "../includes/fillit.h" +#include "fillit.h" /* ** Function that display error message *s on fd diff --git a/srcs/main.c b/main.c similarity index 93% rename from srcs/main.c rename to main.c index 0896793..fb5b7cc 100644 --- a/srcs/main.c +++ b/main.c @@ -6,11 +6,11 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/02/12 13:20:48 by vmanzoni #+# #+# */ -/* Updated: 2019/04/14 17:44:38 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/14 21:37:27 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ -#include "../includes/fillit.h" +#include "fillit.h" int main(int argc, char **argv) { diff --git a/srcs/print_fillit.c b/print_fillit.c similarity index 90% rename from srcs/print_fillit.c rename to print_fillit.c index 57188d3..5744511 100644 --- a/srcs/print_fillit.c +++ b/print_fillit.c @@ -6,11 +6,11 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/01 13:35:48 by vmanzoni #+# #+# */ -/* Updated: 2019/04/14 12:13:16 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/14 21:37:31 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ -#include "../includes/fillit.h" +#include "fillit.h" /* void ft_print_fillit() diff --git a/srcs/read_file.c b/read_file.c similarity index 94% rename from srcs/read_file.c rename to read_file.c index b67d965..4681b26 100644 --- a/srcs/read_file.c +++ b/read_file.c @@ -6,11 +6,11 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/13 12:09:46 by vmanzoni #+# #+# */ -/* Updated: 2019/04/14 18:54:53 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/14 21:37:37 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ -#include "../includes/fillit.h" +#include "fillit.h" /* ** Function that read and return a ptr to file From 1e42ba9fbedf2be370da6b048fd5c1a7acc68b09 Mon Sep 17 00:00:00 2001 From: Manzovince Date: Sun, 14 Apr 2019 23:02:29 +0200 Subject: [PATCH 6/6] check_tetri_error WORKING + Parser --- Makefile | 21 ++++++++++----------- fillit.h | 4 +++- handle_errors.c | 28 ++++++++++++++++------------ libft | 1 + main.c | 7 ++++--- read_file.c | 8 +++++--- samples/test | 4 ++++ 7 files changed, 43 insertions(+), 30 deletions(-) create mode 160000 libft create mode 100644 samples/test diff --git a/Makefile b/Makefile index c8b192f..ac53509 100644 --- a/Makefile +++ b/Makefile @@ -6,26 +6,20 @@ # By: vmanzoni +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2019/03/01 13:24:35 by vmanzoni #+# #+# # -# Updated: 2019/04/14 14:21:26 by vmanzoni ### ########.fr # +# Updated: 2019/04/14 22:01:39 by vmanzoni ### ########.fr # # # # **************************************************************************** # NAME = fillit -SRC_DIR = srcs/ - -SRCS = *.c - OBJ_DIR = objs/ - -OBJS = $(SRCS:.c=.o) - HEADER = includes/ +SRCS = *.c +OBJS = $(SRCS:.c=.o) LIB = fillit.h CC = gcc - CFLAGS = -Wall -Werror -Wextra RM = rm -rf @@ -33,15 +27,20 @@ RM = rm -rf all: $(NAME) $(NAME): - $(CC) $(CFLAGS) -I$(HEADER) -c $(addprefix $(SRC_DIR), $(SRCS)) - $(CC) $(OBJS) -o $(NAME) + make -C libft/ + $(CC) $(CFLAGS) -I$(HEADER) -c $(SRCS) + $(CC) -o $(NAME) $(OBJS) -L libft/ -lft + #$(CC) $(CFLAGS) -I$(HEADER) -c $(addprefix $(SRC_DIR), $(SRCS)) + #$(CC) $(OBJS) -o $(NAME) mkdir $(OBJ_DIR) mv $(OBJS) $(OBJ_DIR) clean: + make -C libft/ clean $(RM) $(OBJ_DIR) fclean: clean + make -C libft/ fclean $(RM) $(NAME) re: fclean all diff --git a/fillit.h b/fillit.h index 3a3ea69..9a8ae19 100644 --- a/fillit.h +++ b/fillit.h @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */ -/* Updated: 2019/04/14 17:43:41 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/14 22:32:32 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -35,5 +35,7 @@ void print_test(char *test); char *read_file(char *file); void print_error(char *s); int check_file_errors(char *file); +int check_tetri_errors(char *tetri); +int check_tetri_errors2(char *tetri); #endif diff --git a/handle_errors.c b/handle_errors.c index 37ec9cc..8f4ffd0 100644 --- a/handle_errors.c +++ b/handle_errors.c @@ -6,19 +6,20 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/01 13:29:05 by vmanzoni #+# #+# */ -/* Updated: 2019/04/14 21:37:23 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/14 22:57:14 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ #include "fillit.h" /* -** Function that display error message *s on fd +** Function that display error message *s on fd and exit program */ void print_error(char *s) { write(2, s, strlen(s)); + exit(1); } /* @@ -41,8 +42,8 @@ int check_file_errors(char *file) return (1); if (file[i] == '\n') line_nbr++; - if (file[i] == '\n' && file[i+1] == '\n') - return (1); +// if (file[i] == '\n' && file[i+2] != '.' && file[i+2] != '#') +// return (1); i++; } if (line_nbr < 4 || line_nbr > 129) @@ -61,17 +62,18 @@ int check_tetri_errors(char *tetri) dot = 0; while (tetri[i]) { - if (tetri[i] = '#') + if (tetri[i] == '#') htg++; - else if (tetri[i] = '.') + else if (tetri[i] == '.') dot++; + i++; } if (htg != 4 || dot != 12 || check_tetri_errors2(tetri)) return (1); return (0); } -/* + int check_tetri_errors2(char *tetri) { int i; @@ -79,11 +81,13 @@ int check_tetri_errors2(char *tetri) i = 0; while (tetri[i]) { - if (tetri[i] == '#') - { - - } + if (tetri[i] == '.' || tetri[i] == '\n') + i++; + else if (tetri[i] == '#' && (tetri[i + 1] == '#' || tetri[i - 1] == '#' + || tetri[i + 5] == '#' || tetri[i - 5] == '#')) + i++; + else + return (1); } return (0); } -*/ diff --git a/libft b/libft new file mode 160000 index 0000000..dad20d5 --- /dev/null +++ b/libft @@ -0,0 +1 @@ +Subproject commit dad20d5d96b1865b150de700861cfc63630dffa1 diff --git a/main.c b/main.c index fb5b7cc..96d0dba 100644 --- a/main.c +++ b/main.c @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/02/12 13:20:48 by vmanzoni #+# #+# */ -/* Updated: 2019/04/14 21:37:27 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/14 22:58:47 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,6 +22,8 @@ int main(int argc, char **argv) print_error("Error: Could not read file.\n"); if (check_file_errors(input)) print_error("Error: Invalid file.\n"); + if (check_tetri_errors(input)) + print_error("Error: Tetrimino not valid.\n"); /* Check if every tetrimino is valid Transform input to tetriminos @@ -31,7 +33,6 @@ int main(int argc, char **argv) */ } else - print_error("Error: Please submit a file.\n"); + print_error("Usage: Please submit a file.\n"); return (0); - print_test(input); } diff --git a/read_file.c b/read_file.c index 4681b26..345e91f 100644 --- a/read_file.c +++ b/read_file.c @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/13 12:09:46 by vmanzoni #+# #+# */ -/* Updated: 2019/04/14 21:37:37 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/14 23:01:31 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -46,7 +46,7 @@ char *read_file(char *file) int parse_input(char *input) { - char /*NOM DE LA VARIABLE*/; + char tetri; int c; int i; int j; @@ -60,9 +60,11 @@ int parse_input(char *input) j = 0; while (j < 4) { - /*NOM DE LA VARIABLE[j]*/ = input[c++]; + tetri[j] = input[c++]; j++; } + if (check_tetri_errors(tetri)) + print_error("Error: Tetrimino not valid.\n"); c++; i++; } diff --git a/samples/test b/samples/test new file mode 100644 index 0000000..cb1a109 --- /dev/null +++ b/samples/test @@ -0,0 +1,4 @@ +..#. +..#. +..#. +..