Pomme/src/PommeDebug.cpp

59 lines
1.2 KiB
C++
Raw Normal View History

2020-11-11 20:06:52 +00:00
#include "PommeDebug.h"
#include <SDL.h>
#include <sstream>
#include <iostream>
void ImplementMe(const char* fn, std::string msg, int severity)
{
if (severity >= 0)
{
std::stringstream ss;
ss << "[TODO] \x1b[1m" << fn << "\x1b[22m";
if (!msg.empty())
{
ss << ": " << msg;
}
auto str = ss.str();
std::cerr << (severity > 0 ? "\x1b[31m" : "\x1b[33m") << str << "\x1b[0m\n";
}
if (severity >= 2)
{
std::stringstream ss;
ss << fn << "()";
if (!msg.empty()) ss << "\n" << msg;
auto str = ss.str();
int mbflags = SDL_MESSAGEBOX_ERROR;
if (severity == 0) mbflags = SDL_MESSAGEBOX_INFORMATION;
if (severity == 1) mbflags = SDL_MESSAGEBOX_WARNING;
SDL_ShowSimpleMessageBox(mbflags, "Source port TODO", str.c_str(), nullptr);
}
if (severity >= 2)
{
abort();
}
}
std::string Pomme::FourCCString(uint32_t t, char filler)
{
char b[5];
*(uint32_t*) b = t;
#if !(TARGET_RT_BIGENDIAN)
std::reverse(b, b + 4);
#endif
2020-12-26 16:02:46 +00:00
// Replace any non-alphanumeric character with the filler character.
// This ensures that the resulting string is suitable for use as a filename.
2020-11-11 20:06:52 +00:00
for (int i = 0; i < 4; i++)
{
2020-12-26 16:02:46 +00:00
if (!isalnum(b[i]))
b[i] = filler;
2020-11-11 20:06:52 +00:00
}
b[4] = '\0';
return b;
}