-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// 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; va_start(args, str); | ||
static HANDLE h = GetStdHandle(STD_ERROR_HANDLE); | ||
SetConsoleTextAttribute(h, 0x0F); fprintf(stderr, "[%s] ", prefix); | ||
SetConsoleTextAttribute(h, 0x0C); fprintf(stderr, "Error: "); | ||
SetConsoleTextAttribute(h, 0x07); vfprintf(stderr, str, args); | ||
va_end(args); | ||
} | ||
|
||
void nv_warn(const char *prefix, const char *str, ...) | ||
{ | ||
va_list args; va_start(args, str); | ||
static HANDLE h = GetStdHandle(STD_ERROR_HANDLE); | ||
SetConsoleTextAttribute(h, 0x0F); fprintf(stderr, "[%s] ", prefix); | ||
SetConsoleTextAttribute(h, 0x0E); fprintf(stderr, "Warning: "); | ||
SetConsoleTextAttribute(h, 0x07); vfprintf(stderr, str, args); | ||
va_end(args); | ||
} | ||
|
||
void nv_print(const char *prefix, const char *str, ...) | ||
{ | ||
va_list args; va_start(args, str); | ||
static HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE); | ||
SetConsoleTextAttribute(h, 0x0A); printf("[%s] ", prefix); | ||
SetConsoleTextAttribute(h, 0x07); vprintf(str, args); va_end(args); | ||
} | ||
|
||
#else /* 使用\033控制字符设置字体颜色 */ | ||
|
||
void nv_error(const char *prefix, const char *str, ...) | ||
{ | ||
va_list args; va_start(args, str); | ||
fprintf(stderr, "\033[1m[%s] \033[31mError: \033[m", prefix); | ||
vfprintf(stderr, str, args); va_end(args); | ||
} | ||
|
||
void nv_warn(const char *prefix, const char *str, ...) | ||
{ | ||
va_list args; va_start(args, str); | ||
fprintf(stderr, "\033[1m[%s] \033[33mWarning: \033[m", prefix); | ||
vfprintf(stderr, str, args); va_end(args); | ||
} | ||
|
||
void nv_print(const char *prefix, const char *str, ...) | ||
{ | ||
va_list args; va_start(args, str); | ||
printf("\033[32;1m[%s] \033[m", prefix); vprintf(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; | ||
} |