diff --git a/.github/workflows/PR-test.yml b/.github/workflows/PR-test.yml index d90fab7..de72e84 100644 --- a/.github/workflows/PR-test.yml +++ b/.github/workflows/PR-test.yml @@ -5,7 +5,7 @@ # | Mikachu2333 # | # Created On : <2025-06-19> -# Last Modified : <2025-08-07> +# Last Modified : <2025-08-17> # # Test PR # --------------------------------------------------------------- @@ -14,11 +14,15 @@ name: 测试PR on: pull_request: - types: [opened, - synchronize, # 后续提交 - ready_for_review, # draft PR 转为正式 PR - review_requested, - reopened] + # 仅在开 pr、草稿转正式、手动要求 review、reopen的时候运行测试 + types: [ + opened, + # 因 synchronize 将导致 pr 的构建过于频繁而禁用 + # synchronize, # 在 pr 者 push commit 时每次构建 + ready_for_review, # draft PR 转为正式 PR + review_requested, + reopened, + ] paths: - "src/**" - "lib/**" @@ -31,7 +35,7 @@ jobs: steps: - name: 检出代码 - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: 测试构建情况 run: | @@ -48,7 +52,13 @@ jobs: steps: - name: 检出代码 - uses: actions/checkout@v4 + uses: actions/checkout@v5 + + - name: 创建测试文件 + shell: powershell + run: | + New-Item -Path "$env:USERPROFILE\Documents\Powershell\Microsoft.PowerShell_profile.ps1" -ItemType File -Force + New-Item -Path "$env:USERPROFILE\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1" -ItemType File -Force - name: 安装依赖 run: | diff --git a/.github/workflows/build-on-Linux-x64.yml b/.github/workflows/build-on-Linux-x64.yml index 27cbc83..038e20a 100644 --- a/.github/workflows/build-on-Linux-x64.yml +++ b/.github/workflows/build-on-Linux-x64.yml @@ -20,7 +20,7 @@ jobs: steps: - name: 检出代码 - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: 构建 run: | diff --git a/.github/workflows/build-on-Windows.yml b/.github/workflows/build-on-Windows.yml index c009e28..28bc12e 100644 --- a/.github/workflows/build-on-Windows.yml +++ b/.github/workflows/build-on-Windows.yml @@ -24,7 +24,7 @@ jobs: steps: - name: 检出代码 - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: 安装 GCC uses: msys2/setup-msys2@v2 diff --git a/.github/workflows/build-on-macOS.yml b/.github/workflows/build-on-macOS.yml index a86ea82..a2ae76a 100644 --- a/.github/workflows/build-on-macOS.yml +++ b/.github/workflows/build-on-macOS.yml @@ -20,7 +20,7 @@ jobs: steps: - name: 检出代码 - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: 检查编译器版本 run: | @@ -53,7 +53,7 @@ jobs: steps: - name: 检出代码 - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: 检查编译器版本 run: | diff --git a/.github/workflows/pkg-deb.yml b/.github/workflows/pkg-deb.yml index d3d077c..162ac85 100644 --- a/.github/workflows/pkg-deb.yml +++ b/.github/workflows/pkg-deb.yml @@ -30,7 +30,7 @@ jobs: steps: - name: 检出代码 - uses: actions/checkout@v4 + uses: actions/checkout@v5 with: ref: gh-build @@ -156,7 +156,7 @@ jobs: steps: - name: Download all artifacts - uses: actions/download-artifact@v4 + uses: actions/download-artifact@v5 with: pattern: chsrc-deb-files merge-multiple: true diff --git a/.vscode/launch.json b/.vscode/launch.json index af85601..48cebda 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,13 +8,15 @@ "program": "${workspaceFolder}/chsrc-debug", "args": [ "get", - "python" + "nodejs" ], "preLaunchTask": "构建 debug 版 chsrc", "stopAtEntry": true, "cwd": "${workspaceFolder}", "environment": [], - "externalConsole": false, + // 如果你认为使用弹出窗口难以调试,可尝试设置为false + "externalConsole": true, + // lldb 等请自行设置,不作额外说明 "MIMode": "gdb", // "miDebuggerPath": "/path/to/gdb", "setupCommands": [ @@ -28,7 +30,8 @@ "text": "-gdb-set disassembly-flavor intel", "ignoreFailures": true } - ] + ], + "postDebugTask": "停止 debug 程序" }, { @@ -58,4 +61,4 @@ ] } ] -} +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 74669f2..8939713 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,7 @@ { "editor.fontLigatures": false, + "C_Cpp.autoAddFileAssociations": false, "C_Cpp.intelliSenseEngine": "Tag Parser", "C_Cpp.default.browse.limitSymbolsToIncludedHeaders": false, diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 05447d0..6c4ce8c 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -17,7 +17,8 @@ "kind": "build", "isDefault": true }, - "detail": "使用 just build 编译" + "dependsOn": "停止程序", + "detail": "先停止原有程序,然后使用 just build 编译" }, { "type": "shell", @@ -36,7 +37,6 @@ "kind": "build", "isDefault": false }, - "detail": "使用 just build-in-debug-mode 编译 debug 版" }, { "type": "shell", @@ -94,7 +94,79 @@ "isDefault": false }, "detail": "使用 just test-xy 测试 xy.h" + }, + { + "type": "shell", + "label": "停止 debug 程序", + "windows": { + "command": "powershell", + "args": [ + "-c", + "Get-Process -Name \"chsrc-debug\" -ErrorAction SilentlyContinue | Stop-Process -Force;", + "Get-Process -Name \"gdb\" -ErrorAction SilentlyContinue | Stop-Process -Force;", + "Get-Process -Name \"WindowsDebugLauncher\" -ErrorAction SilentlyContinue | Stop-Process -Force;" + ] + }, + "linux": { + "command": "bash", + "args": [ + "-c", + "if pgrep -f chsrc-debug > /dev/null; then pkill -f chsrc-debug; fi" + ] + }, + "osx": { + "command": "bash", + "args": [ + "-c", + "if pgrep -f chsrc-debug > /dev/null; then pkill -f chsrc-debug; fi" + ] + }, + "group": "build", + "presentation": { + "echo": true, + "reveal": "silent", + "focus": false, + "panel": "shared", + "showReuseMessage": true, + "clear": false + }, + "detail": "停止 debug 版本的 chsrc" + }, + { + "type": "shell", + "label": "停止程序", + "windows": { + "command": "powershell", + "args": [ + "-c", + "Get-Process -Name \"chsrc\" -ErrorAction SilentlyContinue | Stop-Process -Force;" + ] + }, + "linux": { + "command": "bash", + "args": [ + "-c", + "if pgrep -f chsrc > /dev/null; then pkill -f chsrc; fi" + ] + }, + "osx": { + "command": "bash", + "args": [ + "-c", + "if pgrep -f chsrc > /dev/null; then pkill -f chsrc; fi" + ] + }, + "group": "build", + "presentation": { + "echo": true, + "reveal": "always", + "focus": false, + "panel": "shared", + "showReuseMessage": true, + "clear": false + }, + "detail": "跨平台停止 chsrc" } ], "version": "2.0.0" -} +} \ No newline at end of file diff --git a/README.md b/README.md index a416395..2372892 100644 --- a/README.md +++ b/README.md @@ -3,11 +3,11 @@ ! ------------------------------------------------------------- ! Doc Type : Markdown ! Doc Name : README.md - ! Doc Authors : Aoran Zeng + ! Doc Authors : 曾奥然 ! Contributors : Mikachu2333 ! | ! Created On : <2023-12-28> - ! Last Modified : <2025-08-11> + ! Last Modified : <2025-08-22> ! ---------------------------------------------------------- -->
@@ -16,7 +16,7 @@ 全平台通用换源工具与框架 `chsrc`,**目标支持 Linux, Windows (native, MSYS2, Cygwin), macOS, BSD, Android 等尽可能多的操作系统环境,龙芯、飞腾、RISC-V 等尽可能多的 CPU**。 -我们使用 **C11** 来完成上述目标。我们并不使用 Python 或 JS 等解释语言,因为一个简单的换源工具,不应该强行塞给用户一个庞大的解释器和数十、数百 MB 其他文件。 +我们使用 **C11** 来完成上述目标。我们并不使用 Python 或 JavaScript 等解释语言,因为一个简单的换源工具,不应该强行塞给用户一个庞大的解释器和数十、数百 MB 其他文件。 本软件为**自由软件**,SDPX 软件许可证为 `GPL-3.0-or-later and MIT` @@ -39,6 +39,20 @@ +## ❤️ 致所有的朋友们 + +2025年8月11日,我因通宵重构本项目代码而被送去抢救([#252](https://github.com/RubyMetric/chsrc/issues/252),[突发!换源工具 chsrc 作者在重构过程中被送去 120 抢救](https://v2ex.com/t/1151802))。大家给予的关心和帮助让我非常非常感动!在此,我衷心感谢每一位朋友!**无论是开源还是闭源,无论是否为职业程序员,我们其实都是一群使用软件、热心互助、充满友爱的人,这是一个温暖的大家庭**。 + +我为 `chsrc` 采用 GPL 协议,怀着殷切的期望:**希望能够营造像 Richard Stallman 在创建 GNU 项目之前,在 MIT 那样的氛围——写自己用得上的软件,与大家一起开发、维护,简单纯粹,无关商业利益。就像小区、校园自发组建的足球篮球队,从一次偶然的加入,逐渐成长为互相支持的伙伴**。 + +这次经历让我更加深刻地体会到:开源,是一种把大家联系在一起的方式,**它让友情、互助和协作成为可能,也让我们在共同的目标中建立起长期的纽带**。 + +最后,希望大家能够**时刻关注**自己的身体,**你可以随时 `chsrc` `chown` `chgrp` `chmod` 无限次,但是无法 `chbody`**! + +
+ + + ## 🤝 协作与贡献 > [!TIP] @@ -47,14 +61,13 @@ --- > [!NOTE] -> 这是你可以参与的第一个现实世界中有用的C语言项目,[用 VS Code 一分钟内上手编译、运行、测试 chsrc](./doc/01-开发与构建.md) +> 这也许是你可以参与的第一个现实世界中有用的C语言项目,[用 VS Code 一分钟内上手编译、运行、测试 chsrc](./doc/01-开发与构建.md) > > 欢迎对 GitHub、Gitee 协作不熟悉的人以此为契机学习参与贡献, 欢迎任何编程初学者。[从开发到提交PR,我们覆盖全流程文档](./doc/) -,作者可提供一定的 [贡献指导](https://github.com/RubyMetric/chsrc/discussions/50) --- > [!IMPORTANT] -> **`chsrc` 可换源 65+ 目标。每个人仅仅贡献和维护自己熟悉的部分,回报是得到其他所有领域专家的帮助。** [欢迎成为 recipe 维护者](https://github.com/RubyMetric/chsrc/issues/130) +> **`chsrc` 可换源 65+ 目标。每个人仅仅贡献和维护自己熟悉的部分,回报是得到其他所有领域专家的帮助。** [欢迎成为 recipe 维护者](https://github.com/RubyMetric/chsrc/issues/275)
diff --git a/doc/01-开发与构建.md b/doc/01-开发与构建.md index bbea6c8..27a1422 100644 --- a/doc/01-开发与构建.md +++ b/doc/01-开发与构建.md @@ -3,11 +3,11 @@ ! ------------------------------------------------------------- ! Doc Type : Markdown ! Doc Name : 01-开发与构建.md - ! Doc Authors : Aoran Zeng - ! Contributors : Nul None + ! Doc Authors : 曾奥然 + ! Contributors : Nul None ! | ! Created On : <2024-12-27> - ! Last Modified : <2025-07-21> + ! Last Modified : <2025-08-22> ! ---------------------------------------------------------- --> # 开发 chsrc @@ -53,7 +53,7 @@ git clone https://gitee.com/RubyMetric/chsrc.git -b dev 3. **`RELEASE mode`** 4. **`CI-RELEASE mode`** -第四种只在 GitHub Actions 使用,一般只需要前三者;而在开发时你仅需要前两者;如果不需要 Debug,仅仅第一个 **DEV mode** 就够了。 +开发时只需要前两种模式;第四种模式只在 GitHub Actions 使用。 **如果你使用 `just`,可以在 VS Code 中获得更好的体验,按 `Ctrl-Shift-B` 直接使用 DEV mode 构建** diff --git a/doc/02-提交与贡献.md b/doc/02-提交与贡献.md index eefc4fc..288e26b 100644 --- a/doc/02-提交与贡献.md +++ b/doc/02-提交与贡献.md @@ -3,11 +3,11 @@ ! ------------------------------------------------------------- ! Doc Type : Markdown ! Doc Name : 02-提交与贡献.md - ! Doc Authors : Aoran Zeng - ! Contributors : Nul None + ! Doc Authors : 曾奥然 + ! Contributors : Nul None ! | ! Created On : <2024-12-13> - ! Last Modified : <2025-07-21> + ! Last Modified : <2025-08-22> ! ---------------------------------------------------------- --> # 贡献说明 @@ -22,6 +22,8 @@ ## 提交与审阅 +当你提交 PR 的时候,一定要将 PR 指定 chsrc 原仓库的 dev 分支。 + ### 一个简单的 Bug 一个简单的 Bug fix,有写权限的维护者可以直接推送到主仓库的 `dev` 分支 @@ -34,15 +36,14 @@ (1) -1. **如果你是 recipe Chef,则你完全负责这个 recipe,如果你拥有写权限,你可以直接推送代码到 `dev` 分支** -2. 如果你是 recipe Cook,则你需要参考 recipe 中记录的 Cook 信息,如果只有你一个人,且你拥有写权限,你可以直接推送代码。如果有多人,则需要提一个 issue,介绍方案,然后 @ 所有 Cook 来 review +**如果你是 recipe Chef,则你完全负责这个 recipe,如果你拥有写权限,你可以直接推送代码到 `dev` 分支** --- (2) -1. 需要先搜索你修改的部分涉及到的 recipe,然后提 issue @ 所有相关的 recipe Cook 来 review -2. 如果涉及了所有 recipe,则 @ framework Cook,而无需把所有 recipe 的 Cook 都喊过来,但是如果觉得有必要,可以 @ 任意你觉得有能力 review 和能给出建议的人来 review +1. 需要先搜索你修改的部分涉及到的 recipe,然后提 issue @ 所有相关的 recipe Chef 来 review +2. 如果涉及了所有 recipe,则 @ framework Chef,而无需把所有 recipe 的 Chef 都喊过来,但是如果觉得有必要,可以 @ 任意你觉得有能力 review 和能给出建议的人来 review
diff --git a/doc/03-为什么拒绝使用代码格式化工具.md b/doc/03-为什么拒绝使用代码格式化工具.md index f9487bf..08991d7 100644 --- a/doc/03-为什么拒绝使用代码格式化工具.md +++ b/doc/03-为什么拒绝使用代码格式化工具.md @@ -3,31 +3,49 @@ ! ------------------------------------------------------------- ! Doc Type : Markdown ! Doc Name : 03-为什么拒绝使用代码格式化工具.md - ! Doc Authors : Aoran Zeng - ! Contributors : Nul None + ! Doc Authors : 曾奥然 + ! Contributors : Nul None ! Created On : <2025-08-10> - ! Last Modified : <2025-08-11> + ! Last Modified : <2025-08-20> ! ---------------------------------------------------------- --> # chsrc 代码风格 -`chsrc` 项目的第一作者深受 **Ruby** 语言哲学的影响。Ruby 在编程语言界以其 **"程序员幸福感"** 和优雅语法著称。作者同时对 **Perl poem**(Perl 诗歌)这一独特的艺术形式印象深刻。 - -Ruby 的语法优美性在编程行业中具有标杆地位。Matz(松本行弘)提出的 **代码应该为人类而写,偶尔为机器执行** 这一理念,已经成为现代编程语言设计的重要指导原则。 +Ruby 的语法优美性在编程行业中具有标杆地位。Matz(松本行弘)提出的 **代码应该为人类而写,偶尔为机器执行** 这一理念,已经成为现代编程语言设计的重要指导原则。`chsrc` 项目的第一作者深受 **Ruby** 语言哲学的影响。 本项目起源于 AI 编程尚未流行的时代,所有代码全部依赖人类的耐心来维护。现在,我们的代码以及这篇文章不仅会由人类阅读,也会由 AI 阅读。我们始终坚持:**代码的可读性和维护性是项目长期发展的根本保障**。
+ + ## 为什么我们坚持不使用代码格式化工具 代码格式化工具(code formatter)在多人协作的代码仓库中确实有其价值,**参与的人越多,统一格式的需求越迫切**。然而,`chsrc` 项目经过深思熟虑后,拒绝使用代码格式化工具。让我来说明这一决定背后的深层原因。 -像 `Prettier` 这样的工具表面上带来了统一性,但其代价是什么?**它是极度专制的(opiniated)**,这意味着为了获得表面的一致性,我们必须**完全交出代码审美的自主权**。今天我们大部分人使用 `Prettier`,**并非出于真心的认同,而是因为整个前端生态圈的集体胁迫——不用就意味着被边缘化**。 +### 被强迫使用 + +像 `Prettier` 这样的工具表面上带来了统一性,但其代价是什么?**它是极度专制的(opiniated)**,我们必须**完全交出代码审美的自主权**。今天我们大部分人使用 `Prettier`,**并非出于真心的认同,而是因为整个前端生态圈的集体胁迫——不用就意味着被边缘化**。 这种现象的本质令人深思:**少数 `Prettier` 维护者的个人偏好,竟然决定了全球数百万开发者的代码美学标准。这显然是一种技术独裁,坚决拒绝向格式化工具的霸权低头**。 -C语言的格式化工具通常选择 `clang-format`,它的配置选项十分丰富,比 `Prettier` 要理性得多。然而,即便如此,**其配置的复杂性和局限性仍然无法满足 chsrc 对代码美学的严苛要求**。如果你是一位 `clang-format` 的配置专家,我们诚挚邀请您告诉我们如何优雅地处理以下代码场景,**也许这能改变我的立场**。 +
+ +### 一致性 ≠ 美观 ≠ 可读 + +格式化工具只保证了表面的一致性,就像一些校服,一致不一定代表美。同样,一致不一定代表代码就是最易读易懂的。 + +每一个有追求的程序员都应该保留**对代码美学的最后决定权,格式化工具的便利性不应该以牺牲美观性和可维护性为代价**。 + +
+ +### 满足不了我们的需求 + +C语言的格式化工具通常选择 `clang-format`,它的配置选项十分丰富,比 `Prettier` 要理性得多。然而,即便如此,**其配置的复杂性和局限性仍然无法满足 chsrc 对代码格式的严苛要求**。如果你是一位 `clang-format` 的配置专家,我们诚挚邀请您告诉我们如何优雅地处理以下代码场景,**也许这能改变我的立场**。 + +
+ + ### 挑战案例 @@ -36,8 +54,8 @@ C语言的格式化工具通常选择 `clang-format`,它的配置选项十分 `=` 对齐: ```c -char *name = va_arg(args, char*); -char *email = va_arg(args, char*); +char *name = va_arg (args, char*); +char *email = va_arg (args, char*); ``` 复杂逻辑的 `=` 对齐: @@ -52,7 +70,7 @@ if (!matched) matched = iterate_menu (chsrc_wr_menu, input, &target_tmp); ```c #ifdef _WIN32 - #define XY_On_Windows 1 + #define XY_Build_On_Windows 1 #define xy_on_windows true #ifdef XY_DEBUG #define xy_debug_mode 1 @@ -64,31 +82,40 @@ if (!matched) matched = iterate_menu (chsrc_wr_menu, input, &target_tmp);
-## 我们的立场 -**代码不仅仅是给机器执行的指令,更是团队协作和项目传承的重要载体**。 - -每一个有追求的程序员都应该保留对代码美学的最后决定权。格式化工具的便利性不应该以牺牲创造力和个性为代价。在 `chsrc` 项目中,我们选择用更多的时间和精力来精心设计每一行代码。正如 Ruby 社区所倡导的那样,**程序员的幸福感不应该被自动化工具的专制所剥夺。我们追求的不是表面的一致性,而是深层次的代码质量和表达力。这不是对工具的盲目排斥,而是对程序员自主性的坚持。这不是标新立异的固执,而是对代码质量的不妥协。** - -如果你也认同 **代码应该为人类而写** 的理念,欢迎加入我们,一起创造真正优质的代码。 - -
## C语言代码风格 - 整体上基于 `GNU style`,但我们坚持自己的美学原则,在细节上有所改进 -- 类型名: `PascalCase_t` +- 类型名: `PascalCase_t`,即 `UpperCamelCase_t` -- 函数调用时,函数名和`()`之间应当保持一个空格。但是当函数参数为0或1时,不保持该空格 +- 函数定义和调用时,**函数名和`()`之间始终保持一个空格**,如果是在宏中,可紧凑一些,无硬性规定 -- 函数定义时,函数名和`()`之间始终保持一个空格 +- 函数和函数定义之间**一般保持2个空行** + + - 若函数之间有高度关联性,**可用1个空行** + - 若一系列函数和一系列函数存在主题性区别,**可用3个空行**
+ + +## Markdown 写作风格 + +维护者很多时候不是从渲染好的界面来看 Markdown 文件的,而是阅读 Markdown 源文件,所以 Markdown 在源文件层面也要易读。 + +我们保持每个主题之间 **1个`
` + 3个空行** 的简单风格。 + +拒绝使用 VS Code 的 `markdownlint` 插件,**因为它总是用它狭隘的标准给我们增加了巨多的黄色下划线**。 + +
+ + + ## 其他语言代码风格 -我们秉承 **入乡随俗、尊重传统** 的原则,尊重每种语言社区的既定传统。比如,`YAML` 使用2个空格的优雅,`JSON`使用4个空格的规整,`Perl` 使用 Larry Wall 钟爱的4个空格传统。 +我们秉承 **入乡随俗、尊重传统** 的原则,尊重每种语言社区的既定传统。比如,`YAML` 使用2个空格,`JSON`使用4个空格,`Perl` 使用 Larry Wall 钟爱的4个空格。 我们使用 `.editorconfig` 来确保这些格式的应用。 diff --git a/doc/10-如何编写recipe.md b/doc/10-如何编写recipe.md index e2915c8..af88c70 100644 --- a/doc/10-如何编写recipe.md +++ b/doc/10-如何编写recipe.md @@ -3,11 +3,11 @@ ! ------------------------------------------------------------- ! Doc Type : Markdown ! Doc Name : 10-如何编写recipe.md - ! Doc Authors : Aoran Zeng - ! Contributors : Nul None + ! Doc Authors : 曾奥然 + ! Contributors : Nul None ! | ! Created On : <2024-08-19> - ! Last Modified : <2025-08-11> + ! Last Modified : <2025-08-22> ! ---------------------------------------------------------- --> # Write A Recipe Even If You Don't Know C @@ -18,7 +18,7 @@
-我鼓励你为新的软件添加换源支持,因为通过 `chsrc` 框架,这将比写 shell 脚本更加轻松,你的贡献也将非常有价值。理论上每一个 `recipe` 都需要有专人长时间维护 ([招募](https://github.com/RubyMetric/chsrc/issues/130))。 +我鼓励你为新的软件添加换源支持,因为通过 `chsrc` 框架,这将比写 shell 脚本更加轻松,你的贡献也将非常有价值。理论上每一个 `recipe` 都需要有专人长时间维护 ([招募](https://github.com/RubyMetric/chsrc/issues/275))。 - 本项目采用 `GPLv3+` 协议,是真正的**自由软件**,而非仅仅是开源软件 - 代码规范灵活遵循 `GNU` 标准(若标准干扰了可维护性,则并不采纳) @@ -52,6 +52,8 @@ - `source`: 该 `target` 所能换的具体的源,由 `mirror` 提供服务,往往一个 `mirror` 会提供许多 `source` - `recipe`: 是为一个 `target` 定义的具体换源方法,请参考 `src` 目录中的 `recipe` 目录 +- `chef DSL`:是 `chef Domain Specific Language` 的简写,这是一组以 `chef_` 开头的函数,用来定义维护者信息、可用源等元信息 + - **换源链接**: 指镜像站所提供的某一个具体的换源使用的URL - **测速链接**: 用来测速的URL,与 "换源链接" 不同,可分为 **精准测速** 和 **模糊测速** @@ -81,7 +83,7 @@ 该函数将填充 target 所有的必要信息,包括维护信息、换源信息 -7. [设置/修改 "换源 URL" 和 "测速 URL" (how?)](./11-如何设置换源链接与测速链接.md) +7. [设置/修改 "换源链接" 和 "测速链接" (how?)](./11-如何设置换源链接与测速链接.md) 8. 按需实现 `_setsrc()` `_getsrc()` `_resetsrc()`, 可以使用这些函数: diff --git a/doc/11-如何设置换源链接与测速链接.md b/doc/11-如何设置换源链接与测速链接.md index b38fbc5..f50ef68 100644 --- a/doc/11-如何设置换源链接与测速链接.md +++ b/doc/11-如何设置换源链接与测速链接.md @@ -3,8 +3,8 @@ ! ------------------------------------------------------------- ! Doc Type : Markdown ! Doc Name : 11-如何设置换源链接与测速链接.md - ! Doc Authors : Aoran Zeng - ! Contributors : Nul None + ! Doc Authors : 曾奥然 + ! Contributors : Nul None ! | ! Created On : <2025-08-11> ! Last Modified : <2025-08-11> diff --git a/doc/50-协作者与维护者.md b/doc/50-协作者与维护者.md index 9cd46a4..861ffad 100644 --- a/doc/50-协作者与维护者.md +++ b/doc/50-协作者与维护者.md @@ -1,21 +1,34 @@ + + # 协作者与维护者 -作为该语言的资深用户、该软件的专家、镜像站维护人员等,你总是对镜像站和源的可用状态拥有一手信息,我们需要你的帮助。如果想要达到最理想的维护状态,每一个 recipe 都需要有专人长时间维护。所以我们在这个文件记录的是愿意**长期**维护的人,如果是一次性提交代码,只需要在对应 recipe 的文件标头中记录即可。 - -**我们的代码里使用了 recipe (某个菜的烹饪方法) 这个词,因而整个项目便和 "饮食" 有关,比如 `menu`: 汇集了所有的 target 的菜单。因此,我们的维护者身份依然使用了这个惯例:** - -一个 recipe 的协作者可分为: +想要达到最理想的维护状态,每一个 recipe 都需要有专人长时间维护。**我们的代码里使用了 recipe (某个菜的烹饪方法) 这个词,因而整个项目便和 "饮食" 有关,比如 `menu`: 汇集了所有的 target 的菜单。因此,我们的维护者和贡献者身份依然使用了这个惯例:** 1. **Chef** - 主厨: 对一个 recipe 完全负责,有写权限时可以直接推代码 + 品控 (主厨): 对一个 recipe 完全负责,有写权限时可以直接推代码 **目前项目的发展阶段还处于 *外行实现内行* 的情况,比如 Homebrew recipe,实现者根本不是 Homebrew 的真实用户,只是根据各种文档来实现,然后等待用户反馈。所以这里当前的实现者最多只能是 Cook,无法承担 Chef 的责任** 2. **Cook** - 副厨:实现和持续维护 recipe,需要和 Chef 一起 review 代码。可参考 [03-CONTRIBUTING.md](./03-CONTRIBUTING.md) 了解项目是如何进行提交和审阅代码的 + 掌勺:一个 recipe 的主要作者 + +3. **Saucier** + + 调味:一个 recipe 的次要贡献者 (除主要作者外的其他人)
-**项目采用申请制,Chef 仅有1人,Cook 可有多人。请提交 PULL REQUEST 在对应的 recipe 文件中添加自己,并在 [issue #130](https://github.com/RubyMetric/chsrc/issues/130) 留言。** +**Chef 采用申请制,每个 recipe 仅有1人,请提交 PULL REQUEST 在对应的 recipe 文件中添加自己,并在 [issue #275 +](https://github.com/RubyMetric/chsrc/issues/275) 留言。** diff --git a/doc/README.md b/doc/README.md index c9f0fda..d1af190 100644 --- a/doc/README.md +++ b/doc/README.md @@ -3,11 +3,11 @@ ! ------------------------------------------------------------- ! Doc Type : Markdown ! Doc Name : (Document Introduction.md) - ! Doc Authors : Aoran Zeng - ! Contributors : Nul None + ! Doc Authors : 曾奥然 + ! Contributors : Nul None ! | ! Created On : <2024-12-27> - ! Last Modified : <2025-08-11> + ! Last Modified : <2025-08-22> ! ---------------------------------------------------------- --> # 文档说明 @@ -23,7 +23,7 @@ E2E (End-to-End) 开发文档: 具体 recipe 相关: - 如何编写一个具体的 recipe,请参考 [10-如何编写recipe.md](./10-如何编写recipe.md) -- 如何修改换源URL、模糊/精准测速URL,请参考 [11-如何设置换源链接与测速链接.md](./11-如何设置换源链接与测速链接.md) +- 如何修改换源链接、模糊/精准测速链接,请参考 [11-如何设置换源链接与测速链接.md](./11-如何设置换源链接与测速链接.md)
diff --git a/lib/xy.h b/lib/xy.h index 9a00e97..7bfcb61 100644 --- a/lib/xy.h +++ b/lib/xy.h @@ -1,25 +1,28 @@ /** ------------------------------------------------------------ - * Copyright © 2023-2025 Aoran Zeng, Heng Guo + * Copyright © 2023-2025 曾奥然, 郭恒 * SPDX-License-Identifier: MIT * ------------------------------------------------------------- - * Lib Name : xy.h - * Lib Authors : Aoran Zeng - * | Heng Guo <2085471348@qq.com> - * Contributors : juzeon + * Lib Authors : 曾奥然 + * | 郭恒 <2085471348@qq.com> + * Contributors : juzeon * | Mikachu2333 * | * Created On : <2023-08-28> - * Last Modified : <2025-08-09> + * Last Modified : <2025-08-22> * - * xy: 襄阳、咸阳 - * Corss-Platform C11 utilities for CLI applications in mixed - * flavor (mostly Ruby) + * + * xy: 襄阳、咸阳 + * + * 为跨平台命令行应用程序准备的 C11 实用函数和宏 (utilities) + * + * 该库的特点是混合多种编程语言风味 (绝大多数为 Ruby),每个 API + * 均使用 @flavor 标注其参考依据 * ------------------------------------------------------------*/ #ifndef XY_H #define XY_H -#define _XY_Version "v0.1.5.5-2025/08/09" +#define _XY_Version "v0.1.7.0-2025/08/22" #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" @@ -41,6 +44,7 @@ #include #include #include +#include // opendir() closedir() #if defined(__STDC__) && __STDC_VERSION__ >= 202311 #define XY_Deprecate_This(msg) [[deprecated(msg)]] @@ -53,54 +57,55 @@ #endif -/* Global */ +/* 全局变量 */ bool xy_enable_color = true; -// #define NDEBUG +/* 由 xy_init() 赋值 */ +bool xy_on_windows = false; +bool xy_on_linux = false; +bool xy_on_macos = false; +bool xy_on_bsd = false; +bool xy_on_android = false; + +char *xy_os_devnull = NULL; + #ifdef _WIN32 - #define XY_On_Windows 1 - #define xy_on_windows true - #define xy_on_linux false - #define xy_on_macos false - #define xy_on_bsd false - #define xy_os_devnull "nul" + #define XY_Build_On_Windows 1 + #include - #define xy_useutf8() SetConsoleOutputCP (65001) + #include #elif defined(__linux__) || defined(__linux) - #define XY_On_Linux 1 - #define xy_on_windows false - #define xy_on_linux true - #define xy_on_macos false - #define xy_on_bsd false - #define xy_os_devnull "/dev/null" - #define xy_useutf8() + #define XY_Build_On_Linux 1 + #define XY_Build_On_Unix 1 #elif defined(__APPLE__) - #define XY_On_macOS 1 - #define xy_on_windows false - #define xy_on_linux false - #define xy_on_macos true - #define xy_on_bsd false - #define xy_os_devnull "/dev/null" - #define xy_useutf8() + #define XY_Build_On_macOS 1 + #define XY_Build_On_Unix 1 #elif defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__) - #define XY_On_BSD 1 - #define xy_on_windows false - #define xy_on_linux false - #define xy_on_macos false - #define xy_on_bsd true - #define xy_os_devnull "/dev/null" - #define xy_useutf8() + #define XY_Build_On_BSD 1 + #define XY_Build_On_Unix 1 #endif + + +/** + * assert() 会被 NDEBUG 关闭,但我们也没有必要强制开启它,还是留给用户定义 + */ +// #undef NDEBUG +#define xy_noop() ((void)0) + #define assert_str(a, b) assert (xy_streql ((a), (b))) -#define xy_unsupported() assert(!"Unsuppoted") -#define xy_unimplemented() assert(!"Unimplemented temporarily") -#define xy_unreached() assert(!"This code shouldn't be reached") +#define xy_panic(reason) assert(!reason) +#define xy_unsupported() xy_panic("Unsuppoted") +#define xy_unimplemented() xy_panic("Unimplemented temporarily") +#define xy_unreached() xy_panic("This code shouldn't be reached") +#define xy_cant_be_null(p) if(!p) xy_panic("This pointer can't be null") + + static void _xy_print_int (int n) {printf ("%d", n);} static void _xy_print_long (long n) {printf ("%ld", n);} @@ -120,6 +125,9 @@ static void _xy_println_bool (bool b) {printf("%s\n", (b) ? "true" : "false"); static void _xy_println_str (char *str) {printf ("%s\n", str);} static void _xy_println_const_str (const char *str) {printf ("%s\n", str);} +/** + * @flavor Ruby, Python + */ #define print(x) _Generic((x), \ int: _xy_print_int, \ long: _xy_print_long, \ @@ -129,9 +137,12 @@ static void _xy_println_const_str (const char *str) {printf ("%s\n", str);} bool: _xy_print_bool, \ char *: _xy_print_str, \ const char *: _xy_print_const_str, \ - default: assert(!"Unsupported type for print()!") \ + default: xy_panic("Unsupported type for print()!") \ )(x) +/** + * @flavor JVM family, Rust + */ #define println(x) _Generic((x), \ int: _xy_println_int, \ long: _xy_println_long, \ @@ -141,14 +152,21 @@ static void _xy_println_const_str (const char *str) {printf ("%s\n", str);} bool: _xy_println_bool, \ char *: _xy_println_str, \ const char *: _xy_println_const_str, \ - default: assert(!"Unsupported type for println()/say()!") \ + default: xy_panic("Unsupported type for println()/say()!") \ )(x) +/* @flavor Perl/Raku */ #define say println - +/* @flavor PHP */ +#define echo println +/** + * @flavor HTML + */ void br () { puts (""); } void p (const char *s) { printf ("%s\n", s); } -#define xy_arylen(x) (sizeof (x) / sizeof (x[0])) + +#define xy_c_array_len(arr) (sizeof (arr) / sizeof (arr[0])) + static inline void * xy_malloc0 (size_t size) @@ -164,7 +182,15 @@ xy_malloc0 (size_t size) ******************************************************/ /** - * 将str中所有的pat字符串替换成replace,返回一个全新的字符串 + * @brief 将 str 中所有的 pat 字符串替换成 replace,返回一个全新的字符串;也可用作删除、缩小、扩张 + * + * @flavor Ruby: String#gsub + * + * @param str 原字符串 + * @param pat 要替换的字符串 + * @param replace 替换成的字符串 + * + * @return 替换后的新字符串 */ static char * xy_str_gsub (const char *str, const char *pat, const char *replace) @@ -219,8 +245,12 @@ xy_str_gsub (const char *str, const char *pat, const char *replace) return ret; } + +/** + * @flavor 见 xy_strcat() + */ static char * -xy_2strjoin (const char *str1, const char *str2) +xy_2strcat (const char *str1, const char *str2) { size_t len = strlen (str1); size_t size = len + strlen (str2) + 1; @@ -230,8 +260,24 @@ xy_2strjoin (const char *str1, const char *str2) return ret; } + +/** + * @brief 将多个字符串连接成一个字符串 + * + * @flavor C语言存在 strcat(),然而限制比较大,我们重新实现 + + * `concat` 这个API广泛应用于包括 Ruby、JavaScript、JVM family、C# + * + * 但由于 xy_str_concat() 显著长于 xy_strcat(),而这个 API 在 chsrc 中 + * 又大量使用,所以我们选择后者这个更简短的形式 + * + * @param count 连接的字符串数量 + * @param ... 连接的字符串 + * + * @return 拼接的新字符串 + */ static char * -xy_strjoin (unsigned int count, ...) +xy_strcat (unsigned int count, ...) { size_t al_fixed = 256; char *ret = calloc (1, al_fixed); @@ -284,6 +330,14 @@ xy_strjoin (unsigned int count, ...) return ret; } + +/** + * @brief 复制一个字符串,返回复制的新字符串 + * + * @param str 要复制的字符串 + * + * @return 复制的新字符串 + */ static char * xy_strdup (const char *str) { @@ -377,6 +431,7 @@ new_str: return buf; } + static bool xy_streql (const char *str1, const char *str2) { @@ -412,18 +467,23 @@ xy_streql_ic(const char *str1, const char *str2) return true; } + static char * xy_str_to_quietcmd (const char *cmd) { char *ret = NULL; #ifdef _WIN32 - ret = xy_2strjoin (cmd, " >nul 2>nul "); + ret = xy_2strcat (cmd, " >nul 2>nul "); #else - ret = xy_2strjoin (cmd, " 1>/dev/null 2>&1 "); + ret = xy_2strcat (cmd, " 1>/dev/null 2>&1 "); #endif return ret; } + +/** + * @flavor Ruby: String#end_with? + */ static bool xy_str_end_with (const char *str, const char *suffix) { @@ -448,6 +508,9 @@ xy_str_end_with (const char *str, const char *suffix) return true; } +/** + * @flavor Ruby: String#start_with? + */ static bool xy_str_start_with (const char *str, const char *prefix) { @@ -477,6 +540,9 @@ xy_str_start_with (const char *str, const char *prefix) return true; } +/** + * @flavor Ruby: String#delete_prefix + */ static char * xy_str_delete_prefix (const char *str, const char *prefix) { @@ -490,6 +556,9 @@ xy_str_delete_prefix (const char *str, const char *prefix) return cur; } +/** + * @flavor Ruby: String#delete_suffix + */ static char * xy_str_delete_suffix (const char *str, const char *suffix) { @@ -505,6 +574,9 @@ xy_str_delete_suffix (const char *str, const char *suffix) return new; } +/** + * @flavor Ruby: String#strip + */ static char * xy_str_strip (const char *str) { @@ -556,29 +628,29 @@ _xy_log (int level, const char *prompt, const char *content) */ if (level & _XY_Log_Plain) { - str = xy_strjoin (3, prompt, ": ", content); + str = xy_strcat (3, prompt, ": ", content); } else if (level & _XY_Log_Success) { - str = xy_strjoin (3, prompt, ": ", xy_str_to_green (content)); + str = xy_strcat (3, prompt, ": ", xy_str_to_green (content)); } else if (level & _XY_Log_Info) { - str = xy_strjoin (3, prompt, ": ", xy_str_to_blue (content)); + str = xy_strcat (3, prompt, ": ", xy_str_to_blue (content)); } else if (level & _XY_Log_Warn) { - str = xy_strjoin (3, prompt, ": ", xy_str_to_yellow (content)); + str = xy_strcat (3, prompt, ": ", xy_str_to_yellow (content)); to_stderr = true; } else if (level & _XY_Log_Error) { - str = xy_strjoin (3, prompt, ": ", xy_str_to_red (content)); + str = xy_strcat (3, prompt, ": ", xy_str_to_red (content)); to_stderr = true; } else { - // xy_assert ("CAN'T REACH!"); + xy_unreached(); } if (to_stderr) @@ -594,7 +666,7 @@ _xy_log (int level, const char *prompt, const char *content) /** - * brkt 系列输出受 pip 启发,为了输出方便,使用 xy.h 的程序应该 + * @flavor brkt 系列输出受 Python 的 pip 启发,为了输出方便,使用 xy.h 的程序应该 * * 1.若想完全自定义颜色和输出位置: * @@ -612,7 +684,7 @@ _xy_log (int level, const char *prompt, const char *content) static void xy_log_brkt_to (const char *prompt, const char *content, FILE *stream) { - char *str = xy_strjoin (4, "[", prompt, "] ", content); + char *str = xy_strcat (4, "[", prompt, "] ", content); fprintf (stream, "%s\n", str); free (str); } @@ -632,12 +704,12 @@ _xy_log_brkt (int level, const char *prompt1, const char *prompt2, const char *c if (level & _XY_Log_Plain) { - str = xy_strjoin (6, "[", prompt1, " ", prompt2, "] ", content); + str = xy_strcat (6, "[", prompt1, " ", prompt2, "] ", content); } else if (level & _XY_Log_Success) { /* [app 成功] [app success] */ - str = xy_strjoin (6, + str = xy_strcat (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) @@ -645,26 +717,26 @@ _xy_log_brkt (int level, const char *prompt1, const char *prompt2, const char *c /* [app 信息] [app info] [app 提示] [app notice] */ - str = xy_strjoin (6, + str = xy_strcat (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) { /* [app 警告] [app warn] */ - str = xy_strjoin (6, + str = xy_strcat (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) { /* [app 错误] [app error] */ - str = xy_strjoin (6, + str = xy_strcat (6, "[", xy_str_to_red (prompt1), " ", xy_str_to_bold (xy_str_to_red (prompt2)), "] ", xy_str_to_red (content)); to_stderr = true; } else { - // xy_assert ("CAN'T REACH!"); + xy_unreached(); } if (to_stderr) @@ -683,20 +755,22 @@ _xy_log_brkt (int level, const char *prompt1, const char *prompt2, const char *c /****************************************************** * System ******************************************************/ + /** - * 执行cmd,返回某行输出结果,并对已经遍历过的行执行iter_func + * @brief 执行 `cmd`,返回某行输出结果,并对已经遍历过的行执行 `func` * - * @param cmd 要执行的命令 - * @param n 指定命令执行输出的结果行中的某一行,0 表示最后一行,n (n>0) 表示第n行 - * 该函数会返回这一行的内容 - * @param iter_func 对遍历时经过的行的内容,进行函数调用 + * @param cmd 要执行的命令 + * @param n 指定命令执行输出的结果行中的某一行,0 表示最后一行,n (n>0) 表示第n行 + * @param func 对遍历时经过的行的内容,进行函数调用 + * + * @return 返回第 `n` 行的内容 * * @note 返回的字符串最后面一般有换行符号 * - * 由于目标行会被返回出来,所以 iter_func() 并不执行目标行,只会执行遍历过的行 + * 由于目标行会被返回出来,所以 `func` 并不执行目标行,只会执行遍历过的行 */ static char * -xy_run_iter (const char *cmd, unsigned long n, bool (*iter_func) (const char *)) +xy_run_iter_lines (const char *cmd, unsigned long n, bool (*func) (const char *)) { const int size = 512; char *buf = (char *) malloc (size); @@ -720,9 +794,9 @@ xy_run_iter (const char *cmd, unsigned long n, bool (*iter_func) (const char * count += 1; if (n == count) break; - if (iter_func) + if (func) { - if (iter_func (buf)) { + if (func (buf)) { pclose (stream); return ret; } @@ -736,10 +810,48 @@ xy_run_iter (const char *cmd, unsigned long n, bool (*iter_func) (const char * static char * xy_run (const char *cmd, unsigned long n) { - return xy_run_iter (cmd, n, NULL); + return xy_run_iter_lines (cmd, n, NULL); } +/** + * @brief 捕获命令的输出 + * + * @param[in] cmd 要执行的命令 + * @param[out] output 捕获的标准输出 + * + * @return 返回命令的执行状态 + */ +static int +xy_run_capture (const char *cmd, char **output) +{ + int cap = 8192; /* 假如1行100个字符,大约支持80行输出 */ + char *buf = (char *) xy_malloc0 (cap); + + FILE *stream = popen (cmd, "r"); + if (stream == NULL) + { + fprintf (stderr, "xy: 命令执行失败\n"); + return -1; + } + + int size = 0; + size_t n; + while ((n = fread (buf + size, 1, cap - size, stream)) > 0) { + size += n; + if (size == cap) + { + cap *= 2; + char *new_buf = realloc (buf, cap); + buf = new_buf; + } + } + buf[size] = '\0'; + + int status = pclose (stream); + *output = buf; + return status; +} /****************************************************** @@ -747,7 +859,7 @@ xy_run (const char *cmd, unsigned long n) ******************************************************/ /** - * 该函数同 just 中的 os_family(),只区分 windows, unix + * @flavor 该函数同 just 中的 os_family(),只区分 windows, unix * * @return 返回 "windows" 或 "unix" */ @@ -763,7 +875,7 @@ _xy_os_family () /** - * 该函数返回所在 os family 的对应字符串 + * @brief 该函数返回所在 os family 的对应字符串 */ static const char * xy_os_depend_str (const char *str_for_win, const char *str_for_unix) @@ -775,6 +887,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 () static char * _xy_os_home () @@ -787,21 +905,70 @@ _xy_os_home () return home; } + +/** + * @brief 返回 Windows 上的 Documents 目录 + * + * @note 警告,不可使用 HOME 目录直接拼接,若用户移动了 Documents,将导致错误 + * @warning 非 Windows 返回 NULL + */ +static char * +_xy_win_documents () +{ +#ifdef XY_Build_On_Windows + char documents_path[MAX_PATH]; + HRESULT result = SHGetFolderPathA (NULL, CSIDL_MYDOCUMENTS, NULL, + SHGFP_TYPE_CURRENT, documents_path); + + if (SUCCEEDED (result)) + return xy_strdup (documents_path); + + return xy_2strcat (xy_os_home, "\\Documents"); +#else + return NULL; +#endif +} + #define xy_win_powershell_profile _xy_win_powershell_profile () #define xy_win_powershellv5_profile _xy_win_powershellv5_profile () + +/** + * @brief 返回 Windows 上 pwsh (>=v5) 的配置文件路径 + * + * @warning 非 Windows 返回 NULL + */ static char * _xy_win_powershell_profile () { - return xy_2strjoin ( - xy_os_home, "\\Documents\\PowerShell\\Microsoft.PowerShell_profile.ps1"); + if (xy_on_windows) + { + char *documents_dir = _xy_win_documents (); + char *profile_path = xy_2strcat (documents_dir, "\\PowerShell\\Microsoft.PowerShell_profile.ps1"); + free (documents_dir); + return profile_path; + } + else + return NULL; } -char * + +/** + * @brief 返回 Windows 上自带的 powershell (v5) 的配置文件路径 + * + * @warning 非 Windows 返回 NULL + */ +static char * _xy_win_powershellv5_profile () { - return xy_2strjoin ( - xy_os_home, - "\\Documents\\WindowsPowerShell\\Microsoft.PowerShell_profile.ps1"); + if (xy_on_windows) + { + char *documents_dir = _xy_win_documents (); + char *profile_path = xy_2strcat (documents_dir, "\\WindowsPowerShell\\Microsoft.PowerShell_profile.ps1"); + free (documents_dir); + return profile_path; + } + else + return NULL; } #define xy_zshrc "~/.zshrc" @@ -817,15 +984,15 @@ xy_file_exist (const char *path) const char *new_path = path; if (xy_str_start_with (path, "~")) { - new_path = xy_2strjoin (xy_os_home, path + 1); + new_path = xy_2strcat (xy_os_home, path + 1); } // 0 即 F_OK return (0==access (new_path, 0)) ? true : false; } /** - * @note xy_file_exist() 和 xy_dir_exist() 两个函数在所有平台默认都支持使用 '~', - * 但实现中都没有调用 xy_normalize_path(),以防万一,调用前可能需要用户手动调用它 + * @note `xy_file_exist()` 和 `xy_dir_exist()` 两个函数在所有平台默认都支持使用 '~', + * 但实现中都没有调用 `xy_normalize_path()`,以防万一,调用前可能需要用户手动调用它 */ static bool xy_dir_exist (const char *path) @@ -835,13 +1002,13 @@ xy_dir_exist (const char *path) { if (xy_str_start_with (path, "~")) { - dir = xy_2strjoin (xy_os_home, path + 1); + dir = xy_2strcat (xy_os_home, path + 1); } } if (xy_on_windows) { -#ifdef XY_On_Windows +#ifdef XY_Build_On_Windows // 也可以用 opendir() #include DWORD attr = GetFileAttributesA (dir); @@ -862,72 +1029,498 @@ xy_dir_exist (const char *path) } else { - int status = system (xy_2strjoin ("test -d ", dir)); + int status = system (xy_2strcat ("test -d ", dir)); if (0==status) return true; else return false; } + + return false; } /** - * 1. 删除路径左右两边多出来的空白符 - * 2. 将 ~/ 转换为绝对路径 + * @brief 规范化路径 + * + * @details + * 1. 删除路径左右两边多出来的空白符 + * - 防止通过间接方式得到的路径包含了空白字符 (如 grep 出来的结果) + * - 防止维护者多写了空白字符 + * 2. 将 ~ 转换为绝对路径 + * 3. 在Windows上,使用标准的 \ 作为路径分隔符 */ static char * xy_normalize_path (const char *path) { - char *new = xy_str_strip (path); // 防止开发者多写了空白符 + char *new = xy_str_strip (path); + + if (xy_str_start_with (new, "~")) + { + new = xy_2strcat (xy_os_home, xy_str_delete_prefix (new, "~")); + } if (xy_on_windows) - { - if (xy_str_start_with (new, "~/")) - { - // 或 %USERPROFILE% - new = xy_strjoin (3, xy_os_home, "\\", - xy_str_delete_prefix (new, "~/")); - } - new = xy_str_gsub (new, "/", "\\"); - } + return xy_str_gsub (new, "/", "\\"); else - { - if (xy_str_start_with (new, "~/")) - { - new = xy_strjoin (3, xy_os_home, "/", - xy_str_delete_prefix (new, "~/")); - } - } - - return new; + return new; } + +/** + * @brief 返回一个路径的父目录名 + * + * @note + * - 返回的是真正的 "目录名" (就像文件名一样),而不是 "路径",所以一定是不含末尾斜杠的 + * - 在Windows上,使用标准的 \ 作为路径分隔符 + */ static char * xy_parent_dir (const char *path) { char *dir = xy_normalize_path (path); + + /* 不管是否为Windows,全部统一使用 / 作为路径分隔符,方便后续处理 */ + dir = xy_str_gsub (dir, "\\", "/"); + + if (xy_str_end_with (dir, "/")) + dir = xy_str_delete_suffix (dir, "/"); + char *last = NULL; - if (xy_on_windows) + + last = strrchr (dir, '/'); + if (!last) { - last = strrchr (dir, '\\'); - if (!last) + /* 路径中没有一个 / 是很奇怪的,我们直接返回 . 作为当前目录 */ + return "."; + } + *last = '\0'; + + /* Windows上重新使用 \ 作为路径分隔符 */ + if (xy_on_windows) + return xy_str_gsub (dir, "/", "\\"); + else + return dir; +} + + + +void +xy_detect_os () +{ + // C: + char *drive = getenv ("SystemDrive"); + if (drive) + { + char path[256]; + snprintf (path, sizeof (path), "%s\\Users", drive); + DIR *d = opendir (path); + if (d) { - /* current dir */ - return "."; + xy_on_windows = true; + closedir (d); + return; + } + } + + FILE *fp = fopen ("/proc/version", "r"); + if (fp) + { + char buf[256] = {0}; + fread (buf, 1, sizeof(buf) - 1, fp); + fclose (fp); + if (strstr (buf, "Android")) + { + xy_on_android = true; + return; + } + else if (strstr (buf, "Linux")) + { + xy_on_linux = true; + return; + } + } + + /* 判断 macOS */ + DIR *d = opendir ("/System/Applications"); + if (d) + { + closedir (d); + d = opendir ("/Library/Apple"); + if (d) + { + xy_on_macos = true; + closedir (d); + } + } + + /* 最后判断 BSD */ + fp = popen ("uname -s", "r"); + if (!fp) + { + if (opendir ("/etc/rc.d")) + { + closedir (d); + xy_on_bsd = true; + return; } - *last = '\0'; } else { - last = strrchr (dir, '/'); - if (!last) - { - /* current dir */ - return "."; - } - *last = '\0'; + char buf[256]; + fgets (buf, sizeof (buf), fp); + pclose (fp); + if (strstr (buf, "BSD") != NULL) + xy_on_bsd = true; + } + + if (!(xy_on_windows || xy_on_linux || xy_on_android || xy_on_macos || xy_on_bsd)) + xy_panic ("Unknown operating system"); +} + + +void +xy_use_utf8 () +{ +#ifdef XY_Build_On_Windows + SetConsoleOutputCP (65001); +#endif +} + + +/** + * @note 该函数必须被首先调用,方能使用各个跨操作系统的函数 + */ +void +xy_init () +{ + xy_detect_os (); + + if (xy_on_windows) + xy_os_devnull = "nul"; + else + xy_os_devnull = "/dev/null"; + + xy_use_utf8 (); +} + + +/****************************************************** + * Container + ******************************************************/ +typedef struct XySeqItem_t +{ + struct XySeqItem_t *prev; + struct XySeqItem_t *next; + + void *data; +} +XySeqItem_t; + +typedef struct XySeq_t +{ + XySeqItem_t *first_item; + XySeqItem_t *last_item; + + uint32_t length; +} +XySeq_t; + + +XySeq_t* +xy_seq_new (void) +{ + XySeq_t *seq = xy_malloc0 (sizeof (XySeq_t)); + if (!seq) return NULL; + + seq->first_item = NULL; + seq->last_item = NULL; + seq->length = 0; + + return seq; +} + +/** + * @flavor Python: len() + */ +uint32_t +xy_seq_len (XySeq_t *seq) +{ + xy_cant_be_null (seq); + return seq->length; +} + +/** + * @flavor Ruby: Enumerable#first + */ +void * +xy_seq_first (XySeq_t *seq) +{ + xy_cant_be_null (seq); + return seq->first_item ? seq->first_item->data : NULL; +} + +/** + * @flavor Ruby: Enumerable#last + */ +void * +xy_seq_last (XySeq_t *seq) +{ + xy_cant_be_null (seq); + return seq->last_item ? seq->last_item->data : NULL; +} + +/** + * @flavor Ruby: Array#at + * + * @note 序号从1开始 + * + * @return 如果seq中并没有第n个数据,则返回NULL + */ +void * +xy_seq_at (XySeq_t *seq, int n) +{ + xy_cant_be_null (seq); + + if (0 == n) xy_panic ("The index must begin from 1, not 0"); + + if (1 == n) return seq->first_item ? seq->first_item->data : NULL; + + XySeqItem_t *it = seq->first_item; + for (uint32_t i = 1; i < n && it; i++) + { + it = it->next; + } + return it ? it->data : NULL; +} + + +/** + * @flavor Perl: push + */ +void +xy_seq_push (XySeq_t *seq, void *data) +{ + xy_cant_be_null (seq); + + XySeqItem_t *it = xy_malloc0 (sizeof (XySeqItem_t));; + + it->data = data; + it->prev = NULL; + it->next = NULL; + + // 更新 item 间关系 + XySeqItem_t *l = seq->last_item; + if (l) + { + it->prev = l; + l->next = it; + } + + // 更新 seq 信息 + seq->last_item = it; + if (0==seq->length) + seq->first_item = it; + + seq->length++; +} + + +/** + * @flavor Perl: pop + */ +void * +xy_seq_pop (XySeq_t *seq) +{ + xy_cant_be_null (seq); + + if (0==seq->length) return NULL; + + // 更新 item 间关系 + XySeqItem_t *l = seq->last_item; + XySeqItem_t *p = l->prev; + // 考虑 seq 当前只有1项的情况 + if (p) p->next = NULL; + l->prev = NULL; + + // 更新 seq 信息 + seq->last_item = p; + // 考虑 seq 当前只有1项的情况 + if (!p) seq->first_item = NULL; + seq->length--; + + void *data = l->data; + free (l); + return data; +} + + +/** + * @flavor Ruby: Array#each + */ +void +xy_seq_each (XySeq_t *seq, void (*func) (void *, void *), void *user_data) +{ + xy_cant_be_null (seq); + xy_cant_be_null (func); + + for (XySeqItem_t *it = seq->first_item; it; it = it->next) + { + func (it->data, user_data); + } +} + +/** + * @flavor Ruby: Enumerable#find + */ +void * +xy_seq_find (XySeq_t *seq, bool (*func) (void *, void *), void *user_data) +{ + xy_cant_be_null (seq); + xy_cant_be_null (func); + + for (XySeqItem_t *it = seq->first_item; it; it = it->next) + { + if (func (it->data, user_data)) + { + return it->data; + } + } + return NULL; +} + + + +#define _XY_Map_Buckets_Count 97 + +struct _XyHashBucket_t +{ + struct _XyHashBucket_t *next; + char *key; + void *value; +}; + +typedef struct XyMap_t +{ + struct _XyHashBucket_t **buckets; + + uint32_t length; +} +XyMap_t; + + +XyMap_t * +xy_map_new () +{ + XyMap_t *map = xy_malloc0 (sizeof (XyMap_t)); + map->buckets = xy_malloc0 (sizeof (struct _XyHashBucket_t *) * _XY_Map_Buckets_Count); + + map->length = 0; + + return map; +} + + +uint32_t +xy_map_len (XyMap_t *map) +{ + xy_cant_be_null (map); + return map->length; +} + + +unsigned long +xy_hash (const char* str) +{ + unsigned long h = 5381; + int c; + while ((c = *str++)) + h = ((h << 5) + h) + c; /* h * 33 + c */ + return h; +} + + +/** + * @flavor JavaScript: map.set + */ +void +xy_map_set (XyMap_t *map, const char *key, void *value) +{ + xy_cant_be_null (map); + xy_cant_be_null (key); + + unsigned long hash = xy_hash (key); + uint32_t index = hash % _XY_Map_Buckets_Count; + + // 若 key 已经存在 + struct _XyHashBucket_t *maybe = map->buckets[index]; + while (maybe) + { + if (xy_streql (maybe->key, key)) + { + maybe->value = value; + return; + } + maybe = maybe->next; + } + + // 若 key 不存在 + struct _XyHashBucket_t *bucket = xy_malloc0 (sizeof (struct _XyHashBucket_t)); + + bucket->key = xy_strdup (key); + bucket->value = value; + bucket->next = map->buckets[index]; + map->buckets[index] = bucket; + + map->length++; +} + + +/** + * @flavor JavaScript: map.get + */ +void * +xy_map_get (XyMap_t *map, const char *key) +{ + xy_cant_be_null (map); + xy_cant_be_null (key); + + unsigned long hash = xy_hash (key); + uint32_t index = hash % _XY_Map_Buckets_Count; + + struct _XyHashBucket_t *maybe = map->buckets[index]; + while (maybe) + { + if (xy_streql (maybe->key, key)) + { + return maybe->value; + } + maybe = maybe->next; + } + + return NULL; +} + +/** + * @flavor Ruby: Hash#each + */ +void +xy_map_each ( + XyMap_t *map, + void (*func) (const char *key, void *value, void *user_data), + void *user_data) +{ + xy_cant_be_null (map); + xy_cant_be_null (func); + + for (uint32_t i = 0; i < _XY_Map_Buckets_Count; i++) + { + struct _XyHashBucket_t *bucket = map->buckets[i]; + while (bucket) + { + func (bucket->key, bucket->value, user_data); + bucket = bucket->next; + } } - return dir; } #endif \ No newline at end of file diff --git a/src/chsrc-main.c b/src/chsrc-main.c index f6ed771..86a05d7 100644 --- a/src/chsrc-main.c +++ b/src/chsrc-main.c @@ -1,145 +1,89 @@ /** ------------------------------------------------------------ - * Copyright © 2023-2025 Aoran Zeng, Heng Guo + * Copyright © 2023-2025 曾奥然, 郭恒 * SPDX-License-Identifier: GPL-3.0-or-later * ------------------------------------------------------------- - * Project Name : chsrc - * Project Authors : Aoran Zeng - * | Heng Guo <2085471348@qq.com> - * Contributors : Aaron Ruan - * | Rui Chen - * | Shengwei Chen <414685209@qq.com> - * | BlockLune - * | Mr. Will - * | Terrasse - * | Lontten - * | happy game - * | Word2VecT - * | xuan - * | GnixAij - * | ChatGPT - * | czyt - * | zouri - * | yongxiang <1926885268@qq.com> - * | YU-7 <2747046473@qq.com> - * | juzeon - * | Jialin Lyu - * | GitHub Copilot - * | ccy - * | MadDogOwner - * | sanchuanhehe - * | Mikachu2333 - * | Rui Yang - * | BingChunMoLi - * | - * Created On : <2023-08-28> - * Last Modified : See * - * chsrc: Change Source —— 全平台通用命令行换源工具 + * chsrc: Change Source + * + * 全平台通用换源工具与框架 + * + * Change Source everywhere for every software + * + * 项目创建者: 曾奥然, 郭恒 + * ------------------------------------------------------------- + * + * 这是一个高度依靠贡献者的项目,我们直接把每一位贡献者写进了代码 + * 里,这是比 Git commit message 更加稳定的方式。但我们不满足于仅 + * 把大家写在注释里,因为C语言在编译时会无情地把这些信息抹去。 + * + * 所以,我们让每一位贡献者直接参与运行时! + * + * 想象一下,每一位贡献者都化作一串比特,穿梭于全国各地的桌面PC中, + * 流淌在数据中心的机房,分身在手机、路由器、小型嵌入式设备中... + * 每当 chsrc 执行一次 recipe 相关的操作,这些比特便会复苏,贡献者 + * 的信息随之浮现。它提醒着使用者:在你与开源世界的每一次交互背后, + * 都是许多人的协作,跨越省份与疆域,以代码相连。 + * + * 我们希望营造像 Richard Stallman 在创建 GNU 项目之前,在 MIT 时 + * 那样的氛围 —— 写自己用得上的软件,与大家一起开发、维护,简单纯 + * 粹,无关商业利益。就像小区、校园自发组建的足球篮球队,从一次偶 + * 然的加入,逐渐成长为互相支持的伙伴。 * ------------------------------------------------------------*/ -#define Chsrc_Version "0.2.2.3" -#define Chsrc_Release_Date "2025/08/11" +#define Chsrc_Version "0.2.2.3-dev6" +#define Chsrc_Release_Date "2025/08/22" #define Chsrc_Maintain_URL "https://github.com/RubyMetric/chsrc" #define Chsrc_Maintain_URL2 "https://gitee.com/RubyMetric/chsrc" #include "framework/core.c" #include "framework/chef.c" +void +chsrc_register_contributors () +{ + /* 项目创建者 */ + chef_register_contributor ("@ccmywish", "曾奥然", "ccmywish@qq.com", NULL); + // 该 ID 为 Gitee ID + chef_register_contributor ("@G_I_Y", "郭恒", "2085471348@qq.com", NULL); -#include "recipe/lang/rawstr4c.h" - -#include "recipe/lang/Ruby/Ruby.c" -#include "recipe/lang/Python/common.h" - #include "recipe/lang/Python/pip.c" - #include "recipe/lang/Python/Poetry.c" - #include "recipe/lang/Python/PDM.c" - #include "recipe/lang/Python/Rye.c" - #include "recipe/lang/Python/uv.c" -#include "recipe/lang/Python/Python.c" - -#include "recipe/lang/JavaScript/common.h" - #include "recipe/lang/JavaScript/npm.c" - #include "recipe/lang/JavaScript/pnpm.c" - #include "recipe/lang/JavaScript/Yarn.c" -#include "recipe/lang/JavaScript/JavaScript.c" -#include "recipe/lang/JavaScript/Bun.c" -#include "recipe/lang/JavaScript/nvm.c" - -#include "recipe/lang/Perl.c" -#include "recipe/lang/PHP.c" -#include "recipe/lang/Lua.c" -#include "recipe/lang/Go.c" -#include "recipe/lang/Java.c" - -#include "recipe/lang/Rust/common.h" - #include "recipe/lang/Rust/rustup.c" - #include "recipe/lang/Rust/Cargo.c" - -#include "recipe/lang/Dart/common.h" -#include "recipe/lang/Dart/Pub.c" -#include "recipe/lang/Dart/Flutter.c" - -#include "recipe/lang/Haskell.c" -#include "recipe/lang/OCaml.c" -#include "recipe/lang/R.c" -#include "recipe/lang/Julia.c" -#include "recipe/lang/NuGet.c" -#include "recipe/lang/Clojure.c" - - -#include "recipe/os/rawstr4c.h" -#include "recipe/os/APT/common.h" -// Debian-based -#include "recipe/os/APT/Debian.c" -#include "recipe/os/APT/Ubuntu.c" -#include "recipe/os/APT/Kali-Linux.c" -#include "recipe/os/APT/Raspberry-Pi-OS.c" -// Ubuntu-based -#include "recipe/os/APT/Linux-Mint.c" -#include "recipe/os/APT/Trisquel.c" -#include "recipe/os/APT/Linux-Lite.c" -// Debian-based and Ubuntu-based -#include "recipe/os/APT/Armbian.c" -// Independent -#include "recipe/os/APT/ROS.c" -#include "recipe/os/APT/Termux.c" -#include "recipe/os/APT/openKylin.c" -#include "recipe/os/APT/deepin.c" - -#include "recipe/os/YUM/common.h" -#include "recipe/os/YUM/Fedora-Linux.c" -#include "recipe/os/YUM/AlmaLinux.c" -#include "recipe/os/YUM/Rocky-Linux.c" -#include "recipe/os/YUM/openEuler.c" -#include "recipe/os/YUM/Anolis-OS.c" - -#include "recipe/os/pacman/Arch-Linux.c" -#include "recipe/os/pacman/Manjaro-Linux.c" -#include "recipe/os/pacman/MSYS2.c" - -#include "recipe/os/openSUSE.c" -#include "recipe/os/Alpine-Linux.c" -#include "recipe/os/Gentoo-Linux.c" -#include "recipe/os/Void-Linux.c" -#include "recipe/os/Solus.c" -#include "recipe/os/OpenWrt.c" - -#include "recipe/os/BSD/FreeBSD.c" -#include "recipe/os/BSD/NetBSD.c" -#include "recipe/os/BSD/OpenBSD.c" - - -#include "recipe/ware/TeX-Live.c" -#include "recipe/ware/Emacs.c" -#include "recipe/ware/WinGet.c" -#include "recipe/ware/Homebrew/Homebrew.c" -#include "recipe/ware/CocoaPods.c" -#include "recipe/ware/Nix.c" -#include "recipe/ware/Guix.c" -#include "recipe/ware/Flatpak.c" -#include "recipe/ware/Docker/Docker.c" -#include "recipe/ware/Anaconda/Anaconda.c" + /* 所有贡献者 (按参与贡献时间排序) */ + chef_register_contributor ("@Aaron-212", "Aaron Ruan", "aaron212cn@outlook.com", NULL); + chef_register_contributor ("@chenrui333", "Rui Chen", "rui@chenrui.dev", NULL); + chef_register_contributor ("@livelycode36", "Shengwei Chen", "414685209@qq.com", NULL); + chef_register_contributor ("@Gn3po4g", "Peng Gao", "gn3po4g@outlook.com", NULL); + chef_register_contributor ("@BlockLune", "BlockLune", "blocklune@gmail.com", NULL); + chef_register_contributor ("@MrWillCom", "Mr. Will", "mr.will.com@outlook.com", NULL); + chef_register_contributor ("@Jerry-Terrasse", "Terrasse", "terrasse@qq.com", NULL); + chef_register_contributor ("@lontten", "Lontten", "lontten@163.com", NULL); + chef_register_contributor ("@happy-game", "Happy Game", "happygame1024@gmail.com", NULL); + chef_register_contributor ("@Word2VecT", "Word2VecT", "tangzinan@bupt.edu.cn", NULL); + chef_register_contributor ("@wickdynex", "Xuan", "wick.dynex@qq.com", NULL); + chef_register_contributor ("@Efterklang", "GnixAij", "gaojiaxing0220@gmail.com", NULL); + chef_register_contributor ("@czyt", "czyt", "czyt.go@gmail.com", NULL); + chef_register_contributor ("@XUANJI233", "XUANJI233", "xuanji233@outlook.com", NULL); + chef_register_contributor ("@Yangmoooo", "Yangmoooo", "yangmoooo@outlook.com", NULL); + chef_register_contributor ("@zouri", "Zouri", "guoshuaisun@outlook.com", NULL); + chef_register_contributor ("@xyx1926885268", "Yongxiang", "1926885268@qq.com", NULL); + chef_register_contributor ("@YU-7", "YU-7", "2747046473@qq.com", NULL); + chef_register_contributor ("@juzeon", "juzeon", "skyjuzheng@gmail.com", NULL); + chef_register_contributor ("@jialinlvcn", "Jialin Lyu", "jialinlvcn@aliyun.com", NULL); + chef_register_contributor ("@Kattos", "ccy", "icuichengyi@gmail.com", NULL); + chef_register_contributor ("@xrgzs", "MadDogOwner", "xiaoran@xrgzs.top", NULL); + chef_register_contributor ("@sanchuanhehe", "sanchuanhehe", "wyihe5520@gmail.com", NULL); + chef_register_contributor ("@Mikachu2333", "Mikachu2333", "mikachu.23333@zohomail.com", NULL); + chef_register_contributor ("@techoc", "Rui Yang", "techoc@foxmail.com", NULL); + chef_register_contributor ("@BingChunMoLi", "BingChunMoLi", "bingchunmoli@bingchunmoli.com", NULL); + // 该 ID 为 Gitee ID + chef_register_contributor ("@hezonglun", "HeZongLun", "hezonglun123456@outlook.com", NULL); + /** + * AI贡献者: + * + * ChatGPT、GitHub Copilot、DeepSeek + * + * 这几位是贡献者显式说明的,也许还有隐式使用的一些AI并没有被记录下来,可以添加在这里 + */ +} #include "recipe/menu.c" @@ -152,7 +96,7 @@ cli_print_available_mirrors () { { char *msg = ENGLISH ? "To specify a source, use chsrc set " : "指定使用某源,请使用 chsrc set "; - say (bdblue(xy_strjoin (3, msg, "", " \n"))); + say (bdblue(xy_strcat (3, msg, "", " \n"))); } { @@ -169,7 +113,7 @@ cli_print_available_mirrors () say ("--------- -------------- ------------------------------------- ---------------------"); } - for (int i = 0; i < xy_arylen (chsrc_available_mirrors); i++) + for (int i = 0; i < xy_c_array_len (chsrc_available_mirrors); i++) { MirrorSite_t *mir = chsrc_available_mirrors[i]; printf ("%-14s%-18s%-41s ", mir->code, mir->abbr, mir->site); say (mir->name); @@ -178,12 +122,13 @@ cli_print_available_mirrors () /** - * 遍历以 / 为分隔符的别名字符串,对每个别名调用回调函数 + * @brief 遍历以 / 为分隔符的别名字符串,对每个别名调用回调函数 * - * @param aliases 空格分隔的 alias 字符串 - * @param callback 对每个 alias 调用的回调函数 - * @param user_data 传递给回调函数的用户数据 - * @return 如果回调函数返回true则停止遍历并返回true,否则返回false + * @param aliases 空格分隔的 alias 字符串 + * @param callback 对每个 alias 调用的回调函数 + * @param user_data 传递给回调函数的用户数据 + * + * @return 如果回调函数返回true则停止遍历并返回true,否则返回false */ bool iterate_aliases (const char *aliases, bool (*callback)(const char *alias, void *user_data), void *user_data) @@ -219,27 +164,28 @@ iterate_aliases (const char *aliases, bool (*callback)(const char *alias, void * /** - * 用于 cli_print_supported_targets_ 的回调函数,打印每个别名 + * 用于 cli_print_targets_for_menu 的回调函数,打印每个别名 */ bool -print_alias_callback (const char *alias, void *user_data) +callback_print_alias (const char *alias, void *user_data) { printf ("%s ", alias); return false; // 继续遍历,不停止 } void -cli_print_supported_targets_ (TargetRegisterInfo_t menu[], size_t size) +callback_print_targets (void *data, void *NOUSE) { - for (int i = 0; i < size; i++) - { - TargetRegisterInfo_t *entry = &menu[i]; + Target_t *target = (Target_t *) data; + // 使用通用的别名遍历函数打印所有别名 + iterate_aliases (target->aliases, callback_print_alias, NULL); + br(); // 每个target换行 +} - // 使用通用的别名遍历函数打印所有别名 - iterate_aliases (entry->target->aliases, print_alias_callback, NULL); - - br(); // 每个target换行 - } +void +cli_print_targets_for_menu (XySeq_t *menu) +{ + xy_seq_each (menu, callback_print_targets, NULL); br(); // 最后额外换行 } @@ -256,50 +202,51 @@ cli_print_supported_targets () char *msg = ENGLISH ? "Programming Languages" : "编程语言"; say (bdgreen(msg)); say ("-------------------------"); - cli_print_supported_targets_ (chsrc_pl_menu, xy_arylen(chsrc_pl_menu)); + cli_print_targets_for_menu (ProgStore.pl); } { char *msg = ENGLISH ? "Operating Systems" : "操作系统"; say (bdgreen(msg)); say ("-------------------------"); - cli_print_supported_targets_ (chsrc_os_menu, xy_arylen(chsrc_os_menu)); + cli_print_targets_for_menu (ProgStore.os); } { char *msg = ENGLISH ? "Softwares" : "软件"; say (bdgreen(msg)); say ("-------------------------"); - cli_print_supported_targets_ (chsrc_wr_menu, xy_arylen(chsrc_wr_menu)); + cli_print_targets_for_menu (ProgStore.wr); } } void -cli_print_supported_pl () +cli_print_menu (char *menu) { - char *msg = ENGLISH ? "Support following Programming Languages (same line indicates these targets are compatible)\n" - : "支持对以下编程语言生态换源 (同一行表示这几个目标兼容)\n"; - say (bdgreen(msg)); - - cli_print_supported_targets_ (chsrc_pl_menu, xy_arylen(chsrc_pl_menu)); -} - -void -cli_print_supported_os () -{ - char *msg = ENGLISH ? "Support following Operating Systems (same line indicates these targets are compatible)\n" - : "支持对以下操作系统换源 (同一行表示这几个目标兼容)\n"; - say (bdgreen(msg)); - cli_print_supported_targets_ (chsrc_os_menu, xy_arylen(chsrc_os_menu)); -} - -void -cli_print_supported_wr () -{ - char *msg = ENGLISH ? "Support following Softwares (same line indicates these targets are compatible)\n" - : "支持对以下软件换源 (同一行表示这几个目标兼容)\n"; - say (bdgreen(msg)); - cli_print_supported_targets_ (chsrc_wr_menu, xy_arylen(chsrc_wr_menu)); + if (xy_streql (menu, "pl")) + { + char *msg = + ENGLISH ? "Support following Programming Languages (same line indicates these targets are compatible)\n" + : "支持对以下编程语言生态换源 (同一行表示这几个目标兼容)\n"; + say (bdgreen(msg)); + cli_print_targets_for_menu (ProgStore.pl); + } + else if (xy_streql (menu, "os")) + { + char *msg = + ENGLISH ? "Support following Operating Systems (same line indicates these targets are compatible)\n" + : "支持对以下操作系统换源 (同一行表示这几个目标兼容)\n"; + say (bdgreen(msg)); + cli_print_targets_for_menu (ProgStore.os); + } + else if (xy_streql (menu, "wr")) + { + char *msg = + ENGLISH ? "Support following Softwares (same line indicates these targets are compatible)\n" + : "支持对以下软件换源 (同一行表示这几个目标兼容)\n"; + say (bdgreen(msg)); + cli_print_targets_for_menu (ProgStore.wr); + } } @@ -334,28 +281,28 @@ cli_print_target_features (Target_t *target, const char *input_target_name) { char *msg = ENGLISH ? " Get: View the current source state " : " Get: 查看当前源状态 "; - char *get_msg = xy_strjoin (3, msg, "| chsrc get ", input_target_name); + char *get_msg = xy_strcat (3, msg, "| chsrc get ", input_target_name); if (target->getfn != NULL) printf (" %s%s\n", bdgreen(YesMark), purple(get_msg)); else printf (" %s%s\n", bdred(NoMark), get_msg);br(); } { char *msg = ENGLISH ? " Reset: Reset to the default source " : " Reset: 重置回默认源 "; - char *reset_msg = xy_strjoin (3, msg, "| chsrc reset ", input_target_name); + char *reset_msg = xy_strcat (3, msg, "| chsrc reset ", input_target_name); if (target->resetfn != NULL) printf (" %s%s\n", bdgreen(YesMark), purple(reset_msg)); else printf (" %s%s\n", bdred(NoMark), reset_msg);br(); } { - char *msg = ENGLISH ? " UserDefine: using user-defined source URL " : " UserDefine: 用户自定义换源URL "; - char *user_define_msg = xy_strjoin (5, msg, "| chsrc set ", input_target_name, " https://user-define-url.org/", input_target_name); + char *msg = ENGLISH ? " UserDefine: using user-defined source link " : " UserDefine: 用户自定义换源链接 "; + char *user_define_msg = xy_strcat (5, msg, "| chsrc set ", input_target_name, " https://user-define-url.org/", input_target_name); if (target->can_user_define) printf (" %s%s\n", bdgreen(YesMark), purple(user_define_msg)); else printf (" %s%s\n", bdred(NoMark), user_define_msg);br(); } { char *msg = ENGLISH ? " Locally: Change source only for this project " : " Locally: 仅对本项目换源 "; - char *locally_msg = xy_strjoin (3, msg, "| chsrc set -local ", input_target_name); + char *locally_msg = xy_strcat (3, msg, "| chsrc set -local ", input_target_name); switch (target->cap_local) { @@ -376,7 +323,7 @@ cli_print_target_features (Target_t *target, const char *input_target_name) { char *msg = ENGLISH ? " English: Output in English " : " English: 英文输出 "; - char *english_msg = xy_strjoin (3, msg, "| chsrc set -en ", input_target_name); + char *english_msg = xy_strcat (3, msg, "| chsrc set -en ", input_target_name); if (target->can_english) printf (" %s%s\n", bdgreen(YesMark), purple(english_msg)); else printf (" %s%s\n", bdred(NoMark), english_msg);br(); } @@ -384,7 +331,7 @@ cli_print_target_features (Target_t *target, const char *input_target_name) if (target->note) { char *msg = ENGLISH ? "NOTE: " : "备注: "; - printf ("%s%s\n", bdyellow (msg), bdyellow (target->note)); + printf ("%s%s\n\n", bdyellow (msg), bdyellow (target->note)); } } @@ -392,29 +339,14 @@ cli_print_target_features (Target_t *target, const char *input_target_name) void cli_print_target_maintain_info (Target_t *target, const char *input_target_name) { - if (target->authors && target->authors_n > 0) - { - char *msg = ENGLISH ? "Recipe Original Authors: " : "食谱原始作者: "; - printf ("%s", bdblue(msg)); - for (size_t i = 0; i < target->authors_n; i++) - { - if (i > 0) printf (", "); - printf ("%s <%s>", - target->authors[i].name ? target->authors[i].name : "Unknown", - target->authors[i].email ? target->authors[i].email : "unknown@example.com"); - } - printf ("\n"); - } - if (target->created_on) { char *msg = ENGLISH ? "Recipe Created On: " : "食谱创建时间: "; printf ("%s%s\n", bdblue(msg), target->created_on); } - { - char *msg = ENGLISH ? "Current Chef: " : "当前主厨: "; + char *msg = ENGLISH ? "Current Chef: " : "品控: "; if (target->chef) { printf ("%s%s <%s>\n", bdblue(msg), @@ -423,14 +355,14 @@ cli_print_target_maintain_info (Target_t *target, const char *input_target_name) } else { - char *msg1 = CHINESE ? "暂空缺, 欢迎担任!" : "Vacant, Welcome to hold the position"; + char *msg1 = CHINESE ? "该 recipe 的负责人暂空缺, 欢迎担任" : "Vacant, Welcome to hold the position"; printf ("%s%s\n", bdblue(msg), bdgreen(msg1)); } } { - char *msg = ENGLISH ? "Current Cooks: " : "当前副厨: "; + char *msg = ENGLISH ? "Cooks: " : "掌勺: "; if (target->cooks && target->cooks_n > 0) { printf ("%s", bdblue(msg)); @@ -438,35 +370,33 @@ cli_print_target_maintain_info (Target_t *target, const char *input_target_name) { if (i > 0) printf (", "); printf ("%s <%s>", - target->cooks[i].name ? target->cooks[i].name : "Unknown", - target->cooks[i].email ? target->cooks[i].email : "unknown@example.com"); + target->cooks[i]->name ? target->cooks[i]->name : "Unknown", + target->cooks[i]->email ? target->cooks[i]->email : "unknown@example.com"); } printf ("\n"); } else { - char *msg1 = CHINESE ? "暂空缺, 欢迎担任!" : "Vacant, Welcome to hold the position!"; + char *msg1 = CHINESE ? "暂空缺, 欢迎担任" : "Vacant, Welcome to hold the position"; printf ("%s%s\n", bdblue(msg), bdgreen(msg1)); } } { - char *msg = ENGLISH ? "Contributors: " : "贡献者: "; - if (target->contributors && target->contributors_n > 0) + char *msg = ENGLISH ? "Sauciers: " : "调味: "; + if (target->sauciers && target->sauciers_n > 0) { printf ("%s", bdblue(msg)); - for (size_t i = 0; i < target->contributors_n; i++) + for (size_t i = 0; i < target->sauciers_n; i++) { if (i > 0) printf (", "); - printf ("%s <%s>", - target->contributors[i].name ? target->contributors[i].name : "Unknown", - target->contributors[i].email ? target->contributors[i].email : "unknown@example.com"); + printf ("%s <%s>", target->sauciers[i]->name, target->sauciers[i]->email ); } - printf ("\n"); + br(); } else { - char *msg1 = CHINESE ? "暂空缺, 欢迎参与贡献!" : "Vacant, Welcome to contribute!"; + char *msg1 = CHINESE ? "暂空缺, 欢迎参与贡献" : "Vacant, Welcome to contribute!"; printf ("%s%s\n", bdblue(msg), bdgreen(msg1)); } } @@ -496,7 +426,7 @@ cli_print_version () void cli_print_help () { - char *version_string = purple("v" Chsrc_Version "-" Chsrc_Release_Date); + char *version_string = "v" Chsrc_Version "-" Chsrc_Release_Date; const char *raw = CHINESE ? RAWSTR_chsrc_USAGE_CHINESE : RAWSTR_chsrc_USAGE_ENGLISH; @@ -521,64 +451,98 @@ cli_print_issues () /** - * 用于 iterate_menu_ 的回调函数,检查别名是否匹配用户输入 + * @brief 用于 callback_find_target() 的回调函数,检查别名是否匹配用户输入 */ bool -match_alias_callback (const char *alias, void *user_data) +callback_match_alias (const char *alias, void *user_data) { const char *input = (const char *)user_data; return xy_streql_ic (input, alias); } +/** + * @brief 用于 iterate_menu() 的回调函数 + */ +bool +callback_is_one_of_target_aliases (void *data, void *input) +{ + Target_t *target = (Target_t *) data; + if (iterate_aliases (target->aliases, callback_match_alias, input)) + { + target->preludefn(); + return true; + } + else + return false; +} /** - * 查询用户输入 @param:input 是否与该 @param:menu 中的某个 target 匹配 + * 查询用户输入 `input` 是否与该 `menu` 中的某个 target 匹配 * 若匹配将直接调用 prelude * - * @param[in] menu menu - * @param[in] size menu 大小 - * @param[in] input 用户输入的目标名 - * @param[out] target 返回匹配到的 Target_t 指针 + * @param[in] menu menu + * @param[in] input 用户输入的目标名 + * @param[out] target 返回匹配到的 Target_t 指针 * * @return 匹配到则返回true,未匹配到则返回false */ -#define iterate_menu(ary, input, target) iterate_menu_(ary, xy_arylen(ary), input, target) bool -iterate_menu_ (TargetRegisterInfo_t menu[], size_t size, const char *input, Target_t **target) +iterate_menu (XySeq_t *menu, const char *input, Target_t **target) { - for (int i = 0; i < size; i++) + Target_t *t = xy_seq_find (menu, callback_is_one_of_target_aliases, (void *) input); + + if (t) { - TargetRegisterInfo_t *entry = &menu[i]; + *target = t; + t->preludefn(); + return true; + } + else + { + *target = NULL; + return false; + } +} - if (iterate_aliases (entry->target->aliases, match_alias_callback, (void *)input)) - { - if (entry->prelude) - { - entry->prelude(); - } - else - { - chsrc_error ("该target未定义 prelude()"); - } - *target = entry->target; - return true; - } +void +callback_perform_all_prelude_for_menu (void *data, void *NOUSE) +{ + Target_t *target = (Target_t *) data; + + if (!target->preludefn) + { + chef_debug_target (target); + chsrc_panic ("未定义 _prelude() !"); } - *target = NULL; - return false; + target->preludefn(); +} + +/** + * @brief 用于检查所有 _prelude() 是否能正常工作 + * + * 为了防止 DEBUG 模式下运行流程和普通模式下运行流程不一样,我们只在 Get, Set, Reset + * 之后才运行该函数 + */ +void +chsrc_perform_all_prelude () +{ + chsrc_debug ("prelude", "DEBUG模式下, 额外检查所有 _prelude() 是否能正常工作"); + xy_seq_each (ProgStore.pl, callback_perform_all_prelude_for_menu, NULL); + xy_seq_each (ProgStore.os, callback_perform_all_prelude_for_menu, NULL); + xy_seq_each (ProgStore.wr, callback_perform_all_prelude_for_menu, NULL); } /** - * 我们总是最后告诉用户一些维护信息 + * @brief 在必要的时期,最后告诉用户一些信息 */ void -cli_notify_lastly_for_users () +chsrc_op_epilogue () { br(); - chsrc_note2 (RAWSTR_chsrc_last_message); + chsrc_note2 (RAWSTR_chsrc_op_epilogue); } @@ -592,7 +556,7 @@ typedef enum { } TargetOp; /** - * 寻找target,并根据 @param:code 执行相应的操作 + * 寻找target,并根据 `code` 执行相应的操作 * * @param input 用户输入的目标 * @param code 对target要执行的操作 @@ -603,11 +567,13 @@ typedef enum { bool get_target (const char *input, TargetOp code, char *option) { + chsrc_register_contributors (); + Target_t *target = NULL; - bool matched = iterate_menu (chsrc_pl_menu, input, &target); - if (!matched) matched = iterate_menu (chsrc_os_menu, input, &target); - if (!matched) matched = iterate_menu (chsrc_wr_menu, input, &target); + bool matched = iterate_menu (ProgStore.pl, input, &target); + if (!matched) matched = iterate_menu (ProgStore.os, input, &target); + if (!matched) matched = iterate_menu (ProgStore.wr, input, &target); if (!matched) return false; @@ -617,7 +583,7 @@ get_target (const char *input, TargetOp code, char *option) { target->setfn(option); } - else chsrc_error (xy_strjoin (3, "暂未对 ", input, " 实现 set 功能,邀您帮助: chsrc issue")); + else chsrc_error (xy_strcat (3, "暂未对 ", input, " 实现 set 功能,邀您帮助: chsrc issue")); } else if (TargetOp_Reset_Source==code) { @@ -625,7 +591,7 @@ get_target (const char *input, TargetOp code, char *option) { target->resetfn(option); } - else chsrc_error (xy_strjoin (3, "暂未对 ", input, " 实现 reset 功能,邀您帮助: chsrc issue")); + else chsrc_error (xy_strcat (3, "暂未对 ", input, " 实现 reset 功能,邀您帮助: chsrc issue")); } else if (TargetOp_Get_Source==code) { @@ -633,13 +599,13 @@ get_target (const char *input, TargetOp code, char *option) { target->getfn(""); } - else chsrc_error (xy_strjoin (3, "暂未对 ", input, " 实现 get 功能,邀您帮助: chsrc issue")); + else chsrc_error (xy_strcat (3, "暂未对 ", input, " 实现 get 功能,邀您帮助: chsrc issue")); } else if (TargetOp_List_Config==code) { { char *msg = ENGLISH ? "To specify a source, use chsrc set " : "指定使用某源,请使用 chsrc set "; - say (bdblue(xy_strjoin (3, msg, input, " \n"))); + say (bdblue(xy_strcat (3, msg, input, " \n"))); } { @@ -649,7 +615,7 @@ get_target (const char *input, TargetOp code, char *option) { char *msg1 = ENGLISH ? "Mirror abbr" : "镜像站简写"; - char *msg2 = ENGLISH ? "Source URL" : "换源URL"; + char *msg2 = ENGLISH ? "Source URL" : "换源链接"; char *msg3 = ENGLISH ? "Mirror Name" : "镜像站"; char *format = ENGLISH ? " %-13s%-33s%-38s%s\n" : " %-13s%-36s%-46s%s\n"; printf (format, "code", msg1, msg2, msg3); @@ -679,19 +645,26 @@ get_target (const char *input, TargetOp code, char *option) if (TargetOp_Set_Source==code || TargetOp_Measure_Source==code) { - cli_notify_lastly_for_users(); + chsrc_op_epilogue (); } +#ifdef XY_DEBUG chef_debug_target (target); + chsrc_perform_all_prelude (); +#endif return true; } + int main (int argc, char const *argv[]) { - xy_useutf8 (); argc -= 1; + chsrc_init_framework (); + chsrc_init_menu (); + + argc -= 1; if (0==argc) { @@ -760,7 +733,7 @@ main (int argc, char const *argv[]) else { char *msg = ENGLISH ? "Unknown option: " : "未识别的命令行选项 "; - chsrc_error (xy_2strjoin (msg, argv[i])); return Exit_Unknown; + chsrc_error (xy_2strcat (msg, argv[i])); return Exit_Unknown; } cli_arg_Target_pos++; cli_arg_Mirror_pos++; @@ -815,25 +788,39 @@ main (int argc, char const *argv[]) else { target = argv[cli_arg_Target_pos]; - if (xy_streql (target, "mirrors") || xy_streql (target, "mirror")) + if ( xy_streql (target, "mirrors") + || xy_streql (target, "mirror")) { - cli_print_available_mirrors (); return Exit_OK; + cli_print_available_mirrors (); + return Exit_OK; } - else if (xy_streql (target, "targets") || xy_streql (target, "target")) + + else if ( xy_streql (target, "targets") + || xy_streql (target, "target")) { - cli_print_supported_targets (); return Exit_OK; + cli_print_supported_targets (); + return Exit_OK; } + else if (xy_streql (target, "os")) { - cli_print_supported_os (); return Exit_OK; + cli_print_menu ("os"); + return Exit_OK; } - else if (xy_streql (target, "lang") || xy_streql (target, "pl") || xy_streql (target, "language")) + + else if ( xy_streql (target, "lang") + || xy_streql (target, "pl") + || xy_streql (target, "language")) { - cli_print_supported_pl(); return Exit_OK; + cli_print_menu ("pl"); + return Exit_OK; } - else if (xy_streql (target, "ware") || xy_streql (target, "software")) + + else if ( xy_streql (target, "ware") + || xy_streql (target, "software")) { - cli_print_supported_wr (); return Exit_OK; + cli_print_menu ("wr"); + return Exit_OK; } matched = get_target (target, TargetOp_List_Config, NULL); @@ -943,7 +930,7 @@ main (int argc, char const *argv[]) { char *msg1 = ENGLISH ? "Unknown command `" : "不支持的命令 "; char *msg2 = ENGLISH ? "`. Use `chsrc help` to view usage" : ". 请使用 chsrc help 查看使用方式"; - chsrc_error (xy_strjoin (3, msg1, command, msg2)); + chsrc_error (xy_strcat (3, msg1, command, msg2)); return Exit_Unknown; } diff --git a/src/framework/chef-helper.c b/src/framework/chef-helper.c index 9113f7b..c513aa1 100644 --- a/src/framework/chef-helper.c +++ b/src/framework/chef-helper.c @@ -2,10 +2,10 @@ * SPDX-License-Identifier: GPL-3.0-or-later * ------------------------------------------------------------- * File Name : chef-helper.c - * File Authors : Aoran Zeng - * Contributors : Nul None + * File Authors : 曾奥然 + * Contributors : Nul None * Created On : <2025-07-14> - * Last Modified : <2025-08-09> + * Last Modified : <2025-08-20> * * For chefs (recipe makers) and sometimes framewoker * to do some work not releated to OS operations @@ -40,5 +40,5 @@ chef_ensure_trailing_slash (char *str) if (len == 0 || str[len - 1] == '/') return xy_strdup (str); - return xy_2strjoin (str, "/"); + return xy_2strcat (str, "/"); } diff --git a/src/framework/chef.c b/src/framework/chef.c index 991ac0c..6a78794 100644 --- a/src/framework/chef.c +++ b/src/framework/chef.c @@ -2,47 +2,122 @@ * SPDX-License-Identifier: GPL-3.0-or-later * ------------------------------------------------------------- * File Name : chef.c - * File Authors : Aoran Zeng - * Contributors : Nul None + * File Authors : 曾奥然 + * Contributors : Nul None * Created On : <2025-08-09> - * Last Modified : <2025-08-11> + * Last Modified : <2025-08-22> * * chef DSL: for chefs (recipe makers) to define a target * ------------------------------------------------------------*/ #pragma once -#define chef_allow_gsr(t) this->getfn = t##_getsrc; this->setfn = t##_setsrc; this->resetfn = t##_resetsrc; -#define chef_allow_s(t) this->getfn = NULL; this->setfn = t##_setsrc; this->resetfn = NULL; -#define chef_allow_sr(t) this->getfn = NULL; this->setfn = t##_setsrc; this->resetfn = t##_resetsrc; -#define chef_allow_gs(t) this->getfn = t##_getsrc; this->setfn = t##_setsrc; this->resetfn = NULL; +void +chef_debug_target (Target_t *target) +{ +#ifdef XY_DEBUG + if (!target) + { + chsrc_debug2 ("target", "Target is NULL"); + return; + } + + say ("DEBUG Target Information:"); + printf (" Aliases: %s\n", target->aliases); + + printf (" Get Function: %p\n", target->getfn); + printf (" Set Function: %p\n", target->setfn); + printf (" Reset Function: %p\n", target->resetfn); + printf (" Prelude Function: %p\n", target->preludefn); + + printf (" Inited?: %d\n", target->inited); + + printf (" Sources: %p\n", target->sources); + printf (" Sources Count: %d\n", target->sources_n); + + printf (" Chef: %p\n", target->chef); + printf (" Cooks: %p\n", target->cooks); + printf (" Cooks Count: %d\n", target->cooks_n); + printf (" Sauciers: %p\n", target->sauciers); + printf (" Sauciers Count: %d\n", target->sauciers_n); +#endif +} + + +void +chef_debug_contributor (Contributor_t *contributor) +{ +#ifdef XY_DEBUG + if (!contributor) + { + chsrc_debug2 ("contrib", "Contributor is NULL"); + return; + } + + say ("DEBUG Contributor Information:"); + printf (" ID: %s\n", contributor->id); + printf (" Name: %s\n", contributor->name); + printf (" Email: %s\n", contributor->email); + printf (" DisplayName: %s\n", contributor->display_name); +#endif +} + + +/** + * @brief 登记所有贡献者 + * + * @param id 贡献者 ID,这个ID最好是GitHub用户名,但也可以不是,只需要在 chsrc 内部进行区分即可 + * @param display_name 如果没有提供该参数,则使用 name + */ +void +chef_register_contributor (char *id, char *name, char *email, char *display_name) +{ + if (!id || !name || !email) + xy_unreached(); + + Contributor_t *contributor = xy_malloc0 (sizeof (Contributor_t)); + contributor->id = xy_strdup (id); + contributor->name = xy_strdup (name); + contributor->email = xy_strdup (email); + + if (!display_name) + contributor->display_name = xy_strdup (name); + else + contributor->display_name = xy_strdup (display_name); + + xy_map_set (ProgStore.contributors, id, contributor); +} /** * @brief 修改 Provider 的测速地址 + * + * @note 这个修改的是全局 Provider 里的信息。往往用来设置 UpstreamProvider */ void chef_set_provider_speed_measure_url (SourceProvider_t *provider, char *url) { provider->psmi.skip = NotSkip; provider->psmi.url = xy_strdup (url); - chsrc_debug ("m", xy_strjoin (4, "recipe 重新为 ", provider->code, " 设置测速链接: ", url)); + chsrc_debug ("m", xy_strcat (4, "recipe 重新为 ", provider->code, "(镜像站信息本身) 设置测速链接: ", url)); } /** * @brief 修改 Provider 的测速精度 + * + * @note 这个修改的是全局 Provider 里的信息。往往用来设置 UpstreamProvider */ void chef_set_provider_speed_measure_accuracy (SourceProvider_t *provider, bool accuracy) { provider->psmi.accurate = accuracy; - chsrc_debug ("m", xy_strjoin (4, "recipe 重新为 ", provider->code, " 设置测速精度: ", accuracy ? "精准" : "粗略")); + chsrc_debug ("m", xy_strcat (4, "recipe 重新为 ", provider->code, "(镜像站信息本身) 设置测速精度: ", accuracy ? "精准" : "粗略")); } /** - * @brief 提供一个函数,这个函数基于 "换源 URL" 和用户提供的数据来构造和填充精准测速链接 + * @brief 提供一个函数,这个函数基于 "换源链接" 和用户提供的数据来构造和填充精准测速链接 */ void chef_set_sources_speed_measure_url_with_func ( @@ -50,8 +125,11 @@ chef_set_sources_speed_measure_url_with_func ( char *(*func)(const char *url, const char *user_data), char *user_data) { + xy_cant_be_null (target); + Source_t *sources = target->sources; int n = target->sources_n; + for (int i=0; iinited) + { + if (other->preludefn) + other->preludefn(); + else + { + chef_debug_target (other); + chsrc_panic ("`other` 未定义 _prelude() !"); + } + } + + this->sources = other->sources; + this->sources_n = other->sources_n; } void chef_allow_english (Target_t *target) { - if (!target) - return; - + xy_cant_be_null (target); target->can_english = true; } void chef_forbid_english (Target_t *target) { - if (!target) - return; - + xy_cant_be_null (target); target->can_english = false; } @@ -100,8 +196,7 @@ chef_forbid_english (Target_t *target) void chef_allow_local_mode (Target_t *target, Capability_t cap, const char *explain_zh, const char *explain_en) { - if (!target) - return; + xy_cant_be_null (target); target->cap_local = cap; @@ -124,8 +219,7 @@ chef_allow_local_mode (Target_t *target, Capability_t cap, const char *explain_z void chef_allow_user_define (Target_t *target) { - if (!target) - return; + xy_cant_be_null (target); target->can_user_define = true; target->can_user_define_explain = NULL; @@ -134,8 +228,7 @@ chef_allow_user_define (Target_t *target) void chef_forbid_user_define (Target_t *target) { - if (!target) - return; + xy_cant_be_null (target); target->can_user_define = false; @@ -148,113 +241,116 @@ chef_forbid_user_define (Target_t *target) void chef_set_note (Target_t *target, const char *note_zh, const char *note_en) { - if (!target) - return; + xy_cant_be_null (target); const char *msg = CHINESE ? note_zh : note_en; if (msg) - target->note = xy_strdup(msg); + target->note = xy_strdup (msg); } -void -chef_set_contributors (Target_t *target, uint32_t count, ...) + +/** + * @brief 验证该 `id` 所指的贡献者确有其人 + */ +Contributor_t * +chef_verify_contributor (const char *id) { - if (!target || count==0) - return; + xy_cant_be_null (id); - target->contributors_n = count; - target->contributors = xy_malloc0 (count * sizeof(Contributor_t)); - - va_list args; - va_start(args, count); - - for (uint32_t i = 0; i < count; i++) + Contributor_t *c = xy_map_get (ProgStore.contributors, id); + if (!c) { - char *name = va_arg(args, char*); - char *email = va_arg(args, char*); - - target->contributors[i].name = xy_strdup (name); - target->contributors[i].email = xy_strdup (email); + char error[256]; + snprintf (error, sizeof (error), "贡献者 %s 不存在, 是否写错?或请在 chsrc-main.c 中登记该贡献者", id); + chsrc_panic (error); } + return c; } +/** + * @brief 设置 Chef (recipe 负责人) + */ void -chef_set_authors (Target_t *target, size_t count, ...) +chef_set_chef (Target_t *target, const char *id) { - if (!target || count == 0) - return; + xy_cant_be_null (target); - va_list args; - va_start(args, count); - - target->authors = xy_malloc0 (count * sizeof(Contributor_t)); - target->authors_n = count; - - for (size_t i = 0; i < count; i++) + /* Chef 可为空 */ + if (!id) { - char *name = va_arg(args, char*); - char *email = va_arg(args, char*); - - target->authors[i].name = xy_strdup(name); - target->authors[i].email = xy_strdup(email); + target->chef = NULL; + return; } - va_end(args); -} - - -void -chef_set_chef (Target_t *target, char *name, char *email) -{ - if (!target || !name || !email) - return; - - target->chef = xy_malloc0 (sizeof(Contributor_t)); - target->chef->name = xy_strdup (name); - target->chef->email = xy_strdup (email); + Contributor_t *c = chef_verify_contributor (id); + target->chef = c; } +/** + * @brief 设置 Cooks (recipe 核心作者) + */ void chef_set_cooks (Target_t *target, size_t count, ...) { - if (!target) - return; + xy_cant_be_null (target); if (count == 0) { - target->cooks = NULL; - target->cooks_n = 0; + chsrc_panic ("recipe 一定至少有1位作者(cooks)"); return; } va_list args; - va_start(args, count); + va_start (args, count); - target->cooks = xy_malloc0 (count * sizeof(Contributor_t)); + target->cooks = xy_malloc0 (count * sizeof (Contributor_t*)); target->cooks_n = count; for (size_t i = 0; i < count; i++) { - char *name = va_arg(args, char*); - char *email = va_arg(args, char*); - - target->cooks[i].name = xy_strdup(name); - target->cooks[i].email = xy_strdup(email); + char *id = va_arg (args, char*); + target->cooks[i] = chef_verify_contributor (id); } - va_end(args); + va_end (args); } +void +chef_set_sauciers (Target_t *target, uint32_t count, ...) +{ + xy_cant_be_null (target); + + if (count == 0) + { + target->sauciers = NULL; + target->sauciers_n = 0; + return; + } + + va_list args; + va_start (args, count); + + target->sauciers = xy_malloc0 (count * sizeof (Contributor_t*)); + target->sauciers_n = count; + + for (uint32_t i = 0; i < count; i++) + { + char *id = va_arg (args, char*); + target->sauciers[i] = chef_verify_contributor (id); + } +} + + void chef_set_created_on (Target_t *target, char *date) { - if (!target) - return; + xy_cant_be_null (target); + xy_cant_be_null (date); target->created_on = xy_strdup (date); } @@ -263,8 +359,8 @@ chef_set_created_on (Target_t *target, char *date) void chef_set_last_updated (Target_t *target, char *date) { - if (!target) - return; + xy_cant_be_null (target); + xy_cant_be_null (date); target->last_updated = xy_strdup (date); } @@ -273,36 +369,8 @@ chef_set_last_updated (Target_t *target, char *date) void chef_set_sources_last_updated (Target_t *target, char *date) { - if (!target) - return; + xy_cant_be_null (target); + xy_cant_be_null (date); target->sources_last_updated = xy_strdup (date); } - - -void -chef_debug_target (Target_t *target) -{ -#ifdef XY_DEBUG - if (!target) - { - chsrc_debug2 ("t", "Target is NULL"); - return; - } - - say ("Debug Target Information:"); - printf (" Get Function: %p\n", target->getfn); - printf (" Set Function: %p\n", target->setfn); - printf (" Reset Function: %p\n", target->resetfn); - printf (" Sources: %p\n", target->sources); - printf (" Sources Count: %lld\n", target->sources_n); - - printf (" Authors: %p\n", target->authors); - printf (" Authors Count: %lld\n", target->authors_n); - printf (" Chef: %p\n", target->chef); - printf (" Cooks: %p\n", target->cooks); - printf (" Cooks Count: %lld\n", target->cooks_n); - printf (" Contributors: %p\n", target->contributors); - printf (" Contributors Count: %lld\n", target->contributors_n); -#endif -} diff --git a/src/framework/core.c b/src/framework/core.c index 41eff2f..2b343a6 100644 --- a/src/framework/core.c +++ b/src/framework/core.c @@ -2,14 +2,14 @@ * SPDX-License-Identifier: GPL-3.0-or-later * ------------------------------------------------------------- * File Name : core.c - * File Authors : Aoran Zeng - * | Heng Guo <2085471348@qq.com> + * File Authors : 曾奥然 + * | 郭恒 <2085471348@qq.com> * Contributors : Peng Gao * | Happy Game * | Yangmoooo * | * Created On : <2023-08-29> - * Last Modified : <2025-08-10> + * Last Modified : <2025-08-22> * * chsrc framework * ------------------------------------------------------------*/ @@ -137,6 +137,21 @@ ProgStatus = }; +/* Global Program Store */ +struct +{ + XySeq_t *pl; + XySeq_t *os; + XySeq_t *wr; + XyMap_t *contributors; /* 所有贡献者 */ +} +ProgStore = +{ + .pl = NULL, + .os = NULL, + .wr = NULL, + .contributors = NULL, +}; @@ -159,6 +174,7 @@ ProgStatus = #define chsrc_debug(dom,str) #endif #define chsrc_verbose(str) xy_info(App_Name "(VERBOSE)",str) +#define chsrc_panic(reason) xy_error(App_Name "(PANIC)",reason); exit(Exit_MaintainerCause) #define faint(str) xy_str_to_faint(str) #define red(str) xy_str_to_red(str) @@ -206,6 +222,20 @@ chsrc_alert2 (const char *str) } + +void +chsrc_init_framework () +{ + xy_init (); + + ProgStore.contributors = xy_map_new (); + ProgStore.pl = xy_seq_new (); + ProgStore.os = xy_seq_new (); + ProgStore.wr = xy_seq_new (); +} + + + void chsrc_log_write (const char *filename) { @@ -219,8 +249,8 @@ chsrc_log_backup (const char *filename) { char *msg = ENGLISH ? "BACKUP" : "备份"; - char *bak = xy_2strjoin (filename, ".bak"); - xy_log_brkt (blue(App_Name), bdblue(msg), xy_strjoin (3, bdyellow(filename), " -> ", bdgreen(bak))); + char *bak = xy_2strcat (filename, ".bak"); + xy_log_brkt (blue(App_Name), bdblue(msg), xy_strcat (3, bdyellow(filename), " -> ", bdgreen(bak))); } #define YesMark "✓" @@ -251,12 +281,12 @@ log_check_result (const char *check_what, const char *check_type, bool exist) if (!exist) { - xy_log_brkt (App_Name, bdred (chk_msg), xy_strjoin (5, + xy_log_brkt (App_Name, bdred (chk_msg), xy_strcat (5, red (NoMark " "), check_type, " ", red (check_what), not_exist_msg)); } else { - xy_log_brkt (App_Name, bdgreen (chk_msg), xy_strjoin (5, + xy_log_brkt (App_Name, bdgreen (chk_msg), xy_strcat (5, green (YesMark " "), check_type, " ", green (check_what), exist_msg)); } } @@ -288,7 +318,7 @@ log_cmd_result (bool result, int exit_status) { char buf[8] = {0}; sprintf (buf, "%d", exit_status); - char *log = xy_2strjoin (red (fail_msg), bdred (buf)); + char *log = xy_2strcat (red (fail_msg), bdred (buf)); xy_log_brkt (red (App_Name), bdred (run_msg), log); } } @@ -303,11 +333,11 @@ log_cmd_result (bool result, int exit_status) /** * 检测二进制程序是否存在 * - * @param check_cmd 检测 @param:prog_name 是否存在的一段命令,一般来说,填 @param:prog_name 本身即可, + * @param check_cmd 检测 `prog_name` 是否存在的一段命令,一般来说,填 `prog_name` 本身即可, * 但是某些情况下,需要使用其他命令绕过一些特殊情况,比如 python 这个命令在Windows上 * 会自动打开 Microsoft Store,需避免 * - * @param prog_name 要检测的二进制程序名 + * @param prog_name 要检测的二进制程序名 * */ bool @@ -325,7 +355,7 @@ query_program_exist (char *check_cmd, char *prog_name, int mode) { if (mode & Noisy_When_NonExist) { - // xy_warn (xy_strjoin(4, "× 命令 ", progname, " 不存在,", buf)); + // xy_warn (xy_strcat(4, "× 命令 ", progname, " 不存在,", buf)); log_check_result (prog_name, msg, false); } return false; @@ -340,33 +370,37 @@ query_program_exist (char *check_cmd, char *prog_name, int mode) /** - * @brief 生成用于 '检测一个程序是否存在' 的命令,该内部函数由 chsrc_check_program() 家族调用 + * @brief 生成用于 “检测一个程序是否存在” 的命令,该内部函数由 chsrc_check_program() 家族调用 * - * 检查一个程序是否存在时,我们曾经使用 "调用 程序名 --version" 的方式 (即 cmd_to_check_program2()), - * 但是该方式有三个问题: - * - * 1. 该程序得到直接执行,可能不太安全 (虽然基本不可能) - * 2. 有一些程序启动速度太慢,即使只调用 --version,也依旧会花费许多时间,比如 mvn - * 3. 有些程序并不支持 --version 选项 (虽然基本不可能) - * - * @note Unix 中,where 仅在 zsh 中可以使用,sh 和 Bash 中均无法使用,因为其并非二进制程序 - * 所以在 Unix 中,只能使用 which 或 whereis + * @note + * 1. Unix 中,'where' 命令仅在 Zsh 中可以使用,sh 和 Bash 中均无法使用,因为其并非二进制程序 + * 2. 因部分 Linux 发行版中没有 'which' 和 'whereis' 命令,使用 'command -v' 代替 */ static char * cmd_to_check_program (char *prog_name) { - char *check_tool = xy_on_windows ? "where " : "which "; + char *check_tool = xy_on_windows ? "where " : "command -v "; - char *quiet_cmd = xy_str_to_quietcmd (xy_2strjoin (check_tool, prog_name)); + char *quiet_cmd = xy_str_to_quietcmd (xy_2strcat (check_tool, prog_name)); return quiet_cmd; } + +/** + * @brief 通过 `调用程序名 --version` 的方式检测程序是否存在 + * + * @deprecated 因存在以下三个问题弃用: + * + * 1. 该程序得到直接执行,可能不太安全 (虽然基本不可能) + * 2. 有一些程序启动速度太慢,即使只调用 --version,也依旧会花费许多时间,比如 mvn + * 3. 有些程序并不支持 --version 选项 (虽然基本不可能) + */ XY_Deprecate_This("Use cmd_to_check_program() instead") static char * cmd_to_check_program2 (char *prog_name) { - char *quiet_cmd = xy_str_to_quietcmd (xy_2strjoin (prog_name, " --version")); + char *quiet_cmd = xy_str_to_quietcmd (xy_2strcat (prog_name, " --version")); return quiet_cmd; } @@ -431,7 +465,7 @@ chsrc_ensure_program (char *prog_name) { char *msg1 = ENGLISH ? "not found " : "未找到 "; char *msg2 = ENGLISH ? " command, please check for existence" : " 命令,请检查是否存在"; - chsrc_error (xy_strjoin (3, msg1, prog_name, msg2)); + chsrc_error (xy_strcat (3, msg1, prog_name, msg2)); exit (Exit_UserCause); } } @@ -476,7 +510,7 @@ query_mirror_exist (Source_t *sources, size_t size, char *target_name, char *inp { char *msg1 = ENGLISH ? "Currently " : "当前 "; char *msg2 = ENGLISH ? " doesn't have any source available. Please contact the maintainers" : " 无任何可用源,请联系维护者"; - chsrc_error (xy_strjoin (3, msg1, target_name, msg2)); + chsrc_error (xy_strcat (3, msg1, target_name, msg2)); exit (Exit_MaintainerCause); } @@ -484,7 +518,7 @@ query_mirror_exist (Source_t *sources, size_t size, char *target_name, char *inp { char *msg1 = ENGLISH ? "Currently " : "当前 "; char *msg2 = ENGLISH ? " only the upstream source exists. Please contact the maintainers" : " 仅存在上游默认源,请联系维护者"; - chsrc_error (xy_strjoin (3, msg1, target_name, msg2)); + chsrc_error (xy_strcat (3, msg1, target_name, msg2)); exit (Exit_MaintainerCause); } @@ -503,7 +537,7 @@ query_mirror_exist (Source_t *sources, size_t size, char *target_name, char *inp : " 目前唯一可用镜像站,感谢他们的慷慨支持"; const char *name = ENGLISH ? sources[1].mirror->abbr : sources[1].mirror->name; - chsrc_succ (xy_strjoin (4, name, msg1, target_name, msg2)); + chsrc_succ (xy_strcat (4, name, msg1, target_name, msg2)); } if (xy_streql ("first", input)) @@ -532,11 +566,11 @@ query_mirror_exist (Source_t *sources, size_t size, char *target_name, char *inp { char *msg1 = ENGLISH ? "Mirror site " : "镜像站 "; char *msg2 = ENGLISH ? " doesn't exist" : " 不存在"; - chsrc_error (xy_strjoin (3, msg1, input, msg2)); + chsrc_error (xy_strcat (3, msg1, input, msg2)); } char *msg = ENGLISH ? "To see available sources, use chsrc list " : "查看可使用源,请使用 chsrc list "; - chsrc_error (xy_2strjoin (msg, target_name)); + chsrc_error (xy_2strcat (msg, target_name)); exit (Exit_UserCause); } return idx; @@ -609,11 +643,11 @@ measure_speed_for_url (void *url) /** * @note 我们用 —L,因为部分链接会跳转到其他地方,比如: RubyChina, npmmirror */ - char *curl_cmd = xy_strjoin (10, "curl -qsL ", ipv6, + char *curl_cmd = #xy_strcat (8, "curl -qsL ", ipv6, " -o ", os_devnull, " -w \"%{http_code} %{speed_download}\" -m", time_sec, " -A ", ProgStatus.user_agent, " ", url); - + // chsrc_info (xy_2strjoin ("测速命令 ", curl_cmd)); char *curl_buf = xy_run (curl_cmd, 0); return curl_buf; @@ -637,8 +671,8 @@ parse_and_say_curl_result (char *curl_buf) if (200!=http_code) { - char *http_code_str = yellow (xy_2strjoin ("HTTP码 ", curl_buf)); - say (xy_strjoin (3, speedstr, " | ", http_code_str)); + char *http_code_str = yellow (xy_2strcat ("HTTP码 ", curl_buf)); + say (xy_strcat (3, speedstr, " | ", http_code_str)); } else { @@ -709,7 +743,7 @@ measure_speed_for_every_source (Source_t sources[], int size, double speed_recor { char *msg1 = ENGLISH ? "Maintainers don't offer " : "维护者未提供 "; char *msg2 = ENGLISH ? " mirror site's speed measure link, so skip it" : " 镜像站测速链接,跳过该站点(需修复)"; - chsrc_warn (xy_strjoin (3, msg1, provider->code, msg2)); + chsrc_warn (xy_strcat (3, msg1, provider->code, msg2)); speed = 0; speed_records[i] = speed; @@ -721,7 +755,7 @@ measure_speed_for_every_source (Source_t sources[], int size, double speed_recor if (chef_is_url (provider_speed_url)) { url = xy_strdup (provider_speed_url); - chsrc_debug ("m", xy_2strjoin ("使用镜像站整体测速链接: ", url)); + chsrc_debug ("m", xy_2strcat ("使用镜像站整体测速链接: ", url)); } } else if (provider_skip) @@ -735,13 +769,13 @@ measure_speed_for_every_source (Source_t sources[], int size, double speed_recor { url = xy_strdup (dedicated_speed_url); has_dedicated_speed_url = true; - chsrc_debug ("m", xy_2strjoin ("使用专用测速链接: ", url)); + chsrc_debug ("m", xy_2strcat ("使用专用测速链接: ", url)); } else { /* 防止维护者没填,这里有一些脏数据,我们软处理:假装该链接URL不存在 */ has_dedicated_speed_url = false; - chsrc_debug ("m", xy_2strjoin ("专用测速链接为脏数据,请修复: ", provider->name)); + chsrc_debug ("m", xy_2strcat ("专用测速链接为脏数据,请修复: ", provider->name)); } } @@ -777,7 +811,7 @@ measure_speed_for_every_source (Source_t sources[], int size, double speed_recor { skip_reason = ENGLISH ? "SKIP for no reason" : "无理由跳过"; } - measure_msgs[i] = xy_strjoin (4, faint(" x "), msg, " ", yellow(faint(skip_reason))); + measure_msgs[i] = xy_strcat (4, faint(" x "), msg, " ", yellow(faint(skip_reason))); println (measure_msgs[i]); /* 下一位 */ @@ -804,11 +838,11 @@ measure_speed_for_every_source (Source_t sources[], int size, double speed_recor if (xy_streql ("upstream", provider->code)) { - measure_msgs[i] = xy_strjoin (7, faint(" ^ "), msg, " (", src.url, ") ", accurate_msg, faint(" ... ")); + measure_msgs[i] = xy_strcat (7, faint(" ^ "), msg, " (", src.url, ") ", accurate_msg, faint(" ... ")); } else { - measure_msgs[i] = xy_strjoin (5, faint(" - "), msg, " ", accurate_msg, faint(" ... ")); + measure_msgs[i] = xy_strcat (5, faint(" - "), msg, " ", accurate_msg, faint(" ... ")); } print (measure_msgs[i]); @@ -848,7 +882,7 @@ auto_select_mirror (Source_t *sources, size_t size, const char *target_name) { char *msg1 = ENGLISH ? "Currently " : "当前 "; char *msg2 = ENGLISH ? "No any source, please contact maintainers: chsrc issue" : " 无任何可用源,请联系维护者: chsrc issue"; - chsrc_error (xy_strjoin (3, msg1, target_name, msg2)); + chsrc_error (xy_strcat (3, msg1, target_name, msg2)); exit (Exit_MaintainerCause); } @@ -913,21 +947,21 @@ auto_select_mirror (Source_t *sources, size_t size, const char *target_name) : " 目前唯一可用镜像站,感谢他们的慷慨支持"; const char *name = ENGLISH ? sources[fast_idx].mirror->abbr : sources[fast_idx].mirror->name; - say (xy_strjoin (5, msg1, bdgreen(name), green(is), green(target_name), green(msg2))); + say (xy_strcat (5, msg1, bdgreen(name), green(is), green(target_name), green(msg2))); } else { char *msg = ENGLISH ? "FASTEST mirror site: " : "最快镜像站: "; const char *name = ENGLISH ? sources[fast_idx].mirror->abbr : sources[fast_idx].mirror->name; - say (xy_2strjoin (msg, green(name))); + say (xy_2strcat (msg, green(name))); } // https://github.com/RubyMetric/chsrc/pull/71 if (in_measure_mode()) { char *msg = ENGLISH ? "URL of above source: " : "镜像源地址: "; - say (xy_2strjoin (msg, green(sources[fast_idx].url))); + say (xy_2strcat (msg, green(sources[fast_idx].url))); } return fast_idx; @@ -988,6 +1022,14 @@ source_has_empty_url (Source_t *source) Source_t chsrc_yield_source (Target_t *t, char *option) { + /** + * 防止某些意外时刻 _setsrc() 等函数会被直接调,但此时 _prelude() 还没有执行过 + * 我们在这里卡一道,确保 _prelude() 被调用 + * + * 目前可能出现这种情况的时候:组换源的时候,组成菜的 _setsrc() 被直接调用 + */ + if (!t->inited) t->preludefn(); + Source_t source; if (chsrc_in_target_group_mode() && ProgStatus.leader_selected_index==-1) { @@ -1046,7 +1088,7 @@ chsrc_confirm_source (Source_t *source) else { char *msg = ENGLISH ? "SELECT mirror site: " : "选中镜像站: "; - say (xy_strjoin (5, msg, green (source->mirror->abbr), " (", green (source->mirror->code), ")")); + say (xy_strcat (5, msg, green (source->mirror->abbr), " (", green (source->mirror->code), ")")); } hr(); @@ -1095,7 +1137,7 @@ chsrc_custom_user_agent (char *user_agent) #define MSG_EN_STILL "Still need to operate manually according to the above prompts. " #define MSG_CN_STILL "仍需按上述提示手工操作" -#define thank_mirror(msg) chsrc_log(xy_2strjoin(msg,purple(ENGLISH?source->mirror->abbr:source->mirror->name))) +#define thank_mirror(msg) chsrc_log(xy_2strcat(msg,purple(ENGLISH?source->mirror->abbr:source->mirror->name))) /** * @param source 可为NULL @@ -1323,17 +1365,17 @@ chsrc_run_as_a_service (const char *cmd) FILE * chsrc_make_tmpfile (char *filename, char *postfix, bool loud, char **tmpfilename) { -#ifdef XY_On_Windows +#ifdef XY_Build_On_Windows /** * Windows 上没有 mkstemps(),只有 mkstemp() 和 _mktemp_s(),这后两者效果是等价的,只不过传参不同, * 这意味着我们无法给一个文件名后缀(postfix),只能生成一个临时文件名 * 然而 PowerShell 的执行,即使加了 -File 参数,也必须要求你拥有 .ps1 后缀 * 这使得我们在 Windows 上只能创建一个假的临时文件 */ - char *tmpfile = xy_strjoin (3, "chsrc_tmp_", filename, postfix); + char *tmpfile = xy_strcat (3, "chsrc_tmp_", filename, postfix); FILE *f = fopen (tmpfile, "w+"); #else - char *tmpfile = xy_strjoin (5, "/tmp/", "chsrc_tmp_", filename, "_XXXXXX", postfix); + char *tmpfile = xy_strcat (5, "/tmp/", "chsrc_tmp_", filename, "_XXXXXX", postfix); size_t postfix_len = strlen (postfix); /* 和 _mktemp_s() 参数不同,前者是整个缓存区大小,这里的长度是后缀长度 */ @@ -1344,14 +1386,14 @@ chsrc_make_tmpfile (char *filename, char *postfix, bool loud, char **tmpfilename if (!f) { char *msg = CHINESE ? "无法创建临时文件: " : "Unable to create temporary file: "; - msg = xy_2strjoin (msg, tmpfile); + msg = xy_2strcat (msg, tmpfile); chsrc_error2 (msg); exit (Exit_ExternalError); } else if (loud) { char *msg = CHINESE ? "已创建临时文件: " : "Temporary file created: "; - msg = xy_2strjoin (msg, tmpfile); + msg = xy_2strcat (msg, tmpfile); chsrc_succ2 (msg); } @@ -1389,7 +1431,7 @@ chsrc_run_as_bash_file (const char *script_content) char *msg = CHINESE ? "即将执行 Bash 脚本内容:" : "The Bash script content will be executed:"; chsrc_note2 (msg); println (faint(script_content)); - char *cmd = xy_2strjoin ("bash ", tmpfile); + char *cmd = xy_2strcat ("bash ", tmpfile); chsrc_run (cmd, RunOpt_Dont_Abort_On_Failure); remove (tmpfile); } @@ -1409,7 +1451,7 @@ chsrc_run_as_sh_file (const char *script_content) char *msg = CHINESE ? "即将执行 sh 脚本内容:" : "The sh script content will be executed:"; chsrc_note2 (msg); println (faint(script_content)); - char *cmd = xy_2strjoin ("sh ", tmpfile); + char *cmd = xy_2strcat ("sh ", tmpfile); chsrc_run (cmd, RunOpt_Dont_Abort_On_Failure); remove (tmpfile); } @@ -1428,7 +1470,7 @@ chsrc_run_as_pwsh_file (const char *script_content) char *msg = CHINESE ? "即将执行 PowerShell 脚本内容:" : "The PowerShell script content will be executed:"; chsrc_note2 (msg); println (faint(script_content)); - char *cmd = xy_2strjoin ("pwsh ", tmpfile); + char *cmd = xy_2strcat ("pwsh ", tmpfile); chsrc_run (cmd, RunOpt_Dont_Abort_On_Failure); remove (tmpfile); } @@ -1443,7 +1485,7 @@ XY_Deprecate_This("Don't use this function") void chsrc_run_in_inline_bash_shell (const char *cmdline) { - char *cmd = xy_strjoin (3, "bash -c '", cmdline, "'"); + char *cmd = xy_strcat (3, "bash -c '", cmdline, "'"); chsrc_run (cmd, RunOpt_Dont_Abort_On_Failure); } @@ -1457,7 +1499,7 @@ XY_Deprecate_This("Don't use this function") void chsrc_run_in_inline_pwsh_shell (const char *cmdline) { - char *cmd = xy_strjoin (3, "pwsh -Command '", cmdline, "'"); + char *cmd = xy_strcat (3, "pwsh -Command '", cmdline, "'"); chsrc_run (cmd, RunOpt_Dont_Abort_On_Failure); } @@ -1474,25 +1516,25 @@ chsrc_view_env (const char *var1, ...) bool first = true; while (var) { -#ifdef XY_On_Windows +#ifdef XY_Build_On_Windows if (first) { - cmd = xy_strjoin (3, "set ", var, " "); + cmd = xy_strcat (3, "set ", var, " "); first = false; } else { - cmd = xy_strjoin (4, cmd, "& set ", var, " "); + cmd = xy_strcat (4, cmd, "& set ", var, " "); } #else if (first) { - cmd = xy_strjoin (5, "echo ", var, "=$", var, " "); + cmd = xy_strcat (5, "echo ", var, "=$", var, " "); first = false; } else { - cmd = xy_strjoin (6, cmd, "; echo ", var, "=$", var, " "); + cmd = xy_strcat (6, cmd, "; echo ", var, "=$", var, " "); } #endif var = va_arg (vars, const char *); @@ -1508,7 +1550,7 @@ chsrc_view_env (const char *var1, ...) */ // chsrc_run (cmd, RunOpt_Dont_Notify_On_Success|RunOpt_No_Last_New_Line|RunOpt_Dont_Abort_On_Failure); int status = system (cmd); - if (status!=0) {/* NOOP */} + if (status!=0) { xy_noop(); } } else { @@ -1525,11 +1567,11 @@ chsrc_view_file (const char *path) path = xy_normalize_path (path); if (xy_on_windows) { - cmd = xy_2strjoin ("type ", path); + cmd = xy_2strcat ("type ", path); } else { - cmd = xy_2strjoin ("cat ", path); + cmd = xy_2strcat ("cat ", path); } chsrc_run_as_a_service (cmd); @@ -1555,13 +1597,13 @@ chsrc_ensure_dir (const char *dir) { mkdir_cmd = "mkdir -p "; } - char *cmd = xy_2strjoin (mkdir_cmd, dir); + char *cmd = xy_2strcat (mkdir_cmd, dir); cmd = xy_str_to_quietcmd (cmd); chsrc_run_as_a_service (cmd); char *msg = ENGLISH ? "Directory doesn't exist, created automatically " : "目录不存在,已自动创建 "; - chsrc_alert2 (xy_2strjoin (msg, dir)); + chsrc_alert2 (xy_2strcat (msg, dir)); } @@ -1580,8 +1622,8 @@ chsrc_append_to_file (const char *str, const char *filename) FILE *f = fopen (file, "a"); if (NULL==f) { - char *msg = ENGLISH ? xy_2strjoin ("Unable to open file to write: ", file) - : xy_2strjoin ("无法打开文件以写入: ", file); + char *msg = ENGLISH ? xy_2strcat ("Unable to open file to write: ", file) + : xy_2strcat ("无法打开文件以写入: ", file); chsrc_error2 (msg); exit (Exit_UserCause); } @@ -1591,8 +1633,8 @@ chsrc_append_to_file (const char *str, const char *filename) size_t ret = fwrite (str, len, 1, f); if (ret != 1) { - char *msg = ENGLISH ? xy_2strjoin ("Write failed to ", file) - : xy_2strjoin ("写入文件失败: ", file); + char *msg = ENGLISH ? xy_2strcat ("Write failed to ", file) + : xy_2strcat ("写入文件失败: ", file); chsrc_error2 (msg); exit (Exit_UserCause); } @@ -1607,11 +1649,11 @@ log_anyway: char *cmd = NULL; if (xy_on_windows) { - cmd = xy_strjoin (4, "echo ", str, " >> ", file); + cmd = xy_strcat (4, "echo ", str, " >> ", file); } else { - cmd = xy_strjoin (4, "echo '", str, "' >> ", file); + cmd = xy_strcat (4, "echo '", str, "' >> ", file); } chsrc_run_a_service (cmd); */ @@ -1636,7 +1678,7 @@ chsrc_prepend_to_file (const char *str, const char *filename) } else { - cmd = xy_strjoin (4, "sed -i '1i ", str, "' ", file); + cmd = xy_strcat (4, "sed -i '1i ", str, "' ", file); } chsrc_run_as_a_service (cmd); @@ -1660,11 +1702,11 @@ chsrc_overwrite_file (const char *str, const char *filename) char *cmd = NULL; if (xy_on_windows) { - cmd = xy_strjoin (4, "echo ", str, " > ", file); + cmd = xy_strcat (4, "echo ", str, " > ", file); } else { - cmd = xy_strjoin (4, "echo '", str, "' > ", file); + cmd = xy_strcat (4, "echo '", str, "' > ", file); } chsrc_run_as_a_service (cmd); @@ -1687,14 +1729,14 @@ chsrc_backup (const char *path) if (!exist) { char *msg = ENGLISH ? "File doesn't exist, skip backup: " : "文件不存在,跳过备份: "; - chsrc_alert2 (xy_2strjoin (msg, path)); + chsrc_alert2 (xy_2strcat (msg, path)); return; } if (xy_on_bsd || xy_on_macos) { /* BSD 和 macOS 的 cp 不支持 --backup 选项 */ - cmd = xy_strjoin (5, "cp -f ", path, " ", path, ".bak"); + cmd = xy_strcat (5, "cp -f ", path, " ", path, ".bak"); } else if (xy_on_windows) { @@ -1702,7 +1744,7 @@ chsrc_backup (const char *path) * @note /Y 表示覆盖 * @note 默认情况下会输出一个 "已复制 1个文件" */ - cmd = xy_strjoin (5, "copy /Y ", path, " ", path, ".bak 1>nul"); + cmd = xy_strcat (5, "copy /Y ", path, " ", path, ".bak 1>nul"); } else { @@ -1717,12 +1759,12 @@ chsrc_backup (const char *path) /* cp (GNU coreutils) 9.4 */ if (strstr (ver, "GNU coreutils")) { - cmd = xy_strjoin (5, "cp ", path, " ", path, ".bak --backup='t'"); + cmd = xy_strcat (5, "cp ", path, " ", path, ".bak --backup='t'"); } else { /* 非 GNU 的 cp 可能不支持 --backup ,如 busybox cp */ - cmd = xy_strjoin (5, "cp -f ", path, " ", path, ".bak"); + cmd = xy_strcat (5, "cp -f ", path, " ", path, ".bak"); } } @@ -1742,7 +1784,7 @@ chsrc_get_cpuarch () char *ret; char *msg; -#if XY_On_Windows +#if XY_Build_On_Windows SYSTEM_INFO info; GetSystemInfo (&info); WORD num = info.wProcessorArchitecture; @@ -1795,7 +1837,7 @@ chsrc_get_cpucore () { int cores = 2; -#if XY_On_Windows +#if XY_Build_On_Windows SYSTEM_INFO info; GetSystemInfo (&info); DWORD num = info.dwNumberOfProcessors; diff --git a/src/framework/struct.h b/src/framework/struct.h index 111d7af..0800efd 100644 --- a/src/framework/struct.h +++ b/src/framework/struct.h @@ -2,12 +2,12 @@ * SPDX-License-Identifier: GPL-3.0-or-later * ------------------------------------------------------------- * File Name : struct.h - * File Authors : Aoran Zeng - * | Heng Guo <2085471348@qq.com> + * File Authors : 曾奥然 + * | 郭恒 <2085471348@qq.com> * Contributors : Shengwei Chen <414685209@qq.com> * | * Created On : <2023-08-29> - * Last Modified : <2025-08-11> + * Last Modified : <2025-08-22> * * chsrc struct * ------------------------------------------------------------*/ @@ -94,8 +94,6 @@ Source_t; /* 由 prelude() 填充 */ #define FeedByPrelude NULL -#define def_sources_n(t) const size_t t##_sources_n = xy_arylen(t##_sources) - typedef enum Capability_t { @@ -109,8 +107,10 @@ Capability_t; typedef struct Contributor_t { - char *name; + char *id; /* 全局唯一贡献者标识符,防止反复写信息,以 @ 开头 */ + char *name; /* 贡献者姓名; 鉴于该项目完全依赖于贡献者,建议留下真实姓名或者昵称 */ char *email; + char *display_name; /* recipe 结束时会显示贡献者信息,如果你不愿显示真实姓名或者昵称,可以另外提供一个名字 */ } Contributor_t; @@ -124,8 +124,12 @@ typedef struct Target_t void (*setfn) (char *option); void (*resetfn) (char *option); - Source_t *sources; - size_t sources_n; + /* 初始化函数,用于填充该 struct 的各种信息 */ + void (*preludefn) (void); + bool inited; /* 是否执行过了 preludefn() */ + + Source_t *sources; + int sources_n; /* Features */ @@ -140,41 +144,36 @@ typedef struct Target_t char *note; /* 备注 */ - /* Recipe maintain info */ + /* recipe 维护信息 */ char *created_on; char *last_updated; char *sources_last_updated; - Contributor_t *authors; - size_t authors_n; - - Contributor_t *contributors; - size_t contributors_n; - - Contributor_t *chef; /* Chef 仅有一个 */ - Contributor_t *cooks; /* Cook 可以有多个 */ - size_t cooks_n; + Contributor_t *chef; /* 该 recipe *当前*的总负责人 (可以任职也可以休职) */ + Contributor_t **cooks; /* 该 recipe 的主要作者 */ + int cooks_n; + Contributor_t **sauciers; /* 该 recipe 的次要贡献者 (除主要作者外的其他人) */ + int sauciers_n; } Target_t; -typedef struct TargetRegisterInfo_t -{ - Target_t *target; /* target 本身 */ - void (*prelude) (void); /* 填充 target 信息等预置操作 */ -} -TargetRegisterInfo_t; - #define def_target(t, aliases) void t##_getsrc(char *option);void t##_setsrc(char *option);void t##_resetsrc(char *option); Target_t t##_target={aliases}; -/* 以下宏仅能放在 prelude() 中使用 */ +#define chef_allow_gsr(t) this->getfn = t##_getsrc; this->setfn = t##_setsrc; this->resetfn = t##_resetsrc; +#define chef_allow_s(t) this->getfn = NULL; this->setfn = t##_setsrc; this->resetfn = NULL; +#define chef_allow_sr(t) this->getfn = NULL; this->setfn = t##_setsrc; this->resetfn = t##_resetsrc; +#define chef_allow_gs(t) this->getfn = t##_getsrc; this->setfn = t##_setsrc; this->resetfn = NULL; +#define chef_allow_NOOP(t) +#define chef_prep_this(t,op) Target_t *this = &t##_target; this->inited = true; chef_allow_##op(t); + #define use_this(t) Target_t *this = &t##_target; -#define use_this_source(t) use_this(t); Source_t source = chsrc_yield_source_and_confirm (this, option); +#define chsrc_use_this_source(t) Target_t *this = &t##_target; Source_t source = chsrc_yield_source_and_confirm (this, option); #define def_sources_begin() Source_t sources[] = { #define def_sources_end() }; \ - this->sources_n = xy_arylen(sources); \ + this->sources_n = xy_c_array_len(sources); \ char *_sources_storage = xy_malloc0 (sizeof(sources)); \ memcpy (_sources_storage, sources, sizeof(sources)); \ this->sources = (Source_t *)_sources_storage; diff --git a/src/rawstr4c.h b/src/rawstr4c.h index 9fc19aa..3cb50f9 100644 --- a/src/rawstr4c.h +++ b/src/rawstr4c.h @@ -12,5 +12,5 @@ char RAWSTR_chsrc_for_v[] = "\143\150\163\162\143\040\100\166\145\162\100\012\10 char RAWSTR_chsrc_for_issue[] = "\346\210\221\344\273\254\345\220\214\346\227\266\345\234\250\040\107\151\164\110\165\142\040\345\222\214\040\107\151\164\145\145\040\346\216\245\345\217\227\040\151\163\163\165\145\040\345\222\214\040\102\165\147\040\346\212\245\345\221\212\072\012\012\040\040\055\040\150\164\164\160\163\072\057\057\147\151\164\150\165\142\056\143\157\155\057\122\165\142\171\115\145\164\162\151\143\057\143\150\163\162\143\057\151\163\163\165\145\163\012\040\040\055\040\150\164\164\160\163\072\057\057\147\151\164\145\145\056\143\157\155\057\122\165\142\171\115\145\164\162\151\143\057\143\150\163\162\143\057\151\163\163\165\145\163\012\012\012\346\254\242\350\277\216\345\217\202\344\270\216\345\205\267\344\275\223\344\273\273\345\212\241\072\012\012\040\040\040\123\150\145\154\154\040\141\165\164\157\055\143\157\155\160\154\145\164\151\157\156\040\347\273\210\347\253\257\345\221\275\344\273\244\350\207\252\345\212\250\350\241\245\345\205\250\072\012\012\040\040\040\040\040\040\040\040\150\164\164\160\163\072\057\057\147\151\164\150\165\142\056\143\157\155\057\122\165\142\171\115\145\164\162\151\143\057\143\150\163\162\143\057\151\163\163\165\145\163\057\062\060\064\012\012\040\040\040\346\220\234\351\233\206\344\270\212\346\270\270\351\273\230\350\256\244\346\272\220\345\234\260\345\235\200\357\274\214\345\270\256\345\212\251\350\277\233\350\241\214\040\143\150\163\162\143\040\162\145\163\145\164\072\012\012\040\040\040\040\040\040\040\040\150\164\164\160\163\072\057\057\147\151\164\150\165\142\056\143\157\155\057\122\165\142\171\115\145\164\162\151\143\057\143\150\163\162\143\057\151\163\163\165\145\163\057\061\061\061\012\012\040\040\040\346\220\234\351\233\206\346\265\213\351\200\237\345\234\260\345\235\200\357\274\214\350\277\233\350\241\214\347\262\276\345\207\206\346\265\213\351\200\237\072\012\012\040\040\040\040\040\040\040\040\150\164\164\160\163\072\057\057\147\151\164\150\165\142\056\143\157\155\057\122\165\142\171\115\145\164\162\151\143\057\143\150\163\162\143\057\151\163\163\165\145\163\057\062\060\065\012\012\040\040\040\345\270\256\345\212\251\346\262\241\346\234\211\351\242\204\347\274\226\350\257\221\347\232\204\345\271\263\345\217\260\347\274\226\345\206\231\040\163\150\145\154\154\040\350\204\232\346\234\254\072\012\012\040\040\040\040\040\040\040\040\150\164\164\160\163\072\057\057\147\151\164\150\165\142\056\143\157\155\057\122\165\142\171\115\145\164\162\151\143\057\143\150\163\162\143\057\151\163\163\165\145\163\057\062\063\060\012\012\012\346\224\257\346\214\201\347\232\204\351\200\232\347\224\250\351\225\234\345\203\217\347\253\231\072\012\040\040\055\040\150\164\164\160\163\072\057\057\147\151\164\150\165\142\056\143\157\155\057\122\165\142\171\115\145\164\162\151\143\057\143\150\163\162\143\057\167\151\153\151\012"; -char RAWSTR_chsrc_last_message[] = "\012\040\040\040\052\040\347\262\276\345\207\206\346\265\213\351\200\237\072\040\350\203\275\347\234\237\345\256\236\345\217\215\346\230\240\344\275\240\346\234\252\346\235\245\344\275\277\347\224\250\350\257\245\350\265\204\346\272\220\346\227\266\347\232\204\351\200\237\345\272\246\357\274\214\345\233\240\344\270\272\345\256\203\347\233\264\346\216\245\346\265\213\351\207\217\344\275\240\345\205\263\346\263\250\347\232\204\351\202\243\344\270\252\350\265\204\346\272\220\343\200\202\012\040\040\040\052\040\346\250\241\347\263\212\346\265\213\351\200\237\072\040\344\273\205\344\273\243\350\241\250\350\257\245\351\225\234\345\203\217\347\253\231\346\217\220\344\276\233\346\234\215\345\212\241\347\232\204\344\270\200\344\270\252\345\217\257\350\203\275\351\200\237\345\272\246\343\200\202\345\233\240\350\200\214\345\217\257\350\203\275\344\274\232\345\207\272\347\216\260\346\265\213\351\200\237\346\225\260\345\200\274\350\276\203\351\253\230\357\274\214\344\275\206\345\256\236\351\231\205\344\275\277\347\224\250\344\275\223\351\252\214\344\270\215\344\275\263\347\232\204\347\216\260\350\261\241\343\200\202\012\345\275\223\344\275\240\351\201\207\345\210\260\346\250\241\347\263\212\346\265\213\351\200\237\346\227\266\357\274\214\350\257\267\345\260\275\345\217\257\350\203\275\345\220\221\346\210\221\344\273\254\346\217\220\344\272\244\345\207\206\347\241\256\347\232\204\346\265\213\351\200\237\351\223\276\346\216\245\072\040\143\150\163\162\143\040\151\163\163\165\145"; +char RAWSTR_chsrc_op_epilogue[] = "\012\040\040\040\052\040\347\262\276\345\207\206\346\265\213\351\200\237\072\040\350\203\275\347\234\237\345\256\236\345\217\215\346\230\240\344\275\240\346\234\252\346\235\245\344\275\277\347\224\250\350\257\245\350\265\204\346\272\220\346\227\266\347\232\204\351\200\237\345\272\246\357\274\214\345\233\240\344\270\272\345\256\203\347\233\264\346\216\245\346\265\213\351\207\217\344\275\240\345\205\263\346\263\250\347\232\204\351\202\243\344\270\252\350\265\204\346\272\220\343\200\202\012\040\040\040\052\040\346\250\241\347\263\212\346\265\213\351\200\237\072\040\344\273\205\344\273\243\350\241\250\350\257\245\351\225\234\345\203\217\347\253\231\346\217\220\344\276\233\346\234\215\345\212\241\347\232\204\344\270\200\344\270\252\345\217\257\350\203\275\351\200\237\345\272\246\343\200\202\345\233\240\350\200\214\345\217\257\350\203\275\344\274\232\345\207\272\347\216\260\346\265\213\351\200\237\346\225\260\345\200\274\350\276\203\351\253\230\357\274\214\344\275\206\345\256\236\351\231\205\344\275\277\347\224\250\344\275\223\351\252\214\344\270\215\344\275\263\347\232\204\347\216\260\350\261\241\343\200\202\012\345\275\223\344\275\240\351\201\207\345\210\260\346\250\241\347\263\212\346\265\213\351\200\237\346\227\266\357\274\214\350\257\267\345\260\275\345\217\257\350\203\275\345\220\221\346\210\221\344\273\254\346\217\220\344\272\244\345\207\206\347\241\256\347\232\204\346\265\213\351\200\237\351\223\276\346\216\245\072\040\143\150\163\162\143\040\151\163\163\165\145"; diff --git a/src/rawstr4c.md b/src/rawstr4c.md index 86071bc..9fad98a 100644 --- a/src/rawstr4c.md +++ b/src/rawstr4c.md @@ -2,10 +2,10 @@ ! SPDX-License-Identifier: GPL-3.0-or-later ! ------------------------------------------------------------- ! Config Type : rawstr4c (Markdown) - ! Config Authors: Aoran Zeng - ! Contributors : Nil Null + ! Config Authors: 曾奥然 + ! Contributors : Nil Null ! Created On : <2025-07-22> - ! Last Modified : <2025-08-09> + ! Last Modified : <2025-08-22> ! ---------------------------------------------------------- --> # [rawstr4c] input for chsrc @@ -72,7 +72,7 @@ 邀请您担任 Chef, 为用户把关您熟悉的 recipe 源代码地址: https://github.com/RubyMetric/chsrc - 成为维护者: https://github.com/RubyMetric/chsrc/issues/130 + 成为维护者: https://github.com/RubyMetric/chsrc/issues/275 ```
@@ -123,7 +123,7 @@ MAINTAIN: We invite you to become a Chef to ensure the quality of recipes you are familiar with for users: Source Code: @url@ - Become a Maintainer: https://github.com/RubyMetric/chsrc/issues/130 + Become a Maintainer: https://github.com/RubyMetric/chsrc/issues/275 ```
@@ -189,7 +189,7 @@ Written by Aoran Zeng, Heng Guo and contributors. (See chsrc-main.c) ## 最后告诉用户一些维护信息 -- name = `last_message` +- name = `op_epilogue` ``` diff --git a/src/recipe/lang/Clojure.c b/src/recipe/lang/Clojure.c index c3b0db7..e052f81 100644 --- a/src/recipe/lang/Clojure.c +++ b/src/recipe/lang/Clojure.c @@ -7,24 +7,22 @@ def_target(pl_clojure, "clojure/clojars/cloj/lein"); void pl_clojure_prelude () { - use_this(pl_clojure); - chef_allow_s(pl_clojure); + chef_prep_this (pl_clojure, s); chef_set_created_on (this, "2023-09-10"); chef_set_last_updated (this, "2025-08-10"); - chef_set_sources_last_updated (this, "2025-07-14"); + chef_set_sources_last_updated (this, "2025-08-21"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 0); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 1, "@hezonglun"); chef_allow_local_mode (this, FullyCan, NULL, NULL); chef_forbid_english(this); chef_allow_user_define(this); def_sources_begin() - {&UpstreamProvider, NULL, DelegateToUpstream}, + {&UpstreamProvider,"https://repo.clojars.org/", DelegateToUpstream}, {&MirrorZ, "https://mirrors.cernet.edu.cn/clojars/", DelegateToMirror}, {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/clojars/", DelegateToMirror}, {&Nju, "https://mirror.nju.edu.cn/clojars/", DelegateToMirror}, @@ -38,7 +36,7 @@ pl_clojure_prelude () void pl_clojure_setsrc (char *option) { - use_this_source(pl_clojure); + chsrc_use_this_source (pl_clojure); if (chsrc_in_local_mode()) { diff --git a/src/recipe/lang/Dart/Flutter.c b/src/recipe/lang/Dart/Flutter.c index 0139575..3fe1332 100644 --- a/src/recipe/lang/Dart/Flutter.c +++ b/src/recipe/lang/Dart/Flutter.c @@ -7,19 +7,15 @@ def_target(pl_dart_flutter, "flutter"); void pl_dart_flutter_prelude (void) { - use_this(pl_dart_flutter); - chef_allow_gsr(pl_dart_flutter); + chef_prep_this (pl_dart_flutter, gsr); chef_set_created_on (this, "2023-09-10"); chef_set_last_updated (this, "2025-07-11"); chef_set_sources_last_updated (this, "2025-04-15"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 2, - "czyt", "czyt.go@gmail.com", - "MadDogOwner", "xiaoran@xrgzs.top"); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 2, "@czyt", "@xrgzs"); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_allow_english(this); @@ -55,13 +51,13 @@ pl_dart_flutter_getsrc (char *option) void pl_dart_flutter_setsrc (char *option) { - use_this_source(pl_dart_flutter); + chsrc_use_this_source (pl_dart_flutter); char *w = NULL; char *cmd = NULL; if (xy_on_windows) { - cmd = xy_strjoin (3, "setx FLUTTER_STORAGE_BASE_URL \"", source.url, "\""); + cmd = xy_strcat (3, "setx FLUTTER_STORAGE_BASE_URL \"", source.url, "\""); chsrc_run (cmd, RunOpt_No_Last_New_Line); } else @@ -70,7 +66,7 @@ pl_dart_flutter_setsrc (char *option) char *bashrc = xy_bashrc; chsrc_backup (zshrc); - w = xy_strjoin (3, "export FLUTTER_STORAGE_BASE_URL=\"", source.url, "\"\n"); + w = xy_strcat (3, "export FLUTTER_STORAGE_BASE_URL=\"", source.url, "\"\n"); chsrc_append_to_file (w, zshrc); if (xy_file_exist (bashrc)) diff --git a/src/recipe/lang/Dart/Pub.c b/src/recipe/lang/Dart/Pub.c index e53eee2..19c6078 100644 --- a/src/recipe/lang/Dart/Pub.c +++ b/src/recipe/lang/Dart/Pub.c @@ -7,19 +7,15 @@ def_target(pl_dart, "dart/pub"); void pl_dart_prelude (void) { - use_this(pl_dart); - chef_allow_gsr(pl_dart); + chef_prep_this (pl_dart, gsr); chef_set_created_on (this, "2023-09-10"); chef_set_last_updated (this, "2025-07-11"); chef_set_sources_last_updated (this, "2025-04-15"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 2, - "czyt", "czyt.go@gmail.com", - "MadDogOwner", "xiaoran@xrgzs.top"); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 2, "@czyt", "@xrgzs"); chef_allow_local_mode (this, FullyCan, NULL, NULL); chef_allow_english(this); @@ -51,13 +47,13 @@ pl_dart_getsrc (char *option) void pl_dart_setsrc (char *option) { - use_this_source(pl_dart); + chsrc_use_this_source (pl_dart); char *w = NULL; char *cmd = NULL; if (xy_on_windows) { - cmd = xy_strjoin (3, "setx PUB_HOSTED_URL \"", source.url, "\""); + cmd = xy_strcat (3, "setx PUB_HOSTED_URL \"", source.url, "\""); chsrc_run (cmd, RunOpt_No_Last_New_Line); } else @@ -66,7 +62,7 @@ pl_dart_setsrc (char *option) char *bashrc = xy_bashrc; chsrc_backup (zshrc); - w = xy_strjoin (3, "export PUB_HOSTED_URL=\"", source.url, "\"\n"); + w = xy_strcat (3, "export PUB_HOSTED_URL=\"", source.url, "\"\n"); chsrc_append_to_file (w, zshrc); diff --git a/src/recipe/lang/Go.c b/src/recipe/lang/Go.c index 7fb01e0..d3a2559 100644 --- a/src/recipe/lang/Go.c +++ b/src/recipe/lang/Go.c @@ -21,19 +21,15 @@ def_target(pl_go, "go/golang/goproxy"); void pl_go_prelude () { - use_this(pl_go); - chef_allow_gsr(pl_go); + chef_prep_this (pl_go, gsr); chef_set_created_on (this, "2023-08-30"); chef_set_last_updated (this, "2025-08-10"); chef_set_sources_last_updated (this, "2025-07-12"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 2, - "czyt", "czyt.go@gmail.com", - "Rui Yang", "techoc@foxmail.com"); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 2, "@czyt", "@techoc"); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_forbid_english(this); @@ -84,12 +80,12 @@ pl_go_setsrc (char *option) { pl_go_check_cmd (); - use_this_source(pl_go); + chsrc_use_this_source (pl_go); char *cmd = "go env -w GO111MODULE=on"; chsrc_run (cmd, RunOpt_Default); - cmd = xy_strjoin (3, "go env -w GOPROXY=", source.url, ",direct"); + cmd = xy_strcat (3, "go env -w GOPROXY=", source.url, ",direct"); chsrc_run (cmd, RunOpt_Default); chsrc_conclude (&source); diff --git a/src/recipe/lang/Haskell.c b/src/recipe/lang/Haskell.c index 60d7983..c49fd1e 100644 --- a/src/recipe/lang/Haskell.c +++ b/src/recipe/lang/Haskell.c @@ -7,24 +7,22 @@ def_target(pl_haskell, "haskell/cabal/stack/hackage"); void pl_haskell_prelude () { - use_this(pl_haskell); - chef_allow_s(pl_haskell); + chef_prep_this (pl_haskell, s); chef_set_created_on (this, "2023-09-10"); chef_set_last_updated (this, "2025-08-10"); - chef_set_sources_last_updated (this, "2023-09-10"); + chef_set_sources_last_updated (this, "2025-08-22"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 0); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 1, "@hezonglun"); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_forbid_english(this); chef_allow_user_define(this); def_sources_begin() - {&UpstreamProvider, NULL, DelegateToUpstream}, + {&UpstreamProvider, "https://hackage.haskell.org", DelegateToUpstream}, {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/hackage", DelegateToMirror}, {&Bfsu, "https://mirrors.bfsu.edu.cn/hackage", DelegateToMirror}, {&Nju, "https://mirror.nju.edu.cn/hackage", DelegateToMirror}, @@ -41,7 +39,7 @@ pl_haskell_prelude () void pl_haskell_setsrc (char *option) { - use_this_source(pl_haskell); + chsrc_use_this_source (pl_haskell); char *content = xy_str_gsub (RAWSTR_pl_haskell_cabal_config, "@url@", source.url); @@ -55,12 +53,12 @@ pl_haskell_setsrc (char *option) config = "~/.cabal/config"; } - chsrc_note2 (xy_strjoin (3, "请向 ", config, " 中手动添加:")); + chsrc_note2 (xy_strcat (3, "请向 ", config, " 中手动添加:")); println (content); config = xy_normalize_path ("~/.stack/config.yaml"); content = xy_str_gsub (RAWSTR_pl_haskell_stackage_yaml, "@url@", source.url); - chsrc_note2 (xy_strjoin (3, "请向 ", config, " 中手动添加:")); + chsrc_note2 (xy_strcat (3, "请向 ", config, " 中手动添加:")); println (content); chsrc_conclude (&source); diff --git a/src/recipe/lang/Java.c b/src/recipe/lang/Java.c index c3fd705..c374948 100644 --- a/src/recipe/lang/Java.c +++ b/src/recipe/lang/Java.c @@ -7,18 +7,15 @@ def_target(pl_java, "java/maven/mvn/maven-daemon/mvnd/gradle"); void pl_java_prelude () { - use_this(pl_java); - chef_allow_gsr(pl_java); + chef_prep_this (pl_java, gsr); chef_set_created_on (this, "2023-08-31"); chef_set_last_updated (this, "2025-08-10"); chef_set_sources_last_updated (this, "2024-12-18"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 1, - "BingChunMoLi", "bingchunmoli@bingchunmoli.com"); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 1, "@BingChunMoLi"); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_forbid_english(this); @@ -85,7 +82,6 @@ pl_java_find_maven_config () return "~/.m2/settings.xml"; } - char * pl_java_find_maven_daemon_config () { @@ -114,12 +110,12 @@ pl_java_getsrc (char *option) if (maven_exist) { char *maven_config = pl_java_find_maven_config (); - chsrc_note2 (xy_2strjoin ("请查看 ", maven_config)); + chsrc_note2 (xy_2strcat ("请查看 ", maven_config)); } if(maven_daemon_exist) { char *maven_config = pl_java_find_maven_daemon_config (); - chsrc_note2 (xy_2strjoin ("请查看 ", maven_config)); + chsrc_note2 (xy_2strcat ("请查看 ", maven_config)); } } @@ -137,7 +133,7 @@ pl_java_setsrc (char *option) bool maven_exist, gradle_exist, maven_daemon_exist; pl_java_check_cmd (&maven_exist, &gradle_exist, &maven_daemon_exist); - use_this_source(pl_java); + chsrc_use_this_source(pl_java); use_custom_user_agent(); if (maven_exist) { @@ -145,7 +141,7 @@ pl_java_setsrc (char *option) file = xy_str_gsub (file, "@name@", source.mirror->name); file = xy_str_gsub (file, "@url@", source.url); char *maven_config = pl_java_find_maven_config (); - chsrc_note2 (xy_strjoin (3, "请在 maven 配置文件 ", maven_config, " 中添加:")); + chsrc_note2 (xy_strcat (3, "请在 maven 配置文件 ", maven_config, " 中添加:")); println (file); } diff --git a/src/recipe/lang/JavaScript/Bun.c b/src/recipe/lang/JavaScript/Bun.c index 3f3780d..bf3d3a9 100644 --- a/src/recipe/lang/JavaScript/Bun.c +++ b/src/recipe/lang/JavaScript/Bun.c @@ -7,26 +7,21 @@ def_target(pl_js_bun, "bun"); void pl_js_bun_prelude (void) { - use_this(pl_js_bun); - chef_allow_gsr(pl_js_bun); + chef_prep_this (pl_js_bun, gsr); chef_set_created_on (this, "2024-09-29"); chef_set_last_updated (this, "2025-07-22"); chef_set_sources_last_updated (this, "2025-07-22"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 1, - "Lontten", "lontten@163.com"); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 1, "@lontten"); chef_allow_local_mode (this, FullyCan, NULL, NULL); chef_allow_english(this); chef_allow_user_define(this); - // 用的是 npm Registry 的源,所以使用 pl_js_group 的源 - this->sources = pl_js_group_target.sources; - this->sources_n = pl_js_group_target.sources_n; + chef_use_other_target_sources (this, &pl_js_group_target); } /** @@ -62,7 +57,7 @@ pl_js_bun_setsrc (char *option) } else { - chsrc_note2 (xy_strjoin (3, "请手动写入以下内容到 ", xy_normalize_path ("~/.bunfig.toml"), " 文件中")); + chsrc_note2 (xy_strcat (3, "请手动写入以下内容到 ", xy_normalize_path ("~/.bunfig.toml"), " 文件中")); } println (content); diff --git a/src/recipe/lang/JavaScript/JavaScript.c b/src/recipe/lang/JavaScript/JavaScript.c index 9fd6dbf..0c9faef 100644 --- a/src/recipe/lang/JavaScript/JavaScript.c +++ b/src/recipe/lang/JavaScript/JavaScript.c @@ -70,8 +70,7 @@ pl_js_group_setsrc (char *option) chsrc_set_target_group_mode (); - use_this(pl_js_group); - Source_t source = chsrc_yield_source_and_confirm (this, option); + chsrc_use_this_source (pl_js_group); if (npm_exist) { diff --git a/src/recipe/lang/JavaScript/Yarn.c b/src/recipe/lang/JavaScript/Yarn.c index d5662be..a80515f 100644 --- a/src/recipe/lang/JavaScript/Yarn.c +++ b/src/recipe/lang/JavaScript/Yarn.c @@ -7,26 +7,21 @@ def_target(pl_js_yarn, "yarn"); void pl_js_yarn_prelude (void) { - use_this(pl_js_yarn); - chef_allow_gsr(pl_js_yarn); + chef_prep_this (pl_js_yarn, gsr); chef_set_created_on (this, "2023-09-09"); chef_set_last_updated (this, "2025-07-11"); chef_set_sources_last_updated (this, "2025-07-11"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 1, - "Mr. Will", "mr.will.com@outlook.com"); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 1, "@MrWillCom"); chef_allow_local_mode (this, FullyCan, NULL, NULL); chef_allow_english(this); chef_allow_user_define(this); - // 使用 pl_js_group 的源 - this->sources = pl_js_group_target.sources; - this->sources_n = pl_js_group_target.sources_n; + chef_use_other_target_sources (this, &pl_js_group_target); } static double @@ -68,9 +63,9 @@ pl_js_yarn_setsrc (char *option) if (pl_js_yarn_get_yarn_version () >= 2) { if (chsrc_in_local_mode()) // Yarn 默认情况下就是基于本项目换源 - cmd = xy_2strjoin ("yarn config set npmRegistryServer ", source.url); + cmd = xy_2strcat ("yarn config set npmRegistryServer ", source.url); else - cmd = xy_2strjoin ("yarn config set npmRegistryServer --home ", source.url); + cmd = xy_2strcat ("yarn config set npmRegistryServer --home ", source.url); chsrc_run (cmd, RunOpt_No_Last_New_Line); } @@ -84,7 +79,7 @@ pl_js_yarn_setsrc (char *option) return; } // 不再阻止换源命令输出到终端,即不再调用 xy_str_to_quietcmd() - cmd = xy_2strjoin ("yarn config set registry ", source.url); + cmd = xy_2strcat ("yarn config set registry ", source.url); chsrc_run (cmd, RunOpt_No_Last_New_Line); } diff --git a/src/recipe/lang/JavaScript/common.h b/src/recipe/lang/JavaScript/common.h index cb00110..03e24ee 100644 --- a/src/recipe/lang/JavaScript/common.h +++ b/src/recipe/lang/JavaScript/common.h @@ -14,17 +14,16 @@ def_target(pl_js_group, "js/javascript/node/nodejs"); void pl_js_group_prelude (void) { - use_this(pl_js_group); - chef_allow_gsr(pl_js_group); + chef_prep_this (pl_js_group, gsr); chef_set_created_on (this, "2023-09-09"); chef_set_last_updated (this, "2025-07-11"); chef_set_sources_last_updated (this, "2025-07-11"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 1, "happy game", "happygame1024@gmail.com"); - chef_set_contributors (this,0); + chef_set_chef (this, "@happy-game"); + // 组换源的 leader target 应把所有 follower target 的贡献者都记录过来 + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 2, "@lontten", "@MrWillCom"); chef_allow_local_mode (this, PartiallyCan, "支持 npm, yarn v2, pnpm, 不支持 yarn v1", @@ -45,22 +44,20 @@ pl_js_group_prelude (void) -def_target(pl_js_nodejs_binary, "__internal_use_nodejs_binary__"); +def_target(pl_js_nodejs_binary, "__internal_target_nodejs_binary__"); void pl_js_nodejs_binary_prelude (void) { - use_this(pl_js_nodejs_binary); - chef_allow_gsr(pl_js_group); + chef_prep_this (pl_js_nodejs_binary, NOOP); chef_set_created_on (this, "2023-09-09"); - chef_set_last_updated (this, "2025-07-11"); + chef_set_last_updated (this, "2025-08-22"); chef_set_sources_last_updated (this, "2025-07-11"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 0); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 0); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_allow_english(this); diff --git a/src/recipe/lang/JavaScript/npm.c b/src/recipe/lang/JavaScript/npm.c index c723d6c..c359ddf 100644 --- a/src/recipe/lang/JavaScript/npm.c +++ b/src/recipe/lang/JavaScript/npm.c @@ -7,26 +7,21 @@ def_target(pl_js_npm, "npm"); void pl_js_npm_prelude (void) { - use_this(pl_js_npm); - chef_allow_gsr(pl_js_npm); + chef_prep_this (pl_js_npm, gsr); chef_set_created_on (this, "2023-08-30"); chef_set_last_updated (this, "2025-07-11"); chef_set_sources_last_updated (this, "2025-07-11"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 1, - "Mr. Will", "mr.will.com@outlook.com"); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 1, "@MrWillCom"); chef_allow_local_mode (this, FullyCan, NULL, NULL); chef_allow_english(this); chef_allow_user_define(this); - // 使用 pl_js_group 的源 - this->sources = pl_js_group_target.sources; - this->sources_n = pl_js_group_target.sources_n; + chef_use_other_target_sources (this, &pl_js_group_target); } @@ -50,9 +45,9 @@ pl_js_npm_setsrc (char *option) char *cmd = NULL; if (chsrc_in_local_mode()) - cmd = xy_2strjoin ("npm config --location project set registry ", source.url); + cmd = xy_2strcat ("npm config --location project set registry ", source.url); else - cmd = xy_2strjoin ("npm config set registry ", source.url); + cmd = xy_2strcat ("npm config set registry ", source.url); chsrc_run (cmd, RunOpt_No_Last_New_Line); diff --git a/src/recipe/lang/JavaScript/nvm.c b/src/recipe/lang/JavaScript/nvm.c index 6a81141..91676ab 100644 --- a/src/recipe/lang/JavaScript/nvm.c +++ b/src/recipe/lang/JavaScript/nvm.c @@ -7,17 +7,15 @@ def_target(pl_js_nvm, "nvm"); void pl_js_nvm_prelude (void) { - use_this(pl_js_nvm); - chef_allow_gsr(pl_js_nvm); + chef_prep_this (pl_js_nvm, gsr); chef_set_created_on (this, "2024-09-23"); chef_set_last_updated (this, "2025-06-19"); chef_set_sources_last_updated (this, "2025-06-19"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 0); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 0); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_allow_english(this); @@ -25,9 +23,7 @@ pl_js_nvm_prelude (void) chef_set_note (this, "nvm 不支持 Fish shell", "nvm does not support Fish"); - // 使用 pl_js_nodejs_binary 的源 - this->sources = pl_js_nodejs_binary_target.sources; - this->sources_n = pl_js_nodejs_binary_target.sources_n; + chef_use_other_target_sources (this, &pl_js_nodejs_binary_target); } @@ -50,7 +46,7 @@ pl_js_nvm_setsrc (char *option) { Source_t source = chsrc_yield_source_and_confirm (&pl_js_nodejs_binary_target, option); - char *w = xy_strjoin (3, "export NVM_NODEJS_ORG_MIRROR=", source.url, "\n"); + char *w = xy_strcat (3, "export NVM_NODEJS_ORG_MIRROR=", source.url, "\n"); char *zshrc = xy_zshrc; char *bashrc = xy_bashrc; diff --git a/src/recipe/lang/JavaScript/pnpm.c b/src/recipe/lang/JavaScript/pnpm.c index 07e597c..42577ba 100644 --- a/src/recipe/lang/JavaScript/pnpm.c +++ b/src/recipe/lang/JavaScript/pnpm.c @@ -7,25 +7,21 @@ def_target(pl_js_pnpm, "pnpm"); void pl_js_pnpm_prelude (void) { - use_this(pl_js_pnpm); - chef_allow_gsr(pl_js_pnpm); + chef_prep_this (pl_js_pnpm, gsr); chef_set_created_on (this, "2024-04-18"); chef_set_last_updated (this, "2025-07-11"); chef_set_sources_last_updated (this, "2025-07-11"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 0); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 0); chef_allow_local_mode (this, FullyCan, NULL, NULL); chef_allow_english(this); chef_allow_user_define(this); - // 使用 pl_js_group 的源 - this->sources = pl_js_group_target.sources; - this->sources_n = pl_js_group_target.sources_n; + chef_use_other_target_sources (this, &pl_js_group_target); } @@ -50,9 +46,9 @@ pl_js_pnpm_setsrc (char *option) char *cmd = NULL; if (chsrc_in_local_mode()) - cmd = xy_2strjoin ("pnpm config --location project set registry ", source.url); + cmd = xy_2strcat ("pnpm config --location project set registry ", source.url); else - cmd = xy_2strjoin ("pnpm config -g set registry ", source.url); + cmd = xy_2strcat ("pnpm config -g set registry ", source.url); chsrc_run (cmd, RunOpt_No_Last_New_Line); diff --git a/src/recipe/lang/Julia.c b/src/recipe/lang/Julia.c index c4e191d..632d83e 100644 --- a/src/recipe/lang/Julia.c +++ b/src/recipe/lang/Julia.c @@ -7,24 +7,22 @@ def_target(pl_julia, "julia"); void pl_julia_prelude () { - use_this(pl_julia); - chef_allow_gs(pl_julia); + chef_prep_this (pl_julia, gs); chef_set_created_on (this, "2023-08-31"); chef_set_last_updated (this, "2025-08-10"); - chef_set_sources_last_updated (this, "2025-07-14"); + chef_set_sources_last_updated (this, "2025-08-22"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 0); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 1, "@hezonglun"); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_allow_english(this); chef_allow_user_define(this); def_sources_begin() - {&UpstreamProvider, NULL, DelegateToUpstream}, + {&UpstreamProvider, "https://pkg.julialang.org", DelegateToUpstream}, {&Pku, "https://mirrors.pku.edu.cn/julia", DelegateToMirror}, {&Nju, "https://mirror.nju.edu.cn/julia", DelegateToMirror}, {&Iscas, "https://mirror.iscas.ac.cn/julia", DelegateToMirror} @@ -54,9 +52,9 @@ pl_julia_getsrc (char *option) void pl_julia_setsrc (char *option) { - use_this_source(pl_julia); + chsrc_use_this_source (pl_julia); - char *w = xy_strjoin (3, "ENV[\"JULIA_PKG_SERVER\"] = \"", source.url, "\""); + char *w = xy_strcat (3, "ENV[\"JULIA_PKG_SERVER\"] = \"", source.url, "\""); chsrc_append_to_file (w, PL_Julia_Config); diff --git a/src/recipe/lang/Lua.c b/src/recipe/lang/Lua.c index fcdbd7b..52b81f3 100644 --- a/src/recipe/lang/Lua.c +++ b/src/recipe/lang/Lua.c @@ -14,24 +14,22 @@ def_target(pl_lua, "lua/luarocks"); void pl_lua_prelude () { - use_this(pl_lua); - chef_allow_gs(pl_lua); + chef_prep_this (pl_lua, gs); chef_set_created_on (this, "2023-09-27"); chef_set_last_updated (this, "2025-08-10"); - chef_set_sources_last_updated (this, "2025-07-14"); + chef_set_sources_last_updated (this, "2025-08-22"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 0); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 1, "@hezonglun"); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_forbid_english(this); chef_allow_user_define(this); def_sources_begin() - {&UpstreamProvider, NULL, DelegateToUpstream}, + {&UpstreamProvider, "https://luarocks.org", DelegateToUpstream}, {&Api7, "https://luarocks.cn", DelegateToMirror} def_sources_end() } @@ -50,17 +48,16 @@ pl_lua_getsrc (char *option) void pl_lua_setsrc (char *option) { - use_this(pl_lua); - Source_t source = chsrc_yield_source_and_confirm (this, option); + chsrc_use_this_source (pl_lua); - char *config = xy_strjoin (3, "rocks_servers = {\n" + char *config = xy_strcat (3, "rocks_servers = {\n" " \"", source.url, "\"\n" "}"); chsrc_note2 ("请手动修改 ~/.luarocks/config.lua 文件 (用于下载):"); println (config); - char *upload_config = xy_strjoin (3, "key = \"\"\n" + char *upload_config = xy_strcat (3, "key = \"\"\n" "server = \"", source.url, "\""); chsrc_note2 ("请手动修改 ~/.luarocks/upload_config.lua 文件 (用于上传):"); diff --git a/src/recipe/lang/NuGet.c b/src/recipe/lang/NuGet.c index ec54878..19b0bea 100644 --- a/src/recipe/lang/NuGet.c +++ b/src/recipe/lang/NuGet.c @@ -7,17 +7,15 @@ def_target(pl_nuget, "nuget/net/.net/dotnet"); void pl_nuget_prelude () { - use_this(pl_nuget); - chef_allow_gs(pl_nuget); + chef_prep_this (pl_nuget, gs); chef_set_created_on (this, "2023-09-10"); chef_set_last_updated (this, "2025-08-10"); chef_set_sources_last_updated (this, "2024-04-18"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 0); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 0); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_forbid_english(this); diff --git a/src/recipe/lang/OCaml.c b/src/recipe/lang/OCaml.c index 0b419d7..d5e064f 100644 --- a/src/recipe/lang/OCaml.c +++ b/src/recipe/lang/OCaml.c @@ -7,17 +7,15 @@ def_target(pl_ocaml, "ocaml/opam"); void pl_ocaml_prelude () { - use_this(pl_ocaml); - chef_allow_gs(pl_ocaml); + chef_prep_this (pl_ocaml, gs); chef_set_created_on (this, "2023-09-15"); chef_set_last_updated (this, "2025-08-10"); chef_set_sources_last_updated (this, "2025-07-14"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 0); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 0); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_forbid_english(this); @@ -53,16 +51,16 @@ pl_ocaml_setsrc (char *option) { pl_ocaml_check_cmd (); - use_this_source(pl_ocaml); + chsrc_use_this_source (pl_ocaml); - char *cmd = xy_strjoin (3, "opam repo set-url default ", + char *cmd = xy_strcat (3, "opam repo set-url default ", source.url, " --all --set-default"); chsrc_run (cmd, RunOpt_Default); chsrc_alert2 ("如果是首次使用 opam ,请使用以下命令进行初始化"); - println (xy_2strjoin ("opam init default ", source.url)); + println (xy_2strcat ("opam init default ", source.url)); chsrc_conclude (&source); } diff --git a/src/recipe/lang/PHP.c b/src/recipe/lang/PHP.c index af33dd7..fbea3e7 100644 --- a/src/recipe/lang/PHP.c +++ b/src/recipe/lang/PHP.c @@ -7,17 +7,15 @@ def_target(pl_php, "php/composer"); void pl_php_prelude () { - use_this(pl_php); - chef_allow_gs(pl_php); + chef_prep_this (pl_php, gs); chef_set_created_on (this, "2023-08-30"); chef_set_last_updated (this, "2025-08-10"); chef_set_sources_last_updated (this, "2024-09-14"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 0); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 0); chef_allow_local_mode (this, FullyCan, NULL, NULL); chef_forbid_english(this); @@ -57,8 +55,7 @@ pl_php_setsrc (char *option) { pl_php_check_cmd (); - use_this(pl_php); - Source_t source = chsrc_yield_source_and_confirm (this, option); + chsrc_use_this_source (pl_php); char *where = " -g "; if (chsrc_in_local_mode()) @@ -66,7 +63,7 @@ pl_php_setsrc (char *option) where = " "; } - char *cmd = xy_strjoin (4, "composer config", where, "repo.packagist composer ", source.url); + char *cmd = xy_strcat (4, "composer config", where, "repo.packagist composer ", source.url); chsrc_run (cmd, RunOpt_Default); chsrc_conclude (&source); diff --git a/src/recipe/lang/Perl.c b/src/recipe/lang/Perl.c index e0bc629..f998bb4 100644 --- a/src/recipe/lang/Perl.c +++ b/src/recipe/lang/Perl.c @@ -7,24 +7,22 @@ def_target(pl_perl, "perl/cpan"); void pl_perl_prelude () { - use_this(pl_perl); - chef_allow_gs(pl_perl); + chef_prep_this (pl_perl, gs); chef_set_created_on (this, "2023-09-31"); chef_set_last_updated (this, "2025-08-10"); - chef_set_sources_last_updated (this, "2024-05-24"); + chef_set_sources_last_updated (this, "2025-08-21"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 0); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 1, "@hezonglun"); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_forbid_english(this); chef_allow_user_define(this); def_sources_begin() - {&UpstreamProvider, NULL, DelegateToUpstream}, + {&UpstreamProvider, "https://www.cpan.org/", DelegateToUpstream}, {&Bfsu, "https://mirrors.bfsu.edu.cn/CPAN/", DelegateToMirror}, {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/CPAN/", DelegateToMirror}, {&Bjtu, "https://mirror.bjtu.edu.cn/cpan/", DelegateToMirror}, @@ -59,9 +57,9 @@ pl_perl_getsrc (char *option) void pl_perl_setsrc (char *option) { - use_this_source(pl_perl); + chsrc_use_this_source (pl_perl); - char *cmd = xy_strjoin (3, + char *cmd = xy_strcat (3, "perl -MCPAN -e \"CPAN::HandleConfig->load(); CPAN::HandleConfig->edit('urllist', 'unshift', '", source.url, "'); CPAN::HandleConfig->commit()\""); chsrc_run (cmd, RunOpt_Default); diff --git a/src/recipe/lang/Python/PDM.c b/src/recipe/lang/Python/PDM.c index ed5084c..a52b582 100644 --- a/src/recipe/lang/Python/PDM.c +++ b/src/recipe/lang/Python/PDM.c @@ -7,25 +7,21 @@ def_target(pl_python_pdm, "pdm"); void pl_python_pdm_prelude (void) { - use_this(pl_python_pdm); - chef_allow_gsr(pl_python_pdm); + chef_prep_this (pl_python_pdm, gsr); chef_set_created_on (this, "2024-06-05"); chef_set_last_updated (this, "2025-07-11"); chef_set_sources_last_updated (this, "2025-07-11"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 0); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 0); - chef_allow_local_mode (this, FullyCan, "支持项目级配置", "Supports project-level configuration"); + chef_allow_local_mode (this, FullyCan, NULL, NULL); chef_allow_english(this); chef_allow_user_define(this); - // 使用 pl_python_group 的源 - this->sources = pl_python_group_target.sources; - this->sources_n = pl_python_group_target.sources_n; + chef_use_other_target_sources (this, &pl_python_group_target); } @@ -52,9 +48,9 @@ pl_python_pdm_setsrc (char *option) char *cmd = NULL; if (chsrc_in_local_mode()) - cmd = xy_2strjoin ("pdm config --local pypi.url ", source.url); + cmd = xy_2strcat ("pdm config --local pypi.url ", source.url); else - cmd = xy_2strjoin ("pdm config --global pypi.url ", source.url); + cmd = xy_2strcat ("pdm config --global pypi.url ", source.url); chsrc_run (cmd, RunOpt_No_Last_New_Line); diff --git a/src/recipe/lang/Python/Poetry.c b/src/recipe/lang/Python/Poetry.c index 8392059..02e9580 100644 --- a/src/recipe/lang/Python/Poetry.c +++ b/src/recipe/lang/Python/Poetry.c @@ -7,25 +7,21 @@ def_target(pl_python_poetry, "poetry"); void pl_python_poetry_prelude (void) { - use_this(pl_python_poetry); - chef_allow_gsr(pl_python_poetry); + chef_prep_this (pl_python_poetry, gsr); chef_set_created_on (this, "2024-08-08"); chef_set_last_updated (this, "2025-07-11"); chef_set_sources_last_updated (this, "2025-07-11"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 0); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 0); chef_allow_local_mode (this, FullyCan, "Poetry 默认使用项目级换源", "Poetry uses project-level source changing by default"); chef_allow_english(this); chef_allow_user_define(this); - // 使用 pl_python_group 的源 - this->sources = pl_python_group_target.sources; - this->sources_n = pl_python_group_target.sources_n; + chef_use_other_target_sources (this, &pl_python_group_target); } void @@ -50,7 +46,7 @@ pl_python_poetry_setsrc (char *option) if (!chsrc_in_local_mode()) chsrc_alert2 ("Poetry 仅支持项目级换源"); - cmd = xy_2strjoin ("poetry source add my_mirror ", source.url); + cmd = xy_2strcat ("poetry source add my_mirror ", source.url); chsrc_run (cmd, RunOpt_No_Last_New_Line); if (chsrc_in_standalone_mode()) diff --git a/src/recipe/lang/Python/Python.c b/src/recipe/lang/Python/Python.c index 6a4b439..e7809f0 100644 --- a/src/recipe/lang/Python/Python.c +++ b/src/recipe/lang/Python/Python.c @@ -58,8 +58,7 @@ pl_python_group_setsrc (char *option) chsrc_set_target_group_mode (); - use_this(pl_python_group); - Source_t source = chsrc_yield_source_and_confirm (this, option); + chsrc_use_this_source (pl_python_group); // 交给后面检查命令的存在性 diff --git a/src/recipe/lang/Python/Rye.c b/src/recipe/lang/Python/Rye.c index 26b5050..fd1cbfb 100644 --- a/src/recipe/lang/Python/Rye.c +++ b/src/recipe/lang/Python/Rye.c @@ -9,25 +9,21 @@ def_target(pl_python_rye, "rye"); void pl_python_rye_prelude (void) { - use_this(pl_python_rye); - chef_allow_gsr(pl_python_rye); + chef_prep_this (pl_python_rye, gsr); chef_set_created_on (this, "2024-12-06"); chef_set_last_updated (this, "2025-08-09"); chef_set_sources_last_updated (this, "2025-08-09"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 0); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 0); - chef_allow_local_mode (this, FullyCan, "支持项目级配置", "Supports project-level configuration"); + chef_allow_local_mode (this, FullyCan, NULL, NULL); chef_allow_english(this); chef_allow_user_define(this); - // 使用 pl_python_group 的源 - this->sources = pl_python_group_target.sources; - this->sources_n = pl_python_group_target.sources_n; + chef_use_other_target_sources (this, &pl_python_group_target); } char * @@ -45,7 +41,7 @@ void pl_python_rye_getsrc (char *option) { char *rye_config = pl_python_find_rye_config (); - chsrc_note2 (xy_strjoin (3, "请查看 ", rye_config, " 配置文件中的 [[sources]] 节内容")); + chsrc_note2 (xy_strcat (3, "请查看 ", rye_config, " 配置文件中的 [[sources]] 节内容")); } @@ -64,7 +60,7 @@ pl_python_rye_setsrc (char *option) content = xy_str_gsub (content, "@2@", source.url); char *rye_config = pl_python_find_rye_config (); - chsrc_note2 (xy_strjoin (3, "请在配置文件 ", rye_config, " 中添加:")); + chsrc_note2 (xy_strcat (3, "请在配置文件 ", rye_config, " 中添加:")); println (content); chsrc_determine_chgtype (ChgType_Manual); diff --git a/src/recipe/lang/Python/common.h b/src/recipe/lang/Python/common.h index 9045dd5..85d521e 100644 --- a/src/recipe/lang/Python/common.h +++ b/src/recipe/lang/Python/common.h @@ -14,7 +14,7 @@ static char * pl_python_speed_url_constructor (const char *url, const char *user_data) { char *str = xy_str_delete_suffix (url, "/simple"); - str = xy_2strjoin (str, "/packages/56/e4/55aaac2b15af4dad079e5af329a79d961e5206589d0e02b1e8da221472ed/tensorflow-2.18.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl"); + str = xy_2strcat (str, "/packages/56/e4/55aaac2b15af4dad079e5af329a79d961e5206589d0e02b1e8da221472ed/tensorflow-2.18.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl"); return str; } @@ -22,19 +22,16 @@ pl_python_speed_url_constructor (const char *url, const char *user_data) void pl_python_group_prelude (void) { - use_this(pl_python_group); - chef_allow_gsr(pl_python_group); + chef_prep_this (pl_python_group, gsr); chef_set_created_on (this, "2023-09-03"); chef_set_last_updated (this, "2025-07-14"); chef_set_sources_last_updated (this, "2025-07-11"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 1, "happy game", "happygame1024@gmail.com"); - chef_set_contributors (this, 1, - "yongxiang", "1926885268@qq.com"); - + chef_set_chef (this, "@happy-game"); + // 组换源的 leader target 应把所有 follower target 的贡献者都记录过来 + chef_set_cooks (this, 2, "@ccmywish", "@happy-game"); + chef_set_sauciers (this, 2, "@xyx1926885268", "@Kattos"); chef_allow_local_mode (this, PartiallyCan, "部分包管理器支持项目级换源", "Some package managers support project-level source changing"); chef_allow_english(this); @@ -76,7 +73,7 @@ pl_python_check_unofficial_pkger (bool *poetry_exist, bool *pdm_exist, bool *uv_ /** - * @param[out] prog 返回 Python 的可用名,如果不可用,则返回 NULL + * @param[out] prog_name 返回 Python 的可用名,如果不可用,则返回 NULL */ void pl_python_get_py_program_name (char **prog_name) diff --git a/src/recipe/lang/Python/pip.c b/src/recipe/lang/Python/pip.c index 1a2dc41..db26c49 100644 --- a/src/recipe/lang/Python/pip.c +++ b/src/recipe/lang/Python/pip.c @@ -7,25 +7,21 @@ def_target(pl_python_pip, "pip"); void pl_python_pip_prelude (void) { - use_this(pl_python_pip); - chef_allow_gsr(pl_python_pip); + chef_prep_this (pl_python_pip, gsr); chef_set_created_on (this, "2023-09-03"); chef_set_last_updated (this, "2025-07-11"); chef_set_sources_last_updated (this, "2025-07-11"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 0); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 0); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_allow_english(this); chef_allow_user_define(this); - // 使用 pl_python_group 的源 - this->sources = pl_python_group_target.sources; - this->sources_n = pl_python_group_target.sources_n; + chef_use_other_target_sources (this, &pl_python_group_target); } @@ -35,7 +31,7 @@ pl_python_pip_getsrc (char *option) char *py_prog_name = NULL; pl_python_get_py_program_name (&py_prog_name); - char *cmd = xy_2strjoin (py_prog_name, " -m pip config get global.index-url"); + char *cmd = xy_2strcat (py_prog_name, " -m pip config get global.index-url"); chsrc_run (cmd, RunOpt_Default); } @@ -65,7 +61,7 @@ pl_python_pip_setsrc (char *option) // 这里用的是 config --user,会写入用户目录(而不是项目目录) // https://github.com/RubyMetric/chsrc/issues/39 // 经测试,Windows上调用换源命令,会写入 C:\Users\RubyMetric\AppData\Roaming\pip\pip.ini - char *cmd = xy_2strjoin (py_prog_name, xy_2strjoin (" -m pip config --user set global.index-url ", source.url)); + char *cmd = xy_2strcat (py_prog_name, xy_2strcat (" -m pip config --user set global.index-url ", source.url)); chsrc_run (cmd, RunOpt_No_Last_New_Line); if (chsrc_in_standalone_mode()) diff --git a/src/recipe/lang/Python/uv.c b/src/recipe/lang/Python/uv.c index 89314c1..83f90b1 100644 --- a/src/recipe/lang/Python/uv.c +++ b/src/recipe/lang/Python/uv.c @@ -7,27 +7,21 @@ def_target(pl_python_uv, "uv"); void pl_python_uv_prelude (void) { - use_this(pl_python_uv); - chef_allow_gsr(pl_python_uv); + chef_prep_this (pl_python_uv, gsr); chef_set_created_on (this, "2024-12-11"); chef_set_last_updated (this, "2025-08-09"); chef_set_sources_last_updated (this, "2025-08-09"); - chef_set_authors (this, 1, "happy game", "happygame1024@gmail.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 2, - "ccy", "icuichengyi@gmail.com", - "Aoran Zeng", "ccmywish@qq.com"); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@happy-game"); + chef_set_sauciers (this, 2, "@Kattos", "@ccmywish"); chef_allow_local_mode (this, FullyCan, NULL, NULL); chef_allow_english(this); chef_allow_user_define(this); - // 使用 pl_python_group 的源 - this->sources = pl_python_group_target.sources; - this->sources_n = pl_python_group_target.sources_n; + chef_use_other_target_sources (this, &pl_python_group_target); } @@ -51,7 +45,7 @@ pl_python_find_uv_config (bool mkdir) { if (chsrc_in_local_mode()) { - return xy_2strjoin (PL_Python_uv_Local_ConfigPath, PL_Python_uv_ConfigFile); + return xy_2strcat (PL_Python_uv_Local_ConfigPath, PL_Python_uv_ConfigFile); } else { @@ -66,12 +60,12 @@ pl_python_find_uv_config (bool mkdir) return NULL; } - char *config_dir = xy_2strjoin(appdata, "\\uv\\"); + char *config_dir = xy_2strcat(appdata, "\\uv\\"); if (mkdir) { chsrc_ensure_dir (config_dir); } - return xy_2strjoin (config_dir, PL_Python_uv_ConfigFile); + return xy_2strcat (config_dir, PL_Python_uv_ConfigFile); } else { @@ -80,7 +74,7 @@ pl_python_find_uv_config (bool mkdir) { chsrc_ensure_dir (PL_Python_uv_User_ConfigPath); } - return xy_2strjoin (PL_Python_uv_User_ConfigPath, PL_Python_uv_ConfigFile); + return xy_2strcat (PL_Python_uv_User_ConfigPath, PL_Python_uv_ConfigFile); } } } @@ -125,7 +119,7 @@ pl_python_uv_setsrc (char *option) const char *source_content = xy_str_gsub (RAWSTR_pl_python_uv_config_source_content, "@url@", source.url); -#if defined(XY_On_macOS) || defined(XY_On_BSD) +#if defined(XY_Build_On_macOS) || defined(XY_Build_On_BSD) char *sed_cmd = "sed -i '' "; #else char *sed_cmd = "sed -i "; diff --git a/src/recipe/lang/R.c b/src/recipe/lang/R.c index 0be2c4a..c259744 100644 --- a/src/recipe/lang/R.c +++ b/src/recipe/lang/R.c @@ -7,17 +7,15 @@ def_target(pl_r, "r/cran"); void pl_r_prelude () { - use_this(pl_r); - chef_allow_gs(pl_r); + chef_prep_this (pl_r, gs); chef_set_created_on (this, "2023-09-21"); chef_set_last_updated (this, "2025-08-10"); - chef_set_sources_last_updated (this, "2023-09-04"); + chef_set_sources_last_updated (this, "2025-08-21"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 0); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 1, "@hezonglun"); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_forbid_english(this); @@ -25,7 +23,7 @@ pl_r_prelude () // 以下注释的,是不含有bioconductor的镜像站,我们在换cran的同时,也直接帮助用户换bioconductor def_sources_begin() - {&UpstreamProvider, NULL, DelegateToUpstream}, + {&UpstreamProvider, "https://cran.r-project.org/", DelegateToUpstream}, {&Sjtug_Zhiyuan, "https://mirrors.sjtug.sjtu.edu.cn/cran/", DelegateToMirror}, // {&Ali, "https://mirrors.aliyun.com/CRAN/", DelegateToMirror}, {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/CRAN/", DelegateToMirror}, @@ -64,15 +62,15 @@ pl_r_getsrc (char *option) void pl_r_setsrc (char *option) { - use_this_source(pl_r); + chsrc_use_this_source (pl_r); char *bioconductor_url = xy_str_delete_suffix (xy_str_delete_suffix (source.url, "cran/"), "CRAN/"); - bioconductor_url = xy_2strjoin(bioconductor_url, "bioconductor"); + bioconductor_url = xy_2strcat(bioconductor_url, "bioconductor"); - const char *w1 = xy_strjoin (3, "options(\"repos\" = c(CRAN=\"", source.url, "\"))\n" ); - const char *w2 = xy_strjoin (3, "options(BioC_mirror=\"", bioconductor_url, "\")\n" ); + const char *w1 = xy_strcat (3, "options(\"repos\" = c(CRAN=\"", source.url, "\"))\n" ); + const char *w2 = xy_strcat (3, "options(BioC_mirror=\"", bioconductor_url, "\")\n" ); - char *w = xy_2strjoin (w1, w2); + char *w = xy_2strcat (w1, w2); // 或者我们调用 r.exe --slave -e 上面的内容 diff --git a/src/recipe/lang/Ruby/Ruby.c b/src/recipe/lang/Ruby/Ruby.c index d3b2643..074201f 100644 --- a/src/recipe/lang/Ruby/Ruby.c +++ b/src/recipe/lang/Ruby/Ruby.c @@ -14,17 +14,15 @@ def_target(pl_ruby, "gem/ruby/rb/rubygem/rubygems/bundler"); void pl_ruby_prelude (void) { - use_this(pl_ruby); - chef_allow_gsr(pl_ruby); + chef_prep_this (pl_ruby, gsr); chef_set_created_on (this, "2023-08-29"); chef_set_last_updated (this, "2025-08-11"); chef_set_sources_last_updated (this, "2024-12-18"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_cooks (this, 0); - chef_set_contributors (this, 0); + chef_set_chef (this, "@ccmywish"); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 0); chef_allow_local_mode (this, PartiallyCan, "支持 bundler. 不支持 gem", "Support bundler. Not support gem"); chef_allow_english(this); @@ -58,7 +56,7 @@ pl_ruby_remove_gem_source (const char *source) char *cmd = NULL; if (chef_is_url (source)) { - cmd = xy_2strjoin ("gem sources -r ", source); + cmd = xy_2strcat ("gem sources -r ", source); chsrc_run (cmd, RunOpt_Default); } return false @@ -72,14 +70,14 @@ pl_ruby_setsrc (char *option) { chsrc_ensure_program ("gem"); - use_this_source(pl_ruby); + chsrc_use_this_source (pl_ruby); char *cmd = NULL; // step1 - xy_run_iter ("gem sources -l", 0, pl_ruby_remove_gem_source); + xy_run_iter_lines ("gem sources -l", 0, pl_ruby_remove_gem_source); - cmd = xy_2strjoin ("gem source -a ", source.url); + cmd = xy_2strcat ("gem source -a ", source.url); chsrc_run (cmd, RunOpt_Default); // 我们在 step1 中,把源全部清空了,但是现在 RubyGems 的行为是: 当清空会自动给你把默认源给加回来 @@ -95,7 +93,7 @@ pl_ruby_setsrc (char *option) where = " --local "; } - cmd = xy_strjoin (4, "bundle config", where, "'mirror.https://rubygems.org' ", source.url); + cmd = xy_strcat (4, "bundle config", where, "'mirror.https://rubygems.org' ", source.url); chsrc_run (cmd, RunOpt_No_Last_New_Line); chsrc_determine_chgtype (ChgType_Auto); diff --git a/src/recipe/lang/Rust/Cargo.c b/src/recipe/lang/Rust/Cargo.c index 43a89cc..940b5a8 100644 --- a/src/recipe/lang/Rust/Cargo.c +++ b/src/recipe/lang/Rust/Cargo.c @@ -7,19 +7,15 @@ def_target(pl_rust_cargo, "rust/cargo/crate/crates"); void pl_rust_cargo_prelude (void) { - use_this(pl_rust_cargo); - chef_allow_gsr(pl_rust_cargo); + chef_prep_this (pl_rust_cargo, gsr); chef_set_created_on (this, "2023-08-30"); chef_set_last_updated (this, "2025-07-22"); chef_set_sources_last_updated (this, "2025-06-18"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 1, - "Mikachu2333", "mikachu.23333@zohomail.com"); - + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 1, "@Mikachu2333"); chef_allow_local_mode (this, PartiallyCan, "可以基于本项目换源吗?请帮助确认", "Can it change sources based on this project? Please help confirm"); chef_forbid_english (this); @@ -66,13 +62,13 @@ pl_rust_cargo_getsrc (char *option) void pl_rust_cargo_setsrc (char *option) { - use_this_source(pl_rust_cargo); + chsrc_use_this_source (pl_rust_cargo); char *content = RAWSTR_pl_rust_cargo_config; content = xy_str_gsub (content, "@url@", source.url); - chsrc_note2 (xy_strjoin (3, "请手动写入以下内容到 ", xy_normalize_path ("~/.cargo/config.toml"), " 文件中:")); + chsrc_note2 (xy_strcat (3, "请手动写入以下内容到 ", xy_normalize_path ("~/.cargo/config.toml"), " 文件中:")); println (content); chsrc_determine_chgtype (ChgType_Auto); diff --git a/src/recipe/lang/Rust/rustup.c b/src/recipe/lang/Rust/rustup.c index 637c236..2ad6364 100644 --- a/src/recipe/lang/Rust/rustup.c +++ b/src/recipe/lang/Rust/rustup.c @@ -10,19 +10,15 @@ def_target(pl_rust_rustup, "rustup"); void pl_rust_rustup_prelude (void) { - use_this(pl_rust_rustup); - chef_allow_gsr(pl_rust_rustup); + chef_prep_this (pl_rust_rustup, gsr); chef_set_created_on (this, "2024-10-02"); chef_set_last_updated (this, "2025-08-07"); chef_set_sources_last_updated (this, "2025-08-07"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 2, - "Yangmoooo", "yangmoooo@outlook.com", - "Mikachu2333", "mikachu.23333@zohomail.com"); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 2, "@Yangmoooo", "@Mikachu2333"); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_forbid_english (this); @@ -60,22 +56,22 @@ pl_rust_rustup_getsrc (char *option) void pl_rust_rustup_setsrc (char *option) { - use_this_source(pl_rust_rustup); + chsrc_use_this_source (pl_rust_rustup); -#ifdef XY_On_Windows +#ifdef XY_Build_On_Windows - char *cmd1 = xy_strjoin (3, "setx RUSTUP_DIST_SERVER \"", source.url, "\""); - char *cmd2 = xy_strjoin (3, "setx RUSTUP_UPDATE_ROOT \"", source.url, "/rustup\""); + char *cmd1 = xy_strcat (3, "setx RUSTUP_DIST_SERVER \"", source.url, "\""); + char *cmd2 = xy_strcat (3, "setx RUSTUP_UPDATE_ROOT \"", source.url, "/rustup\""); - char *cmd = xy_strjoin (3, cmd1, " & ", cmd2); + char *cmd = xy_strcat (3, cmd1, " & ", cmd2); chsrc_run (cmd, RunOpt_Dont_Notify_On_Success|RunOpt_No_Last_New_Line); #else - char *w1 = xy_strjoin (3, "export RUSTUP_DIST_SERVER=\"", source.url, "\"\n"); - char *w2 = xy_strjoin (3, "export RUSTUP_UPDATE_ROOT=\"", source.url, "/rustup\"\n"); + char *w1 = xy_strcat (3, "export RUSTUP_DIST_SERVER=\"", source.url, "\"\n"); + char *w2 = xy_strcat (3, "export RUSTUP_UPDATE_ROOT=\"", source.url, "/rustup\"\n"); - char *w = xy_2strjoin (w1, w2); + char *w = xy_2strcat (w1, w2); char *bashrc = xy_bashrc; if (xy_file_exist (bashrc)) @@ -94,10 +90,10 @@ pl_rust_rustup_setsrc (char *option) char *fishrc = xy_fishrc; if (xy_file_exist (fishrc)) { - char *w1 = xy_strjoin (3, "set -x RUSTUP_DIST_SERVER ", source.url, "\n"); - char *w2 = xy_strjoin (3, "set -x RUSTUP_UPDATE_ROOT ", source.url, "/rustup\n"); + char *w1 = xy_strcat (3, "set -x RUSTUP_DIST_SERVER ", source.url, "\n"); + char *w2 = xy_strcat (3, "set -x RUSTUP_UPDATE_ROOT ", source.url, "/rustup\n"); - char *w = xy_2strjoin (w1, w2); + char *w = xy_2strcat (w1, w2); chsrc_backup (fishrc); chsrc_append_to_file (w, fishrc); diff --git a/src/recipe/menu.c b/src/recipe/menu.c index a784aee..403adac 100644 --- a/src/recipe/menu.c +++ b/src/recipe/menu.c @@ -1,102 +1,192 @@ /** ------------------------------------------------------------ * SPDX-License-Identifier: GPL-3.0-or-later * ------------------------------------------------------------- - * File Authors : Aoran Zeng + * File Authors : 曾奥然 * Contributors : Mikachu2333 * | * Created On : <2023-09-01> - * Major Revision : 3 - * Last Modified : <2025-08-10> + * Major Revision : 5 + * Last Modified : <2025-08-22> * ------------------------------------------------------------*/ -#define t(o) &o##_target, &o##_prelude +#include "lang/rawstr4c.h" -TargetRegisterInfo_t -chsrc_pl_menu[] = +#include "lang/Ruby/Ruby.c" +#include "lang/Python/common.h" + #include "lang/Python/pip.c" + #include "lang/Python/Poetry.c" + #include "lang/Python/PDM.c" + #include "lang/Python/Rye.c" + #include "lang/Python/uv.c" +#include "lang/Python/Python.c" + +#include "lang/JavaScript/common.h" + #include "lang/JavaScript/npm.c" + #include "lang/JavaScript/pnpm.c" + #include "lang/JavaScript/Yarn.c" +#include "lang/JavaScript/JavaScript.c" +#include "lang/JavaScript/Bun.c" +#include "lang/JavaScript/nvm.c" + +#include "lang/Perl.c" +#include "lang/PHP.c" +#include "lang/Lua.c" +#include "lang/Go.c" +#include "lang/Java.c" + +#include "lang/Rust/common.h" + #include "lang/Rust/rustup.c" + #include "lang/Rust/Cargo.c" + +#include "lang/Dart/common.h" +#include "lang/Dart/Pub.c" +#include "lang/Dart/Flutter.c" + +#include "lang/Haskell.c" +#include "lang/OCaml.c" +#include "lang/R.c" +#include "lang/Julia.c" +#include "lang/NuGet.c" +#include "lang/Clojure.c" + + +#include "os/rawstr4c.h" +#include "os/APT/common.h" +// Debian-based +#include "os/APT/Debian.c" +#include "os/APT/Ubuntu.c" +#include "os/APT/Kali-Linux.c" +#include "os/APT/Raspberry-Pi-OS.c" +// Ubuntu-based +#include "os/APT/Linux-Mint.c" +#include "os/APT/Trisquel.c" +#include "os/APT/Linux-Lite.c" +// Debian-based and Ubuntu-based +#include "os/APT/Armbian.c" +// Independent +#include "os/APT/ROS.c" +#include "os/APT/Termux.c" +#include "os/APT/openKylin.c" +#include "os/APT/deepin.c" + +#include "os/YUM/common.h" +#include "os/YUM/Fedora-Linux.c" +#include "os/YUM/AlmaLinux.c" +#include "os/YUM/Rocky-Linux.c" +#include "os/YUM/openEuler.c" +#include "os/YUM/Anolis-OS.c" + +#include "os/pacman/Arch-Linux.c" +#include "os/pacman/Manjaro-Linux.c" +#include "os/pacman/MSYS2.c" + +#include "os/openSUSE.c" +#include "os/Alpine-Linux.c" +#include "os/Gentoo-Linux.c" +#include "os/Void-Linux.c" +#include "os/Solus.c" +#include "os/OpenWrt.c" + +#include "os/BSD/FreeBSD.c" +#include "os/BSD/NetBSD.c" +#include "os/BSD/OpenBSD.c" + + +#include "ware/TeX-Live.c" +#include "ware/Emacs.c" +#include "ware/WinGet.c" +#include "ware/Homebrew/Homebrew.c" +#include "ware/CocoaPods.c" +#include "ware/Nix.c" +#include "ware/Guix.c" +#include "ware/Flatpak.c" +#include "ware/Docker/Docker.c" +#include "ware/Anaconda/Anaconda.c" + + +void +chsrc_init_menu () { - {t(pl_ruby)}, - {t(pl_python_group)}, - {t(pl_python_pip)}, - {t(pl_python_poetry)}, - {t(pl_python_pdm)}, - {t(pl_python_rye)}, - {t(pl_python_uv)}, - {t(pl_js_group)}, - {t(pl_js_bun)}, - {t(pl_js_npm)}, - {t(pl_js_yarn)}, - {t(pl_js_pnpm)}, - {t(pl_js_nvm)}, - {t(pl_perl)}, - {t(pl_php)}, - {t(pl_lua)}, - {t(pl_go)}, - {t(pl_rust_cargo)}, - {t(pl_rust_rustup)}, - {t(pl_java)}, - {t(pl_clojure)}, - {t(pl_dart)}, - {t(pl_dart_flutter)}, - {t(pl_nuget)}, - {t(pl_haskell)}, - {t(pl_ocaml)}, - {t(pl_r)}, - {t(pl_julia)}, -}; +#define add(t) xy_seq_push(ProgStore.pl, &pl_##t##_target); (&pl_##t##_target)->preludefn = pl_##t##_prelude + add (ruby); + add (python_group); + add (python_pip); + add (python_poetry); + add (python_pdm); + add (python_rye); + add (python_uv); + add (js_group); + add (js_bun); + add (js_npm); + add (js_yarn); + add (js_pnpm); + add (js_nvm); + add (perl); + add (php); + add (lua); + add (go); + add (rust_cargo); + add (rust_rustup); + add (java); + add (clojure); + add (dart); + add (dart_flutter); + add (nuget); + add (haskell); + add (ocaml); + add (r); + add (julia); +#undef add +#define add(t) xy_seq_push(ProgStore.os, &os_##t##_target); (&os_##t##_target)->preludefn = os_##t##_prelude + add (ubuntu); + add (linuxmint); + add (debian); + add (fedora); + add (opensuse); + add (kali); + add (msys2); + add (arch); + add (archlinuxcn); + add (manjaro); + add (gentoo); + add (rockylinux); + add (almalinux); + add (alpine); + add (voidlinux); + add (solus); + add (trisquel); + add (linuxlite); + add (ros); + add (raspberrypi); + add (armbian); + add (openwrt); + add (termux); + add (openkylin); + add (openeuler); + add (anolis); + add (deepin); + add (freebsd); + add (netbsd); + add (openbsd); +#undef add +#define add(t) xy_seq_push(ProgStore.wr, &wr_##t##_target); (&wr_##t##_target)->preludefn = wr_##t##_prelude + add (winget); + add (homebrew); + add (cocoapods); + add (docker); + add (flatpak); + add (nix); + add (guix); + add (emacs); + add (tex); + add (anaconda); +#undef add -TargetRegisterInfo_t -chsrc_os_menu[] = -{ - {t(os_ubuntu)}, - {t(os_linuxmint)}, - {t(os_debian)}, - {t(os_fedora)}, - {t(os_opensuse)}, - {t(os_kali)}, - {t(os_msys2)}, - {t(os_arch)}, - {t(os_archlinuxcn)}, - {t(os_manjaro)}, - {t(os_gentoo)}, - {t(os_rockylinux)}, - {t(os_almalinux)}, - {t(os_alpine)}, - {t(os_voidlinux)}, - {t(os_solus)}, - {t(os_trisquel)}, - {t(os_linuxlite)}, - {t(os_ros)}, - {t(os_raspberrypi)}, - {t(os_armbian)}, - {t(os_openwrt)}, - {t(os_termux)}, - {t(os_openkylin)}, - {t(os_openeuler)}, - {t(os_anolis)}, - {t(os_deepin)}, - {t(os_freebsd)}, - {t(os_netbsd)}, - {t(os_openbsd)}, -}; - - -TargetRegisterInfo_t -chsrc_wr_menu[] = -{ - {t(wr_winget)}, - {t(wr_homebrew)}, - {t(wr_cocoapods)}, - {t(wr_docker)}, - {t(wr_flatpak)}, - {t(wr_nix)}, - {t(wr_guix)}, - {t(wr_emacs)}, - {t(wr_tex)}, - {t(wr_anaconda)}, -}; -#undef t + // Internal Target 不会由用户使用,需要特殊对待 + pl_js_nodejs_binary_target.preludefn = pl_js_nodejs_binary_prelude; +} diff --git a/src/recipe/os/APT/Armbian.c b/src/recipe/os/APT/Armbian.c index 84220d1..ce8e1d2 100644 --- a/src/recipe/os/APT/Armbian.c +++ b/src/recipe/os/APT/Armbian.c @@ -7,19 +7,15 @@ def_target(os_armbian, "armbian"); void os_armbian_prelude () { - use_this(os_armbian); - chef_allow_gsr(os_armbian); + chef_prep_this (os_armbian, gsr); chef_set_created_on (this, "2024-06-14"); chef_set_last_updated (this, "2025-08-10"); chef_set_sources_last_updated (this, "2024-11-21"); - chef_set_authors (this, 1, "Shengwei Chen", "414685209@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 2, - "Aoran Zeng", "ccmywish@qq.com", - "Yangmoooo", "yangmoooo@outlook.com"); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@livelycode36"); + chef_set_sauciers (this, 2, "@ccmywish", "@Yangmoooo"); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_forbid_english(this); @@ -64,11 +60,11 @@ os_armbian_setsrc (char *option) { chsrc_ensure_root (); - use_this_source(os_armbian); + chsrc_use_this_source (os_armbian); chsrc_backup (OS_Armbian_SourceList); - char *cmd = xy_strjoin (3, "sed -E -i 's@https?[^ ]*armbian/?[^ ]*@", source.url, + char *cmd = xy_strcat (3, "sed -E -i 's@https?[^ ]*armbian/?[^ ]*@", source.url, "@g' " OS_Armbian_SourceList); chsrc_run (cmd, RunOpt_Default); diff --git a/src/recipe/os/APT/Debian.c b/src/recipe/os/APT/Debian.c index ecb935a..970e873 100644 --- a/src/recipe/os/APT/Debian.c +++ b/src/recipe/os/APT/Debian.c @@ -7,20 +7,15 @@ def_target(os_debian, "debian"); void os_debian_prelude () { - use_this(os_debian); - chef_allow_gsr(os_debian); + chef_prep_this (os_debian, gsr); chef_set_created_on (this, "2023-09-02"); chef_set_last_updated (this, "2025-08-10"); chef_set_sources_last_updated (this, "2025-07-11"); - chef_set_authors (this, 2, - "Aoran Zeng", "ccmywish@qq.com", - "Heng Guo", "2085471348@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 1, - "Yangmoooo", "yangmoooo@outlook.com"); + chef_set_chef (this, NULL); + chef_set_cooks (this, 2, "@ccmywish", "@G_I_Y"); + chef_set_sauciers (this, 1, "@Yangmoooo"); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_forbid_english(this); @@ -77,7 +72,7 @@ static bool os_debian_does_old_sourcelist_use_cdrom (void) { /* 我们只检查旧版sourcelist,因为 common.h 中的填充只支持旧版 */ - char *cmd = xy_2strjoin ("grep -q '^deb cdrom:' ", OS_Debian_old_SourceList); + char *cmd = xy_2strcat ("grep -q '^deb cdrom:' ", OS_Debian_old_SourceList); int ret = system (cmd); bool use_cdrom = ret == 0; @@ -88,15 +83,15 @@ os_debian_does_old_sourcelist_use_cdrom (void) void os_debian_setsrc_for_deb822 (char *option) { - use_this_source(os_debian); + chsrc_use_this_source (os_debian); chsrc_backup (OS_Debian_SourceList_DEB822); - char *cmd = xy_strjoin (3, "sed -E -i 's@https?://.*/debian/?@", source.url, "@g' " OS_Debian_SourceList_DEB822); + char *cmd = xy_strcat (3, "sed -E -i 's@https?://.*/debian/?@", source.url, "@g' " OS_Debian_SourceList_DEB822); chsrc_run (cmd, RunOpt_Default); /* debian-security 源和其他源不一样 */ - cmd = xy_strjoin (3, "sed -E -i 's@https?://.*/debian-security/?@", source.url, "-security@g' " OS_Debian_SourceList_DEB822); + cmd = xy_strcat (3, "sed -E -i 's@https?://.*/debian-security/?@", source.url, "-security@g' " OS_Debian_SourceList_DEB822); chsrc_run (cmd, RunOpt_Default); chsrc_run ("apt update", RunOpt_No_Last_New_Line); @@ -149,7 +144,7 @@ os_debian_setsrc (char *option) } } - use_this_source(os_debian); + chsrc_use_this_source (os_debian); chsrc_alert2 ("如果遇到无法拉取 HTTPS 源的情况,请手动运行:"); say ("apt install apt-transport-https ca-certificates"); @@ -160,7 +155,7 @@ os_debian_setsrc (char *option) chsrc_backup (OS_Debian_old_SourceList); } - char *cmd = xy_strjoin (3, "sed -E -i \'s@https?://.*/debian/?@", source.url, "@g\' " OS_Debian_old_SourceList); + char *cmd = xy_strcat (3, "sed -E -i \'s@https?://.*/debian/?@", source.url, "@g\' " OS_Debian_old_SourceList); chsrc_run (cmd, RunOpt_Default); chsrc_run ("apt update", RunOpt_No_Last_New_Line); diff --git a/src/recipe/os/APT/Kali-Linux.c b/src/recipe/os/APT/Kali-Linux.c index 2f2b6c0..7b85209 100644 --- a/src/recipe/os/APT/Kali-Linux.c +++ b/src/recipe/os/APT/Kali-Linux.c @@ -7,19 +7,15 @@ def_target(os_kali, "kali"); void os_kali_prelude () { - use_this(os_kali); - chef_allow_gsr(os_kali); + chef_prep_this (os_kali, gsr); chef_set_created_on (this, "2023-09-29"); chef_set_last_updated (this, "2025-08-10"); chef_set_sources_last_updated (this, "2025-06-20"); - chef_set_authors (this, 1, "Heng Guo", "2085471348@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 2, - "Yangmoooo", "yangmoooo@outlook.com", - "Happy Game", "happygame1024@gmail.com"); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@G_I_Y"); + chef_set_sauciers (this, 2, "@Yangmoooo", "@happy-game"); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_forbid_english(this); @@ -51,11 +47,11 @@ os_kali_setsrc (char *option) { chsrc_ensure_root (); - use_this_source(os_kali); + chsrc_use_this_source (os_kali); chsrc_backup (OS_Apt_SourceList); - char *cmd = xy_strjoin (3, "sed -E -i \'s@https?://.*/kali/?@", + char *cmd = xy_strcat (3, "sed -E -i \'s@https?://.*/kali/?@", source.url, "@g\' " OS_Apt_SourceList); diff --git a/src/recipe/os/APT/Linux-Lite.c b/src/recipe/os/APT/Linux-Lite.c index b3c7578..5b951a6 100644 --- a/src/recipe/os/APT/Linux-Lite.c +++ b/src/recipe/os/APT/Linux-Lite.c @@ -7,18 +7,15 @@ def_target(os_linuxlite, "linuxlite"); void os_linuxlite_prelude () { - use_this(os_linuxlite); - chef_allow_gsr(os_linuxlite); + chef_prep_this (os_linuxlite, gsr); chef_set_created_on (this, "2023-09-29"); chef_set_last_updated (this, "2025-08-10"); chef_set_sources_last_updated (this, "2024-11-21"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 1, - "Yangmoooo", "yangmoooo@outlook.com"); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 1, "@Yangmoooo"); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_forbid_english(this); @@ -49,11 +46,11 @@ os_linuxlite_setsrc (char *option) { chsrc_ensure_root (); - use_this_source(os_linuxlite); + chsrc_use_this_source (os_linuxlite); chsrc_backup (OS_Apt_SourceList); - char *cmd = xy_strjoin (3, "sed -E -i 's@https?://.*/.*/?@", source.url, "@g' " OS_Apt_SourceList); + char *cmd = xy_strcat (3, "sed -E -i 's@https?://.*/.*/?@", source.url, "@g' " OS_Apt_SourceList); chsrc_run ("apt update", RunOpt_No_Last_New_Line); diff --git a/src/recipe/os/APT/Linux-Mint.c b/src/recipe/os/APT/Linux-Mint.c index 02dba06..36371cf 100644 --- a/src/recipe/os/APT/Linux-Mint.c +++ b/src/recipe/os/APT/Linux-Mint.c @@ -7,18 +7,15 @@ def_target(os_linuxmint, "linuxmint"); void os_linuxmint_prelude () { - use_this(os_linuxmint); - chef_allow_gs(os_linuxmint); + chef_prep_this (os_linuxmint, gs); chef_set_created_on (this, "2023-09-29"); chef_set_last_updated (this, "2025-08-10"); chef_set_sources_last_updated (this, "2024-11-21"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 1, - "Happy Game", "happygame1024@gmail.com"); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 1, "@happy-game"); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_forbid_english(this); @@ -61,7 +58,7 @@ os_linuxmint_setsrc (char *option) { chsrc_ensure_root (); - use_this_source(os_linuxmint); + chsrc_use_this_source (os_linuxmint); chsrc_backup (OS_LinuxMint_SourceList); @@ -69,7 +66,7 @@ os_linuxmint_setsrc (char *option) // 暂不实现自动替换基于debian或ubuntu的基础源 char *version_codename = xy_run ("sed -nr 's/^VERSION_CODENAME=([^\"]+)/\1/p' " ETC_OS_RELEASE, 0); // sed -i '// s|http[^ ]*||g' OS_LinuxMint_SourceList - char* cmd = xy_strjoin (5, "sed -i '/", + char* cmd = xy_strcat (5, "sed -i '/", version_codename, "/ s|http[^ ]*|", source.url, "|g' " OS_LinuxMint_SourceList); diff --git a/src/recipe/os/APT/ROS.c b/src/recipe/os/APT/ROS.c index 62302a5..fa38c24 100644 --- a/src/recipe/os/APT/ROS.c +++ b/src/recipe/os/APT/ROS.c @@ -7,19 +7,15 @@ def_target(os_ros, "ros/ros2"); void os_ros_prelude () { - use_this(os_ros); - chef_allow_gs(os_ros); + chef_prep_this (os_ros, gs); chef_set_created_on (this, "2023-09-03"); chef_set_last_updated (this, "2025-08-10"); chef_set_sources_last_updated (this, "2024-04-18"); - chef_set_authors (this, 1, "Heng Guo", "2085471348@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 2, - "Aoran Zeng", "ccmywish@qq.com", - "zouri", "guoshuaisun@outlook.com"); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@G_I_Y"); + chef_set_sauciers (this, 2, "@ccmywish", "@zouri"); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_forbid_english(this); @@ -59,12 +55,12 @@ os_ros_setsrc (char *option) { chsrc_ensure_root (); - use_this_source(os_ros); + chsrc_use_this_source (os_ros); chsrc_backup (OS_ROS_SourceList); char *cmd = NULL; - cmd = xy_strjoin(3, "sed -E -i \'s@https?://.*/ros/ubuntu/?@", source.url, "/ros/ubuntu@g\' " OS_ROS_SourceList); + cmd = xy_strcat(3, "sed -E -i \'s@https?://.*/ros/ubuntu/?@", source.url, "/ros/ubuntu@g\' " OS_ROS_SourceList); chsrc_run(cmd, RunOpt_Default); cmd = "apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654"; diff --git a/src/recipe/os/APT/Raspberry-Pi-OS.c b/src/recipe/os/APT/Raspberry-Pi-OS.c index 6406925..182c51a 100644 --- a/src/recipe/os/APT/Raspberry-Pi-OS.c +++ b/src/recipe/os/APT/Raspberry-Pi-OS.c @@ -9,18 +9,15 @@ def_target(os_raspberrypi, "raspi/raspberrypi"); void os_raspberrypi_prelude () { - use_this(os_raspberrypi); - chef_allow_gsr(os_raspberrypi); + chef_prep_this (os_raspberrypi, gsr); chef_set_created_on (this, "2023-09-29"); chef_set_last_updated (this, "2025-08-10"); chef_set_sources_last_updated (this, "2023-09-29"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 1, - "Yangmoooo", "yangmoooo@outlook.com"); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 1, "@Yangmoooo"); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_forbid_english(this); @@ -53,11 +50,11 @@ os_raspberrypi_setsrc (char *option) { chsrc_ensure_root(); // HELP: 不确定是否需要 - use_this_source(os_raspberrypi); + chsrc_use_this_source (os_raspberrypi); chsrc_backup (OS_RaspberryPi_SourceList); - char *cmd = xy_strjoin (3, "sed -E -i 's@https?://.*/.*/?@", source.url, + char *cmd = xy_strcat (3, "sed -E -i 's@https?://.*/.*/?@", source.url, "@g' " OS_RaspberryPi_SourceList); chsrc_run (cmd, RunOpt_Default); diff --git a/src/recipe/os/APT/Termux.c b/src/recipe/os/APT/Termux.c index 1ff60c5..a0b0eee 100644 --- a/src/recipe/os/APT/Termux.c +++ b/src/recipe/os/APT/Termux.c @@ -7,17 +7,15 @@ def_target(os_termux, "termux"); void os_termux_prelude () { - use_this(os_termux); - chef_allow_gsr(os_termux); + chef_prep_this (os_termux, gsr); chef_set_created_on (this, "2025-03-04"); chef_set_last_updated (this, "2025-08-10"); chef_set_sources_last_updated (this, "2025-03-04"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 0); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 0); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_forbid_english(this); @@ -61,9 +59,9 @@ os_termux_setsrc (char *option) // chsrc_ensure_root (); Termux下禁止使用root - use_this_source(os_termux); + chsrc_use_this_source (os_termux); - char *cmd = xy_strjoin (3, "sed -i 's@^\\(deb.*stable main\\)$@#\\1\\ndeb ", + char *cmd = xy_strcat (3, "sed -i 's@^\\(deb.*stable main\\)$@#\\1\\ndeb ", source.url, "apt/termux-main stable main@' " OS_Termux_SourceList); chsrc_run (cmd, RunOpt_Default); diff --git a/src/recipe/os/APT/Trisquel.c b/src/recipe/os/APT/Trisquel.c index 2b44952..3ac2e79 100644 --- a/src/recipe/os/APT/Trisquel.c +++ b/src/recipe/os/APT/Trisquel.c @@ -9,17 +9,15 @@ def_target(os_trisquel, "trisquel"); void os_trisquel_prelude () { - use_this(os_trisquel); - chef_allow_gsr(os_trisquel); + chef_prep_this (os_trisquel, gsr); chef_set_created_on (this, "2023-09-29"); chef_set_last_updated (this, "2025-08-10"); chef_set_sources_last_updated (this, "2024-11-21"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 0); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 0); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_forbid_english(this); @@ -53,11 +51,11 @@ os_trisquel_setsrc (char *option) { chsrc_ensure_root (); - use_this_source(os_trisquel); + chsrc_use_this_source (os_trisquel); chsrc_backup (OS_Apt_SourceList); - char *cmd = xy_strjoin (3, "sed -E -i 's@https?://.*/trisquel/?@", source.url, "@g' /etc/apt/sources.list"); + char *cmd = xy_strcat (3, "sed -E -i 's@https?://.*/trisquel/?@", source.url, "@g' /etc/apt/sources.list"); chsrc_run (cmd, RunOpt_Default); chsrc_run ("apt update", RunOpt_No_Last_New_Line); diff --git a/src/recipe/os/APT/Ubuntu.c b/src/recipe/os/APT/Ubuntu.c index 2d16f2b..9c4f8a5 100644 --- a/src/recipe/os/APT/Ubuntu.c +++ b/src/recipe/os/APT/Ubuntu.c @@ -8,20 +8,15 @@ def_target(os_ubuntu, "ubuntu/zorinos"); void os_ubuntu_prelude () { - use_this(os_ubuntu); - chef_allow_gsr(os_ubuntu); + chef_prep_this (os_ubuntu, gsr); chef_set_created_on (this, "2023-08-30"); chef_set_last_updated (this, "2025-08-10"); chef_set_sources_last_updated (this, "2025-07-11"); - chef_set_authors (this, 2, - "Aoran Zeng", "ccmywish@qq.com", - "Heng Guo", "2085471348@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 1, - "Zhao", "1792582687@qq.com"); + chef_set_chef (this, NULL); + chef_set_cooks (this, 2, "@ccmywish", "@G_I_Y"); + chef_set_sauciers (this, 1, "@XUANJI233"); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_forbid_english(this); @@ -80,7 +75,7 @@ os_ubuntu_getsrc (char *option) void os_ubuntu_setsrc_for_deb822 (char *option) { - use_this_source(os_ubuntu); + chsrc_use_this_source (os_ubuntu); chsrc_backup (OS_Ubuntu_SourceList_DEB822); @@ -88,11 +83,11 @@ os_ubuntu_setsrc_for_deb822 (char *option) char *cmd = NULL; if (strncmp (arch, "x86_64", 6)==0) { - cmd = xy_strjoin (3, "sed -E -i \'s@https?://.*/ubuntu/?@", source.url, "@g\' " OS_Ubuntu_SourceList_DEB822); + cmd = xy_strcat (3, "sed -E -i \'s@https?://.*/ubuntu/?@", source.url, "@g\' " OS_Ubuntu_SourceList_DEB822); } else { - cmd = xy_strjoin (3, "sed -E -i \'s@https?://.*/ubuntu-ports/?@", source.url, "-ports@g\' " OS_Ubuntu_SourceList_DEB822); + cmd = xy_strcat (3, "sed -E -i \'s@https?://.*/ubuntu-ports/?@", source.url, "-ports@g\' " OS_Ubuntu_SourceList_DEB822); } chsrc_run (cmd, RunOpt_Default); @@ -123,7 +118,7 @@ os_ubuntu_setsrc (char *option) bool sourcelist_exist = ensure_debian_or_ubuntu_old_sourcelist (OS_Is_Ubuntu); - use_this_source(os_ubuntu); + chsrc_use_this_source (os_ubuntu); /* 不存在的时候,用的是我们生成的无效文件,不要备份 */ if (sourcelist_exist) @@ -135,11 +130,11 @@ os_ubuntu_setsrc (char *option) char *cmd = NULL; if (0==strncmp (arch, "x86_64", 6)) { - cmd = xy_strjoin (3, "sed -E -i \'s@https?://.*/ubuntu/?@", source.url, "@g\' " OS_Ubuntu_old_SourceList); + cmd = xy_strcat (3, "sed -E -i \'s@https?://.*/ubuntu/?@", source.url, "@g\' " OS_Ubuntu_old_SourceList); } else { - cmd = xy_strjoin (3, "sed -E -i \'s@https?://.*/ubuntu-ports/?@", source.url, "-ports@g\' " OS_Ubuntu_old_SourceList); + cmd = xy_strcat (3, "sed -E -i \'s@https?://.*/ubuntu-ports/?@", source.url, "-ports@g\' " OS_Ubuntu_old_SourceList); } chsrc_run (cmd, RunOpt_Default); diff --git a/src/recipe/os/APT/deepin.c b/src/recipe/os/APT/deepin.c index 094c76a..8f01ed1 100644 --- a/src/recipe/os/APT/deepin.c +++ b/src/recipe/os/APT/deepin.c @@ -7,18 +7,15 @@ def_target(os_deepin, "deepin"); void os_deepin_prelude () { - use_this(os_deepin); - chef_allow_gsr(os_deepin); + chef_prep_this (os_deepin, gsr); chef_set_created_on (this, "2023-09-26"); chef_set_last_updated (this, "2025-08-10"); chef_set_sources_last_updated (this, "2024-09-14"); - chef_set_authors (this, 1, "Heng Guo", "2085471348@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 1, - "Yangmoooo", "yangmoooo@outlook.com"); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@G_I_Y"); + chef_set_sauciers (this, 1, "@Yangmoooo"); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_forbid_english(this); @@ -56,11 +53,11 @@ os_deepin_setsrc (char *option) { chsrc_ensure_root(); - use_this_source(os_deepin); + chsrc_use_this_source (os_deepin); chsrc_backup (OS_Apt_SourceList); - char *cmd = xy_strjoin (3, "sed -E -i \'s@https?://.*/deepin/?@", + char *cmd = xy_strcat (3, "sed -E -i \'s@https?://.*/deepin/?@", source.url, "@g\' " OS_Apt_SourceList); diff --git a/src/recipe/os/APT/openKylin.c b/src/recipe/os/APT/openKylin.c index a6aaa50..8d6ddd4 100644 --- a/src/recipe/os/APT/openKylin.c +++ b/src/recipe/os/APT/openKylin.c @@ -10,18 +10,15 @@ def_target(os_openkylin, "openkylin"); void os_openkylin_prelude () { - use_this(os_openkylin); - chef_allow_gsr(os_openkylin); + chef_prep_this (os_openkylin, gsr); chef_set_created_on (this, "2023-09-06"); chef_set_last_updated (this, "2025-08-10"); chef_set_sources_last_updated (this, "2023-09-29"); - chef_set_authors (this, 1, "Heng Guo", "2085471348@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 1, - "Aoran Zeng", "ccmywish@qq.com"); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@G_I_Y"); + chef_set_sauciers (this, 1, "@ccmywish"); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_forbid_english(this); @@ -47,11 +44,11 @@ os_openkylin_setsrc (char *option) { chsrc_ensure_root(); - use_this_source(os_openkylin); + chsrc_use_this_source (os_openkylin); chsrc_backup (OS_Apt_SourceList); - char *cmd = xy_strjoin (3, "sed -E -i 's@https?://.*/openkylin/?@", source.url, "@g'" OS_Apt_SourceList); + char *cmd = xy_strcat (3, "sed -E -i 's@https?://.*/openkylin/?@", source.url, "@g'" OS_Apt_SourceList); chsrc_run (cmd, RunOpt_Default); chsrc_run ("apt update", RunOpt_No_Last_New_Line); diff --git a/src/recipe/os/Alpine-Linux.c b/src/recipe/os/Alpine-Linux.c index f9f7a29..f7e98bd 100644 --- a/src/recipe/os/Alpine-Linux.c +++ b/src/recipe/os/Alpine-Linux.c @@ -7,18 +7,15 @@ def_target(os_alpine, "alpine"); void os_alpine_prelude () { - use_this(os_alpine); - chef_allow_gs(os_alpine); + chef_prep_this (os_alpine, gs); chef_set_created_on (this, "2023-09-24"); chef_set_last_updated (this, "2025-08-10"); chef_set_sources_last_updated (this, "2024-09-14"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 1, - "Yangmoooo", "yangmoooo@outlook.com"); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 1, "@Yangmoooo"); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_allow_english(this); @@ -57,9 +54,9 @@ os_alpine_setsrc (char *option) { // chsrc_ensure_root(); // HELP: 不确定是否需要root - use_this_source(os_alpine); + chsrc_use_this_source (os_alpine); - char* cmd = xy_strjoin (3, + char* cmd = xy_strcat (3, "sed -i 's#https\\?://dl-cdn.alpinelinux.org/alpine#", source.url, "#g' /etc/apk/repositories" ); chsrc_run (cmd, RunOpt_Default); diff --git a/src/recipe/os/BSD/FreeBSD.c b/src/recipe/os/BSD/FreeBSD.c index 669a77c..e8fe85a 100644 --- a/src/recipe/os/BSD/FreeBSD.c +++ b/src/recipe/os/BSD/FreeBSD.c @@ -7,17 +7,15 @@ def_target(os_freebsd, "freebsd"); void os_freebsd_prelude () { - use_this(os_freebsd); - chef_allow_s(os_freebsd); + chef_prep_this (os_freebsd, s); chef_set_created_on (this, "2023-09-03"); chef_set_last_updated (this, "2025-08-10"); chef_set_sources_last_updated (this, "2023-09-27"); - chef_set_authors (this, 2, "Aoran Zeng", "ccmywish@qq.com", "Heng Guo", "2085471348@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 0); + chef_set_chef (this, NULL); + chef_set_cooks (this, 2, "@ccmywish", "@G_I_Y"); + chef_set_sauciers (this, 0); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_forbid_english(this); @@ -48,7 +46,7 @@ os_freebsd_setsrc (char *option) // 据 @ykla,FreeBSD不自带sudo,但是我们依然要保证是root权限 chsrc_ensure_root (); - use_this(os_freebsd); + use_this (os_freebsd); int index = use_specific_mirror_or_auto_select (option, this); Source_t source = this->sources[index]; @@ -57,9 +55,9 @@ os_freebsd_setsrc (char *option) chsrc_log2 ("1. 添加 freebsd-pkg 源 (二进制安装包)"); chsrc_ensure_dir ("/usr/local/etc/pkg/repos"); - char *conf = xy_strjoin (3, "/usr/local/etc/pkg/repos/", source.mirror->code, ".conf"); + char *conf = xy_strcat (3, "/usr/local/etc/pkg/repos/", source.mirror->code, ".conf"); - char *pkg_content = xy_strjoin (4, + char *pkg_content = xy_strcat (4, source.mirror->code, ": { \n" " url: \"http://", source.url, "/freebsd-pkg/${ABI}/latest\",\n" "}\n" @@ -68,7 +66,7 @@ os_freebsd_setsrc (char *option) chsrc_overwrite_file (pkg_content, conf); chsrc_note2 ( - xy_strjoin (3, "若要使用季度分支,请在", conf ,"中将latest改为quarterly")); + xy_strcat (3, "若要使用季度分支,请在", conf ,"中将latest改为quarterly")); chsrc_alert2 ("若要使用HTTPS源,请先安装securtiy/ca_root_ns,并将'http'改成'https',最后使用'pkg update -f'刷新缓存即可\n"); br(); @@ -84,14 +82,14 @@ os_freebsd_setsrc (char *option) { source = this->sources[index-1]; // 使用NJU的前一个源,即USTC源 } - char *git_cmd = xy_strjoin (3, "git clone --depth 1 https://", source.url, "/freebsd-ports/ports.git /usr/ports"); + char *git_cmd = xy_strcat (3, "git clone --depth 1 https://", source.url, "/freebsd-ports/ports.git /usr/ports"); chsrc_run (git_cmd, RunOpt_Default); source = this->sources[index]; // 恢复至选中的源 chsrc_alert2 ("下次更新请使用 git -C /usr/ports pull 而非使用 gitup"); } else { - char *fetch = xy_strjoin (3, "fetch https://", source.url, "/freebsd-ports/ports.tar.gz"); // 70多MB + char *fetch = xy_strcat (3, "fetch https://", source.url, "/freebsd-ports/ports.tar.gz"); // 70多MB char *unzip = "tar -zxvf ports.tar.gz -C /usr/ports"; char *delete = "rm ports.tar.gz"; chsrc_run (fetch, RunOpt_Default); @@ -105,7 +103,7 @@ os_freebsd_setsrc (char *option) // https://help.mirrors.cernet.edu.cn/FreeBSD-ports/ chsrc_backup ("/etc/make.conf"); - char *ports = xy_strjoin (3, "MASTER_SITE_OVERRIDE?=http://", source.url, "/freebsd-ports/distfiles/${DIST_SUBDIR}/\n"); + char *ports = xy_strcat (3, "MASTER_SITE_OVERRIDE?=http://", source.url, "/freebsd-ports/distfiles/${DIST_SUBDIR}/\n"); chsrc_append_to_file (ports, "/etc/make.conf"); @@ -113,7 +111,7 @@ os_freebsd_setsrc (char *option) /* chsrc_backup ("/etc/portsnap.conf"); - char *portsnap =xy_strjoin(3,"s@(.*)SERVERNAME=[\\.|a-z|A-Z]*@\\1SERVERNAME=", source.url, + char *portsnap =xy_strcat(3,"s@(.*)SERVERNAME=[\\.|a-z|A-Z]*@\\1SERVERNAME=", source.url, "@g < /etc/portsnap.conf.bak"); chsrc_overwrite_file (portsnap, "/etc/portsnap.conf"); @@ -131,7 +129,7 @@ os_freebsd_setsrc (char *option) char *update_cp = "cp /etc/freebsd-update.conf /etc/freebsd-update.conf.bak"; chsrc_run (update_cp, RunOpt_Default); - char *update =xy_strjoin (3,"s@(.*)SERVERNAME [\\.|a-z|A-Z]*@\\1SERVERNAME ", + char *update =xy_strcat (3,"s@(.*)SERVERNAME [\\.|a-z|A-Z]*@\\1SERVERNAME ", source.url, "@g < /etc/freebsd-update.conf.bak"); diff --git a/src/recipe/os/BSD/NetBSD.c b/src/recipe/os/BSD/NetBSD.c index c318f2b..5358312 100644 --- a/src/recipe/os/BSD/NetBSD.c +++ b/src/recipe/os/BSD/NetBSD.c @@ -7,17 +7,15 @@ def_target(os_netbsd, "netbsd"); void os_netbsd_prelude () { - use_this(os_netbsd); - chef_allow_gs(os_netbsd); + chef_prep_this (os_netbsd, gs); chef_set_created_on (this, "2023-09-05"); chef_set_last_updated (this, "2025-08-10"); chef_set_sources_last_updated (this, "2025-07-31"); - chef_set_authors (this, 2, "Aoran Zeng", "ccmywish@qq.com", "Heng Guo", "2085471348@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 0); + chef_set_chef (this, NULL); + chef_set_cooks (this, 2, "@ccmywish", "@G_I_Y"); + chef_set_sauciers (this, 0); chef_allow_local_mode (this, CanNot, NULL, NULL); @@ -60,7 +58,7 @@ os_netbsd_setsrc (char *option) { chsrc_ensure_root (); - use_this_source(os_netbsd); + chsrc_use_this_source (os_netbsd); chsrc_backup ("/usr/pkg/etc/pkgin/repositories.conf"); @@ -68,7 +66,7 @@ os_netbsd_setsrc (char *option) char *vercmd = "cat /etc/os-release | grep \"VERSION=\" | grep -Po \"[8-9].[0-9]+\""; char *version = xy_run (vercmd, 0); - char *url = xy_strjoin (5, chef_ensure_trailing_slash (source.url), arch, "/", version, "/All"); + char *url = xy_strcat (5, chef_ensure_trailing_slash (source.url), arch, "/", version, "/All"); chsrc_overwrite_file (url, "/usr/pkg/etc/pkgin/repositories.conf"); chsrc_conclude (&source); diff --git a/src/recipe/os/BSD/OpenBSD.c b/src/recipe/os/BSD/OpenBSD.c index 2c50c13..b099822 100644 --- a/src/recipe/os/BSD/OpenBSD.c +++ b/src/recipe/os/BSD/OpenBSD.c @@ -7,17 +7,15 @@ def_target(os_openbsd, "openbsd"); void os_openbsd_prelude () { - use_this(os_openbsd); - chef_allow_gs(os_openbsd); + chef_prep_this (os_openbsd, gs); chef_set_created_on (this, "2023-09-03"); chef_set_last_updated (this, "2025-08-10"); chef_set_sources_last_updated (this, "2025-07-31"); - chef_set_authors (this, 2, "Heng Guo", "2085471348@qq.com", "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 0); + chef_set_chef (this, NULL); + chef_set_cooks (this, 2, "@G_I_Y", "@ccmywish"); + chef_set_sauciers (this, 0); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_forbid_english(this); @@ -59,7 +57,7 @@ os_openbsd_setsrc (char *option) { chsrc_ensure_root (); - use_this_source(os_openbsd); + chsrc_use_this_source (os_openbsd); chsrc_backup ("/etc/installurl"); chsrc_overwrite_file (source.url, "/etc/installurl"); diff --git a/src/recipe/os/Gentoo-Linux.c b/src/recipe/os/Gentoo-Linux.c index 7878c01..4e25fdb 100644 --- a/src/recipe/os/Gentoo-Linux.c +++ b/src/recipe/os/Gentoo-Linux.c @@ -7,18 +7,15 @@ def_target(os_gentoo, "gentoo"); void os_gentoo_prelude () { - use_this(os_gentoo); - chef_allow_s(os_gentoo); + chef_prep_this (os_gentoo, s); chef_set_created_on (this, "2023-09-05"); chef_set_last_updated (this, "2025-08-10"); chef_set_sources_last_updated (this, "2025-06-20"); - chef_set_authors (this, 1, "Heng Guo", "2085471348@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 1, - "Aoran Zeng", "ccmywish@qq.com"); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@G_I_Y"); + chef_set_sauciers (this, 1, "@ccmywish"); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_allow_english(this); @@ -45,16 +42,16 @@ os_gentoo_setsrc (char *option) { chsrc_ensure_root (); - use_this_source(os_gentoo); + chsrc_use_this_source (os_gentoo); chsrc_backup ("/etc/portage/repos.conf/gentoo.conf"); - char *cmd = xy_strjoin (3, "sed -i \"s#rsync://.*/gentoo-portage#rsync://", + char *cmd = xy_strcat (3, "sed -i \"s#rsync://.*/gentoo-portage#rsync://", source.url, "gentoo-portage#g"); chsrc_run (cmd, RunOpt_Default); - char *w = xy_strjoin (3, "GENTOO_MIRRORS=\"https://", source.url, "gentoo\"\n"); + char *w = xy_strcat (3, "GENTOO_MIRRORS=\"https://", source.url, "gentoo\"\n"); chsrc_append_to_file (w, "/etc/portage/make.conf"); diff --git a/src/recipe/os/OpenWrt.c b/src/recipe/os/OpenWrt.c index 6f02ba6..19643ab 100644 --- a/src/recipe/os/OpenWrt.c +++ b/src/recipe/os/OpenWrt.c @@ -7,19 +7,15 @@ def_target(os_openwrt, "openwrt/opkg/LEDE"); void os_openwrt_prelude () { - use_this(os_openwrt); - chef_allow_gsr(os_openwrt); + chef_prep_this (os_openwrt, gsr); chef_set_created_on (this, "2024-08-08"); chef_set_last_updated (this, "2025-08-10"); chef_set_sources_last_updated (this, "2024-12-14"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 2, - "Yangmoooo", "yangmoooo@outlook.com", - "happy game", "happygame1024@gmail.com"); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 2, "@Yangmoooo", "@happy-game"); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_allow_english(this); @@ -61,11 +57,11 @@ os_openwrt_setsrc (char *option) { chsrc_ensure_root (); - use_this_source(os_openwrt); + chsrc_use_this_source (os_openwrt); chsrc_backup (OS_OpenWRT_SourceConfig); - char *cmd = xy_strjoin (3, "sed -E -i 's@https?://.*/releases@", source.url, "/releases@g' " OS_OpenWRT_SourceConfig); + char *cmd = xy_strcat (3, "sed -E -i 's@https?://.*/releases@", source.url, "/releases@g' " OS_OpenWRT_SourceConfig); chsrc_run (cmd, RunOpt_No_Last_New_Line); chsrc_run ("opkg update", RunOpt_No_Last_New_Line); diff --git a/src/recipe/os/Solus.c b/src/recipe/os/Solus.c index 55a3e86..989da7b 100644 --- a/src/recipe/os/Solus.c +++ b/src/recipe/os/Solus.c @@ -7,17 +7,15 @@ def_target(os_solus, "solus"); void os_solus_prelude () { - use_this(os_solus); - chef_allow_s(os_solus); + chef_prep_this (os_solus, s); chef_set_created_on (this, "2023-09-29"); chef_set_last_updated (this, "2025-08-10"); chef_set_sources_last_updated (this, "2023-09-29"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 0); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 0); chef_allow_local_mode (this, CanNot, NULL, NULL); @@ -43,9 +41,9 @@ os_solus_setsrc (char *option) { chsrc_ensure_root (); - use_this_source(os_solus); + chsrc_use_this_source (os_solus); - char *cmd = xy_2strjoin ("eopkg add-repo Solus ", source.url); + char *cmd = xy_2strcat ("eopkg add-repo Solus ", source.url); chsrc_run (cmd, RunOpt_Default); chsrc_determine_chgtype (ChgType_Auto); diff --git a/src/recipe/os/Void-Linux.c b/src/recipe/os/Void-Linux.c index c984e46..ace7dd6 100644 --- a/src/recipe/os/Void-Linux.c +++ b/src/recipe/os/Void-Linux.c @@ -7,18 +7,15 @@ def_target(os_voidlinux, "voidlinux"); void os_voidlinux_prelude () { - use_this(os_voidlinux); - chef_allow_gsr(os_voidlinux); + chef_prep_this (os_voidlinux, gsr); chef_set_created_on (this, "2023-09-24"); chef_set_last_updated (this, "2025-08-10"); chef_set_sources_last_updated (this, "2024-12-18"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 1, - "Yangmoooo", "yangmoooo@outlook.com"); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 1, "@Yangmoooo"); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_forbid_english(this); @@ -52,18 +49,18 @@ os_voidlinux_setsrc (char *option) { chsrc_ensure_root (); - use_this_source(os_voidlinux); + chsrc_use_this_source (os_voidlinux); chsrc_ensure_dir ("/etc/xbps.d"); char *cmd = "cp /usr/share/xbps.d/*-repository-*.conf /etc/xbps.d/"; chsrc_run (cmd, RunOpt_Default); - cmd = xy_strjoin (3, + cmd = xy_strcat (3, "sed -i 's|https://repo-default.voidlinux.org|", source.url, "|g' /etc/xbps.d/*-repository-*.conf" ); chsrc_run (cmd, RunOpt_Default); - cmd = xy_strjoin (3, + cmd = xy_strcat (3, "sed -i 's|https://alpha.de.repo.voidlinux.org|", source.url, "|g' /etc/xbps.d/*-repository-*.conf" ); diff --git a/src/recipe/os/YUM/AlmaLinux.c b/src/recipe/os/YUM/AlmaLinux.c index ecfb04c..2112c3a 100644 --- a/src/recipe/os/YUM/AlmaLinux.c +++ b/src/recipe/os/YUM/AlmaLinux.c @@ -7,18 +7,15 @@ def_target(os_almalinux, "alma/almalinux"); void os_almalinux_prelude () { - use_this(os_almalinux); - chef_allow_s(os_almalinux); + chef_prep_this (os_almalinux, s); chef_set_created_on (this, "2024-06-12"); chef_set_last_updated (this, "2025-08-10"); - chef_set_sources_last_updated (this, "2024-12-18"); + chef_set_sources_last_updated (this, "2025-08-22"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 1, - "Yangmoooo", "yangmoooo@outlook.com"); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 1, "@Yangmoooo"); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_forbid_english(this); @@ -27,7 +24,7 @@ os_almalinux_prelude () chef_set_note(this, NULL, NULL); def_sources_begin() - {&UpstreamProvider, "http://repo.almalinux.org/almalinux", FeedByPrelude}, + {&UpstreamProvider, "http://repo.almalinux.org/almalinux", DelegateToUpstream}, {&Ali, "https://mirrors.aliyun.com/almalinux", FeedByPrelude}, {&Volcengine, "https://mirrors.volces.com/almalinux", FeedByPrelude}, {&Sjtug_Zhiyuan, "https://mirrors.sjtug.sjtu.edu.cn/almalinux", FeedByPrelude}, @@ -35,7 +32,10 @@ os_almalinux_prelude () {&Nju, "https://mirror.nju.edu.cn/almalinux", FeedByPrelude} def_sources_end() - chef_set_provider_speed_measure_url (&UpstreamProvider, "https://raw.repo.almalinux.org/almalinux/9.5/isos/x86_64/AlmaLinux-9-latest-x86_64-minimal.iso"); +#define link "/9.6/isos/x86_64/AlmaLinux-9-latest-x86_64-minimal.iso" + chef_set_sources_speed_measure_url_with_postfix (this, link); + chef_set_provider_speed_measure_url (&UpstreamProvider, "https://raw.repo.almalinux.org/almalinux" link); +#undef link } /** @@ -46,9 +46,9 @@ os_almalinux_setsrc (char *option) { chsrc_ensure_root (); - use_this_source(os_almalinux); + chsrc_use_this_source (os_almalinux); - char *cmd = xy_strjoin (3, + char *cmd = xy_strcat (3, "sed -e 's|^mirrorlist=|#mirrorlist=|g' -e 's|^#\\s*baseurl=https://repo.almalinux.org/almalinux|baseurl=", source.url, "|g' -i.bak /etc/yum.repos.d/almalinux*.repo"); chsrc_run (cmd, RunOpt_Default); diff --git a/src/recipe/os/YUM/Anolis-OS.c b/src/recipe/os/YUM/Anolis-OS.c index 706a7af..6761ef7 100644 --- a/src/recipe/os/YUM/Anolis-OS.c +++ b/src/recipe/os/YUM/Anolis-OS.c @@ -7,17 +7,15 @@ def_target(os_anolis, "anolis/openanolis"); void os_anolis_prelude () { - use_this(os_anolis); - chef_allow_s(os_anolis); + chef_prep_this (os_anolis, s); chef_set_created_on (this, "2023-09-24"); chef_set_last_updated (this, "2025-08-10"); chef_set_sources_last_updated (this, "2024-06-12"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 0); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 0); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_forbid_english(this); @@ -41,9 +39,9 @@ os_anolis_setsrc (char *option) { chsrc_ensure_root (); - use_this_source(os_anolis); + chsrc_use_this_source (os_anolis); - char *cmd = xy_strjoin (3, "sed -i.bak -E 's|https?://(mirrors\\.openanolis\\.cn/anolis)|", source.url, "|g' /etc/yum.repos.d/*.repo"); + char *cmd = xy_strcat (3, "sed -i.bak -E 's|https?://(mirrors\\.openanolis\\.cn/anolis)|", source.url, "|g' /etc/yum.repos.d/*.repo"); chsrc_run (cmd, RunOpt_Default); chsrc_run ("dnf makecache", RunOpt_Default); diff --git a/src/recipe/os/YUM/Fedora-Linux.c b/src/recipe/os/YUM/Fedora-Linux.c index 66c12e5..9abbed9 100644 --- a/src/recipe/os/YUM/Fedora-Linux.c +++ b/src/recipe/os/YUM/Fedora-Linux.c @@ -7,20 +7,15 @@ def_target(os_fedora, "fedora"); void os_fedora_prelude () { - use_this(os_fedora); - chef_allow_sr(os_fedora); + chef_prep_this (os_fedora, sr); chef_set_created_on (this, "2023-09-26"); chef_set_last_updated (this, "2025-08-10"); chef_set_sources_last_updated (this, "2025-06-20"); - chef_set_authors (this, 2, - "Heng Guo", "2085471348@qq.com", - "happy game", "happygame1024@gmail.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 1, "happy game", "happygame1024@gmail.com"); - chef_set_contributors (this, 1, - "Aoran Zeng", "ccmywish@qq.com"); + chef_set_chef (this, "@happy-game"); + chef_set_cooks (this, 2, "@G_I_Y", "@happy-game"); + chef_set_sauciers (this, 1, "@ccmywish"); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_forbid_english(this); @@ -55,7 +50,7 @@ os_fedora_setsrc (char *option) { chsrc_ensure_root (); - use_this_source(os_fedora); + chsrc_use_this_source (os_fedora); chsrc_alert2 ("Fedora 38 及以下版本暂不支持"); @@ -63,7 +58,7 @@ os_fedora_setsrc (char *option) chsrc_backup ("/etc/yum.repos.d/fedora-updates.repo"); // 取消对 baseurl 的注释 - char* cmd = xy_strjoin (5, "sed ", + char* cmd = xy_strcat (5, "sed ", "-i 's|^#baseurl=|baseurl=", "|g' ", "/etc/yum.repos.d/fedora.repo ", @@ -73,7 +68,7 @@ os_fedora_setsrc (char *option) // 替换 // (1) baseurl=<>/releases/... // (2) baseurl=<>/updates/... - cmd = xy_strjoin (7, "sed ", + cmd = xy_strcat (7, "sed ", "-i -E 's!^baseurl=.*?/(releases|updates)/!baseurl=", source.url, "/\\1/", diff --git a/src/recipe/os/YUM/Rocky-Linux.c b/src/recipe/os/YUM/Rocky-Linux.c index 146c449..db748d7 100644 --- a/src/recipe/os/YUM/Rocky-Linux.c +++ b/src/recipe/os/YUM/Rocky-Linux.c @@ -7,18 +7,15 @@ def_target(os_rockylinux, "rocky/rockylinux"); void os_rockylinux_prelude () { - use_this(os_rockylinux); - chef_allow_sr(os_rockylinux); + chef_prep_this (os_rockylinux, sr); chef_set_created_on (this, "2023-09-24"); chef_set_last_updated (this, "2025-08-10"); chef_set_sources_last_updated (this, "2025-06-20"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 1, - "happy game", "happygame1024@gmail.com"); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 1, "@happy-game"); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_forbid_english(this); @@ -49,7 +46,7 @@ os_rockylinux_setsrc (char *option) { chsrc_ensure_root (); - use_this_source(os_rockylinux); + chsrc_use_this_source (os_rockylinux); char *version_str = xy_run ("sed -nr 's/ROCKY_SUPPORT_PRODUCT_VERSION=\"(.*)\"/\\1/p' " ETC_OS_RELEASE, 0); double version = atof (version_str); @@ -58,7 +55,7 @@ os_rockylinux_setsrc (char *option) if (version < 9) { - cmd = xy_strjoin (3, + cmd = xy_strcat (3, "sed -e 's|^mirrorlist=|#mirrorlist=|g' " "-e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=", source.url, "|g' " "-i.bak /etc/yum.repos.d/Rocky-*.repo" @@ -70,7 +67,7 @@ os_rockylinux_setsrc (char *option) } else { - cmd = xy_strjoin (3, + cmd = xy_strcat (3, "sed -e 's|^mirrorlist=|#mirrorlist=|g' " "-e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=", source.url, "|g' " "-i.bak /etc/yum.repos.d/rocky-extras.repo /etc/yum.repos.d/rocky.repo" diff --git a/src/recipe/os/YUM/openEuler.c b/src/recipe/os/YUM/openEuler.c index 98ddc6e..f7a2517 100644 --- a/src/recipe/os/YUM/openEuler.c +++ b/src/recipe/os/YUM/openEuler.c @@ -7,21 +7,15 @@ def_target(os_openeuler, "openeuler"); void os_openeuler_prelude () { - use_this(os_openeuler); - chef_allow_gs(os_openeuler); + chef_prep_this (os_openeuler, gs); chef_set_created_on (this, "2023-09-06"); chef_set_last_updated (this, "2025-08-10"); chef_set_sources_last_updated (this, "2025-06-20"); - chef_set_authors (this, 1, "Heng Guo", "2085471348@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 3, - "Aoran Zeng", "ccmywish@qq.com", - "Yangmoooo", "yangmoooo@outlook.com", - "happy game", "happygame1024@gmail.com"); - + chef_set_cooks (this, 1, "@G_I_Y"); + chef_set_chef (this, NULL); + chef_set_sauciers (this, 3, "@ccmywish", "@Yangmoooo", "@happy-game"); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_forbid_english(this); @@ -66,14 +60,14 @@ os_openeuler_setsrc (char *option) { chsrc_ensure_root (); - use_this_source(os_openeuler); + chsrc_use_this_source (os_openeuler); chsrc_backup (OS_openEuler_SourceList); // 替换 baseurl=<>/openEuler-xx.xx/... // openEuler-xx.xx 为 openEuler 版本号 // sed -E 's!^baseurl=.*?/openEuler-([^/]+)!baseurl=$(source.url)/openEuler-\1/!g' OS_openEuler_SourceList - char* cmd = xy_strjoin (6, "sed ", + char* cmd = xy_strcat (6, "sed ", "-i -E 's!^baseurl=.*?/openEuler-([^/]+)!baseurl=", source.url, "openEuler-\\1", diff --git a/src/recipe/os/openSUSE.c b/src/recipe/os/openSUSE.c index 4811ff8..bb5052f 100644 --- a/src/recipe/os/openSUSE.c +++ b/src/recipe/os/openSUSE.c @@ -7,18 +7,15 @@ def_target(os_opensuse, "opensuse/opensuse-leap/opensuse-tumbleweed"); void os_opensuse_prelude () { - use_this(os_opensuse); - chef_allow_s(os_opensuse); + chef_prep_this (os_opensuse, s); chef_set_created_on (this, "2023-09-17"); chef_set_last_updated (this, "2025-08-10"); chef_set_sources_last_updated (this, "2025-06-20"); - chef_set_authors (this, 1, "Heng Guo", "2085471348@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 1, - "Aoran Zeng", "ccmywish@qq.com"); + chef_set_chef (this, NULL); + chef_set_cooks (this, 2, "@ccmywish", "@G_I_Y"); + chef_set_sauciers (this, 0); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_forbid_english(this); @@ -46,7 +43,7 @@ os_opensuse_setsrc (char *option) { // chsrc_ensure_root (); - use_this_source(os_opensuse); + chsrc_use_this_source (os_opensuse); while (1) { chsrc_note2 ("请选择你的操作系统为:"); diff --git a/src/recipe/os/pacman/Arch-Linux.c b/src/recipe/os/pacman/Arch-Linux.c index a200b26..725e152 100644 --- a/src/recipe/os/pacman/Arch-Linux.c +++ b/src/recipe/os/pacman/Arch-Linux.c @@ -10,19 +10,15 @@ def_target(os_arch, "arch/archlinux"); void os_arch_prelude () { - use_this(os_arch); - chef_allow_gs(os_arch); + chef_prep_this (os_arch, gs); chef_set_created_on (this, "2023-09-05"); chef_set_last_updated (this, "2025-08-10"); chef_set_sources_last_updated (this, "2025-06-20"); - chef_set_authors (this, 2, "Aoran Zeng", "ccmywish@qq.com", - "Heng Guo", "2085471348@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 1, "happy game", "happygame1024@gmail.com"); - chef_set_contributors (this, 1, - "happy game", "happygame1024@gmail.com"); + chef_set_chef (this, "@happy-game"); + chef_set_cooks (this, 2, "@ccmywish", "@G_I_Y"); + chef_set_sauciers (this, 1, "@happy-game"); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_forbid_english(this); @@ -70,7 +66,7 @@ os_arch_setsrc (char *option) { chsrc_ensure_root (); - use_this_source(os_arch); + chsrc_use_this_source (os_arch); chsrc_backup (OS_Pacman_MirrorList); @@ -81,12 +77,12 @@ os_arch_setsrc (char *option) if (strncmp(arch, "x86_64", 6)==0) { is_x86 = true; - to_write = xy_strjoin (3, "Server = ", source.url, "/$repo/os/$arch"); + to_write = xy_strcat (3, "Server = ", source.url, "/$repo/os/$arch"); } else { is_x86 = false; - to_write = xy_strjoin (3, "Server = ", source.url, "arm/$arch/$repo"); + to_write = xy_strcat (3, "Server = ", source.url, "arm/$arch/$repo"); } /* 配置文件中,越前面的优先级越高 */ @@ -116,18 +112,15 @@ def_target(os_archlinuxcn, "archlinuxcn/archcn"); void os_archlinuxcn_prelude () { - use_this(os_archlinuxcn); - chef_allow_gs(os_archlinuxcn); + chef_prep_this (os_archlinuxcn, gs); chef_set_created_on (this, "2023-09-05"); chef_set_last_updated (this, "2025-08-10"); chef_set_sources_last_updated (this, "2024-07-03"); - chef_set_authors (this, 2, "Aoran Zeng", "ccmywish@qq.com", "Heng Guo", "2085471348@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 1, - "happy game", "happygame1024@gmail.com"); + chef_set_chef (this, NULL); + chef_set_cooks (this, 2, "@ccmywish", "@G_I_Y"); + chef_set_sauciers (this, 1, "@happy-game"); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_forbid_english(this); @@ -169,7 +162,7 @@ os_archlinuxcn_setsrc (char *option) { chsrc_ensure_root (); - use_this_source(os_archlinuxcn); + chsrc_use_this_source (os_archlinuxcn); chsrc_backup (OS_Pacman_ArchLinuxCN_MirrorList); @@ -181,13 +174,13 @@ os_archlinuxcn_setsrc (char *option) if (ret == 0) { - char *sed_cmd = xy_strjoin (4, "sed -i '/\\[archlinuxcn\\]/{n;s|^Server = .*|Server = ", + char *sed_cmd = xy_strcat (4, "sed -i '/\\[archlinuxcn\\]/{n;s|^Server = .*|Server = ", source.url, "$arch|;}' ", OS_Pacman_ArchLinuxCN_MirrorList); chsrc_run (sed_cmd, RunOpt_Default); } else { - char *archlinuxcn_config = xy_strjoin (3, "\n[archlinuxcn]\nServer = ", source.url, "$arch\n"); + char *archlinuxcn_config = xy_strcat (3, "\n[archlinuxcn]\nServer = ", source.url, "$arch\n"); chsrc_append_to_file (archlinuxcn_config, OS_Pacman_ArchLinuxCN_MirrorList); } diff --git a/src/recipe/os/pacman/MSYS2.c b/src/recipe/os/pacman/MSYS2.c index b5b3406..825d454 100644 --- a/src/recipe/os/pacman/MSYS2.c +++ b/src/recipe/os/pacman/MSYS2.c @@ -7,18 +7,15 @@ def_target(os_msys2, "msys2/msys"); void os_msys2_prelude () { - use_this(os_msys2); - chef_allow_s(os_msys2); + chef_prep_this (os_msys2, s); chef_set_created_on (this, "2023-09-06"); chef_set_last_updated (this, "2025-08-10"); chef_set_sources_last_updated (this, "2025-06-20"); - chef_set_authors (this, 1, "Heng Guo", "2085471348@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 1, - "Aoran Zeng", "ccmywish@qq.com"); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@G_I_Y"); + chef_set_sauciers (this, 1, "@ccmywish"); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_forbid_english(this); @@ -46,18 +43,18 @@ os_msys2_prelude () void os_msys2_setsrc (char *option) { - use_this_source(os_msys2); + chsrc_use_this_source (os_msys2); chsrc_backup ("/etc/pacman.d/mirrorlist.mingw32"); chsrc_backup ("/etc/pacman.d/mirrorlist.mingw64"); chsrc_backup ("/etc/pacman.d/mirrorlist.msys"); - char *prev = xy_strjoin (3, "请针对你的架构下载安装此目录下的文件:", + char *prev = xy_strcat (3, "请针对你的架构下载安装此目录下的文件:", source.url, "distrib/<架构>/"); chsrc_note2 (prev); - char *cmd = xy_strjoin (3, "sed -i \"s#https\?://mirror.msys2.org/#", + char *cmd = xy_strcat (3, "sed -i \"s#https\?://mirror.msys2.org/#", source.url, "#g\" /etc/pacman.d/mirrorlist* "); diff --git a/src/recipe/os/pacman/Manjaro-Linux.c b/src/recipe/os/pacman/Manjaro-Linux.c index 75d5c70..1859897 100644 --- a/src/recipe/os/pacman/Manjaro-Linux.c +++ b/src/recipe/os/pacman/Manjaro-Linux.c @@ -7,16 +7,14 @@ def_target(os_manjaro, "manjaro"); void os_manjaro_prelude () { - use_this(os_manjaro); - chef_allow_s(os_manjaro); + chef_prep_this (os_manjaro, s); chef_set_created_on (this, "2023-09-06"); chef_set_last_updated (this, "2025-08-10"); - chef_set_authors (this, 1, "Heng Guo", "2085471348@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 0); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@G_I_Y"); + chef_set_sauciers (this, 0); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_forbid_english(this); diff --git a/src/recipe/recipe-template.c b/src/recipe/recipe-template.c index 8975e38..8f75e26 100644 --- a/src/recipe/recipe-template.c +++ b/src/recipe/recipe-template.c @@ -2,11 +2,11 @@ * SPDX-License-Identifier: GPL-3.0-or-later * ------------------------------------------------------------- * File Name : recipe-template.c - * File Authors : Aoran Zeng - * Contributors : Nil Null + * File Authors : 曾奥然 + * Contributors : Mikachu2333 * | * Created On : <2024-08-09> - * Last Modified : <2025-08-11> + * Last Modified : <2025-08-22> * ------------------------------------------------------------- * 本文件作为一个通用模板: * @@ -58,29 +58,24 @@ RubyMetric = { void __prelude (void) { - use_this(_); - chef_allow_gsr(_); - // chef_allow_s(_); - // chef_allow_gs(_); - // chef_allow_sr(_); + // op 可以为 NOOP|s|sr|gsr|gs, 代表支持 Get Set Reset 三种操作 + chef_prep_this (_, op); - chef_set_created_on (this, "2024-08-09"); - chef_set_last_updated (this, "2025-08-12"); - chef_set_sources_last_updated (this, "2025-08-11"); - - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 1, - "Nil Null", "nil@null.org"); + chef_set_created_on (this, "2024-08-09"); // 文件创建日期 + chef_set_last_updated (this, "2025-08-12"); // 文件最后一次更新日期 + chef_set_sources_last_updated (this, "2025-08-11"); // 镜像源最后一次更新日期 + chef_set_chef (this, "@ccmywish"); // recipe 负责人 + chef_set_cooks (this, 2, "@ccmywish", "@nilnull"); // recipe 核心作者 + // 做了贡献?将自己的信息加在这里! + chef_set_sauciers (this, 2, "@nulnone", "@someone"); chef_allow_local_mode (this, PartiallyCan, "具体说明是否支持项目级换源...", "Tell users the local mode support"); - // chef_allow_english(this); + // chef_allow_english(this); // 项目是否支持英文 chef_forbid_english(this); - // chef_allow_user_define(this); + // chef_allow_user_define(this); // 是否支持用户自定义镜像源 chef_forbid_user_define(this); chef_set_note ("中文备注说明...", "English note..."); @@ -117,7 +112,7 @@ void __setsrc (char *option) { /* 下面这行是必须的,注入 source 变量 */ - use_this_source(_); + chsrc_use_this_source (_); /* 如果是 target group,你可能想要指定不同的 target 来使用它的源 */ // Source_t source = chsrc_yield_source_and_confirm (&pl_js_group_target, option); @@ -141,3 +136,7 @@ void /* 往往统一在 _setsrc() 中实现,直接调用即可 */ // __setsrc (option); } + + +// 最后,请将自己的文件加入到 menu.c 和 chsrc-main.c 对应的位置 +// 形式可以参考其附近的其他食谱 diff --git a/src/recipe/ware/Anaconda/Anaconda.c b/src/recipe/ware/Anaconda/Anaconda.c index 6ac92a5..6faba38 100644 --- a/src/recipe/ware/Anaconda/Anaconda.c +++ b/src/recipe/ware/Anaconda/Anaconda.c @@ -9,19 +9,15 @@ def_target(wr_anaconda, "conda/anaconda"); void wr_anaconda_prelude () { - use_this(wr_anaconda); - chef_allow_gs(wr_anaconda); + chef_prep_this (wr_anaconda, gs); chef_set_created_on (this, "2023-09-10"); chef_set_last_updated (this, "2025-08-09"); chef_set_sources_last_updated (this, "2025-07-14"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 2, - "Yangmoooo", "yangmoooo@outlook.com", - "yongxiang", "1926885268@qq.com"); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 2, "@Yangmoooo", "@xyx1926885268"); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_forbid_english(this); @@ -56,12 +52,12 @@ wr_anaconda_getsrc (char *option) void wr_anaconda_setsrc (char *option) { - use_this_source(wr_anaconda); + chsrc_use_this_source (wr_anaconda); char *w = xy_str_gsub (RAWSTR_wr_anaconda_condarc, "@1@", source.url); /* Windows 也是在这里 */ - char *configfile = xy_2strjoin (xy_os_home, "/.condarc"); + char *configfile = xy_2strcat (xy_os_home, "/.condarc"); if (xy_on_windows) { @@ -78,7 +74,7 @@ wr_anaconda_setsrc (char *option) } } - chsrc_note2 (xy_strjoin (3, "请向 ", configfile, " 中手动添加:")); + chsrc_note2 (xy_strcat (3, "请向 ", configfile, " 中手动添加:")); println (w); chsrc_note2 ("然后运行 conda clean -i 清除索引缓存,保证用的是镜像站提供的索引"); diff --git a/src/recipe/ware/CocoaPods.c b/src/recipe/ware/CocoaPods.c index 1483dba..88f4f78 100644 --- a/src/recipe/ware/CocoaPods.c +++ b/src/recipe/ware/CocoaPods.c @@ -7,17 +7,15 @@ def_target(wr_cocoapods, "cocoa/cocoapods/cocoapod"); void wr_cocoapods_prelude () { - use_this(wr_cocoapods); - chef_allow_s(wr_cocoapods); + chef_prep_this (wr_cocoapods, s); chef_set_created_on (this, "2024-06-08"); chef_set_last_updated (this, "2025-08-09"); chef_set_sources_last_updated (this, "2025-07-13"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 0); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 0); chef_allow_local_mode (this, CanNot, NULL, NULL); @@ -40,17 +38,17 @@ wr_cocoapods_prelude () void wr_cocoapods_setsrc (char *option) { - use_this_source(wr_cocoapods); + chsrc_use_this_source (wr_cocoapods); chsrc_note2 ("请手动执行以下命令:"); p("cd ~/.cocoapods/repos"); p("pod repo remove master"); - char *git_cmd = xy_strjoin (3, "git clone ", source.url, " master"); + char *git_cmd = xy_strcat (3, "git clone ", source.url, " master"); p(git_cmd); br(); chsrc_note2 ("最后进入项目工程目录,在Podfile中第一行加入:"); - char *source_str = xy_strjoin (3, "source '", source.url, "'"); + char *source_str = xy_strcat (3, "source '", source.url, "'"); p(source_str); chsrc_determine_chgtype (ChgType_Manual); diff --git a/src/recipe/ware/Docker/Docker.c b/src/recipe/ware/Docker/Docker.c index 8c7d8c8..65bd54a 100644 --- a/src/recipe/ware/Docker/Docker.c +++ b/src/recipe/ware/Docker/Docker.c @@ -24,19 +24,15 @@ def_target(wr_docker, "docker/dockerhub"); void wr_docker_prelude () { - use_this(wr_docker); - chef_allow_gs(wr_docker); + chef_prep_this (wr_docker, gs); chef_set_created_on (this, "2024-06-08"); chef_set_last_updated (this, "2025-08-09"); chef_set_sources_last_updated (this, "2025-07-14"); - chef_set_authors (this, 2, - "happy game", "happygame1024@gmail.com", - "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 1, "happy game", "happygame1024@gmail.com"); - chef_set_contributors (this, 0); + chef_set_chef (this, "@happy-game"); + chef_set_cooks (this, 2, "@happy-game", "@ccmywish"); + chef_set_sauciers (this, 0); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_forbid_english(this); @@ -75,7 +71,7 @@ wr_docker_setsrc (char *option) { chsrc_ensure_root (); - use_this_source(wr_docker); + chsrc_use_this_source (wr_docker); if (xy_on_linux || xy_on_bsd) { @@ -118,7 +114,7 @@ wr_docker_setsrc (char *option) /* 不存在 /etc/docker/daemon.json 时可以直接写入文件 */ chsrc_alert2 ("未找到Docker配置文件, 将自动创建"); chsrc_ensure_dir ("/etc/docker"); - chsrc_run ( xy_2strjoin ("touch ", WR_Docker_ConfigFile), RunOpt_Default); + chsrc_run ( xy_2strcat ("touch ", WR_Docker_ConfigFile), RunOpt_Default); chsrc_append_to_file (to_add, WR_Docker_ConfigFile); } diff --git a/src/recipe/ware/Emacs.c b/src/recipe/ware/Emacs.c index 3e69010..d0b7e84 100644 --- a/src/recipe/ware/Emacs.c +++ b/src/recipe/ware/Emacs.c @@ -14,17 +14,15 @@ def_target(wr_emacs, "emacs/elpa"); void wr_emacs_prelude () { - use_this(wr_emacs); - chef_allow_s(wr_emacs); + chef_prep_this (wr_emacs, s); chef_set_created_on (this, "2023-10-10"); chef_set_last_updated (this, "2025-08-09"); chef_set_sources_last_updated (this, "2025-07-13"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 0); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 0); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_forbid_english(this); @@ -49,7 +47,7 @@ wr_emacs_prelude () void wr_emacs_setsrc (char *option) { - use_this_source(wr_emacs); + chsrc_use_this_source (wr_emacs); chsrc_note2 ("Emacs换源涉及Elisp, 需要手动查阅并换源:"); p (source.url); diff --git a/src/recipe/ware/Flatpak.c b/src/recipe/ware/Flatpak.c index 7a010d4..0163298 100644 --- a/src/recipe/ware/Flatpak.c +++ b/src/recipe/ware/Flatpak.c @@ -7,18 +7,15 @@ def_target(wr_flatpak, "flatpak/flathub"); void wr_flatpak_prelude () { - use_this(wr_flatpak); - chef_allow_gsr(wr_flatpak); + chef_prep_this (wr_flatpak, gsr); chef_set_created_on (this, "2023-09-11"); chef_set_last_updated (this, "2025-08-09"); chef_set_sources_last_updated (this, "2025-05-27"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 1, - "Jialin Lyu", "jialinlvcn@aliyun.com"); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 1, "@jialinlvcn"); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_forbid_english(this); @@ -66,10 +63,10 @@ wr_flatpak_getsrc (char *option) void wr_flatpak_setsrc (char *option) { - use_this_source(wr_flatpak); + chsrc_use_this_source (wr_flatpak); chsrc_alert2 ("若出现问题,可先调用以下命令:"); - char *note = xy_strjoin (3, + char *note = xy_strcat (3, "wget ", source.url, "/flathub.gpg\n" "flatpak remote-modify --gpg-import=flathub.gpg flathub" ); @@ -80,7 +77,7 @@ wr_flatpak_setsrc (char *option) "尝试运行 flatpak remote-modify flathub --url=https://flathub.org/repo"; say (repo_note); - char *cmd = xy_2strjoin ("flatpak remote-modify flathub --url=", source.url); + char *cmd = xy_2strcat ("flatpak remote-modify flathub --url=", source.url); chsrc_run (cmd, RunOpt_Default); chsrc_determine_chgtype (ChgType_Auto); diff --git a/src/recipe/ware/Guix.c b/src/recipe/ware/Guix.c index ec37298..a31483a 100644 --- a/src/recipe/ware/Guix.c +++ b/src/recipe/ware/Guix.c @@ -7,17 +7,15 @@ def_target(wr_guix, "guix"); void wr_guix_prelude () { - use_this(wr_guix); - chef_allow_s(wr_guix); + chef_prep_this (wr_guix, s); chef_set_created_on (this, "2023-09-11"); chef_set_last_updated (this, "2025-08-09"); chef_set_sources_last_updated (this, "2025-07-13"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 0); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 0); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_forbid_english(this); @@ -39,9 +37,9 @@ wr_guix_prelude () void wr_guix_setsrc (char *option) { - use_this_source(wr_guix); + chsrc_use_this_source (wr_guix); - char *file = xy_strjoin (3, "(list (channel\n" + char *file = xy_strcat (3, "(list (channel\n" " (inherit (car %default-channels))\n" " (url \"", source.url, "\")))"); diff --git a/src/recipe/ware/Homebrew/Homebrew.c b/src/recipe/ware/Homebrew/Homebrew.c index 525cd69..cc76335 100644 --- a/src/recipe/ware/Homebrew/Homebrew.c +++ b/src/recipe/ware/Homebrew/Homebrew.c @@ -9,18 +9,15 @@ def_target(wr_homebrew, "brew/homebrew"); void wr_homebrew_prelude () { - use_this(wr_homebrew); - chef_allow_gs(wr_homebrew); + chef_prep_this (wr_homebrew, gs); chef_set_created_on (this, "2023-09-10"); chef_set_last_updated (this, "2025-08-09"); chef_set_sources_last_updated (this, "2025-07-13"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 1, - "Word2VecT", "tangzinan@bupt.edu.cn"); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 1, "@Word2VecT"); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_allow_english(this); @@ -43,7 +40,7 @@ void wr_homebrew_getsrc (char *option) { int status = system (RAWSTR_wr_homebrew_read_config_cmd); - if (status != 0) { /* NOOP */ } + if (status != 0) { xy_noop(); } } /** @@ -56,7 +53,7 @@ wr_homebrew_getsrc (char *option) void wr_homebrew_setsrc (char *option) { - use_this_source(wr_homebrew); + chsrc_use_this_source (wr_homebrew); char *w = xy_str_gsub (RAWSTR_wr_homebrew_config_in_bash, "@1@", source.url); diff --git a/src/recipe/ware/Nix.c b/src/recipe/ware/Nix.c index 1fa010f..b39379c 100644 --- a/src/recipe/ware/Nix.c +++ b/src/recipe/ware/Nix.c @@ -7,17 +7,15 @@ def_target(wr_nix, "nix"); void wr_nix_prelude () { - use_this(wr_nix); - chef_allow_s(wr_nix); + chef_prep_this (wr_nix, s); chef_set_created_on (this, "2023-09-26"); chef_set_last_updated (this, "2025-08-09"); chef_set_sources_last_updated (this, "2025-07-13"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 0); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 0); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_forbid_english(this); @@ -52,21 +50,21 @@ wr_nix_setsrc (char *option) { wr_nix_check_cmd (); - use_this_source(wr_nix); + chsrc_use_this_source (wr_nix); - char *cmd = xy_strjoin (3, "nix-channel --add ", source.url, "nixpkgs-unstable nixpkgs"); + char *cmd = xy_strcat (3, "nix-channel --add ", source.url, "nixpkgs-unstable nixpkgs"); chsrc_run (cmd, RunOpt_Default); - char *w = xy_strjoin (3, "substituters = ", source.url, "store https://cache.nixos.org/"); + char *w = xy_strcat (3, "substituters = ", source.url, "store https://cache.nixos.org/"); chsrc_append_to_file (w, "~/.config/nix/nix.conf"); chsrc_run ("nix-channel --update", RunOpt_Default); chsrc_note2 ("若你使用的是NixOS,请确认你的系统版本(如22.11),并手动运行:"); - cmd = xy_strjoin (3, "nix-channel --add ", source.url, "nixpkgs- nixpkgs"); + cmd = xy_strcat (3, "nix-channel --add ", source.url, "nixpkgs- nixpkgs"); p(cmd); - cmd = xy_strjoin (3, "nix.settings.substituters = [ \"", source.url, "store\" ];"); + cmd = xy_strcat (3, "nix.settings.substituters = [ \"", source.url, "store\" ];"); chsrc_note2 ("若你使用的是NixOS,请额外添加下述内容至 configuration.nix 中"); p(cmd); diff --git a/src/recipe/ware/TeX-Live.c b/src/recipe/ware/TeX-Live.c index 0bd25d4..b267159 100644 --- a/src/recipe/ware/TeX-Live.c +++ b/src/recipe/ware/TeX-Live.c @@ -9,18 +9,15 @@ def_target(wr_tex, "latex/ctan/tex/texlive/miktex/tlmgr/mpm"); void wr_tex_prelude () { - use_this(wr_tex); - chef_allow_gs(wr_tex); + chef_prep_this (wr_tex, gs); chef_set_created_on (this, "2023-09-10"); chef_set_last_updated (this, "2025-08-09"); chef_set_sources_last_updated (this, "2025-07-28"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 1, - "Mikachu2333", "mikachu.23333@zohomail.com"); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 1, "@Mikachu2333"); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_forbid_english(this); @@ -85,20 +82,20 @@ wr_tex_setsrc (char *option) bool tlmgr_exist, mpm_exist; wr_tex_check_cmd (&tlmgr_exist, &mpm_exist); - use_this_source(wr_tex); + chsrc_use_this_source (wr_tex); char *cmd = NULL; if (tlmgr_exist) { - cmd = xy_2strjoin ("tlmgr option repository ", source.url); + cmd = xy_2strcat ("tlmgr option repository ", source.url); chsrc_run (cmd, RunOpt_Default); } if (mpm_exist) { - char *miktex_url = xy_2strjoin (xy_str_delete_suffix (source.url, "texlive/tlnet"), "win32/miktex/tm/packages/"); - cmd = xy_2strjoin ("mpm --set-repository=", miktex_url); + char *miktex_url = xy_2strcat (xy_str_delete_suffix (source.url, "texlive/tlnet"), "win32/miktex/tm/packages/"); + cmd = xy_2strcat ("mpm --set-repository=", miktex_url); chsrc_run (cmd, RunOpt_Default); } diff --git a/src/recipe/ware/WinGet.c b/src/recipe/ware/WinGet.c index 2ffccf1..a05f2a8 100644 --- a/src/recipe/ware/WinGet.c +++ b/src/recipe/ware/WinGet.c @@ -7,17 +7,15 @@ def_target(wr_winget, "winget"); void wr_winget_prelude () { - use_this(wr_winget); - chef_allow_gsr(wr_winget); + chef_prep_this (wr_winget, gsr); chef_set_created_on (this, "2024-06-07"); - chef_set_last_updated (this, "2025-07-13"); + chef_set_last_updated (this, "2025-08-17"); chef_set_sources_last_updated (this, "2025-07-13"); - chef_set_authors (this, 1, "Aoran Zeng", "ccmywish@qq.com"); - chef_set_chef (this, NULL, NULL); - chef_set_cooks (this, 0); - chef_set_contributors (this, 0); + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 1, "@Mikachu2333"); chef_forbid_english(this); chef_allow_user_define(this); @@ -46,10 +44,13 @@ wr_winget_getsrc (char *option) void wr_winget_setsrc (char *option) { - use_this_source(wr_winget); + chsrc_use_this_source (wr_winget); - chsrc_run ("winget source remove winget", RunOpt_Default); - chsrc_run (xy_strjoin (3, "winget source add winget ", source.url, " --trust-level trusted"), RunOpt_Default); + // 2025.8.17 此前用户可能隐式使用默认源导致 remove 失败,故使用 Dont_Abort + chsrc_run ("winget source remove winget", RunOpt_Dont_Abort_On_Failure); + // 2025.8.18 执行两次相同的命令后继续设置,无报错,换源成功。具体原因不明 + chsrc_run ("winget source remove winget", RunOpt_Dont_Abort_On_Failure); + chsrc_run (xy_strcat (3, "winget source add winget ", source.url, " --trust-level trusted"), RunOpt_Default); chsrc_determine_chgtype (ChgType_Auto); chsrc_conclude (&source); diff --git a/test/fw.c b/test/fw.c index efad9af..a391d93 100644 --- a/test/fw.c +++ b/test/fw.c @@ -62,7 +62,7 @@ main (int argc, char const *argv[]) chsrc_overwrite_file ("overwrite", bkup); chsrc_view_file (bkup); - chsrc_log (xy_2strjoin ("CPU arch = ", chsrc_get_cpuarch ())); + chsrc_log (xy_2strcat ("CPU arch = ", chsrc_get_cpuarch ())); print ("chsrc: CPU cores = "); println (chsrc_get_cpucore ()); diff --git a/test/xy.c b/test/xy.c index 7c64414..315a70c 100644 --- a/test/xy.c +++ b/test/xy.c @@ -1,33 +1,45 @@ /** ------------------------------------------------------------ * SPDX-License-Identifier: MIT * ------------------------------------------------------------- - * File Name : xy.c - * File Authors : Aoran Zeng - * Contributors : Nil Null - * | + * Test File : xy.c + * Test Authors : 曾奥然 + * Contributors : Mikachu2333 * Created On : <2023-08-30> - * Last Modified : <2025-08-08> + * Last Modified : <2025-08-22> * * Test xy.h * ------------------------------------------------------------*/ #include "xy.h" +void +print_str_for_seq (void *str, void *NOUSE) +{ + print ((char *) str); +} + +void +print_str_for_map (const char *key, void *value, void *NOUSE) +{ + println (xy_strcat (4, " ", key, " => ", (char *) value)); +} + + int main (int argc, char const *argv[]) { - xy_useutf8 (); + xy_init (); println (xy_os_depend_str ("Hello, Windows!", "Hello, Unix!")); println (3); double dbl = 3.1415; println (dbl); - say (xy_2strjoin ("Xi", "'an")); - say (xy_strjoin (2, "Xi", "'an")); - say (xy_strjoin (3, "屈身守分,", "以待天时,", "不可与命争也")); - say (xy_strjoin (4, "水落鱼梁浅,", "天寒梦泽深。", "羊公碑字在,", "读罢泪沾襟。")); - say (xy_strjoin (6, "楚山横地出,", "汉水接天回。", "冠盖非新里,", "章华即旧台。", "习池风景异,", "归路满尘埃。")); + say (xy_2strcat ("Xi", "'an")); + say (xy_strcat (2, "Xi", "'an")); + say (xy_strcat (3, "屈身守分,", "以待天时,", "不可与命争也")); + say (xy_strcat (4, "水落鱼梁浅,", "天寒梦泽深。", "羊公碑字在,", "读罢泪沾襟。")); + say (xy_strcat (6, "楚山横地出,", "汉水接天回。", "冠盖非新里,", "章华即旧台。", "习池风景异,", "归路满尘埃。")); print (xy_str_to_bold ("粗体")); print (xy_str_to_faint ("浅体")); @@ -97,9 +109,23 @@ main (int argc, char const *argv[]) assert (xy_dir_exist ("~")); if (xy_on_windows) { + say (xy_normalize_path ("~")); + say (xy_normalize_path ("~/")); + // xy_parent_dir() 得到的结果一定是不包含尾斜杠的目录名 + assert_str (xy_parent_dir (xy_normalize_path ("~")), "C:\\Users"); + assert_str (xy_parent_dir (xy_normalize_path ("~/")), "C:\\Users"); + assert (xy_dir_exist ("C:\\Users")); + + say (xy_win_powershell_profile); + say (xy_win_powershellv5_profile); assert (xy_file_exist (xy_win_powershell_profile)); assert (true == xy_file_exist (xy_win_powershellv5_profile)); - assert (xy_dir_exist ("C:\\Users")); + + assert_str (xy_normalize_path ("C:\\a bc\\def\\"), "C:\\a bc\\def\\"); + assert_str (xy_normalize_path ("a/b c/d"), "a\\b c\\d"); + assert_str (xy_normalize_path ("a/b c/d/"), "a\\b c\\d\\"); + assert_str (xy_parent_dir ("a/b c/d"), "a\\b c"); + assert_str (xy_parent_dir ("a/b c\\d/"), "a\\b c"); } else { @@ -117,6 +143,30 @@ main (int argc, char const *argv[]) println (xy_normalize_path (" \n ~/haha/test/123 \n\r ")); assert_str (xy_normalize_path ("~/haha/test"), xy_parent_dir (" ~/haha/test/123")); + + + XySeq_t *seq = xy_seq_new (); + xy_seq_push (seq, "Hello"); + xy_seq_push (seq, "World"); + assert_str ("Hello", xy_seq_at (seq, 1)); + assert_str ("World", xy_seq_at (seq, 2)); + xy_seq_each (seq, print_str_for_seq, NULL); br(); + xy_seq_pop (seq); + assert (1 == xy_seq_len (seq)); + + + XyMap_t *map = xy_map_new (); + xy_map_set (map, "Hello", "World"); + xy_map_set (map, "你好", "世界"); + assert_str ("World", xy_map_get (map, "Hello")); + assert_str ("世界", xy_map_get (map, "你好")); + xy_map_set (map, "Hello", "chsrc"); + assert_str ("chsrc", xy_map_get (map, "Hello")); + assert (2 == xy_map_len (map)); + echo ("{"); + xy_map_each (map, print_str_for_map, NULL); + echo ("}"); + xy_succ ("测试完成", "xy.h 测试全部通过"); // xy_unimplemented(); diff --git a/tool/git-ignore-vscode-settings.ps1 b/tool/git-ignore-vscode-settings.ps1 new file mode 100644 index 0000000..c53f584 --- /dev/null +++ b/tool/git-ignore-vscode-settings.ps1 @@ -0,0 +1,17 @@ +# --------------------------------------------------------------- +# SPDX-License-Identifier: GPL-3.0-or-later +# --------------------------------------------------------------- +# File Name : git-ignore-vscode-settings.ps1 +# File Authors : Aoran Zeng +# Created On : <2025-08-17> +# Last Modified : <2025-08-17> +# +# VS Code 的某些操作/插件会频繁地修改我们的 .vscode/settings.json +# 文件,非常非常烦人,但是该文件又应该被加入仓库,所以我们使用以下 +# 命令来忽略它在本地的变化 +# --------------------------------------------------------------- + +git update-index --skip-worktree .\.vscode\settings.json + +# 恢复方法是: +# git update-index --no-skip-worktree .\.vscode\settings.json