Rename to helper.c

This commit is contained in:
Aoran Zeng
2025-10-28 22:29:57 +08:00
parent fd309e7300
commit fed349827c
6 changed files with 17 additions and 16 deletions

View File

@@ -7,7 +7,7 @@
! Contributors : Nul None <nul@none.org> ! Contributors : Nul None <nul@none.org>
! | ! |
! Created On : <2024-08-19> ! Created On : <2024-08-19>
! Last Modified : <2025-08-22> ! Last Modified : <2025-10-28>
! ---------------------------------------------------------- --> ! ---------------------------------------------------------- -->
# Write A Recipe Even If You Don't Know C # Write A Recipe Even If You Don't Know C
@@ -89,7 +89,8 @@
1. `framework/core.c` 中以 `chsrc_` 开头的所有函数或宏 1. `framework/core.c` 中以 `chsrc_` 开头的所有函数或宏
2. `xy.h` 中以 `xy_` 开头的所有函数或宏 2. `xy.h` 中以 `xy_` 开头的所有函数或宏
3. `chec.c` `chef-helper.c` 中以 `chef_` 开头的所有函数或宏 3. `chec.c` 中以 `chef_` 开头的所有函数或宏
4. `helper.c` 中以 `hp_` 开头的所有函数或宏
一个简单的方法是,在 VS Code 中按快捷键 `Ctrl-T` 搜索上述三种前缀 一个简单的方法是,在 VS Code 中按快捷键 `Ctrl-T` 搜索上述三种前缀

View File

@@ -137,7 +137,7 @@ chef_set_sources_speed_measure_url_with_func (
if (src->url) if (src->url)
{ {
/* 为空时才修改 或者里面是脏数据 */ /* 为空时才修改 或者里面是脏数据 */
if (NULL==src->speed_measure_url || !chef_is_url (src->speed_measure_url)) if (NULL==src->speed_measure_url || !hp_is_url (src->speed_measure_url))
{ {
src->speed_measure_url = func (src->url, user_data); src->speed_measure_url = func (src->url, user_data);
} }

View File

@@ -11,7 +11,7 @@
* | Mikachu2333 <mikachu.23333@zohomail.com> * | Mikachu2333 <mikachu.23333@zohomail.com>
* | * |
* Created On : <2023-08-29> * Created On : <2023-08-29>
* Last Modified : <2025-09-29> * Last Modified : <2025-10-28>
* *
* chsrc framework * chsrc framework
* ------------------------------------------------------------*/ * ------------------------------------------------------------*/
@@ -27,7 +27,7 @@
#include "xy.h" #include "xy.h"
#include "struct.h" #include "struct.h"
#include "mirror.c" #include "mirror.c"
#include "chef-helper.c" #include "helper.c"
#define App_Name "chsrc" #define App_Name "chsrc"
@@ -511,7 +511,7 @@ chsrc_check_file (char *path)
int int
query_mirror_exist (Source_t *sources, size_t size, char *target_name, char *input) query_mirror_exist (Source_t *sources, size_t size, char *target_name, char *input)
{ {
if (chef_is_url (input)) if (hp_is_url (input))
{ {
char *msg = ENGLISH ? "Using user-defined sources for this software is not supported at this time, please contact the developers to ask why or request support" : "暂不支持对该软件使用用户自定义源,请联系开发者询问原因或请求支持"; char *msg = ENGLISH ? "Using user-defined sources for this software is not supported at this time, please contact the developers to ask why or request support" : "暂不支持对该软件使用用户自定义源,请联系开发者询问原因或请求支持";
chsrc_error (msg); chsrc_error (msg);
@@ -764,7 +764,7 @@ measure_speed_for_every_source (Source_t sources[], int size, double speed_recor
} }
else if (!provider_skip && provider_speed_url) else if (!provider_skip && provider_speed_url)
{ {
if (chef_is_url (provider_speed_url)) if (hp_is_url (provider_speed_url))
{ {
url = xy_strdup (provider_speed_url); url = xy_strdup (provider_speed_url);
chsrc_debug ("m", xy_2strcat ("使用镜像站整体测速链接: ", url)); chsrc_debug ("m", xy_2strcat ("使用镜像站整体测速链接: ", url));
@@ -777,7 +777,7 @@ measure_speed_for_every_source (Source_t sources[], int size, double speed_recor
if (dedicated_speed_url) if (dedicated_speed_url)
{ {
if (chef_is_url (dedicated_speed_url)) if (hp_is_url (dedicated_speed_url))
{ {
url = xy_strdup (dedicated_speed_url); url = xy_strdup (dedicated_speed_url);
has_dedicated_speed_url = true; has_dedicated_speed_url = true;
@@ -1055,7 +1055,7 @@ chsrc_yield_source (Target_t *t, char *option)
{ {
source = t->sources[ProgStatus.leader_selected_index]; source = t->sources[ProgStatus.leader_selected_index];
} }
else if (chef_is_url (option)) else if (hp_is_url (option))
{ {
Source_t tmp = { &UserDefinedProvider, option }; Source_t tmp = { &UserDefinedProvider, option };
source = tmp; source = tmp;

View File

@@ -1,18 +1,18 @@
/** ------------------------------------------------------------ /** ------------------------------------------------------------
* SPDX-License-Identifier: GPL-3.0-or-later * SPDX-License-Identifier: GPL-3.0-or-later
* ------------------------------------------------------------- * -------------------------------------------------------------
* File Name : chef-helper.c * File Name : helper.c
* File Authors : <ccmywish@qq.com> * File Authors : <ccmywish@qq.com>
* Contributors : Nul None <nul@none.org> * Contributors : Nul None <nul@none.org>
* Created On : <2025-07-14> * Created On : <2025-07-14>
* Last Modified : <2025-08-20> * Last Modified : <2025-10-28>
* *
* For chefs (recipe makers) and sometimes framewoker * For chefs (recipe makers) and sometimes framewoker
* to do some work not releated to OS operations * to do some work not releated to OS operations
* ------------------------------------------------------------*/ * ------------------------------------------------------------*/
bool bool
chef_is_url (const char *str) hp_is_url (const char *str)
{ {
return (xy_str_start_with (str, "http://") || xy_str_start_with (str, "https://")); return (xy_str_start_with (str, "http://") || xy_str_start_with (str, "https://"));
} }
@@ -21,7 +21,7 @@ chef_is_url (const char *str)
* @return * @return
*/ */
char * char *
chef_remove_trailing_slash (char *str) hp_remove_trailing_slash (char *str)
{ {
char *newstr = xy_strdup (str); char *newstr = xy_strdup (str);
size_t len = strlen (newstr); size_t len = strlen (newstr);
@@ -34,7 +34,7 @@ chef_remove_trailing_slash (char *str)
* @return * @return
*/ */
char * char *
chef_ensure_trailing_slash (char *str) hp_ensure_trailing_slash (char *str)
{ {
size_t len = strlen (str); size_t len = strlen (str);
if (len == 0 || str[len - 1] == '/') if (len == 0 || str[len - 1] == '/')

View File

@@ -54,7 +54,7 @@ bool
pl_ruby_remove_gem_source (const char *source) pl_ruby_remove_gem_source (const char *source)
{ {
char *cmd = NULL; char *cmd = NULL;
if (chef_is_url (source)) if (hp_is_url (source))
{ {
cmd = xy_2strcat ("gem sources -r ", source); cmd = xy_2strcat ("gem sources -r ", source);
chsrc_run (cmd, RunOpt_Default); chsrc_run (cmd, RunOpt_Default);

View File

@@ -66,7 +66,7 @@ os_netbsd_setsrc (char *option)
char *vercmd = "cat /etc/os-release | grep \"VERSION=\" | grep -Po \"[8-9].[0-9]+\""; char *vercmd = "cat /etc/os-release | grep \"VERSION=\" | grep -Po \"[8-9].[0-9]+\"";
char *version = xy_run (vercmd, 0); char *version = xy_run (vercmd, 0);
char *url = xy_strcat (5, chef_ensure_trailing_slash (source.url), arch, "/", version, "/All"); char *url = xy_strcat (5, hp_ensure_trailing_slash (source.url), arch, "/", version, "/All");
chsrc_overwrite_file (url, "/usr/pkg/etc/pkgin/repositories.conf"); chsrc_overwrite_file (url, "/usr/pkg/etc/pkgin/repositories.conf");
chsrc_conclude (&source); chsrc_conclude (&source);