lib

morphux C utility library
Log | Files | Refs | Submodules | README | LICENSE | git clone https://git.ne02ptzero.me/git/lib

commit eb6e405e86e96aff2fa01e22e79df06f68e403be
parent 2d2e1af74c0424cabb0a0e37ddd1e397eb50d24a
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Mon, 24 Apr 2017 19:00:30 +0200

Fix(Prints): Now handling print beginning via macros and sizeof()

Diffstat:
Minc/m_print.h | 13++++++++++++-
Msrc/m_print.c | 8++++----
2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/inc/m_print.h b/inc/m_print.h @@ -32,10 +32,21 @@ # include <m_types.h> # include <morphux.h> -# define M_LOG_NONE (1 << 0) +# define M_COLOR_RED "\033[0;31m" +# define M_COLOR_BLUE "\033[0;34m" +# define M_COLOR_RESET "\033[0m" + +# define M_LOG_NONE (1 << 0) # define M_LOG_FORCE (1 << 2) # define M_LOG_TRUNC (1 << 3) +# define M_LOG_DEF_CHAR ">" + +# define M_PANIC_BEG M_COLOR_RED M_LOG_DEF_CHAR " " M_COLOR_RESET +# define M_ERROR_BEG M_COLOR_RED M_LOG_DEF_CHAR " " M_COLOR_RESET +# define M_WARN_BEG M_COLOR_RED M_LOG_DEF_CHAR " " M_COLOR_RESET +# define M_INFO_BEG M_COLOR_BLUE M_LOG_DEF_CHAR " " M_COLOR_RESET + /*! * \brief Print a string in an error fomat, then call exit with 1 * \note Support printf format diff --git a/src/m_print.c b/src/m_print.c @@ -69,7 +69,7 @@ void m_panic(const char *str, ...) { } else { - write(2, "\033[0;31m> \033[0m", 13); + write(2, M_PANIC_BEG, sizeof(M_PANIC_BEG)); vfprintf(stderr, str, ap); if (str[strlen(str) - 1] != '\n') fprintf(stderr, "\n"); @@ -89,7 +89,7 @@ void m_error(const char *str, ...) { } else { - write(2, "\033[0;31m> \033[0m", 13); + write(2, M_ERROR_BEG, sizeof(M_ERROR_BEG)); vfprintf(stderr, str, ap); if (str[strlen(str) - 1] != '\n') fprintf(stderr, "\n"); @@ -108,7 +108,7 @@ void m_warning(const char *str, ...) { } else { - write(2, "\033[0;31m> \033[0m", 13); + write(2, M_WARN_BEG, sizeof(M_WARN_BEG)); vfprintf(stderr, str, ap); } va_end(ap); @@ -124,7 +124,7 @@ void m_info(const char *str, ...) { } else { - write(1, "\033[0;34m> \033[0m", 13); + write(1, M_INFO_BEG, sizeof(M_INFO_BEG)); vprintf(str, ap); fflush(stdout); }