Skip to content

Commit cc85521

Browse files
committed
重命名部分 API
1 parent 54dbb0e commit cc85521

File tree

4 files changed

+30
-22
lines changed

4 files changed

+30
-22
lines changed

lib/xy.h

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
* -------------------------------------------------------------
55
* Lib Authors : 曾奥然 <[email protected]>
66
* | 郭恒 <[email protected]>
7-
* Contributors : juzeon <skyjuzheng@gmail.com>
8-
* | Mikachu2333 <mikachu.23333@zohomail.com>
7+
* Contributors : Mikachu2333 <mikachu.23333@zohomail.com>
8+
* | juzeon <skyjuzheng@gmail.com>
99
* | BingChunMoLi <[email protected]>
1010
* |
1111
* Created On : <2023-08-28>
12-
* Last Modified : <2025-09-29>
12+
* Last Modified : <2025-10-06>
1313
*
1414
*
1515
* xy: 襄阳、咸阳
@@ -23,7 +23,7 @@
2323
#ifndef XY_H
2424
#define XY_H
2525

26-
#define _XY_Version "v0.2.0.0-2025/08/27"
26+
#define _XY_Version "v0.2.1.0-2025/10/06"
2727
#define _XY_Maintain_URL "https://github.com/RubyMetric/chsrc/blob/dev/lib/xy.h"
2828
#define _XY_Maintain_URL2 "https://gitee.com/RubyMetric/chsrc/blob/dev/lib/xy.h"
2929

@@ -123,6 +123,10 @@ xy =
123123
#define assert_str(a, b) assert (xy_streql ((a), (b)))
124124

125125
#define xy_panic(reason) assert(!reason)
126+
127+
// @flavor Perl, PHP, Raku
128+
#define die xy_panic
129+
126130
#define xy_unsupported() xy_panic("Unsuppoted")
127131
#define xy_unimplemented() xy_panic("Unimplemented temporarily")
128132
#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);}
177181
const char *: _xy_println_const_str, \
178182
default: xy_panic("Unsupported type for println()/say()!") \
179183
)(x)
180-
/* @flavor Perl/Raku */
184+
/* @flavor Raku, Perl */
181185
#define say println
182186
/* @flavor PHP */
183187
#define echo println
@@ -646,10 +650,11 @@ xy_str_find (const char *str, const char *substr)
646650

647651
/**
648652
* @brief 获取字符串下一行的内容
653+
*
649654
* @note 将忽略开头的换行,截取至下一个换行前(不含换行符)
650655
*/
651656
static char *
652-
xy_str_take_until_newline (const char *str)
657+
xy_str_next_nonempty_line (const char *str)
653658
{
654659
if (!str)
655660
return xy_strdup ("");
@@ -674,10 +679,13 @@ xy_str_take_until_newline (const char *str)
674679

675680
/**
676681
* @brief 读取文件内容并返回字符串,失败时返回空字符串
677-
* @note 已处理 `\r\n` 和 `\r`,返回的字符串均为 `\n` 换行
682+
*
683+
* @note 已处理 \r\n 和 \r,返回的字符串均为 \n 换行
684+
*
685+
* @flavor Ruby: IO::read
678686
*/
679687
static char *
680-
xy_file_to_str (const char *path)
688+
xy_file_read (const char *path)
681689
{
682690
FILE *fp = fopen (path, "rb");
683691
if (!fp)

src/framework/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1745,7 +1745,7 @@ chsrc_append_to_file (const char *str, const char *filename)
17451745
}
17461746

17471747
/**
1748-
* @note 本函数不会自动在 str 末尾添加换行符
1748+
* @note 本函数不会自动在 `str` 末尾添加换行符
17491749
*/
17501750
static void
17511751
chsrc_prepend_to_file (const char *str, const char *filename)

src/recipe/lang/Rust/Cargo.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ pl_rust_cargo_prelude (void)
1414
chef_set_sources_last_updated (this, "2025-06-18");
1515

1616
chef_set_chef (this, NULL);
17-
chef_set_cooks (this, 2, "@ccmywish", "@Mikachu2333");
17+
chef_set_cooks (this, 2, "@Mikachu2333", "@ccmywish");
1818
chef_set_sauciers (this, 1, "@happy-game");
1919

20-
chef_allow_local_mode (this, PartiallyCan, "可以基于本项目换源吗?请帮助确认", "Can it change sources based on this project? Please help confirm");
20+
chef_allow_local_mode (this, FullyCan, NULL, NULL);
2121
chef_forbid_english (this);
2222
chef_allow_user_define (this);
2323

@@ -72,15 +72,15 @@ pl_rust_cargo_getsrc (char *option)
7272
{
7373
char *cargo_config_file = xy_normalize_path ("~/.cargo/config.toml");
7474

75-
char *raw_content = xy_file_to_str (cargo_config_file);
75+
char *raw_content = xy_file_read (cargo_config_file);
7676
char *formatted_content = xy_str_gsub (raw_content, " ", "");
7777
formatted_content = xy_str_gsub (formatted_content, "'", "\"");
7878
free (raw_content);
7979

8080
XyStrFindResult_t result_has_mirror = xy_str_find (formatted_content, "replace-with");
8181
if (result_has_mirror.found)
8282
{
83-
char *mirror_name = xy_str_take_until_newline (formatted_content + result_has_mirror.end + 1);
83+
char *mirror_name = xy_str_next_nonempty_line (formatted_content + result_has_mirror.end + 1);
8484
mirror_name = xy_str_delete_prefix (mirror_name, "=\"");
8585
mirror_name = xy_str_delete_suffix (mirror_name, "\"");
8686

@@ -90,7 +90,7 @@ pl_rust_cargo_getsrc (char *option)
9090
pl_rust_cargo_note_get_src_default();
9191
return;
9292
}
93-
char *mirror_url = xy_str_take_until_newline (formatted_content + result_mirror.end + 1);
93+
char *mirror_url = xy_str_next_nonempty_line (formatted_content + result_mirror.end + 1);
9494
mirror_url = xy_str_delete_prefix (mirror_url, "registry=\"");
9595
mirror_url = xy_str_delete_suffix (mirror_url, "\"");
9696
if (xy_str_find (mirror_url, "sparse+").found)
@@ -138,7 +138,7 @@ pl_rust_cargo_setsrc (char *option)
138138
{
139139
chsrc_backup (cargo_config_file);
140140

141-
char *raw_content = xy_file_to_str (cargo_config_file);
141+
char *raw_content = xy_file_read (cargo_config_file);
142142

143143
XyStrFindResult_t result_has_mirror = xy_str_find (raw_content, "replace-with");
144144
if (!result_has_mirror.found)
@@ -147,7 +147,7 @@ pl_rust_cargo_setsrc (char *option)
147147
goto finish;
148148
}
149149

150-
char *mirror_name = xy_str_take_until_newline (raw_content + result_has_mirror.end + 1);
150+
char *mirror_name = xy_str_next_nonempty_line (raw_content + result_has_mirror.end + 1);
151151
mirror_name = xy_str_gsub (mirror_name, " ", "");
152152
mirror_name = xy_str_gsub (mirror_name, "'", "\"");
153153
mirror_name = xy_str_delete_prefix (mirror_name, "=\"");
@@ -160,7 +160,7 @@ pl_rust_cargo_setsrc (char *option)
160160
goto finish;
161161
}
162162

163-
char *mirror_url = xy_str_take_until_newline (raw_content + result_mirror.end + 1);
163+
char *mirror_url = xy_str_next_nonempty_line (raw_content + result_mirror.end + 1);
164164
mirror_url = xy_str_gsub (mirror_url, " ", "");
165165
if (!xy_str_find (mirror_url, "registry").found)
166166
{

test/fw.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
* SPDX-License-Identifier: GPL-3.0-or-later
33
* -------------------------------------------------------------
44
* File Authors : 曾奥然 <[email protected]>
5-
* Contributors : Nil Null <[email protected]>
5+
* Contributors : Mikachu2333 <[email protected]>
66
* Created On : <2024-12-14>
7-
* Last Modified : <2025-08-27>
7+
* Last Modified : <2025-10-06>
88
*
99
* 该文件最好启用 DEBUG mode 编译
1010
* ------------------------------------------------------------*/
@@ -67,13 +67,13 @@ main (int argc, char const *argv[])
6767
remove (tmpfile_bk);
6868

6969
chsrc_append_to_file ("Line4\n", tmpfile);
70-
assert_str (xy_file_to_str (tmpfile), "Line2\n\nLine3\nLine4\n");
70+
assert_str (xy_file_read (tmpfile), "Line2\n\nLine3\nLine4\n");
7171

7272
chsrc_prepend_to_file ("Line1 \n", tmpfile);
73-
assert_str (xy_file_to_str (tmpfile), "Line1 \nLine2\n\nLine3\nLine4\n");
73+
assert_str (xy_file_read (tmpfile), "Line1 \nLine2\n\nLine3\nLine4\n");
7474

7575
chsrc_overwrite_file ("Line999 \nLine998\nLine997\n", tmpfile);
76-
assert_str (xy_file_to_str (tmpfile), "Line999 \nLine998\nLine997\n");
76+
assert_str (xy_file_read (tmpfile), "Line999 \nLine998\nLine997\n");
7777

7878
chsrc_log (xy_2strcat ("CPU arch = ", chsrc_get_cpuarch ()));
7979
print ("chsrc: CPU cores = ");

0 commit comments

Comments
 (0)