chsrc/chsrc.h

365 lines
12 KiB
C
Raw Normal View History

2023-08-29 23:04:54 +08:00
/* --------------------------------------------------------------
* File : chsrc.h
* Authors : Aoran Zeng <ccmywish@qq.com>
* Created on : <2023-08-29>
2023-09-02 19:07:30 +08:00
* Last modified : <2023-09-02>
2023-08-29 23:04:54 +08:00
*
* chsrc:
*
* chsrc.c
* -------------------------------------------------------------*/
2023-08-30 17:10:23 +08:00
#include <stdio.h>
#include "helper.h"
2023-08-29 23:04:54 +08:00
typedef struct {
const char* abbr;
const char* name;
2023-08-31 22:31:24 +08:00
const char* site;
2023-08-29 23:04:54 +08:00
} mirror_info;
// 教育网
2023-08-30 10:31:43 +08:00
// 我们目前根据 https://github.com/mirrorz-org/oh-my-mirrorz 挑选速度前10位
//
2023-08-29 23:04:54 +08:00
mirror_info
2023-08-31 22:31:24 +08:00
MirrorZ = {"MirrorZ", "MirrorZ校园网镜像站", "https://mirrors.cernet.edu.cn/"},
Tuna = {"TUNA", "清华大学开源软件镜像站", "https://mirrors.tuna.tsinghua.edu.cn/"},
Sjtug_Zhiyuan = {"SJTUG-zhiyuan", "上海交通大学致远镜像站", "https://mirrors.sjtug.sjtu.edu.cn/"},
Zju = {"ZJU", "浙江大学开源软件镜像站", "https://mirrors.zju.edu.cn/"},
Lzuoss = {"LZUOSS", "兰州大学开源社区镜像站", "https://mirror.lzu.edu.cn/"},
Jlu = {"JLU", "吉林大学开源镜像站", "https://mirrors.jlu.edu.cn/"},
Bfsu = {"BFSU", "北京外国语大学开源软件镜像站","https://mirrors.bfsu.edu.cn/"},
Pku = {"PKU", "北京大学开源镜像站", "https://mirrors.pku.edu.cn/"},
Bjtu = {"BJTU", "北京交通大学自由与开源软件镜像站", "https://mirror.bjtu.edu.cn/"},
Sustech = {"SUSTech", "南方科技大学开源软件镜像站", "https://mirrors.sustech.edu.cn/"},
Ustc = {"USTC", "中国科学技术大学开源镜像站", "https://mirrors.ustc.edu.cn/"},
// 速度暂时处于10位以后但是目前可用的源
Nju = {"NJU", "南京大学开源镜像站", "https://mirrors.nju.edu.cn/"},
Cqu = {"CQU", "重庆大学开源软件镜像站", "https://mirrors.cqu.edu.cn/"};
2023-08-29 23:04:54 +08:00
2023-08-30 21:56:31 +08:00
2023-08-29 23:04:54 +08:00
// 大型公司
2023-08-30 21:56:31 +08:00
// 注意,腾讯软件源中,有很多链接都已失效,请仔细检查
2023-08-29 23:04:54 +08:00
mirror_info
2023-08-31 22:31:24 +08:00
Ali = {"Ali OPSX", "阿里巴巴开源镜像站", "https://developer.aliyun.com/mirror/"},
Tencent = {"Tencent", "腾讯软件源", "https://mirrors.tencent.com/"},
Netease = {"Netease", "网易开源镜像站", "https://mirrors.163.com/"},
Sohu = {"SOHU", "搜狐开源镜像站", "https://mirrors.sohu.com/"};
2023-08-29 23:04:54 +08:00
2023-08-30 21:56:31 +08:00
2023-08-29 23:04:54 +08:00
// 开源社区
mirror_info
2023-08-31 22:31:24 +08:00
RubyChina = {"RubyChina", "Ruby China 社区", "https://ruby-china.org/"},
GoProxyCN = {"Goproxy.cn", "七牛云 Goproxy.cn", "https://www.qiniu.com/"},
GoProxyIO = {"GOPROXY.IO", "GOPROXY.IO", "https://goproxy.io/"},
NugetOrg = {"NuGet Org", "Nuget Organization", "https://www.nuget.org/"};
2023-08-29 23:04:54 +08:00
2023-08-31 21:40:32 +08:00
mirror_info*
available_mirrors[] = {
2023-09-01 17:38:59 +08:00
&MirrorZ, &Tuna, &Sjtug_Zhiyuan, &Zju, &Lzuoss, &Jlu, &Bfsu, &Pku, &Bjtu, &Sustech, &Ustc, &Nju, &Cqu,
2023-08-31 21:40:32 +08:00
&Ali, &Tencent, &Netease, &Sohu,
&RubyChina, &GoProxyCN, &GoProxyIO
// 暂不支持 NugetOrg
};
2023-08-29 23:04:54 +08:00
typedef struct {
const mirror_info* mirror;
const char* url;
} source_info;
2023-08-30 10:31:43 +08:00
/**
*
*
*
*/
2023-08-30 21:20:11 +08:00
/**
2023-09-02 22:23:49 +08:00
* 2023-09-02
2023-08-30 21:20:11 +08:00
*
* Ruby China
*/
2023-08-29 23:04:54 +08:00
static source_info
pl_ruby_sources[] = {
{&Bfsu, "https://mirrors.bfsu.edu.cn/rubygems/"},
{&Ali, "https://mirrors.aliyun.com/rubygems/"},
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/rubygems/"},
{&Tencent, "https://mirrors.tencent.com/rubygems/"},
2023-09-02 22:23:49 +08:00
// Ruby China 给的链接是不带后缀 / 的,不知道是否带后缀会影响
// 如有问题请报告
{&RubyChina, "https://gems.ruby-china.com/"},
2023-08-30 10:31:43 +08:00
},
2023-08-30 21:20:11 +08:00
/**
* 2023-08-29
*
* Zjupypi在校外访问会自动转向Tuna
*
2023-08-30 21:42:10 +08:00
* TODO: 1. Python用户协助
* 2.
2023-08-30 21:20:11 +08:00
*/
2023-08-30 10:31:43 +08:00
pl_python_sources[] = {
{&Sjtug_Zhiyuan, "https://mirror.sjtu.edu.cn/pypi/web/simple"},
{&Tuna, "https://pypi.tuna.tsinghua.edu.cn/simple"},
{&Lzuoss, "https://mirror.lzu.edu.cn/pypi/web/simple"},
{&Jlu, "https://mirrors.jlu.edu.cn/pypi//web/simple"},
{&Bfsu, "https://mirrors.bfsu.edu.cn/pypi/web/simple"}
2023-08-30 21:20:11 +08:00
},
/**
* 2023-08-30
*
* Sjtug, Tuna, Lzuoss, Jlu, Bfsu,
*
* npm的名
*/
pl_nodejs_sources[] = {
{&Ali, "https://registry.npmmirror.com"},
{&Zju, "https://mirrors.zju.edu.cn/docs/npm/"}
},
/**
* 2023-08-30
*
* https://help.mirrors.cernet.edu.cn/CPAN/
*
* Jlu
*
* TODO: Perl用户协助
*/
pl_perl_sources[] = {
{&Ali, "https://mirrors.aliyun.com/CPAN/"},
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/CPAN/"},
{&Bfsu, "https://mirrors.bfsu.edu.cn/CPAN/"},
{&Bjtu, "https://mirror.bjtu.edu.cn/cpan/"},
2023-08-30 22:27:08 +08:00
{&Lzuoss, "https://mirror.lzu.edu.cn/CPAN/"}
2023-08-30 21:42:10 +08:00
},
/**
* 2023-08-30
*
* TODO: R用户协助
*/
pl_r_sources[] = {
{&Sjtug_Zhiyuan, "https://mirrors.sjtug.sjtu.edu.cn/cran/"},
{&Ali, "https://mirrors.aliyun.com/CRAN/"},
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/CRAN/"},
{&Bfsu, "https://mirrors.bfsu.edu.cn/CRAN/"},
{&Bjtu, "https://mirror.bjtu.edu.cn/cran/"},
},
/**
* 2023-08-30
*
*
*
* TODO: 1. Julia用户协助
* 2.
*/
pl_julia_sources[] = {
{&Sjtug_Zhiyuan, "https://mirrors.sjtug.sjtu.edu.cn/julia"},
{&Pku, "https://mirrors.pku.edu.cn/julia"},
{&Nju, "https://mirror.nju.edu.cn/julia"}
2023-08-30 21:56:31 +08:00
},
/**
* 2023-08-30
*
* TODO: 1. Go用户协助
2023-08-30 22:27:08 +08:00
* 2.
2023-08-30 21:56:31 +08:00
*/
pl_go_sources[] = {
{&Ali, "https://mirrors.aliyun.com/goproxy/"},
{&GoProxyCN, "https://goproxy.cn"},
{&GoProxyIO, "https://goproxy.io"}
},
2023-08-30 17:10:23 +08:00
2023-08-30 22:27:08 +08:00
/**
* 2023-08-30
*
* TODO: 1. Rust用户协助
* 2.
*/
pl_rust_sources[] = {
{&Sjtug_Zhiyuan, "https://mirrors.sjtug.sjtu.edu.cn/crates.io-index/"},
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/crates.io-index/"},
{&Bfsu, "https://mirrors.bfsu.edu.cn/crates.io-index/"},
{&Ustc, "https://mirrors.ustc.edu.cn/crates.io-index/"},
{&Cqu, "https://mirrors.cqu.edu.cn/crates.io-index/"}
},
/**
* 2023-08-30
*
* TODO: 1. Java用户协助
* 2.
* 3.
*/
pl_java_sources[] = {
{&Ali, "https://maven.aliyun.com/repository/public/"}
},
/**
* 2023-08-30
*
*
*
* TODO: 1. Java用户协助
* 2.
* 3.
*/
2023-08-31 22:57:09 +08:00
pl_dotnet_sources[] = {
2023-08-30 22:27:08 +08:00
{&NugetOrg, "https://www.nuget.org/api/v2/"}
},
/**
* 2023-08-30
*
* TODO: 1. PHP用户协助
* 2.
* 3.
*/
pl_php_sources[] = {
{&Ali, "https://mirrors.aliyun.com/composer/"}
};
2023-08-30 21:42:10 +08:00
2023-09-01 22:23:03 +08:00
/**
* 2023-09-01
*
* TODO: 1.
*/
static source_info
2023-08-30 20:05:03 +08:00
os_ubuntu_sources[] = {
2023-08-30 19:24:18 +08:00
{&Ali, "https://mirrors.aliyun.com/ubuntu/"},
{&Bfsu, "https://mirrors.bfsu.edu.cn/ubuntu/"},
{&Ustc, "https://mirrors.ustc.edu.cn/ubuntu/"},
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/ubuntu/"},
{&Tencent, "https://mirrors.tencent.com/ubuntu/"},
2023-08-30 20:06:28 +08:00
{&Netease, "https://mirrors.163.com/ubuntu/"},
{&Sohu, "https://mirrors.sohu.com/ubuntu/"}
2023-09-01 22:23:03 +08:00
},
2023-08-30 20:05:03 +08:00
2023-09-01 22:23:03 +08:00
/**
* 2023-09-01
*
* TODO: 1.
*/
os_debian_sources[] = {
{&Ali, "https://mirrors.aliyun.com/debian/"},
{&Bfsu, "https://mirrors.bfsu.edu.cn/debian/"},
{&Ustc, "https://mirrors.ustc.edu.cn/debian/"},
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/debian/"},
{&Tencent, "https://mirrors.tencent.com/debian/"},
{&Netease, "https://mirrors.163.com/debian/"},
{&Sohu, "https://mirrors.sohu.com/debian/"}
},
/**
* 2023-09-02
*
* TODO: 1.
*/
os_fedora_sources[] = {
{&Ali, "https://mirrors.aliyun.com/fedora/"},
{&Bfsu, "https://mirrors.bfsu.edu.cn/fedora/"},
{&Ustc, "https://mirrors.ustc.edu.cn/fedora/"},
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/fedora/"},
{&Tencent, "https://mirrors.tencent.com/fedora/"},
{&Netease, "https://mirrors.163.com/fedora/"},
{&Sohu, "https://mirrors.sohu.com/fedora/"}
},
/**
* 2023-09-02
*
* TODO: 1.
*/
os_kali_sources[] = {
{&Ali, "https://mirrors.aliyun.com/kali/"},
{&Bfsu, "https://mirrors.bfsu.edu.cn/kali/"},
{&Ustc, "https://mirrors.ustc.edu.cn/kali/"},
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/kali/"},
{&Tencent, "https://mirrors.tencent.com/kali/"},
{&Netease, "https://mirrors.163.com/kali/"},
{&Sohu, "https://mirrors.sohu.com/kali/"}
},
/**
* 2023-09-02
*
* TODO: 1.
*/
os_openbsd_sources[] = {
{&Ali, "https://mirrors.aliyun.com/OpenBSD/"},
{&Bfsu, "https://mirrors.bfsu.edu.cn/OpenBSD/"},
{&Ustc, "https://mirrors.ustc.edu.cn/OpenBSD/"},
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/OpenBSD/"},
{&Tencent, "https://mirrors.tencent.com/OpenBSD/"},
{&Netease, "https://mirrors.163.com/OpenBSD/"},
{&Sohu, "https://mirrors.sohu.com/OpenBSD/"}
},
/**
* 2023-09-02
*
* TODO: 1.
*/
os_mysys2_sources[] = {
{&Ali, "https://mirrors.aliyun.com/msys2/"},
{&Bfsu, "https://mirrors.bfsu.edu.cn/msys2/"},
{&Ustc, "https://mirrors.ustc.edu.cn/msys2/"},
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/msys2/"},
{&Tencent, "https://mirrors.tencent.com/msys2/"},
{&Netease, "https://mirrors.163.com/msys2/"},
{&Sohu, "https://mirrors.sohu.com/msys2/"}
}
;
2023-08-30 17:10:23 +08:00
/* 函数签名 */
bool does_the_program_exist (char* check_cmd, char* progname);
2023-09-02 19:07:30 +08:00
#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); def_target_sources_n(os_fedora);
def_target_sources_n(os_kali); def_target_sources_n(os_openbsd); def_target_sources_n(os_mysys2);
2023-09-02 19:07:30 +08:00
/* 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}