Conceal internal marco

This commit is contained in:
Aoran Zeng 2024-06-11 17:00:22 +08:00
parent 452fc72762
commit cb87e7d09c

View File

@ -17,8 +17,8 @@
#ifndef XY_H
#define XY_H
#define XY_Version "v0.1.2-2024/06/11"
#define XY_Maintain_URL "https://gitee.com/RubyMetric/chsrc/blob/main/xy.h"
#define _XY_Version "v0.1.2-2024/06/11"
#define _XY_Maintain_URL "https://gitee.com/RubyMetric/chsrc/blob/main/xy.h"
#include <assert.h>
#include <stdarg.h>
@ -220,34 +220,34 @@ xy_strdup (const char *str)
return new;
}
#define XY_Str_Bold 1
#define XY_Str_Faint 2
#define XY_Str_Italic 3
#define XY_Str_Underline 4
#define XY_Str_Blink 5
#define XY_Str_Cross 9
#define _XY_Str_Bold 1
#define _XY_Str_Faint 2
#define _XY_Str_Italic 3
#define _XY_Str_Underline 4
#define _XY_Str_Blink 5
#define _XY_Str_Cross 9
#define xy_str_to_bold(str) _xy_str_to_terminal_style (XY_Str_Bold, str)
#define xy_str_to_faint(str) _xy_str_to_terminal_style (XY_Str_Faint, str)
#define xy_str_to_italic(str) _xy_str_to_terminal_style (XY_Str_Italic, str)
#define xy_str_to_underline(str) _xy_str_to_terminal_style (XY_Str_Underline, str)
#define xy_str_to_blink(str) _xy_str_to_terminal_style (XY_Str_Blink, str)
#define xy_str_to_cross(str) _xy_str_to_terminal_style (XY_Str_Cross, str)
#define xy_str_to_bold(str) _xy_str_to_terminal_style (_XY_Str_Bold, str)
#define xy_str_to_faint(str) _xy_str_to_terminal_style (_XY_Str_Faint, str)
#define xy_str_to_italic(str) _xy_str_to_terminal_style (_XY_Str_Italic, str)
#define xy_str_to_underline(str) _xy_str_to_terminal_style (_XY_Str_Underline, str)
#define xy_str_to_blink(str) _xy_str_to_terminal_style (_XY_Str_Blink, str)
#define xy_str_to_cross(str) _xy_str_to_terminal_style (_XY_Str_Cross, str)
#define XY_Str_Red 31
#define XY_Str_Green 32
#define XY_Str_Yellow 33
#define XY_Str_Blue 34
#define XY_Str_Magenta 35
#define XY_Str_Cyan 36
#define _XY_Str_Red 31
#define _XY_Str_Green 32
#define _XY_Str_Yellow 33
#define _XY_Str_Blue 34
#define _XY_Str_Magenta 35
#define _XY_Str_Cyan 36
#define xy_str_to_red(str) _xy_str_to_terminal_style (XY_Str_Red, str)
#define xy_str_to_green(str) _xy_str_to_terminal_style (XY_Str_Green, str)
#define xy_str_to_yellow(str) _xy_str_to_terminal_style (XY_Str_Yellow, str)
#define xy_str_to_blue(str) _xy_str_to_terminal_style (XY_Str_Blue, str)
#define xy_str_to_magenta(str) _xy_str_to_terminal_style (XY_Str_Magenta, str)
#define xy_str_to_red(str) _xy_str_to_terminal_style (_XY_Str_Red, str)
#define xy_str_to_green(str) _xy_str_to_terminal_style (_XY_Str_Green, str)
#define xy_str_to_yellow(str) _xy_str_to_terminal_style (_XY_Str_Yellow, str)
#define xy_str_to_blue(str) _xy_str_to_terminal_style (_XY_Str_Blue, str)
#define xy_str_to_magenta(str) _xy_str_to_terminal_style (_XY_Str_Magenta, str)
#define xy_str_to_purple xy_str_to_magenta
#define xy_str_to_cyan(str) _xy_str_to_terminal_style (XY_Str_Cyan, str)
#define xy_str_to_cyan(str) _xy_str_to_terminal_style (_XY_Str_Cyan, str)
static char *
_xy_str_to_terminal_style (int style, const char *str)
@ -256,29 +256,29 @@ _xy_str_to_terminal_style (int style, const char *str)
switch (style)
{
case XY_Str_Red:
case _XY_Str_Red:
color_fmt_str = "\e[31m%s\e[0m"; break;
case XY_Str_Green:
case _XY_Str_Green:
color_fmt_str = "\e[32m%s\e[0m"; break;
case XY_Str_Yellow:
case _XY_Str_Yellow:
color_fmt_str = "\e[33m%s\e[0m"; break;
case XY_Str_Blue:
case _XY_Str_Blue:
color_fmt_str = "\e[34m%s\e[0m"; break;
case XY_Str_Magenta:
case _XY_Str_Magenta:
color_fmt_str = "\e[35m%s\e[0m"; break;
case XY_Str_Cyan:
case _XY_Str_Cyan:
color_fmt_str = "\e[36m%s\e[0m"; break;
case XY_Str_Bold:
case _XY_Str_Bold:
color_fmt_str = "\e[1m%s\e[0m"; break;
case XY_Str_Faint:
case _XY_Str_Faint:
color_fmt_str = "\e[2m%s\e[0m"; break;
case XY_Str_Italic:
case _XY_Str_Italic:
color_fmt_str = "\e[3m%s\e[0m"; break;
case XY_Str_Underline:
case _XY_Str_Underline:
color_fmt_str = "\e[4m%s\e[0m"; break;
case XY_Str_Blink:
case _XY_Str_Blink:
color_fmt_str = "\e[5m%s\e[0m"; break;
case XY_Str_Cross:
case _XY_Str_Cross:
color_fmt_str = "\e[9m%s\e[0m"; break;
}
@ -414,17 +414,17 @@ xy_str_strip (const char *str)
* Logging
******************************************************/
#define XY_Log_Plain 000000001
#define XY_Log_Success 000000001 << 1
#define XY_Log_Info 000000001 << 2
#define XY_Log_Warn 000000001 << 3
#define XY_Log_Error 000000001 << 4
#define _XY_Log_Plain 000000001
#define _XY_Log_Success 000000001 << 1
#define _XY_Log_Info 000000001 << 2
#define _XY_Log_Warn 000000001 << 3
#define _XY_Log_Error 000000001 << 4
#define xy_log(prompt, str) _xy_log (XY_Log_Plain, prompt, str)
#define xy_succ(prompt,str) _xy_log (XY_Log_Success, prompt, str)
#define xy_info(prompt,str) _xy_log (XY_Log_Info, prompt, str)
#define xy_warn(prompt,str) _xy_log (XY_Log_Warn, prompt, str)
#define xy_error(prompt,str) _xy_log (XY_Log_Error, prompt, str)
#define xy_log(prompt, str) _xy_log (_XY_Log_Plain, prompt, str)
#define xy_succ(prompt,str) _xy_log (_XY_Log_Success, prompt, str)
#define xy_info(prompt,str) _xy_log (_XY_Log_Info, prompt, str)
#define xy_warn(prompt,str) _xy_log (_XY_Log_Warn, prompt, str)
#define xy_error(prompt,str) _xy_log (_XY_Log_Error, prompt, str)
static void
_xy_log (int level, const char *prompt, const char *content)
@ -436,24 +436,24 @@ _xy_log (int level, const char *prompt, const char *content)
/**
* 'app: content'
*/
if (level & XY_Log_Plain)
if (level & _XY_Log_Plain)
{
str = xy_strjoin (3, prompt, ": ", content);
}
else if (level & XY_Log_Success)
else if (level & _XY_Log_Success)
{
str = xy_strjoin (3, prompt, ": ", xy_str_to_green (content));
}
else if (level & XY_Log_Info)
else if (level & _XY_Log_Info)
{
str = xy_strjoin (3, prompt, ": ", xy_str_to_blue (content));
}
else if (level & XY_Log_Warn)
else if (level & _XY_Log_Warn)
{
str = xy_strjoin (3, prompt, ": ", xy_str_to_yellow (content));
to_stderr = true;
}
else if (level & XY_Log_Error)
else if (level & _XY_Log_Error)
{
str = xy_strjoin (3, prompt, ": ", xy_str_to_red (content));
to_stderr = true;
@ -478,11 +478,11 @@ _xy_log (int level, const char *prompt, const char *content)
/**
* remarkably pip 便使xy.h的程序应该基于此再定义自己的 app_info_remarkbaly()
*/
#define xy_log_remarkably(prompt1,prompt2,content) _xy_log_remarkably(XY_Log_Plain, prompt1,prompt2,content)
#define xy_succ_remarkably(prompt1,prompt2,content) _xy_log_remarkably(XY_Log_Success,prompt1,prompt2,content)
#define xy_info_remarkably(prompt1,prompt2,content) _xy_log_remarkably(XY_Log_Info, prompt1,prompt2,content)
#define xy_warn_remarkably(prompt1,prompt2,content) _xy_log_remarkably(XY_Log_Warn, prompt1,prompt2,content)
#define xy_error_remarkably(prompt1,prompt2,content) _xy_log_remarkably(XY_Log_Error, prompt1,prompt2,content)
#define xy_log_remarkably(prompt1,prompt2,content) _xy_log_remarkably(_XY_Log_Plain, prompt1,prompt2,content)
#define xy_succ_remarkably(prompt1,prompt2,content) _xy_log_remarkably(_XY_Log_Success,prompt1,prompt2,content)
#define xy_info_remarkably(prompt1,prompt2,content) _xy_log_remarkably(_XY_Log_Info, prompt1,prompt2,content)
#define xy_warn_remarkably(prompt1,prompt2,content) _xy_log_remarkably(_XY_Log_Warn, prompt1,prompt2,content)
#define xy_error_remarkably(prompt1,prompt2,content) _xy_log_remarkably(_XY_Log_Error, prompt1,prompt2,content)
static void
_xy_log_remarkably (int level, const char *prompt1, const char *prompt2, const char *content)
@ -491,17 +491,17 @@ _xy_log_remarkably (int level, const char *prompt1, const char *prompt2, const c
bool to_stderr = false;
if (level & XY_Log_Plain)
if (level & _XY_Log_Plain)
{
str = xy_strjoin (6, "[", prompt1, " ", prompt2, "] ", content);
}
else if (level & XY_Log_Success)
else if (level & _XY_Log_Success)
{
/* [app 成功] [app success] */
str = xy_strjoin (6,
"[", xy_str_to_green (prompt1), " ", xy_str_to_bold (xy_str_to_green (prompt2)), "] ", xy_str_to_green (content));
}
else if (level & XY_Log_Info)
else if (level & _XY_Log_Info)
{
/* [app 信息] [app info]
[app ] [app notice]
@ -509,14 +509,14 @@ _xy_log_remarkably (int level, const char *prompt1, const char *prompt2, const c
str = xy_strjoin (6,
"[", xy_str_to_blue (prompt1), " ", xy_str_to_bold (xy_str_to_blue (prompt2)), "] ", xy_str_to_blue (content));
}
else if (level & XY_Log_Warn)
else if (level & _XY_Log_Warn)
{
/* [app 警告] [app warn] */
str = xy_strjoin (6,
"[", xy_str_to_yellow (prompt1), " ", xy_str_to_bold (xy_str_to_yellow (prompt2)), "] ", xy_str_to_yellow (content));
to_stderr = true;
}
else if (level & XY_Log_Error)
else if (level & _XY_Log_Error)
{
/* [app 错误] [app error] */
str = xy_strjoin (6,