From 25401fe3bfbba9c0ece5ea6f5446509988593a70 Mon Sep 17 00:00:00 2001 From: G_I_Y Date: Wed, 30 Aug 2023 14:24:26 +0800 Subject: [PATCH] add ubuntu to chsrc.c ,add ubuntu to source_info.h,add xy_strch to helper.h to take place of some characters --- chsrc.c | 34 ++++++++++++++++++++++++++++++++++ chsrc.h | 16 +++++++++++++++- helper.h | 27 +++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 1 deletion(-) diff --git a/chsrc.c b/chsrc.c index 1ad847f..39741af 100644 --- a/chsrc.c +++ b/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;iname; + 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)}, diff --git a/chsrc.h b/chsrc.h index 9f5a9a7..5193b99 100644 --- a/chsrc.h +++ b/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/"}, +}; diff --git a/helper.h b/helper.h index 3413c55..61b5428 100644 --- a/helper.h +++ b/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