Add _sources_n

This commit is contained in:
Aoran Zeng 2023-09-02 19:07:30 +08:00
parent 17d2816140
commit 906aef50a5
2 changed files with 68 additions and 17 deletions

63
chsrc.c
View File

@ -2,7 +2,7 @@
* File : chsrc.c
* Authors : Aoran Zeng <ccmywish@qq.com>
* Created on : <2023-08-28>
* Last modified : <2023-09-01>
* Last modified : <2023-09-02>
*
* chsrc:
*
@ -293,6 +293,48 @@ pl_ruby_getsrc (char* option)
}
int
dblary_maxidx(double* array, int size)
{
double maxval = array[0];
double maxidx = 0;
for (int i=1; i<size; i++) {
if (array[i]>maxval) {
maxval = array[i];
maxidx = i;
}
}
return maxidx;
}
/**
* @maintainer ccmywish
*
* https://mirrors.bfsu.edu.cn/rubygems/gems/nokogiri-1.15.0-java.gem 大小为9.9MB
*/
void
pl_ruby_cesu (char* option)
{
char* url = "";
size_t size = pl_ruby_sources_n;
source_info* sources = pl_ruby_sources;
double speeds[size];
for (int i=0;i<size;i++)
{
source_info src = sources[i];
const char* baseurl = src.url;
char* testurl = xy_2strjoin(baseurl, "gems/nokogiri-1.15.0-java.gem");
double speed = test_speed (testurl);
speeds[i] = speed;
}
int maxidx = dblary_maxidx (speeds, size);
xy_success (xy_2strjoin("最快镜像站为: ", sources[maxidx].mirror->name));
}
/**
* Go换源
@ -626,19 +668,8 @@ os_debian_setsrc (char* option)
}
/************************************** Target Matrix ****************************************/
typedef struct {
void (*setfn)(char* option);
void (*getfn)(char* option);
void (*cesufn)(char* option);
source_info* sources;
size_t sources_count;
} target_info;
#define def_target_info(t, n) target_info t##_target = {t##_setsrc, t##_getsrc, t##_cesu, t##_sources, n};
def_target_info(pl_ruby, 5)
/************************************** Begin Target Matrix ****************************************/
def_target_info(pl_ruby);
target_info
pl_python_target = {pl_python_setsrc, NULL, NULL, pl_python_sources, 5},
@ -700,7 +731,7 @@ static const char const
wr_anaconda, wr_emacs, wr_tex
};
#undef targetinfo
/************************************** End Target Matrix ****************************************/
static const char const*
@ -810,7 +841,7 @@ print_help ()
/**
* targets列表`input`target匹配
*
* @param[out] target_func targets列表中NULL的位置
* @param[out] target_func targets列表中最后的target_info信息
*
* @return truefalse
*/

22
chsrc.h
View File

@ -2,7 +2,7 @@
* File : chsrc.h
* Authors : Aoran Zeng <ccmywish@qq.com>
* Created on : <2023-08-29>
* Last modified : <2023-09-01>
* Last modified : <2023-09-02>
*
* chsrc:
*
@ -272,3 +272,23 @@ os_debian_sources[] = {
/* 函数签名 */
bool does_the_program_exist (char* check_cmd, char* progname);
#define def_target_sources_n(t) const size_t t##_sources_n = xy_arylen(pl_ruby_sources)
def_target_sources_n(pl_ruby); def_target_sources_n(pl_python); def_target_sources_n(pl_nodejs);
def_target_sources_n(pl_perl); def_target_sources_n(pl_php); def_target_sources_n(pl_go);
def_target_sources_n(pl_rust); def_target_sources_n(pl_java); def_target_sources_n(pl_r);
def_target_sources_n(pl_julia);
def_target_sources_n(os_ubuntu); def_target_sources_n(os_debian);
/* Target Info */
typedef struct {
void (*setfn)(char* option);
void (*getfn)(char* option);
void (*cesufn)(char* option);
source_info* sources;
size_t sources_n;
} target_info;
#define def_target_info(t) target_info t##_target = {t##_setsrc, t##_getsrc, t##_cesu, t##_sources, t##_sources_n}