From 81c7802c7116c379905b73ce4eea5fad272f9c44 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Fri, 10 Mar 2017 17:08:34 +0100 Subject: [PATCH] random colored PID in DG() --- libft/includes/ft_printf.h | 4 ++-- libft/includes/libft.h | 6 +++--- libft/src/ft_printf/ft_conversion.c | 2 +- libft/src/ft_printf/ft_printf.c | 4 ++-- libft/src/ft_printf/ft_printf_color.c | 18 ++++++++++++------ libft/src/ft_printf/lib_fmt.c | 2 +- 6 files changed, 21 insertions(+), 15 deletions(-) diff --git a/libft/includes/ft_printf.h b/libft/includes/ft_printf.h index 13a7ca51..f110dc6c 100644 --- a/libft/includes/ft_printf.h +++ b/libft/includes/ft_printf.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:22:54 by jhalford #+# #+# */ -/* Updated: 2017/02/18 13:21:03 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 16:56:01 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -50,7 +50,7 @@ extern t_conv g_convs[]; t_fmt *ft_fmt_init(void); void ft_fmt_print(t_fmt *fmt); -void ft_printf_color(int fd, char **final, char **str); +void ft_printf_color(char **final, char **str, va_list ap); t_fmt *ft_printf_parse(char **format, va_list ap); char *ft_transform(t_fmt *fmt, va_list ap); diff --git a/libft/includes/libft.h b/libft/includes/libft.h index 1b4da10e..68f14403 100644 --- a/libft/includes/libft.h +++ b/libft/includes/libft.h @@ -6,15 +6,15 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:49:04 by jhalford #+# #+# */ -/* Updated: 2017/03/08 11:59:43 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 16:52:40 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef LIBFT_H # define LIBFT_H -# define DG_MSG0 "{inv}{yel}%21s {bol}{blu}%-3d{eoc}" -# define DG_MSG1 ft_path_notdir(__FILE__), __LINE__ +# define DG_MSG0 "{inv}{ran}%5i{yel}%21s {bol}{blu}%-3d{eoc}" +# define DG_MSG1 getpid(), getpid(), ft_path_notdir(__FILE__), __LINE__ # define DG(f, ...) ft_dprintf(STDBUG, DG_MSG0 f "{eoc}\n", DG_MSG1, ##__VA_ARGS__) # include diff --git a/libft/src/ft_printf/ft_conversion.c b/libft/src/ft_printf/ft_conversion.c index 0727b438..eb5bd915 100644 --- a/libft/src/ft_printf/ft_conversion.c +++ b/libft/src/ft_printf/ft_conversion.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:31:48 by jhalford #+# #+# */ -/* Updated: 2017/01/22 16:28:55 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 16:58:21 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/src/ft_printf/ft_printf.c b/libft/src/ft_printf/ft_printf.c index 207a1985..5749004a 100644 --- a/libft/src/ft_printf/ft_printf.c +++ b/libft/src/ft_printf/ft_printf.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:33:27 by jhalford #+# #+# */ -/* Updated: 2017/03/07 15:14:03 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 16:54:15 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -53,7 +53,7 @@ int ft_vdprintf(int fd, const char *format, va_list ap) { tmp = final; if (*str == '{') - ft_printf_color(fd, &final, &str); + ft_printf_color(&final, &str, ap); else if (*str == '%') { if (ft_fmtcalc(&final, &str, ap)) diff --git a/libft/src/ft_printf/ft_printf_color.c b/libft/src/ft_printf/ft_printf_color.c index 33481b49..52669067 100644 --- a/libft/src/ft_printf/ft_printf_color.c +++ b/libft/src/ft_printf/ft_printf_color.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/06 18:07:39 by jhalford #+# #+# */ -/* Updated: 2016/12/09 22:09:21 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 16:58:51 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,9 +14,6 @@ t_stos g_colors[] = { - {"{bol}", ON_BOLD}, - {"{und}", ON_UNDERLINED}, - {"{inv}", ON_INVERTED}, {"{bla}", FG_BLACK}, {"{red}", FG_RED}, {"{gre}", FG_GREEN}, @@ -25,19 +22,28 @@ t_stos g_colors[] = {"{mag}", FG_MAGENTA}, {"{cya}", FG_CYAN}, {"{eoc}", FG_DEFAULT}, + {"{bol}", ON_BOLD}, + {"{und}", ON_UNDERLINED}, + {"{inv}", ON_INVERTED}, {NULL, NULL}, }; -void ft_printf_color(int fd, char **final, char **str) +void ft_printf_color(char **final, char **str, va_list ap) { int i; i = 0; + if (ft_strncmp(*str, "{ran}", 5) == 0) + { + i = va_arg(ap, int) % 7 + 1; + *final = ft_strjoin(*final, g_colors[i].val); + *str += 5; + return ; + } while(g_colors[i].key) { if (ft_strncmp(*str, g_colors[i].key, 5) == 0) { - (void)fd; /* if (isatty(fd)) */ *final = ft_strjoin(*final, g_colors[i].val); *str += 5; diff --git a/libft/src/ft_printf/lib_fmt.c b/libft/src/ft_printf/lib_fmt.c index 5865af59..59caf57a 100644 --- a/libft/src/ft_printf/lib_fmt.c +++ b/libft/src/ft_printf/lib_fmt.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:33:35 by jhalford #+# #+# */ -/* Updated: 2016/11/16 17:46:16 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 16:54:40 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */