diff options
51 files changed, 1540 insertions, 124 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"; +} @@ -8,9 +8,9 @@ int main() char *const str = "3YaZkAP30iGoBWv L H asdf h LbpX8Hx FWHwB2u1FH0S5"; char *begin = "\n \t hgonjour"; char *end = "jesuis\n\t hhh"; - char *empty = " h bonjour je suis "; + char *empty = ""; char *charset = " H"; - char **strs = ft_split(str, charset); + char **strs = ft_split(empty, charset); printf("tab start\n"); for (int i = 0; strs[i] != 0; i++) { diff --git a/c10/bonjour.c b/c10/bonjour.c new file mode 100644 index 0000000..1b6f283 --- /dev/null +++ b/c10/bonjour.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* bonjour.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/20 17:20:22 by cacharle #+# #+# */ +/* Updated: 2019/07/20 17:31:22 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../includes/ft.h" + +int main(int argc, char **argv) +{ + int fd; + char buff[BUFF_SIZE + 1]; + int ret; + if (argc < 2) + write(2, "File name missing.\n", 19); + else if (argc > 2) + write(2, "Too many arguments.\n", 20); + else + { + fd = open(argv[1], O_RDONLY); + if (fd == -1) + { + write(2, "Cannot read file.\n", 18); + return (1); + } + while ((ret = read(fd, buff, BUFF_SIZE))) + write(1, buff, ret); + if (close(fd)) + return (1); + } + return (0); +} diff --git a/c10/ex00/main.c b/c10/ex00/main.c index 0cc4470..67fefe6 100644 --- a/c10/ex00/main.c +++ b/c10/ex00/main.c @@ -6,53 +6,38 @@ /* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/11 18:06:43 by cacharle #+# #+# */ -/* Updated: 2019/07/19 06:33:07 by cacharle ### ########.fr */ +/* Updated: 2019/07/20 17:26:47 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #include <unistd.h> #include <fcntl.h> -#include <stdio.h> -#define BUFFER_SIZE 1024 - -int read_write_file(int fildes) -{ - char buf[BUFFER_SIZE]; - int read_size; - - while ((read_size = read(fildes, buf, BUFFER_SIZE)) != 0) - { - if (read_size < 0) - return (-1); - write(STDOUT_FILENO, buf, read_size); - } - return (0); -} +#define BUF_SIZE 64 int main(int argc, char **argv) { int fildes; + int read_size; + char buf[BUF_SIZE + 1]; - if (argc == 1) + if (argc < 2) { - write(STDERR_FILENO, "File name missing.\n", 20); + write(STDERR_FILENO, "File name missing.\n", 19); return (1); } - else if (argc > 2) + if (argc > 2) { - write(STDERR_FILENO, "Too many arguments.\n", 21); + write(STDERR_FILENO, "Too many arguments.\n", 20); return (1); } - if ((fildes = open(argv[1], O_RDONLY)) < 0) + if ((fildes = open(argv[1], O_RDONLY)) == -1) { write(STDERR_FILENO, "Cannot read file.\n", 18); return (1); } - if ((read_write_file(fildes)) < 0) - { - write(STDERR_FILENO, "Cannot read file.\n", 18); + while ((read_size = read(fildes, buf, BUF_SIZE))) + write(STDOUT_FILENO, buf, read_size); + if (close(fildes)) return (1); - } - close(fildes); return (0); } diff --git a/c10/ex02/include.h b/c10/ex02/include.h index d37df25..f806cec 100644 --- a/c10/ex02/include.h +++ b/c10/ex02/include.h @@ -6,7 +6,7 @@ /* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/16 15:26:12 by cacharle #+# #+# */ -/* Updated: 2019/07/19 06:59:18 by cacharle ### ########.fr */ +/* Updated: 2019/07/19 07:06:04 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,8 @@ int print_tail(char *filename, int tail_size, int argc, int good_counter); int print_file_tail(int fildes, int tail_size); int read_file(int fildes, char **file); -char *ft_memcat(char *file, char buf[BUF_SIZE], int file_size, int read_size); +char *ft_memcat(char *file, char buf[BUF_SIZE], int file_size, + int read_size); /* ** helper.c diff --git a/c11/ex04/ft_is_sort.c b/c11/ex04/ft_is_sort.c index 84d4fe0..7e95ba2 100644 --- a/c11/ex04/ft_is_sort.c +++ b/c11/ex04/ft_is_sort.c @@ -6,11 +6,11 @@ /* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/16 21:39:43 by cacharle #+# #+# */ -/* Updated: 2019/07/18 21:19:29 by cacharle ### ########.fr */ +/* Updated: 2019/07/19 07:37:39 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ -static is_sort_asc(int *tab, int length, int (*f)(int, int)) +static int is_sort_asc(int *tab, int length, int (*f)(int, int)) { int i; @@ -24,7 +24,7 @@ static is_sort_asc(int *tab, int length, int (*f)(int, int)) return (1); } -static is_sort_dsc(int *tab, int length, int (*f)(int, int)) +static int is_sort_dsc(int *tab, int length, int (*f)(int, int)) { int i; @@ -38,7 +38,7 @@ static is_sort_dsc(int *tab, int length, int (*f)(int, int)) return (1); } -int ft_is_sort(int *tab, int length, int (*f)(int, int)) +int ft_is_sort(int *tab, int length, int (*f)(int, int)) { return (is_sort_dsc(tab, length, f) || is_sort_asc(tab, length, f)); } diff --git a/c11/ex06/ft_sort_string_tab.c b/c11/ex06/ft_sort_string_tab.c index c10feaa..4fadff4 100644 --- a/c11/ex06/ft_sort_string_tab.c +++ b/c11/ex06/ft_sort_string_tab.c @@ -6,7 +6,7 @@ /* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/16 21:48:20 by cacharle #+# #+# */ -/* Updated: 2019/07/18 11:04:01 by cacharle ### ########.fr */ +/* Updated: 2019/07/19 07:27:31 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,14 +22,14 @@ int ft_strcmp(char *s1, char *s2) return (*s1 - *s2); } -int is_sorted(char **argv) +int is_sorted(char **tab) { int i; - i = 1; - while (argv[i + 1] != NULL) + i = 0; + while (tab[i + 1] != NULL) { - if (ft_strcmp(argv[i], argv[i + 1]) > 0) + if (ft_strcmp(tab[i], tab[i + 1]) > 0) return (0); i++; } @@ -43,7 +43,7 @@ void ft_sort_string_tab(char **tab) while (!is_sorted(tab)) { - i = 1; + i = 0; while (tab[i + 1] != NULL) { if (ft_strcmp(tab[i], tab[i + 1]) > 0) diff --git a/c11/ex07/ft_advanced_sort_string_tab.c b/c11/ex07/ft_advanced_sort_string_tab.c index efcfb37..96c303d 100644 --- a/c11/ex07/ft_advanced_sort_string_tab.c +++ b/c11/ex07/ft_advanced_sort_string_tab.c @@ -6,7 +6,7 @@ /* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/16 21:51:06 by cacharle #+# #+# */ -/* Updated: 2019/07/18 11:03:31 by cacharle ### ########.fr */ +/* Updated: 2019/07/19 07:27:53 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -13,6 +13,7 @@ void f_fe(int x); int f_ma(int x); int f_len(char *x); int f_cou(char *x); +int f_sor_dsc(int x, int y); int f_sor(int x, int y); int f_lensort(char *a, char *b); @@ -43,21 +44,30 @@ int main() printf("\n------------------------\n"); int sorted[10] = {1, 2, 3, 4, 5, 5, 6}; - printf("sorted %d", ft_is_sort(sorted, 6, &f_sor)); + printf("sorted asc %d\n", ft_is_sort(sorted, 6, &f_sor)); + int sorted_dsc[10] = {7, 6, 4, 1, 0, -10}; + printf("sorted dsc %d", ft_is_sort(sorted_dsc, 6, &f_sor_dsc)); + printf("\n------------------------\n"); - char **a = malloc(sizeof(char*) * 5); + char **a = malloc(sizeof(char*) * 8); a[0] = malloc(sizeof(char) * 32); a[1] = malloc(sizeof(char) * 32); a[2] = malloc(sizeof(char) * 32); a[3] = malloc(sizeof(char) * 32); - strcpy(a[0], "bonjour"); - strcpy(a[1], "je"); - strcpy(a[2], "suis"); - strcpy(a[3], "charles"); - a[4] = NULL; + a[4] = malloc(sizeof(char) * 32); + a[5] = malloc(sizeof(char) * 32); + a[6] = malloc(sizeof(char) * 32); + strcpy(a[0], "dQ4ilBI6T$"); + strcpy(a[1], "16Tz2R$"); + strcpy(a[2], "4zQplLtBc$"); + strcpy(a[3], "7$"); + strcpy(a[4], "7hE84k$"); + strcpy(a[5], "841SqkO$"); + strcpy(a[6], "ItM$"); + a[7] = NULL; ft_sort_string_tab(a); - for (int i = 0; i < 5; i++) + for (int i = 0; i < 7; i++) printf("%s\n", a[i]); printf("\n------------------------\n"); @@ -102,6 +112,13 @@ int f_cou(char *x) return counter > 2; } +int f_sor_dsc(int x, int y) +{ + if (x == y) + return (0); + return x > y ? -1 : 1; +} + int f_sor(int x, int y) { if (x == y) @@ -1,32 +0,0 @@ -#include <stdio.h> -#include "ex00/ft_list.h" -#include "ex00/ft_create_elem.c" -#include "ex01/ft_list_push_front.c" -/*#include "ex02/ft_list_size.c"*/ -/*#include "ex03/ft_list_last.c"*/ -/*#include "ex04/ft_list_push_back.c"*/ -/*#include "ex05/ft_list_push_strs.c"*/ -/*#include "ex06/ft_list_clear.c"*/ -/*#include "ex07/ft_list_at.c"*/ -/*#include "ex08/ft_list_reverse.c"*/ -/*#include "ex09/ft_list_foreach.c"*/ -/*#include "ex10/ft_list_foreach_if.c"*/ -/*#include "ex11/ft_list_find.c"*/ -/*#include "ex12/ft_list_remove_if.c"*/ -/*#include "ex13/ft_list_merge.c"*/ -/*#include "ex14/ft_list_sort.c"*/ -/*#include "ex15/ft_list_reverse_fun.c"*/ -/*#include "ex16/ft_sorted_list_insert.c"*/ -/*#include "ft_sorted_list_merge.c"*/ - -int main() -{ - t_list *list = NULL; - int a = 4; - void *data = &a; - - list = ft_create_elem(data); - printf("%d\n", list->data); - - -} diff --git a/c12/ex02/ft_list.h b/c12/ex02/ft_list.h index 8b736b4..33ad610 100644 --- a/c12/ex02/ft_list.h +++ b/c12/ex02/ft_list.h @@ -6,7 +6,7 @@ /* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/09 14:33:17 by cacharle #+# #+# */ -/* Updated: 2019/07/09 14:42:55 by cacharle ### ########.fr */ +/* Updated: 2019/07/19 08:29:04 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,6 +19,4 @@ typedef struct s_list void *data; } t_ |
