Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
qishipai authored Aug 26, 2021
1 parent 590cdd7 commit 9a89d3e
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// utils.cpp 2021-08-03 by 云中龙++
#include <stdarg.h>
#include <cstdio>
#include "NVutils.h"

#if defined(_WIN32) || defined(_WIN64)

#include <Windows.h> /* 使用Windows API设置字体颜色 */

void nv_error(const char *prefix, const char *str, ...)
{
va_list args;
static HANDLE h = GetStdHandle(STD_ERROR_HANDLE);
SetConsoleTextAttribute(h, 0x0F); fprintf(stderr, "[%s] ", prefix);
SetConsoleTextAttribute(h, 0x0C); fprintf(stderr, "Error: ");
SetConsoleTextAttribute(h, 0x07);
va_start(args, str); vfprintf(stderr, str, args); va_end(args);
}

void nv_warn(const char *prefix, const char *str, ...)
{
va_list args;
static HANDLE h = GetStdHandle(STD_ERROR_HANDLE);
SetConsoleTextAttribute(h, 0x0F); fprintf(stderr, "[%s] ", prefix);
SetConsoleTextAttribute(h, 0x0E); fprintf(stderr, "Warning: ");
SetConsoleTextAttribute(h, 0x07);
va_start(args, str); vfprintf(stderr, str, args); va_end(args);
}

void nv_print(const char *prefix, const char *str, ...)
{
va_list args;
static HANDLE h = GetStdHandle(STD_ERROR_HANDLE);
SetConsoleTextAttribute(h, 0x0A); fprintf(stderr, "[%s] ", prefix);
SetConsoleTextAttribute(h, 0x07);
va_start(args, str); vfprintf(stderr, str, args); va_end(args);
}

#else /* 使用\033控制字符设置字体颜色 */

void nv_error(const char *prefix, const char *str, ...)
{
va_list args;
fprintf(stderr, "\033[1m[%s] \033[31mError: \033[m", prefix);
va_start(args, str); vfprintf(stderr, str, args); va_end(args);
}

void nv_warn(const char *prefix, const char *str, ...)
{
va_list args;
fprintf(stderr, "\033[1m[%s] \033[33mWarning: \033[m", prefix);
va_start(args, str); vfprintf(stderr, str, args); va_end(args);
}

void nv_print(const char *prefix, const char *str, ...)
{
va_list args;
fprintf(stderr, "\033[32;1m[%s] \033[m", prefix);
va_start(args, str); vfprintf(stderr, str, args); va_end(args);
}

#endif /* defined(_WIN32) || defined(_WIN64) */

void nv_revu16(u16_t &x)
{
x = x >> 8 | x << 8;
}

void nv_revu32(u32_t &x)
{
x = x >> 24 | (x & 0xFF0000) >> 8 | (x & 0xFF00) << 8 | x << 24;
}

0 comments on commit 9a89d3e

Please sign in to comment.