mirror of
https://github.com/RubyMetric/chsrc.git
synced 2025-02-24 05:38:13 +08:00
add ubuntu to chsrc.c ,add ubuntu to source_info.h,add xy_strch to helper.h to take place of some characters
This commit is contained in:
parent
0f903c6501
commit
25401fe3bf
34
chsrc.c
34
chsrc.c
@ -76,6 +76,40 @@ pl_ruby_chsrc (char* option)
|
||||
puts(xy_strjoin("chsrc: 感谢镜像提供方:", source_name));
|
||||
}
|
||||
|
||||
void
|
||||
pl_ubuntu_chsrc (char* option)
|
||||
{
|
||||
int selected = 0;
|
||||
for (int i=0;i<sizeof(pl_ruby_sources);i++) {
|
||||
// 循环测速
|
||||
}
|
||||
const char* source_name = pl_ubuntu_sources[selected].mirror->name;
|
||||
const char* source_abbr = pl_ubuntu_sources[selected].mirror->abbr;
|
||||
const char* source_url = pl_ubuntu_sources[selected].url;
|
||||
// #ifdef BEIFEN
|
||||
char* beifen = "cp -rf /etc/apt/sources.list /etc/apt/sources.list.bak";
|
||||
system(beifen);
|
||||
free(beifen);
|
||||
puts("备份文件名: /etc/apt/sources.list.bak");
|
||||
// #endif
|
||||
const char* current_url = xy_strch(source_url,"/","\\/");
|
||||
|
||||
char* cmd = xy_strjoin(xy_strjoin("sed -E \'s/(^[^#]* .*)http[:|\\.|\\/|a-z|A-Z]*\\/ubuntu\\//\\1",current_url),"\\//\'< /etc/apt/sources.list.bak | cat > /etc/apt/sources.list");
|
||||
|
||||
system(cmd);
|
||||
free(cmd);
|
||||
|
||||
#ifndef BEIFEN
|
||||
char* rm = "rm -rf /etc/apt/source.list.bak";
|
||||
system(rm);
|
||||
free(rm);
|
||||
#endif
|
||||
|
||||
|
||||
puts("chsrc: 为'ubuntu'命令换源");
|
||||
puts(xy_strjoin("chsrc: 感谢镜像提供方:", source_name));
|
||||
}
|
||||
|
||||
#define cmdfunc(func) (const char const*)func
|
||||
static const char const
|
||||
*pl_ruby[] = {"gem", "ruby", "rb", NULL, cmdfunc(pl_ruby_chsrc)},
|
||||
|
16
chsrc.h
16
chsrc.h
@ -24,7 +24,10 @@ mirror_info
|
||||
Bfsu = {"BFSU", "北京外国语大学开源软件镜像站"},
|
||||
Pku = {"PKU", "北京大学开源镜像站"},
|
||||
Bjtu = {"BJTU", "北京交通大学自由与开源软件镜像站"},
|
||||
Sustech = {"SUSTech", "南方科技大学开源软件镜像站"};
|
||||
Sustech = {"SUSTech", "南方科技大学开源软件镜像站"},
|
||||
Ustc = {"USTC", "中国科学技术大学开源镜像站"},
|
||||
Wy = {"WY", "网易开源镜像站"},
|
||||
Sohu = {"SOHU", "搜狐开源镜像站"};
|
||||
|
||||
// 大型公司
|
||||
mirror_info
|
||||
@ -50,3 +53,14 @@ pl_ruby_sources[] = {
|
||||
{&Tencent, "https://mirrors.tencent.com/rubygems/"},
|
||||
{&RubyChina, "https://gems.ruby-china.com"},
|
||||
};
|
||||
|
||||
static source_info
|
||||
pl_ubuntu_sources[] = {
|
||||
{&Bfsu, "https://mirrors.bfsu.edu.cn/ubuntu/"},
|
||||
{&Ustc, "https://mirrors.ustc.edu.cn/ubuntu/"},
|
||||
{&Ali, "https://mirrors.aliyun.com/ubuntu/"},
|
||||
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/ubuntu/"},
|
||||
{&Tencent, "https://mirrors.tencent.com/ubuntu/"},
|
||||
{&Wy, "https://mirrors.163.com/ubuntu/"},
|
||||
{&Sohu, "https://mirrors.sohu.com/ubuntu/"},
|
||||
};
|
||||
|
27
helper.h
27
helper.h
@ -43,6 +43,33 @@ xy_strjoin (const char* str1, const char* str2)
|
||||
}
|
||||
|
||||
|
||||
//有一个BUG,每一次替换都会加长到最大长度
|
||||
static char*
|
||||
xy_strch (const char* str, const char src,const char* dest)
|
||||
{
|
||||
size_t str_len = strlen(str);
|
||||
size_t dest_len = strlen(dest);
|
||||
size_t size = str_len*dest_len;
|
||||
char* ret = (char*)malloc(size);
|
||||
int i=0;
|
||||
int j=0;
|
||||
while(i<str_len) {
|
||||
if(str[i]==src) {
|
||||
int k=0;
|
||||
while(k<dest_len){
|
||||
ret[j++] = dest[k++];
|
||||
}
|
||||
i++;
|
||||
}
|
||||
else {
|
||||
ret[j++] = str[i++];
|
||||
}
|
||||
}
|
||||
ret[j] = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
xy_success (const char* str1)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user