feat[debug]: add debug macros

This commit is contained in:
Martin Eyben 2025-03-14 17:14:33 +01:00
parent 979993b5fe
commit e04791c329
3 changed files with 217 additions and 1 deletions

View File

@ -1,7 +1,8 @@
#include <stdio.h> #include <stdio.h>
#include "debug.h"
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
printf("helol wolrd!\n"); TRACE("Hello World");
return 0; return 0;
} }

177
src/utils/ansi_colors.h Executable file
View File

@ -0,0 +1,177 @@
/*! \file ansi_colors.h
* \brief ANSI colors
* Define NCOLOR to remove color
*/
#ifndef __ANSI_COLOR_H__
#define __ANSI_COLOR_H__
/*
* This is free and unencumbered software released into the public domain.
*
* For more information, please refer to <https://unlicense.org>
*/
#if NCOLOR // if we are in no color mode, replace all the define by ""
// Regular text
#define BLK ""
#define RED ""
#define GRN ""
#define YEL ""
#define BLU ""
#define MAG ""
#define CYN ""
#define WHT ""
// Regular bold text
#define BBLK ""
#define BRED ""
#define BGRN ""
#define BYEL ""
#define BBLU ""
#define BMAG ""
#define BCYN ""
#define BWHT ""
#define BOLD ""
// Regular underline text
#define UBLK ""
#define URED ""
#define UGRN ""
#define UYEL ""
#define UBLU ""
#define UMAG ""
#define UCYN ""
#define UWHT ""
// Regular background
#define BLKB ""
#define REDB ""
#define GRNB ""
#define YELB ""
#define BLUB ""
#define MAGB ""
#define CYNB ""
#define WHTB ""
// High intensty background
#define BLKHB ""
#define REDHB ""
#define GRNHB ""
#define YELHB ""
#define BLUHB ""
#define MAGHB ""
#define CYNHB ""
#define WHTHB ""
// High intensty text
#define HBLK ""
#define HRED ""
#define HGRN ""
#define HYEL ""
#define HBLU ""
#define HMAG ""
#define HCYN ""
#define HWHT ""
// Bold high intensity text
#define BHBLK ""
#define BHRED ""
#define BHGRN ""
#define BHYEL ""
#define BHBLU ""
#define BHMAG ""
#define BHCYN ""
#define BHWHT ""
// BLINK TEXT
#define BLINK ""
// Reset
#define reset ""
#define CRESET ""
#define COLOR_RESET ""
#define BLINK_RESET ""
#else
// Regular text
#define BLK "\e[0;30m"
#define RED "\e[0;31m"
#define GRN "\e[0;32m"
#define YEL "\e[0;33m"
#define BLU "\e[0;34m"
#define MAG "\e[0;35m"
#define CYN "\e[0;36m"
#define WHT "\e[0;37m"
// Regular bold text
#define BBLK "\e[1;30m"
#define BRED "\e[1;31m"
#define BGRN "\e[1;32m"
#define BYEL "\e[1;33m"
#define BBLU "\e[1;34m"
#define BMAG "\e[1;35m"
#define BCYN "\e[1;36m"
#define BWHT "\e[1;37m"
#define BOLD "\e[1m"
// Regular underline text
#define UBLK "\e[4;30m"
#define URED "\e[4;31m"
#define UGRN "\e[4;32m"
#define UYEL "\e[4;33m"
#define UBLU "\e[4;34m"
#define UMAG "\e[4;35m"
#define UCYN "\e[4;36m"
#define UWHT "\e[4;37m"
// Regular background
#define BLKB "\e[40m"
#define REDB "\e[41m"
#define GRNB "\e[42m"
#define YELB "\e[43m"
#define BLUB "\e[44m"
#define MAGB "\e[45m"
#define CYNB "\e[46m"
#define WHTB "\e[47m"
// High intensty background
#define BLKHB "\e[0;100m"
#define REDHB "\e[0;101m"
#define GRNHB "\e[0;102m"
#define YELHB "\e[0;103m"
#define BLUHB "\e[0;104m"
#define MAGHB "\e[0;105m"
#define CYNHB "\e[0;106m"
#define WHTHB "\e[0;107m"
// High intensty text
#define HBLK "\e[0;90m"
#define HRED "\e[0;91m"
#define HGRN "\e[0;92m"
#define HYEL "\e[0;93m"
#define HBLU "\e[0;94m"
#define HMAG "\e[0;95m"
#define HCYN "\e[0;96m"
#define HWHT "\e[0;97m"
// Bold high intensity text
#define BHBLK "\e[1;90m"
#define BHRED "\e[1;91m"
#define BHGRN "\e[1;92m"
#define BHYEL "\e[1;93m"
#define BHBLU "\e[1;94m"
#define BHMAG "\e[1;95m"
#define BHCYN "\e[1;96m"
#define BHWHT "\e[1;97m"
// BLINK TEXT
#define BLINK "\033[5m"
// Reset
#define reset "\e[0m"
#define CRESET "\e[0m"
#define COLOR_RESET "\e[0m"
#define BLINK_RESET "\033[0m"
#endif
#endif

38
src/utils/debug.h Executable file
View File

@ -0,0 +1,38 @@
/*! \file debug.h
* \brief Debug utils
*/
#ifndef __DEBUG_H__
#define __DEBUG_H__
#include "stdio.h"
#ifndef UNUSED
#define UNUSED(x) (void)(x)
#endif
#ifdef NDEBUG
#define DBG(str, ...)
#else
/*
* DEBUG Macro
*/
#define DBG(str, ...) \
fprintf(stderr, "\033[31mDEBUG:\033[0m " str "\n", ##__VA_ARGS__)
#endif // DEBUG
#ifndef NTRACE
/*
* TRACE Macro
*/
#define TRACE(str, ...) \
fprintf(stderr, "\033[32mTRACE: %s: \033[0m " str "\n", __FILE__, \
##__VA_ARGS__)
#else
#define TRACE(str, ...)
#endif // NTRACE
//
#endif // !__DEBUG_H__