Commit a98f7b9e authored by Francois Tessier's avatar Francois Tessier

Add custom printf

parent 5468b9d0
#include "tp_utils.hpp"
#include <stdarg.h>
void printMsg ( msg_t type, char* format, ... ) {
va_list args;
va_start(args, format);
char message[1024];
vsprintf ( message, format, args );
switch ( type )
{
case ERROR:
#ifdef COLOR
fprintf ( stderr, RED "[ERR]" RESET " %s", message);
#else
fprintf ( stderr, "[ERR] %s", message);
#endif
break;
case WARNING:
#ifdef COLOR
fprintf ( stdout, YELLOW "[WARN]" RESET " %s", message);
#else
fprintf ( stdout, "[WARN] %s", message);
#endif
break;
case INFO:
#ifdef COLOR
fprintf ( stdout, GREEN "[INFO]" RESET " %s", message);
#else
fprintf ( stdout, "[INFO] %s", message);
#endif
break;
case TIMING:
#ifdef COLOR
fprintf ( stdout, BLUE "[TIME]" RESET " %s", message);
#else
fprintf ( stdout, "[TIME] %s", message);
#endif
break;
default:
break;
}
va_end (args);
}
#ifndef TP_UTILS_H
#define TP_UTILS_H
#include <stdio.h>
#include <stdlib.h>
#define RED "\x1b[31m"
#define GREEN "\x1b[32m"
#define BLUE "\x1b[34m"
#define YELLOW "\x1b[33m"
#define RESET "\x1b[0m"
typedef enum { ERROR, WARNING, INFO, TIMING } msg_t;
void printMsg ( msg_t type, char* format, ... );
#endif /* TP_UTILS_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment