mirror of
https://github.com/thepigeongenerator/tetris_clone.git
synced 2025-12-17 22:15:45 +01:00
Initial commit
This commit is contained in:
32
src/errors.c
Normal file
32
src/errors.c
Normal file
@@ -0,0 +1,32 @@
|
||||
#include "errors.h"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define MAX_STR_LEN 128
|
||||
|
||||
void error(const ErrorCode error_code, const char* format, ...) {
|
||||
char buffer[MAX_STR_LEN] = {0}; // contains the buffer of the final string
|
||||
|
||||
va_list args = {0};
|
||||
va_start(args, format);
|
||||
vsnprintf(buffer, MAX_STR_LEN, format, args);
|
||||
va_end(args);
|
||||
|
||||
printf("\033[91mE\033[0m: %s\n", buffer);
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "something went wrong! :O", buffer, NULL);
|
||||
|
||||
exit(error_code);
|
||||
}
|
||||
|
||||
void warn(const char* format, ...) {
|
||||
char buffer[MAX_STR_LEN] = {0}; // contains the buffer of the final string
|
||||
|
||||
va_list args = {0};
|
||||
va_start(args, format);
|
||||
vsnprintf(buffer, MAX_STR_LEN, format, args);
|
||||
va_end(args);
|
||||
|
||||
printf("\033[93mW\033[0m: %s\n", buffer);
|
||||
}
|
||||
Reference in New Issue
Block a user