diff --git a/libftasm/Makefile b/libftasm/Makefile index 525990c1..f1650b27 100644 --- a/libftasm/Makefile +++ b/libftasm/Makefile @@ -125,15 +125,10 @@ mem/ft_memmove.c\ mem/ft_memset.c\ mem/ft_realloc.c\ path/ft_path_notdir.c\ -printing/ft_putaddr.c\ printing/ft_putchar.c\ -printing/ft_putchar_fd.c\ printing/ft_putendl.c\ -printing/ft_putendl_fd.c\ printing/ft_putnbr.c\ -printing/ft_putnbr_fd.c\ printing/ft_putstr.c\ -printing/ft_putstr_fd.c\ sstr/ft_sstradd.c\ sstr/ft_sstrcat.c\ sstr/ft_sstrdel.c\ diff --git a/libftasm/includes/libft.h b/libftasm/includes/libft.h index bbb8eb25..c168e1f4 100644 --- a/libftasm/includes/libft.h +++ b/libftasm/includes/libft.h @@ -67,14 +67,14 @@ void ft_memdel(void **ap); int ft_putchar(int c); void ft_putstr(char const *s); void ft_putendl(char const *s); -void ft_putnbr(int n); -void ft_putaddr(void *a); +void ft_putnbr(long n); +void ft_putnbr_hex(long n); -void ft_putchar_fd(char c, int fd); +int ft_putchar_fd(int c, int fd); void ft_putstr_fd(char const *s, int fd); void ft_putendl_fd(char const *s, int fd); -void ft_putnbr_fd(int n, int fd); -void ft_putaddr_fd(void *a, int fd); +void ft_putnbr_fd(long n, int fd); +void ft_putnbr_hex_fd(long n, int fd); void *ft_realloc(void *data, int size); diff --git a/libftasm/src/printing/ft_putaddr.c b/libftasm/src/printing/ft_putaddr.c deleted file mode 100644 index 4ef50482..00000000 --- a/libftasm/src/printing/ft_putaddr.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_putaddr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/11/21 15:13:34 by jhalford #+# #+# */ -/* Updated: 2017/02/18 18:47:36 by jhalford ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_putaddr(void *a) -{ - ft_putaddr_fd(a, 1); -} diff --git a/libftasm/src/printing/ft_putchar.c b/libftasm/src/printing/ft_putchar.c index afd2d6bb..400ebaaa 100644 --- a/libftasm/src/printing/ft_putchar.c +++ b/libftasm/src/printing/ft_putchar.c @@ -12,6 +12,12 @@ #include "libft.h" +int ft_putchar_fd(int c, int fd) +{ + write(fd, &c, 1); + return (0); +} + int ft_putchar(int c) { write(1, &c, 1); diff --git a/libftasm/src/printing/ft_putchar_fd.c b/libftasm/src/printing/ft_putchar_fd.c deleted file mode 100644 index 1d1e9a4b..00000000 --- a/libftasm/src/printing/ft_putchar_fd.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_putchar_fd.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/11/03 14:57:39 by jhalford #+# #+# */ -/* Updated: 2016/11/03 14:57:39 by jhalford ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_putchar_fd(char c, int fd) -{ - write(fd, &c, 1); -} diff --git a/libftasm/src/printing/ft_putendl_fd.c b/libftasm/src/printing/ft_putendl_fd.c deleted file mode 100644 index 9b33674c..00000000 --- a/libftasm/src/printing/ft_putendl_fd.c +++ /dev/null @@ -1,22 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_putendl_fd.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/11/03 14:57:42 by jhalford #+# #+# */ -/* Updated: 2016/11/03 14:57:42 by jhalford ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_putendl_fd(char const *s, int fd) -{ - char nl; - - nl = '\n'; - write(fd, s, ft_strlen(s)); - write(fd, &nl, 1); -} diff --git a/libftasm/src/printing/ft_putnbr.c b/libftasm/src/printing/ft_putnbr.c index 2f0a4a94..6d46a4de 100644 --- a/libftasm/src/printing/ft_putnbr.c +++ b/libftasm/src/printing/ft_putnbr.c @@ -12,19 +12,33 @@ #include "libft.h" -void ft_putnbr(int n) +void ft_putnbr_loop(long n, int base, int fd) { - if (n == -2147483648) - { - ft_putchar('-'); - ft_putchar('2'); - ft_putnbr(147483648); - return ; - } - else if (n < 0) - ft_putchar('-'); - n = FT_ABS(n); - if (n >= 10) - ft_putnbr(n / 10); - ft_putchar(n % 10 + '0'); + if (n >= base) + ft_putnbr_loop(n / base, base, fd); + ft_putchar_fd("0123456789abcdef"[n % base], fd); +} + +void ft_putnbr_hex_fd(long n, int fd) +{ + ft_putstr_fd("0x", fd); + ft_putnbr_loop(n, 16, fd); +} + +void ft_putnbr_fd(long n, int fd) +{ + if (n < 0) + ft_putchar_fd('-', fd); + n = FT_ABS(n); + ft_putnbr_loop(n, 10, fd); +} + +void ft_putnbr_hex(long n) +{ + ft_putnbr_hex_fd(n, 1); +} + +void ft_putnbr(long n) +{ + ft_putnbr_fd(n, 1); } diff --git a/libftasm/src/printing/ft_putnbr_fd.c b/libftasm/src/printing/ft_putnbr_fd.c deleted file mode 100644 index da7cf739..00000000 --- a/libftasm/src/printing/ft_putnbr_fd.c +++ /dev/null @@ -1,30 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_putnbr_fd.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/08/02 21:25:03 by jhalford #+# #+# */ -/* Updated: 2016/08/04 21:28:16 by jhalford ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_putnbr_fd(int n, int fd) -{ - if (n == -2147483648) - { - ft_putchar_fd('-', fd); - ft_putchar_fd('2', fd); - ft_putnbr_fd(147483648, fd); - return ; - } - else if (n < 0) - ft_putchar_fd('-', fd); - n = FT_ABS(n); - if (n >= 10) - ft_putnbr_fd(n / 10, fd); - ft_putchar_fd(n % 10 + '0', fd); -} diff --git a/libftasm/src/printing/ft_putstr.c b/libftasm/src/printing/ft_putstr.c index c4e16816..d937668e 100644 --- a/libftasm/src/printing/ft_putstr.c +++ b/libftasm/src/printing/ft_putstr.c @@ -12,6 +12,11 @@ #include "libft.h" +void ft_putstr_fd(char const *s, int fd) +{ + write(fd, s, ft_strlen(s)); +} + void ft_putstr(char const *s) { write(1, s, ft_strlen(s)); diff --git a/libftasm/src/printing/ft_putstr_fd.c b/libftasm/src/printing/ft_putstr_fd.c deleted file mode 100644 index ee82000f..00000000 --- a/libftasm/src/printing/ft_putstr_fd.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_putstr_fd.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/11/03 14:57:48 by jhalford #+# #+# */ -/* Updated: 2016/11/03 14:57:49 by jhalford ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_putstr_fd(char const *s, int fd) -{ - write(fd, s, ft_strlen(s)); -} diff --git a/libftasm/src/str/ft_putaddr_fd.c b/libftasm/src/str/ft_putaddr_fd.c index 261f3a72..a6c52a37 100644 --- a/libftasm/src/str/ft_putaddr_fd.c +++ b/libftasm/src/str/ft_putaddr_fd.c @@ -18,13 +18,17 @@ void ft_putaddr_fd(void *a, int fd) unsigned long long addr; int i; + ft_putnbr((long)a); + ft_putchar('\n'); addr = (unsigned long long)a; out[18] = 0; i = 17; while (addr) { - out[i--] = "0123456789abcdef"[addr % 16]; - addr = addr / 16; + ft_putnbr(addr); + ft_putchar('\n'); + out[i--] = "0123456789ABCDEF"[addr % 16]; + addr /= 16; } out[i--] = 'x'; out[i] = '0';