From 04e8f71d4bf530ff88e0d5601c8fcceb6f25c22e Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Wed, 21 Sep 2016 21:27:23 +0200 Subject: [PATCH] macros prefixed with FT_ --- libftasm/ft_putnbr.c | 2 +- libftasm/ft_putnbr_fd.c | 2 +- libftasm/ft_strrev.c | 21 +++++++++++++++++++++ libftasm/ft_strtrim.c | 4 ++-- libftasm/libft.h | 19 ++++++++++++------- 5 files changed, 37 insertions(+), 11 deletions(-) create mode 100644 libftasm/ft_strrev.c diff --git a/libftasm/ft_putnbr.c b/libftasm/ft_putnbr.c index 08bc2b18..d8aa57a4 100644 --- a/libftasm/ft_putnbr.c +++ b/libftasm/ft_putnbr.c @@ -23,7 +23,7 @@ void ft_putnbr(int n) } else if (n < 0) ft_putchar('-'); - n = ABS(n); + n = FT_ABS(n); if (n >= 10) ft_putnbr(n / 10); ft_putchar(n % 10 + '0'); diff --git a/libftasm/ft_putnbr_fd.c b/libftasm/ft_putnbr_fd.c index 4659739e..da7cf739 100644 --- a/libftasm/ft_putnbr_fd.c +++ b/libftasm/ft_putnbr_fd.c @@ -23,7 +23,7 @@ void ft_putnbr_fd(int n, int fd) } else if (n < 0) ft_putchar_fd('-', fd); - n = ABS(n); + n = FT_ABS(n); if (n >= 10) ft_putnbr_fd(n / 10, fd); ft_putchar_fd(n % 10 + '0', fd); diff --git a/libftasm/ft_strrev.c b/libftasm/ft_strrev.c new file mode 100644 index 00000000..685b0f31 --- /dev/null +++ b/libftasm/ft_strrev.c @@ -0,0 +1,21 @@ +#include "libft.h" + +char *ft_strrev(char *str) +{ + int len; + char tmp; + int i; + + i = 0; + len = 0; + while (str[len] != '\0') + len++; + while (i < len / 2) + { + tmp = str[len - (i + 1)]; + str[len - (i + 1)] = str[i]; + str[i] = tmp; + i++; + } + return (str); +} diff --git a/libftasm/ft_strtrim.c b/libftasm/ft_strtrim.c index 397acd24..b607dbef 100644 --- a/libftasm/ft_strtrim.c +++ b/libftasm/ft_strtrim.c @@ -6,10 +6,10 @@ char *ft_strtrim(char const *s) size_t size; out = ft_strdup(s); - while (*out && SEP(*out)) + while (*out && FT_SEP(*out)) out++; size = ft_strlen(out); - while (size - 1 && SEP(out[size - 1])) + while (size - 1 && FT_SEP(out[size - 1])) { size--; out[size] = '\0'; diff --git a/libftasm/libft.h b/libftasm/libft.h index a2905b24..51ebbbea 100644 --- a/libftasm/libft.h +++ b/libftasm/libft.h @@ -4,13 +4,13 @@ # include # include # include -# define SEP(x) (x == ' ' || x == '\t' || x == '\n') -# define ABS(x) (((x) < 0) ? -(x) : (x)) -# define NEG(x) (((x) < 0) ? 1 : 0) -# define POS(x) (((x) > 0) ? 1 : 0) -# define MIN(a, b) ((a) < (b) ? (a) : (b)) -# define MAX(a, b) ((a) > (b) ? (a) : (b)) -# define DIST(a, b) (ABS((a) - (b))) +# define FT_SEP(x) (x == ' ' || x == '\t' || x == '\n') +# define FT_ABS(x) (((x) < 0) ? -(x) : (x)) +# define FT_NEG(x) (((x) < 0) ? 1 : 0) +# define FT_POS(x) (((x) > 0) ? 1 : 0) +# define FT_MIN(a, b) ((a) < (b) ? (a) : (b)) +# define FT_MAX(a, b) ((a) > (b) ? (a) : (b)) +# define FT_DIST(a, b) (ABS((a) - (b))) typedef struct s_list { @@ -99,5 +99,10 @@ t_list *ft_lst_find(t_list *begin_list, void *data_ref, int (*cmp)()); t_list *ft_lstpop(t_list **lst); int ft_diff(void *a, void *b); +char *ft_strrev(char *str); t_list *ft_id(t_list *a); +char *ft_itoa_base(int nbr, char *base, char *flags); +char *ft_lltoa_base(long long nbr, char *base, char *flags); +char *ft_ulltoa_base(unsigned long long nbr, char *base); +char *ft_uitoa_base(unsigned int nbr, char *base); #endif