Rename some functions

This commit is contained in:
Aoran Zeng 2023-10-05 09:40:10 +08:00
parent 77a6284d83
commit 0fe9289c1d
3 changed files with 26 additions and 26 deletions

40
chsrc.c
View File

@ -3,7 +3,7 @@
* License : GPLv3 * License : GPLv3
* Authors : Aoran Zeng <ccmywish@qq.com> * Authors : Aoran Zeng <ccmywish@qq.com>
* Created on : <2023-08-28> * Created on : <2023-08-28>
* Last modified : <2023-10-04> * Last modified : <2023-10-05>
* *
* chsrc: * chsrc:
* *
@ -12,7 +12,7 @@
* GPLv3 LICENSE.txt * GPLv3 LICENSE.txt
* ------------------------------------------------------------*/ * ------------------------------------------------------------*/
#define Chsrc_Version "v0.1.2-2023/10/04" #define Chsrc_Version "v0.1.2-2023/10/05"
#include "chsrc.h" #include "chsrc.h"
@ -42,7 +42,7 @@ pl_ruby_setsrc (char* option)
{ {
int index = 0; int index = 0;
char* check_cmd = xy_str_to_quietcmd("gem -v"); char* check_cmd = xy_str_to_quietcmd("gem -v");
bool exist = does_the_program_exist (check_cmd, "gem"); bool exist = query_program_exist (check_cmd, "gem");
if (!exist) { if (!exist) {
chsrc_error ("未找到 gem 命令,请检查是否存在"); chsrc_error ("未找到 gem 命令,请检查是否存在");
return; return;
@ -61,7 +61,7 @@ pl_ruby_setsrc (char* option)
chsrc_run(cmd); chsrc_run(cmd);
check_cmd = xy_str_to_quietcmd("bundle -v"); check_cmd = xy_str_to_quietcmd("bundle -v");
exist = does_the_program_exist (check_cmd, "bundle"); exist = query_program_exist (check_cmd, "bundle");
if (!exist) { if (!exist) {
chsrc_error ("未找到 bundle 命令,请检查是否存在"); chsrc_error ("未找到 bundle 命令,请检查是否存在");
return; return;
@ -87,11 +87,11 @@ pl_python_check_cmd_ (char** prog)
*prog = NULL; *prog = NULL;
// 不要调用 python 自己,而是使用 python --version,避免Windows弹出Microsoft Store // 不要调用 python 自己,而是使用 python --version,避免Windows弹出Microsoft Store
char* check_cmd = xy_str_to_quietcmd("python --version"); char* check_cmd = xy_str_to_quietcmd("python --version");
bool exist = does_the_program_exist (check_cmd, "python"); bool exist = query_program_exist (check_cmd, "python");
if (!exist) { if (!exist) {
check_cmd = xy_str_to_quietcmd("python3 --version"); check_cmd = xy_str_to_quietcmd("python3 --version");
exist = does_the_program_exist (check_cmd, "python3"); exist = query_program_exist (check_cmd, "python3");
if (exist) *prog = "python3"; if (exist) *prog = "python3";
} }
else { else {
@ -141,10 +141,10 @@ void
pl_nodejs_check_cmd_ (bool* npm_exist, bool* yarn_exist) pl_nodejs_check_cmd_ (bool* npm_exist, bool* yarn_exist)
{ {
char* check_cmd = xy_str_to_quietcmd("npm -v"); char* check_cmd = xy_str_to_quietcmd("npm -v");
*npm_exist = does_the_program_exist (check_cmd, "npm"); *npm_exist = query_program_exist (check_cmd, "npm");
check_cmd = xy_str_to_quietcmd("yarn -v"); check_cmd = xy_str_to_quietcmd("yarn -v");
*yarn_exist = does_the_program_exist (check_cmd, "yarn"); *yarn_exist = query_program_exist (check_cmd, "yarn");
if (!*npm_exist && !*yarn_exist) { if (!*npm_exist && !*yarn_exist) {
chsrc_error ("未找到 npm 或 yarn 命令,请检查是否存在其一"); chsrc_error ("未找到 npm 或 yarn 命令,请检查是否存在其一");
@ -207,7 +207,7 @@ void
pl_perl_check_cmd_ () pl_perl_check_cmd_ ()
{ {
char* check_cmd = xy_str_to_quietcmd("perl --version"); char* check_cmd = xy_str_to_quietcmd("perl --version");
bool exist = does_the_program_exist (check_cmd, "perl"); bool exist = query_program_exist (check_cmd, "perl");
if (!exist) { if (!exist) {
chsrc_error ("未找到 perl 命令,请检查是否存在"); chsrc_error ("未找到 perl 命令,请检查是否存在");
@ -252,7 +252,7 @@ void
pl_php_check_cmd_() pl_php_check_cmd_()
{ {
char* check_cmd = xy_str_to_quietcmd("composer --version"); char* check_cmd = xy_str_to_quietcmd("composer --version");
bool exist = does_the_program_exist (check_cmd, "composer"); bool exist = query_program_exist (check_cmd, "composer");
if (!exist) { if (!exist) {
chsrc_error ("未找到 composer 命令,请检查是否存在"); chsrc_error ("未找到 composer 命令,请检查是否存在");
@ -331,7 +331,7 @@ void
pl_go_check_cmd_ () pl_go_check_cmd_ ()
{ {
char* check_cmd = xy_str_to_quietcmd("go version"); char* check_cmd = xy_str_to_quietcmd("go version");
bool exist = does_the_program_exist (check_cmd, "go"); bool exist = query_program_exist (check_cmd, "go");
if (!exist) { if (!exist) {
chsrc_error ("未找到 go 相关命令,请检查是否存在"); chsrc_error ("未找到 go 相关命令,请检查是否存在");
@ -423,10 +423,10 @@ pl_java_check_cmd_(bool* maven_exist, bool* gradle_exist)
{ {
char* check_cmd = NULL; char* check_cmd = NULL;
check_cmd = xy_str_to_quietcmd("mvn --version"); check_cmd = xy_str_to_quietcmd("mvn --version");
*maven_exist = does_the_program_exist (check_cmd, "mvn"); *maven_exist = query_program_exist (check_cmd, "mvn");
check_cmd = xy_str_to_quietcmd("gradle --version"); check_cmd = xy_str_to_quietcmd("gradle --version");
*gradle_exist = does_the_program_exist (check_cmd, "gradle"); *gradle_exist = query_program_exist (check_cmd, "gradle");
if (! *maven_exist && ! *gradle_exist) { if (! *maven_exist && ! *gradle_exist) {
chsrc_error ("maven 与 gradle 命令均未找到,请检查是否存在其一"); chsrc_error ("maven 与 gradle 命令均未找到,请检查是否存在其一");
@ -631,7 +631,7 @@ void
pl_ocaml_check_cmd_() pl_ocaml_check_cmd_()
{ {
char* check_cmd = xy_str_to_quietcmd("opam --version"); char* check_cmd = xy_str_to_quietcmd("opam --version");
bool exist = does_the_program_exist (check_cmd, "opam"); bool exist = query_program_exist (check_cmd, "opam");
if (!exist) { if (!exist) {
chsrc_error ("未找到 opam 命令,请检查是否存在"); chsrc_error ("未找到 opam 命令,请检查是否存在");
@ -1453,7 +1453,7 @@ os_freebsd_setsrc (char* option)
// @ccmywish: [2023-09-27] 据 @ykla , NJU的freebsd-ports源没有设置 Git, // @ccmywish: [2023-09-27] 据 @ykla , NJU的freebsd-ports源没有设置 Git,
// 但是我认为由于使用Git还是要比非Git方便许多,我们尽可能坚持使用Git // 但是我认为由于使用Git还是要比非Git方便许多,我们尽可能坚持使用Git
// 而 gitup 又要额外修改它自己的配置,比较麻烦 // 而 gitup 又要额外修改它自己的配置,比较麻烦
bool git_exist = does_the_program_exist (xy_str_to_quietcmd("git version"), "git"); bool git_exist = query_program_exist (xy_str_to_quietcmd("git version"), "git");
if (git_exist) { if (git_exist) {
if (xy_streql("nju",source.mirror->code)) { if (xy_streql("nju",source.mirror->code)) {
source = os_freebsd_sources[index-1]; // 使用NJU的前一个源,即USTC源 source = os_freebsd_sources[index-1]; // 使用NJU的前一个源,即USTC源
@ -1620,10 +1620,10 @@ void
wr_tex_check_cmd_ (bool* tlmgr_exist, bool* mpm_exist) wr_tex_check_cmd_ (bool* tlmgr_exist, bool* mpm_exist)
{ {
char* check_cmd = xy_str_to_quietcmd("tlmgr --version"); char* check_cmd = xy_str_to_quietcmd("tlmgr --version");
*tlmgr_exist = does_the_program_exist (check_cmd, "tlmgr"); *tlmgr_exist = query_program_exist (check_cmd, "tlmgr");
check_cmd = xy_str_to_quietcmd("mpm --version"); check_cmd = xy_str_to_quietcmd("mpm --version");
*mpm_exist = does_the_program_exist (check_cmd, "mpm"); *mpm_exist = query_program_exist (check_cmd, "mpm");
if (!*tlmgr_exist && !*mpm_exist) { if (!*tlmgr_exist && !*mpm_exist) {
xy_error ("chsrc: 未找到 tlmgr 或 mpm 命令,请检查是否存在(其一)"); xy_error ("chsrc: 未找到 tlmgr 或 mpm 命令,请检查是否存在(其一)");
@ -1761,7 +1761,7 @@ void
wr_nix_check_cmd () wr_nix_check_cmd ()
{ {
char* check_cmd = xy_str_to_quietcmd("nix-channel --version"); char* check_cmd = xy_str_to_quietcmd("nix-channel --version");
bool exist = does_the_program_exist (check_cmd, "nix-channel"); bool exist = query_program_exist (check_cmd, "nix-channel");
if (!exist) { if (!exist) {
chsrc_error ("未找到 nix-channel 命令,请检查是否存在"); chsrc_error ("未找到 nix-channel 命令,请检查是否存在");
@ -1866,7 +1866,7 @@ wr_anaconda_setsrc(char* option)
if (xy_on_windows) { if (xy_on_windows) {
char* check_cmd = xy_str_to_quietcmd("conda --version"); char* check_cmd = xy_str_to_quietcmd("conda --version");
bool exist = does_the_program_exist (check_cmd, "conda"); bool exist = query_program_exist (check_cmd, "conda");
if (!exist) { if (!exist) {
xy_error ("chsrc: 未找到 conda 命令,请检查是否存在"); xy_error ("chsrc: 未找到 conda 命令,请检查是否存在");
exit(1); exit(1);
@ -2238,7 +2238,7 @@ get_target (const char* input, TargetOp code, char* option)
else if (Target_Cesu_Source==code) else if (Target_Cesu_Source==code)
{ {
char* check_cmd = xy_str_to_quietcmd("curl --version"); char* check_cmd = xy_str_to_quietcmd("curl --version");
bool exist_b = does_the_program_exist (check_cmd, "curl"); bool exist_b = query_program_exist (check_cmd, "curl");
if (!exist_b) { if (!exist_b) {
xy_error ("chsrc: 没有curl命令,无法测速"); xy_error ("chsrc: 没有curl命令,无法测速");
exit(1); exit(1);

10
chsrc.h
View File

@ -31,7 +31,7 @@
* @param progname * @param progname
*/ */
bool bool
does_the_program_exist (char* check_cmd, char* progname) query_program_exist (char* check_cmd, char* progname)
{ {
char* which = check_cmd; char* which = check_cmd;
@ -56,9 +56,9 @@ does_the_program_exist (char* check_cmd, char* progname)
* @param target * @param target
* @param input default def * @param input default def
*/ */
#define find_mirror(s, input) does_the_input_mirror_exist(s##_sources, s##_sources_n, (char*)#s+3, input) #define find_mirror(s, input) query_mirror_exist(s##_sources, s##_sources_n, (char*)#s+3, input)
int int
does_the_input_mirror_exist (SourceInfo* sources, size_t size, char* target, char* input) query_mirror_exist (SourceInfo* sources, size_t size, char* target, char* input)
{ {
if (0==size) { if (0==size) {
xy_error(xy_strjoin(3, "chsrc: 当前 ", target, " 无任何可用源,请联系维护者")); xy_error(xy_strjoin(3, "chsrc: 当前 ", target, " 无任何可用源,请联系维护者"));
@ -174,7 +174,7 @@ test_speed_url (const char* url)
int int
dblary_maxidx_(double* array, int size) get_max_ele_idx_in_dbl_ary (double* array, int size)
{ {
double maxval = array[0]; double maxval = array[0];
int maxidx = 0; int maxidx = 0;
@ -219,7 +219,7 @@ auto_select_ (SourceInfo* sources, size_t size, const char* target)
} }
speeds[i] = speed; speeds[i] = speed;
} }
int fastidx = dblary_maxidx_ (speeds, size); int fastidx = get_max_ele_idx_in_dbl_ary (speeds, size);
if (onlyone) if (onlyone)
xy_success(xy_strjoin(5, "chsrc: ", sources[fastidx].mirror->name, "", target, " 目前唯一可用镜像站,感谢他们的慷慨支持")); xy_success(xy_strjoin(5, "chsrc: ", sources[fastidx].mirror->name, "", target, " 目前唯一可用镜像站,感谢他们的慷慨支持"));

View File

@ -3,7 +3,7 @@
* License : GPLv3 * License : GPLv3
* Authors : Aoran Zeng <ccmywish@qq.com> * Authors : Aoran Zeng <ccmywish@qq.com>
* Created on : <2023-08-29> * Created on : <2023-08-29>
* Last modified : <2023-09-29> * Last modified : <2023-10-05>
* *
* sources: * sources:
* *