xy.h comments

This commit is contained in:
Mikachu2333 2025-08-18 19:49:48 +08:00 committed by 曾奥然
parent 555eb91d35
commit e98361f33b

View File

@ -19,7 +19,7 @@
#ifndef XY_H #ifndef XY_H
#define XY_H #define XY_H
#define _XY_Version "v0.1.6.0-2025/08/18" #define _XY_Version "v0.1.6.1-2025/08/18"
#define _XY_Maintain_URL "https://github.com/RubyMetric/chsrc/blob/dev/lib/xy.h" #define _XY_Maintain_URL "https://github.com/RubyMetric/chsrc/blob/dev/lib/xy.h"
#define _XY_Maintain_URL2 "https://gitee.com/RubyMetric/chsrc/blob/dev/lib/xy.h" #define _XY_Maintain_URL2 "https://gitee.com/RubyMetric/chsrc/blob/dev/lib/xy.h"
@ -165,7 +165,13 @@ xy_malloc0 (size_t size)
******************************************************/ ******************************************************/
/** /**
* str中所有的pat字符串替换成replace * @brief str pat replace
*
* @param str
* @param pat
* @param replace
*
* @return
*/ */
static char * static char *
xy_str_gsub (const char *str, const char *pat, const char *replace) xy_str_gsub (const char *str, const char *pat, const char *replace)
@ -231,6 +237,15 @@ xy_2strjoin (const char *str1, const char *str2)
return ret; return ret;
} }
/**
* @brief
*
* @param count
* @param ...
*
* @return
*/
static char * static char *
xy_strjoin (unsigned int count, ...) xy_strjoin (unsigned int count, ...)
{ {
@ -285,6 +300,14 @@ xy_strjoin (unsigned int count, ...)
return ret; return ret;
} }
/**
* @brief
*
* @param str
*
* @return
*/
static char * static char *
xy_strdup (const char *str) xy_strdup (const char *str)
{ {
@ -684,14 +707,16 @@ _xy_log_brkt (int level, const char *prompt1, const char *prompt2, const char *c
/****************************************************** /******************************************************
* System * System
******************************************************/ ******************************************************/
/** /**
* cmditer_func * @brief cmditer_func
* *
* @param cmd * @param cmd
* @param n 0 n (n>0) n行 * @param n 0 n (n>0) n行
*
* @param iter_func * @param iter_func
* *
* @return n
*
* @note * @note
* *
* iter_func() * iter_func()
@ -745,8 +770,7 @@ xy_run (const char *cmd, unsigned long n)
******************************************************/ ******************************************************/
/** /**
* just os_family() windows, unix * @note just os_family() windows, unix
*
* @return "windows" "unix" * @return "windows" "unix"
*/ */
#define xy_os_family _xy_os_family () #define xy_os_family _xy_os_family ()
@ -761,7 +785,7 @@ _xy_os_family ()
/** /**
* os family * @brief os family
*/ */
static const char * static const char *
xy_os_depend_str (const char *str_for_win, const char *str_for_unix) xy_os_depend_str (const char *str_for_win, const char *str_for_unix)
@ -773,6 +797,12 @@ xy_os_depend_str (const char *str_for_win, const char *str_for_unix)
} }
/**
* @brief HOME
*
* @note Windows %USERPROFILE%Linux $HOME
* @warning Windows Documents 使 HOME Documents _xy_win_documents()
*/
#define xy_os_home _xy_os_home () #define xy_os_home _xy_os_home ()
static char * static char *
_xy_os_home () _xy_os_home ()
@ -786,6 +816,12 @@ _xy_os_home ()
} }
/**
* @brief Windows Documents
*
* @note 使 HOME Documents
* @warning Windows NULL
*/
static char * static char *
_xy_win_documents () _xy_win_documents ()
{ {
@ -806,7 +842,11 @@ _xy_win_documents ()
#define xy_win_powershell_profile _xy_win_powershell_profile () #define xy_win_powershell_profile _xy_win_powershell_profile ()
#define xy_win_powershellv5_profile _xy_win_powershellv5_profile () #define xy_win_powershellv5_profile _xy_win_powershellv5_profile ()
// 更新 PowerShell 配置文件路径函数 /**
* @brief Windows pwsh (>=v5)
*
* @warning Windows NULL
*/
static char * static char *
_xy_win_powershell_profile () _xy_win_powershell_profile ()
{ {
@ -822,6 +862,11 @@ _xy_win_powershell_profile ()
} }
/**
* @brief Windows powershell (v5)
*
* @warning Windows NULL
*/
static char * static char *
_xy_win_powershellv5_profile () _xy_win_powershellv5_profile ()
{ {
@ -856,8 +901,8 @@ xy_file_exist (const char *path)
} }
/** /**
* @note xy_file_exist() xy_dir_exist() 使 '~' * @note `xy_file_exist()` `xy_dir_exist()` 使 '~'
* xy_normalize_path() * `xy_normalize_path()`
*/ */
static bool static bool
xy_dir_exist (const char *path) xy_dir_exist (const char *path)
@ -923,6 +968,11 @@ xy_normalize_path (const char *path)
new = xy_2strjoin (xy_os_home, xy_str_delete_prefix (new, "~")); new = xy_2strjoin (xy_os_home, xy_str_delete_prefix (new, "~"));
} }
// 在特殊情况下上面的替换最终可能导致形如 `/foo//bar/` 之类的东西
// 建议进行去重处理以防万一
//new = xy_str_gsub (new, "\\", "/");
//new = xy_str_gsub (new, "//", "/");
if (xy_on_windows) if (xy_on_windows)
return xy_str_gsub (new, "/", "\\"); return xy_str_gsub (new, "/", "\\");
else else