From d4715b6683ae57771406f2dcd1d3d9dabcae0680 Mon Sep 17 00:00:00 2001 From: Baco Date: Wed, 25 Aug 2021 20:54:50 +0200 Subject: [PATCH] commit --- C_08/git/ex05/ft_show_tab.c | 64 +++++++++++++++++++++++++++ C_08/git/ex05/ft_stock_str.h | 20 +++++++++ C_08/git/ex05/main.c | 85 ++++++++++++++++++++++++++++++++++++ C_08/git/ex05/main.sh | 14 ++++++ 4 files changed, 183 insertions(+) create mode 100644 C_08/git/ex05/ft_show_tab.c create mode 100644 C_08/git/ex05/ft_stock_str.h create mode 100644 C_08/git/ex05/main.c create mode 100755 C_08/git/ex05/main.sh diff --git a/C_08/git/ex05/ft_show_tab.c b/C_08/git/ex05/ft_show_tab.c new file mode 100644 index 0000000..e75feba --- /dev/null +++ b/C_08/git/ex05/ft_show_tab.c @@ -0,0 +1,64 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_show_tab.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gbaconni +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/08/25 10:17:09 by gbaconni #+# #+# */ +/* Updated: 2021/08/25 12:05:50 by gbaconni ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include "ft_stock_str.h" + +void ft_putstr(char *str) +{ + while (*str != '\0') + write(1, str++, 1); +} + +void ft_putnbr(int nb) +{ + char c; + + if (nb < 0) + { + nb *= -1; + write(1, "-", 1); + } + if (nb >= 0 && nb <= 9) + { + c = nb + '0'; + write(1, &c, 1); + } + else if (nb == -2147483648) + { + ft_putnbr((nb / 10) * -1); + ft_putnbr((nb % 10) * -1); + } + else + { + ft_putnbr(nb / 10); + ft_putnbr(nb % 10); + } +} + +void ft_show_tab(struct s_stock_str *par) +{ + int i; + + i = 0; + while (par && par[i].size > 0) + { + ft_putstr(par[i].str); + ft_putstr("\n"); + ft_putnbr(par[i].size); + ft_putstr("\n"); + ft_putstr(par[i].copy); + ft_putstr("\n"); + i++; + } +} diff --git a/C_08/git/ex05/ft_stock_str.h b/C_08/git/ex05/ft_stock_str.h new file mode 100644 index 0000000..24e3d31 --- /dev/null +++ b/C_08/git/ex05/ft_stock_str.h @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_stock_str.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gbaconni +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/08/25 10:17:09 by gbaconni #+# #+# */ +/* Updated: 2021/08/25 12:05:50 by gbaconni ### ########.fr */ +/* */ +/* ************************************************************************** */ +#ifndef FT_STOCK_STR_H +# define FT_STOCK_STR_H +typedef struct s_stock_str +{ + int size; + char *str; + char *copy; +} t_stock_str; +#endif diff --git a/C_08/git/ex05/main.c b/C_08/git/ex05/main.c new file mode 100644 index 0000000..22126a6 --- /dev/null +++ b/C_08/git/ex05/main.c @@ -0,0 +1,85 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gbaconni +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/08/24 14:00:37 by gbaconni #+# #+# */ +/* Updated: 2021/08/24 14:04:21 by gbaconni ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include "ft_stock_str.h" + +void ft_show_tab(struct s_stock_str *par); + +int ft_strlen(char *str) +{ + int i; + + i = 0; + while (str[i] != '\0') + i++; + return (i); +} + +char *ft_strdup(char *src) +{ + char *str; + char *_str; + int size; + + size = ft_strlen(src); + str = (char *) malloc((size + 1) * sizeof(char)); + if (str == NULL) + return (NULL); + _str = str; + while (*src != '\0') + *str++ = *src++; + *str = '\0'; + str = _str; + return (str); +} + +struct s_stock_str *ft_strs_to_tab(int ac, char **av) +{ + t_stock_str *result; + int i; + + result = (t_stock_str *) malloc((ac + 1) * sizeof(result)); + if (result == NULL) + return (NULL); + i = 0; + while (i < ac) + { + result[i].size = ft_strlen(av[i]); + result[i].str = ft_strdup(av[i]); + result[i].copy = ft_strdup(av[i]); + i++; + } + result[i].size = 0; + result[i].str = 0; + result[i].copy = 0; + return (result); +} + +int main(int argc, char *argv[]) +{ + t_stock_str *par; + int i; + + i = 0; + while (i < argc - 1) + { + argv[i] = argv[i + 1]; + i++; + } + argv[i] = NULL; + argc--; + par = ft_strs_to_tab(argc, argv); + ft_show_tab(par); + return (0); +} diff --git a/C_08/git/ex05/main.sh b/C_08/git/ex05/main.sh new file mode 100755 index 0000000..9db2b06 --- /dev/null +++ b/C_08/git/ex05/main.sh @@ -0,0 +1,14 @@ +#!/bin/sh +set -e +rm -f a.out +find . -type f -name '*.h' -exec \ +norminette -R CheckDefine {} \; +find . -type f -name '*.c' \! -name 'main.c' -exec \ +norminette -R CheckForbiddenSourceHeader {} \; +echo +gcc -Wall -Wextra -Werror -o a.out *.c +#cpp *.c | tail -n 30 +echo +echo $(basename $PWD): +./a.out "$@" +rm -f a.out