diff --git a/lib/xy.h b/lib/xy.h index 85e5747..08dda24 100644 --- a/lib/xy.h +++ b/lib/xy.h @@ -4,12 +4,12 @@ * ------------------------------------------------------------- * Lib Authors : 曾奥然 * | 郭恒 <2085471348@qq.com> - * Contributors : juzeon - * | Mikachu2333 + * Contributors : Mikachu2333 + * | juzeon * | BingChunMoLi * | * Created On : <2023-08-28> - * Last Modified : <2025-09-29> + * Last Modified : <2025-10-06> * * * xy: 襄阳、咸阳 @@ -23,7 +23,7 @@ #ifndef XY_H #define XY_H -#define _XY_Version "v0.2.0.0-2025/08/27" +#define _XY_Version "v0.2.1.0-2025/10/06" #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" @@ -123,6 +123,10 @@ xy = #define assert_str(a, b) assert (xy_streql ((a), (b))) #define xy_panic(reason) assert(!reason) + +// @flavor Perl, PHP, Raku +#define die xy_panic + #define xy_unsupported() xy_panic("Unsuppoted") #define xy_unimplemented() xy_panic("Unimplemented temporarily") #define xy_unreached() xy_panic("This code shouldn't be reached") @@ -177,7 +181,7 @@ static void _xy_println_const_str (const char *str) {printf ("%s\n", str);} const char *: _xy_println_const_str, \ default: xy_panic("Unsupported type for println()/say()!") \ )(x) -/* @flavor Perl/Raku */ +/* @flavor Raku, Perl */ #define say println /* @flavor PHP */ #define echo println @@ -646,10 +650,11 @@ xy_str_find (const char *str, const char *substr) /** * @brief 获取字符串下一行的内容 + * * @note 将忽略开头的换行,截取至下一个换行前(不含换行符) */ static char * -xy_str_take_until_newline (const char *str) +xy_str_next_nonempty_line (const char *str) { if (!str) return xy_strdup (""); @@ -674,10 +679,13 @@ xy_str_take_until_newline (const char *str) /** * @brief 读取文件内容并返回字符串,失败时返回空字符串 - * @note 已处理 `\r\n` 和 `\r`,返回的字符串均为 `\n` 换行 + * + * @note 已处理 \r\n 和 \r,返回的字符串均为 \n 换行 + * + * @flavor Ruby: IO::read */ static char * -xy_file_to_str (const char *path) +xy_file_read (const char *path) { FILE *fp = fopen (path, "rb"); if (!fp) diff --git a/src/framework/core.c b/src/framework/core.c index 70fec13..49f5c8c 100644 --- a/src/framework/core.c +++ b/src/framework/core.c @@ -1745,7 +1745,7 @@ log_anyway: } /** - * @note 本函数不会自动在 str 末尾添加换行符 + * @note 本函数不会自动在 `str` 末尾添加换行符 */ static void chsrc_prepend_to_file (const char *str, const char *filename) diff --git a/src/recipe/lang/Rust/Cargo.c b/src/recipe/lang/Rust/Cargo.c index 9794867..776a702 100644 --- a/src/recipe/lang/Rust/Cargo.c +++ b/src/recipe/lang/Rust/Cargo.c @@ -14,10 +14,10 @@ pl_rust_cargo_prelude (void) chef_set_sources_last_updated (this, "2025-06-18"); chef_set_chef (this, NULL); - chef_set_cooks (this, 2, "@ccmywish", "@Mikachu2333"); + chef_set_cooks (this, 2, "@Mikachu2333", "@ccmywish"); chef_set_sauciers (this, 1, "@happy-game"); - chef_allow_local_mode (this, PartiallyCan, "可以基于本项目换源吗?请帮助确认", "Can it change sources based on this project? Please help confirm"); + chef_allow_local_mode (this, FullyCan, NULL, NULL); chef_forbid_english (this); chef_allow_user_define (this); @@ -72,7 +72,7 @@ pl_rust_cargo_getsrc (char *option) { char *cargo_config_file = xy_normalize_path ("~/.cargo/config.toml"); - char *raw_content = xy_file_to_str (cargo_config_file); + char *raw_content = xy_file_read (cargo_config_file); char *formatted_content = xy_str_gsub (raw_content, " ", ""); formatted_content = xy_str_gsub (formatted_content, "'", "\""); free (raw_content); @@ -80,7 +80,7 @@ pl_rust_cargo_getsrc (char *option) XyStrFindResult_t result_has_mirror = xy_str_find (formatted_content, "replace-with"); if (result_has_mirror.found) { - char *mirror_name = xy_str_take_until_newline (formatted_content + result_has_mirror.end + 1); + char *mirror_name = xy_str_next_nonempty_line (formatted_content + result_has_mirror.end + 1); mirror_name = xy_str_delete_prefix (mirror_name, "=\""); mirror_name = xy_str_delete_suffix (mirror_name, "\""); @@ -90,7 +90,7 @@ pl_rust_cargo_getsrc (char *option) pl_rust_cargo_note_get_src_default(); return; } - char *mirror_url = xy_str_take_until_newline (formatted_content + result_mirror.end + 1); + char *mirror_url = xy_str_next_nonempty_line (formatted_content + result_mirror.end + 1); mirror_url = xy_str_delete_prefix (mirror_url, "registry=\""); mirror_url = xy_str_delete_suffix (mirror_url, "\""); if (xy_str_find (mirror_url, "sparse+").found) @@ -138,7 +138,7 @@ pl_rust_cargo_setsrc (char *option) { chsrc_backup (cargo_config_file); - char *raw_content = xy_file_to_str (cargo_config_file); + char *raw_content = xy_file_read (cargo_config_file); XyStrFindResult_t result_has_mirror = xy_str_find (raw_content, "replace-with"); if (!result_has_mirror.found) @@ -147,7 +147,7 @@ pl_rust_cargo_setsrc (char *option) goto finish; } - char *mirror_name = xy_str_take_until_newline (raw_content + result_has_mirror.end + 1); + char *mirror_name = xy_str_next_nonempty_line (raw_content + result_has_mirror.end + 1); mirror_name = xy_str_gsub (mirror_name, " ", ""); mirror_name = xy_str_gsub (mirror_name, "'", "\""); mirror_name = xy_str_delete_prefix (mirror_name, "=\""); @@ -160,7 +160,7 @@ pl_rust_cargo_setsrc (char *option) goto finish; } - char *mirror_url = xy_str_take_until_newline (raw_content + result_mirror.end + 1); + char *mirror_url = xy_str_next_nonempty_line (raw_content + result_mirror.end + 1); mirror_url = xy_str_gsub (mirror_url, " ", ""); if (!xy_str_find (mirror_url, "registry").found) { diff --git a/test/fw.c b/test/fw.c index 9b0f58d..112bdce 100644 --- a/test/fw.c +++ b/test/fw.c @@ -2,9 +2,9 @@ * SPDX-License-Identifier: GPL-3.0-or-later * ------------------------------------------------------------- * File Authors : 曾奥然 - * Contributors : Nil Null + * Contributors : Mikachu2333 * Created On : <2024-12-14> - * Last Modified : <2025-08-27> + * Last Modified : <2025-10-06> * * 该文件最好启用 DEBUG mode 编译 * ------------------------------------------------------------*/ @@ -67,13 +67,13 @@ main (int argc, char const *argv[]) remove (tmpfile_bk); chsrc_append_to_file ("Line4\n", tmpfile); - assert_str (xy_file_to_str (tmpfile), "Line2\n\nLine3\nLine4\n"); + assert_str (xy_file_read (tmpfile), "Line2\n\nLine3\nLine4\n"); chsrc_prepend_to_file ("Line1 \n", tmpfile); - assert_str (xy_file_to_str (tmpfile), "Line1 \nLine2\n\nLine3\nLine4\n"); + assert_str (xy_file_read (tmpfile), "Line1 \nLine2\n\nLine3\nLine4\n"); chsrc_overwrite_file ("Line999 \nLine998\nLine997\n", tmpfile); - assert_str (xy_file_to_str (tmpfile), "Line999 \nLine998\nLine997\n"); + assert_str (xy_file_read (tmpfile), "Line999 \nLine998\nLine997\n"); chsrc_log (xy_2strcat ("CPU arch = ", chsrc_get_cpuarch ())); print ("chsrc: CPU cores = ");