From be3982bbffe3958d597987b58d0e0ce86e22eb59 Mon Sep 17 00:00:00 2001 From: Aoran Zeng Date: Sat, 14 Dec 2024 09:14:11 +0800 Subject: [PATCH] Remove `xy_run()` last parameter --- include/xy.h | 13 ++++++++++--- src/framework/core.c | 12 ++++++------ src/recipe/lang/Java.c | 2 +- src/recipe/lang/Node.js/Yarn.c | 2 +- src/recipe/lang/Python/Rye.c | 2 +- src/recipe/lang/Ruby.c | 2 +- src/recipe/os/APT/common.h | 4 ++-- src/recipe/os/BSD/NetBSD.c | 2 +- src/recipe/os/YUM/Rocky-Linux.c | 2 +- src/recipe/ware/Docker-Hub.c | 2 +- 10 files changed, 25 insertions(+), 18 deletions(-) diff --git a/include/xy.h b/include/xy.h index b61104c..168472e 100644 --- a/include/xy.h +++ b/include/xy.h @@ -8,7 +8,7 @@ * Contributors : Nil Null * | * Created On : <2023-08-28> - * Last Modified : <2024-11-22> + * Last Modified : <2024-12-14> * * xy: 襄阳、咸阳 * Corss-Platform C utilities for CLI applications in Ruby flavor @@ -17,7 +17,7 @@ #ifndef XY_H #define XY_H -#define _XY_Version "v0.1.4.3-2024/11/22" +#define _XY_Version "v0.1.4.4-2024/12/14" #define _XY_Maintain_URL "https://gitee.com/RubyMetric/chsrc/blob/main/include/xy.h" #include @@ -604,7 +604,7 @@ _xy_log_brkt (int level, const char *prompt1, const char *prompt2, const char *c * 由于目标行会被返回出来,所以 iter_func() 并不执行目标行,只会执行遍历过的行 */ static char * -xy_run (const char *cmd, unsigned long n, void (*iter_func) (const char *)) +xy_run_iter (const char *cmd, unsigned long n, void (*iter_func) (const char *)) { const int size = 512; char *buf = (char *) malloc (size); @@ -637,6 +637,13 @@ xy_run (const char *cmd, unsigned long n, void (*iter_func) (const char *)) return ret; } +static char * +xy_run (const char *cmd, unsigned long n) +{ + xy_run_iter (cmd, n, NULL); +} + + #define xy_os_home _xy_os_home () static char * _xy_os_home () diff --git a/src/framework/core.c b/src/framework/core.c index 2a60016..a579aea 100644 --- a/src/framework/core.c +++ b/src/framework/core.c @@ -499,7 +499,7 @@ measure_speed_for_url (void *url) // chsrc_info (xy_2strjoin ("测速命令 ", curl_cmd)); - char *curl_buf = xy_run (curl_cmd, 0, NULL); + char *curl_buf = xy_run (curl_cmd, 0); // 如果尾部有换行,删除 curl_buf = xy_str_strip (curl_buf); @@ -693,7 +693,7 @@ select_mirror_autoly (Source_t *sources, size_t size, const char *target_name) if (xy_on_windows) { - char *curl_version = xy_run ("curl --version", 1, NULL); + char *curl_version = xy_run ("curl --version", 1); /** * https://github.com/RubyMetric/chsrc/issues/144 * @@ -1023,7 +1023,7 @@ chsrc_ensure_root () char *euid = getenv ("$EUID"); if (NULL==euid) { - char *buf = xy_run ("id -u", 0, NULL); + char *buf = xy_run ("id -u", 0); if (0!=atoi(buf)) goto not_root; else return; } @@ -1288,7 +1288,7 @@ chsrc_backup (const char *path) } else { - char *ver = xy_run (xy_str_to_quietcmd ("cp --version"), 1, NULL); + char *ver = xy_run (xy_str_to_quietcmd ("cp --version"), 1); /* cp (GNU coreutils) 9.4 */ if (strstr (ver, "GNU coreutils")) { @@ -1345,14 +1345,14 @@ chsrc_get_cpuarch () exist = chsrc_check_program_quietly ("arch"); if (exist) { - ret = xy_run ("arch", 0, NULL); + ret = xy_run ("arch", 0); return ret; } exist = chsrc_check_program_quietly ("uname"); if (exist) { - ret = xy_run ("uname -m", 0, NULL); + ret = xy_run ("uname -m", 0); return ret; } else diff --git a/src/recipe/lang/Java.c b/src/recipe/lang/Java.c index afbc024..767dc29 100644 --- a/src/recipe/lang/Java.c +++ b/src/recipe/lang/Java.c @@ -37,7 +37,7 @@ pl_java_check_cmd (bool *maven_exist, bool *gradle_exist) char * pl_java_find_maven_config () { - char *buf = xy_run ("mvn -v", 2, NULL); + char *buf = xy_run ("mvn -v", 2); char *maven_home = xy_str_delete_prefix (buf, "Maven home: "); maven_home = xy_str_strip (maven_home); diff --git a/src/recipe/lang/Node.js/Yarn.c b/src/recipe/lang/Node.js/Yarn.c index 3216070..ae2d2fe 100644 --- a/src/recipe/lang/Node.js/Yarn.c +++ b/src/recipe/lang/Node.js/Yarn.c @@ -11,7 +11,7 @@ static double pl_nodejs_yarn_get_yarn_version () { - char *ver = xy_run ("yarn --version", 0, NULL); + char *ver = xy_run ("yarn --version", 0); double version = atof (ver); return version; } diff --git a/src/recipe/lang/Python/Rye.c b/src/recipe/lang/Python/Rye.c index a0b4433..bb6687e 100644 --- a/src/recipe/lang/Python/Rye.c +++ b/src/recipe/lang/Python/Rye.c @@ -12,7 +12,7 @@ char * pl_python_find_rye_config () { - char *buf = xy_run ("rye config --show-path", 0, NULL); + char *buf = xy_run ("rye config --show-path", 0); char *rye_config = xy_normalize_path (xy_str_strip (buf)); return rye_config; diff --git a/src/recipe/lang/Ruby.c b/src/recipe/lang/Ruby.c index e412fbd..8f77f09 100644 --- a/src/recipe/lang/Ruby.c +++ b/src/recipe/lang/Ruby.c @@ -74,7 +74,7 @@ pl_ruby_setsrc (char *option) char *cmd = NULL; - xy_run ("gem sources -l", 0, pl_ruby_remove_gem_source); + xy_run_iter ("gem sources -l", 0, pl_ruby_remove_gem_source); cmd = xy_2strjoin ("gem source -a ", source.url); chsrc_run (cmd, RunOpt_Default); diff --git a/src/recipe/os/APT/common.h b/src/recipe/os/APT/common.h index 382e8ec..0c7b096 100644 --- a/src/recipe/os/APT/common.h +++ b/src/recipe/os/APT/common.h @@ -61,10 +61,10 @@ ensure_apt_sourcelist (int debian_type) } // 反向引用需要escape一下 - char *codename = xy_run ("sed -nr 's/VERSION_CODENAME=(.*)/\\1/p' " ETC_OS_RELEASE, 0, NULL); + char *codename = xy_run ("sed -nr 's/VERSION_CODENAME=(.*)/\\1/p' " ETC_OS_RELEASE, 0); codename = xy_str_delete_suffix (codename, "\n"); - char *version_id = xy_run ("sed -nr 's/VERSION_ID=\"(.*)\"/\\1/p' " ETC_OS_RELEASE, 0, NULL); + char *version_id = xy_run ("sed -nr 's/VERSION_ID=\"(.*)\"/\\1/p' " ETC_OS_RELEASE, 0); version_id = xy_str_delete_suffix (codename, "\n"); diff --git a/src/recipe/os/BSD/NetBSD.c b/src/recipe/os/BSD/NetBSD.c index aa823f1..84e45e4 100644 --- a/src/recipe/os/BSD/NetBSD.c +++ b/src/recipe/os/BSD/NetBSD.c @@ -53,7 +53,7 @@ os_netbsd_setsrc (char *option) char *arch = chsrc_get_cpuarch (); char *vercmd = "cat /etc/os-release | grep \"VERSION=\" | grep -Po \"[8-9].[0-9]+\""; - char *version = xy_run (vercmd, 0, NULL); + char *version = xy_run (vercmd, 0); char *url = xy_strjoin (5, source.url, arch, "/", version, "/All"); chsrc_overwrite_file (url, "/usr/pkg/etc/pkgin/repositories.conf"); diff --git a/src/recipe/os/YUM/Rocky-Linux.c b/src/recipe/os/YUM/Rocky-Linux.c index 2e03436..01a4b56 100644 --- a/src/recipe/os/YUM/Rocky-Linux.c +++ b/src/recipe/os/YUM/Rocky-Linux.c @@ -38,7 +38,7 @@ os_rockylinux_setsrc (char *option) chsrc_yield_source_and_confirm (os_rockylinux); - char *version_str = xy_run ("sed -nr 's/ROCKY_SUPPORT_PRODUCT_VERSION=\"(.*)\"/\\1/p' " ETC_OS_RELEASE, 0, NULL); + char *version_str = xy_run ("sed -nr 's/ROCKY_SUPPORT_PRODUCT_VERSION=\"(.*)\"/\\1/p' " ETC_OS_RELEASE, 0); version_str = xy_str_delete_suffix (version_str, "\n"); double version = atof (version_str); diff --git a/src/recipe/ware/Docker-Hub.c b/src/recipe/ware/Docker-Hub.c index 9984f41..f688d8d 100644 --- a/src/recipe/ware/Docker-Hub.c +++ b/src/recipe/ware/Docker-Hub.c @@ -97,7 +97,7 @@ wr_dockerhub_setsrc (char *option) source.url, "\")' ", WARE_DockerHub_SourceConfig); - char *ret = xy_run(cmd, 0, NULL); + char *ret = xy_run(cmd, 0); if (ret && !xy_streql(ret, "null\n")) { chsrc_note2 ("已存在源,无需重复添加");