mirror of
https://github.com/RubyMetric/chsrc
synced 2025-06-30 00:23:16 +08:00
Add _sources_n
This commit is contained in:
parent
17d2816140
commit
906aef50a5
63
chsrc.c
63
chsrc.c
@ -2,7 +2,7 @@
|
|||||||
* File : chsrc.c
|
* File : chsrc.c
|
||||||
* 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-09-01>
|
* Last modified : <2023-09-02>
|
||||||
*
|
*
|
||||||
* chsrc:
|
* 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换源
|
* Go换源
|
||||||
@ -626,19 +668,8 @@ os_debian_setsrc (char* option)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/************************************** Target Matrix ****************************************/
|
/************************************** Begin Target Matrix ****************************************/
|
||||||
|
def_target_info(pl_ruby);
|
||||||
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)
|
|
||||||
|
|
||||||
target_info
|
target_info
|
||||||
pl_python_target = {pl_python_setsrc, NULL, NULL, pl_python_sources, 5},
|
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
|
wr_anaconda, wr_emacs, wr_tex
|
||||||
};
|
};
|
||||||
#undef targetinfo
|
#undef targetinfo
|
||||||
|
/************************************** End Target Matrix ****************************************/
|
||||||
|
|
||||||
|
|
||||||
static const char const*
|
static const char const*
|
||||||
@ -810,7 +841,7 @@ print_help ()
|
|||||||
/**
|
/**
|
||||||
* 遍历我们内置的targets列表,查询用户输入`input`是否与我们支持的某个target匹配
|
* 遍历我们内置的targets列表,查询用户输入`input`是否与我们支持的某个target匹配
|
||||||
*
|
*
|
||||||
* @param[out] target_func 如果匹配到,则返回内置targets列表中NULL的位置
|
* @param[out] target_func 如果匹配到,则返回内置targets列表中最后的target_info信息
|
||||||
*
|
*
|
||||||
* @return 匹配到则返回true,未匹配到则返回false
|
* @return 匹配到则返回true,未匹配到则返回false
|
||||||
*/
|
*/
|
||||||
|
22
chsrc.h
22
chsrc.h
@ -2,7 +2,7 @@
|
|||||||
* File : chsrc.h
|
* File : chsrc.h
|
||||||
* 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-01>
|
* Last modified : <2023-09-02>
|
||||||
*
|
*
|
||||||
* chsrc:
|
* chsrc:
|
||||||
*
|
*
|
||||||
@ -272,3 +272,23 @@ os_debian_sources[] = {
|
|||||||
|
|
||||||
/* 函数签名 */
|
/* 函数签名 */
|
||||||
bool does_the_program_exist (char* check_cmd, char* progname);
|
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}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user