diff options
| author | Charles <sircharlesaze@gmail.com> | 2019-07-21 15:26:32 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2019-07-21 15:26:32 +0200 |
| commit | 23ad79e8b41c25bb4992d103d29a17612a52e351 (patch) | |
| tree | 9de3cde07cc38e59f08885171e9f99eeab8ab71b /bsq | |
| parent | 8b6e91bdb56bc01a588718472546f2a88e750b48 (diff) | |
| download | piscine-23ad79e8b41c25bb4992d103d29a17612a52e351.tar.gz piscine-23ad79e8b41c25bb4992d103d29a17612a52e351.tar.bz2 piscine-23ad79e8b41c25bb4992d103d29a17612a52e351.zip | |
c10 done, c11 on going, rush02 probably finished, bsq start
Diffstat (limited to 'bsq')
| -rw-r--r-- | bsq/.gitignore | 2 | ||||
| -rw-r--r-- | bsq/Makefile | 46 | ||||
| -rw-r--r-- | bsq/auteur | 1 | ||||
| -rw-r--r-- | bsq/includes/include.h | 63 | ||||
| -rw-r--r-- | bsq/srcs/helper.c | 62 | ||||
| -rw-r--r-- | bsq/srcs/main.c | 20 | ||||
| -rw-r--r-- | bsq/srcs/parse.c | 42 | ||||
| -rwxr-xr-x | bsq/tests/generate.pl | 21 |
8 files changed, 257 insertions, 0 deletions
diff --git a/bsq/.gitignore b/bsq/.gitignore new file mode 100644 index 0000000..d7756c2 --- /dev/null +++ b/bsq/.gitignore @@ -0,0 +1,2 @@ +a.out +*.o diff --git a/bsq/Makefile b/bsq/Makefile new file mode 100644 index 0000000..11cddfa --- /dev/null +++ b/bsq/Makefile @@ -0,0 +1,46 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2019/07/19 12:09:54 by cacharle #+# #+# # +# Updated: 2019/07/19 15:18:19 by cacharle ### ########.fr # +# # +# **************************************************************************** # + +OUT = bsq +SRCDIR = srcs +SRC = $(SRCDIR)/main.c +OBJ = $(SRC:.c=.o) +INCLUDES = includes/include.h + +CC = gcc +CCFLAGS = -Wall -Wextra #-Werror +LDFLAGS = -Iincludes + +ARGS = 10 10 2 + +.PHONY: all +all: $(OUT) + +$(OUT): $(OBJ) + $(CC) $(CCFLAGS) $(LDFLAGS) -o $@ $^ + +%.o: %.c $(INCLUDES) + $(CC) $(CCFLAGS) $(LDFLAGS) -c -o $@ $< + +.PHONY: clean + rm -f $(OBJ) + +.PHONY: fclean +fclean: clean + rm -f $(OUT) + +.PHONY: re +re: fclean all + +.PHONY: generate +generate: + ./tests/generate.pl ${ARGS} diff --git a/bsq/auteur b/bsq/auteur new file mode 100644 index 0000000..ab605b4 --- /dev/null +++ b/bsq/auteur @@ -0,0 +1 @@ +samzur:cacharle diff --git a/bsq/includes/include.h b/bsq/includes/include.h new file mode 100644 index 0000000..d505857 --- /dev/null +++ b/bsq/includes/include.h @@ -0,0 +1,63 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* include.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/19 13:17:32 by cacharle #+# #+# */ +/* Updated: 2019/07/19 15:55:03 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef INCLUDE_H +# define INCLUDE_H + +# define TRUE 1 +# define FALSE 0 +# define EMPTY 0 +# define OBSTACLE 1 + +struct s_square +{ + int size; + int x; + int y; +}; + +struct s_terrain +{ + char empty; + char fill; + char obstacle; + int size; + char *file; +} + +typedef struct s_terrain t_terrain; +typedef struct s_square t_square; +typedef int t_bool; + +/* +** solve.c - Solve the thing (yes) +*/ + + +/* +** parse.c - Input parsing +** Put file in string, parse it and check if it's valid +*/ + +t_bool check_input(char *input); + +/* +** helper.c - function already made +*/ + +int read_file(int fildes, char **file); +char *ft_memcat(char *file, char buf[BUF_SIZE], int file_size, + int read_size); + + + +#endif diff --git a/bsq/srcs/helper.c b/bsq/srcs/helper.c new file mode 100644 index 0000000..d1fe8bc --- /dev/null +++ b/bsq/srcs/helper.c @@ -0,0 +1,62 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* helper.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/19 15:19:53 by cacharle #+# #+# */ +/* Updated: 2019/07/19 15:19:56 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <unistd.h> +#include <stdlib.h> +#include <fcntl.h> +#include "include.h" + +int read_file(int fildes, char **file) +{ + char buf[BUF_SIZE]; + int file_size; + int read_size; + + file_size = 0; + while ((read_size = read(fildes, buf, BUF_SIZE))) + { + if (read_size < 0) + return (-1); + *file = ft_memcat(*file, buf, file_size, read_size); + file_size += read_size; + } + return (file_size); +} + +char *ft_memcat(char *file, char buf[BUF_SIZE], int file_size, + int read_size) +{ + int i; + char *file_clone; + + if ((file_clone = malloc(sizeof(char) * (file_size + 1))) == NULL) + return (NULL); + i = -1; + while (++i < file_size) + file_clone[i] = file[i]; + free(file); + if ((file = malloc(sizeof(char) * (file_size + read_size + 1))) == NULL) + return (NULL); + i = 0; + while (i < file_size) + { + file[i] = file_clone[i]; + i++; + } + free(file_clone); + while (i < file_size + read_size) + { + file[i] = buf[i - file_size]; + i++; + } + return (file); +} diff --git a/bsq/srcs/main.c b/bsq/srcs/main.c new file mode 100644 index 0000000..637ac13 --- /dev/null +++ b/bsq/srcs/main.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/19 11:01:32 by cacharle #+# #+# */ +/* Updated: 2019/07/19 13:35:23 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "include.h" + +int main(int argc, char **argv) +{ + + + return (0); +} diff --git a/bsq/srcs/parse.c b/bsq/srcs/parse.c new file mode 100644 index 0000000..8c4af3a --- /dev/null +++ b/bsq/srcs/parse.c @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* parse.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/19 15:23:43 by cacharle #+# #+# */ +/* Updated: 2019/07/19 15:55:31 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "include.h" + +t_bool check_input(char *input) +{ + char *line; + int i; + + i = 0; + while (input[i] != '\n') + i++; + if (i < 4) + return (FALSE); + parsed.fill = input[i--]; + parsed.obstacle = input[i--]; + parsed.empty = input[i--]; + // parsed.size = // atoi smth + while (*input != '\n') + input++; + i = 0; + while (input[i]) + { + while (input[i] != '\n') + { + + } + if (i != parsed.size + + + } +} diff --git a/bsq/tests/generate.pl b/bsq/tests/generate.pl new file mode 100755 index 0000000..27bd35f --- /dev/null +++ b/bsq/tests/generate.pl @@ -0,0 +1,21 @@ +#!/usr/bin/perl + +use warnings; +use strict; + +die "program x y density" unless (scalar(@ARGV) == 3); + +my ($x, $y, $density) = @ARGV; + +print "$y.ox\n"; +for (my $i = 0; $i < $y; $i++) { + for (my $j = 0; $j < $x; $j++) { + if (int(rand($y) * 2) < $density) { + print "o"; + } + else { + print "."; + } + } + print "\n"; +} |
