From 0d6c12cbc8370dafcfcb2c1882303ab2610175c6 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sun, 14 Feb 2016 14:42:54 -0500 Subject: Refactor color handling. The main benefit is colored warnings/errors during parsing. --- color.h | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'color.h') diff --git a/color.h b/color.h index 61b71c0..5f66b43 100644 --- a/color.h +++ b/color.h @@ -38,17 +38,35 @@ struct color_table *parse_colors(const char *ls_colors); */ void pretty_print(const struct color_table *colors, const struct BFTW *ftwbuf); +#if __GNUC__ +# define BFS_PRINTF_ATTRIBUTE(f, v) __attribute__((format(printf, f, v))) +#else +# define BFS_PRINTF_ATTRIBUTE(f, v) +#endif + +/** + * Pretty-print a warning message. + * + * @param colors + * The color table to use. + * @param format + * The format string. + * @param ... + * The format string's arguments. + */ +void pretty_warning(const struct color_table *colors, const char *format, ...) BFS_PRINTF_ATTRIBUTE(2, 3); + /** - * Pretty-print an error. + * Pretty-print an error message. * * @param colors * The color table to use. - * @param path - * The file path in error. - * @param error - * The error code that occurred. + * @param format + * The format string. + * @param ... + * The format string's arguments. */ -void print_error(const struct color_table *colors, const char *path, int error); +void pretty_error(const struct color_table *colors, const char *format, ...) BFS_PRINTF_ATTRIBUTE(2, 3); /** * Free a color table. -- cgit v1.2.3