From 4a8a3dcb9a0ea0f269304b74713f773e6cb07ade Mon Sep 17 00:00:00 2001 From: Aoran Zeng Date: Thu, 15 Aug 2024 21:04:49 +0800 Subject: [PATCH] Split r out --- include/source.h | 20 +---------- src/chsrc.c | 49 +-------------------------- src/recipe/catalog.c | 2 +- src/recipe/lang/r.c | 79 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 82 insertions(+), 68 deletions(-) create mode 100644 src/recipe/lang/r.c diff --git a/include/source.h b/include/source.h index 51f1a4f..fa3c7da 100644 --- a/include/source.h +++ b/include/source.h @@ -186,24 +186,6 @@ pl_haskell_sources[] = { -/** - * @time 2023-09-04 更新 - * @note { - * 以下注释的,是不含有bioconductor的镜像站, - * 我们在换cran的同时,也直接帮助用户换bioconductor - * } - */ -pl_r_sources[] = { - {&Upstream, NULL}, - {&Sjtug_Zhiyuan, "https://mirrors.sjtug.sjtu.edu.cn/cran/"}, - // {&Ali, "https://mirrors.aliyun.com/CRAN/"}, - {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/CRAN/"}, - // {&Sustech, "https://mirrors.sustech.edu.cn/CRAN"}, - // {&Bfsu, "https://mirrors.bfsu.edu.cn/CRAN/"}, - // {&Bjtu, "https://mirror.bjtu.edu.cn/cran/"}, -}, - - /** * @time 2023-09-05 更新 * @note 缺少商业公司或开源社区软件源 @@ -724,7 +706,7 @@ wr_tex_sources[] = { def_sources_n(pl_clojure); def_sources_n(pl_dotnet); def_sources_n(pl_dart); def_sources_n(pl_haskell); -def_sources_n(pl_r); def_sources_n(pl_julia); +def_sources_n(pl_julia); def_sources_n(os_ubuntu); def_sources_n(os_mint); def_sources_n(os_debian); def_sources_n(os_fedora); diff --git a/src/chsrc.c b/src/chsrc.c index 046f0cf..86bf67b 100644 --- a/src/chsrc.c +++ b/src/chsrc.c @@ -176,54 +176,7 @@ pl_haskell_setsrc (char *option) #include "recipe/lang/ocaml.c" - -void -pl_r_getsrc (char *option) -{ - // 或参考:https://zhuanlan.zhihu.com/p/585036231 - // - // options()$repos - // options()$BioC_mirror - // - if (xy_on_windows) - { - chsrc_view_file ("~/Documents/.Rprofile"); - } - else - { - chsrc_view_file ("~/.Rprofile"); - } -} - -/** - * R 换源,参考:https://help.mirrors.cernet.edu.cn/CRAN/ - */ -void -pl_r_setsrc (char *option) -{ - SourceInfo source; - chsrc_yield_source (pl_r); - chsrc_confirm_source (&source); - - char *bioconductor_url = xy_str_delete_suffix (xy_str_delete_suffix (source.url, "cran/"), "CRAN/"); - bioconductor_url = xy_2strjoin(bioconductor_url, "bioconductor"); - - const char *towrite1 = xy_strjoin (3, "options(\"repos\" = c(CRAN=\"", source.url, "\"))" ); - const char *towrite2 = xy_strjoin (3, "options(BioC_mirror=\"", bioconductor_url, "\")" ); - - // 或者我们调用 r.exe --slave -e 上面的内容 - if (xy_on_windows) - { - chsrc_append_to_file (towrite1, "~/Documents/.Rprofile"); - chsrc_append_to_file (towrite2, "~/Documents/.Rprofile"); - } - else - { - chsrc_append_to_file (towrite1, "~/.Rprofile"); - chsrc_append_to_file (towrite2, "~/.Rprofile"); - } - chsrc_say_lastly (&source, ChsrcTypeAuto); -} +#include "recipe/lang/r.c" diff --git a/src/recipe/catalog.c b/src/recipe/catalog.c index d4f425e..bfdc372 100644 --- a/src/recipe/catalog.c +++ b/src/recipe/catalog.c @@ -9,7 +9,7 @@ /* Begin Target Matrix */ def_target(pl_dart); -def_target(pl_r); def_target(pl_julia); +def_target(pl_julia); def_target_noget (pl_clojure); def_target_noget (pl_dotnet); def_target_noget (pl_haskell); diff --git a/src/recipe/lang/r.c b/src/recipe/lang/r.c new file mode 100644 index 0000000..3fcb2a5 --- /dev/null +++ b/src/recipe/lang/r.c @@ -0,0 +1,79 @@ +/** ------------------------------------------------------------ + * SPDX-License-Identifier: GPL-3.0-or-later + * ------------------------------------------------------------- + * File Authors : Aoran Zeng + * Contributors : Nil Null + * Created on : <2023-09-21> + * Last modified : <2024-08-15> + * ------------------------------------------------------------*/ + +/** + * @time 2023-09-04 更新 + * @note { + * 以下注释的,是不含有bioconductor的镜像站, + * 我们在换cran的同时,也直接帮助用户换bioconductor + * } + */ +static SourceInfo +pl_r_sources[] = { + {&Upstream, NULL}, + {&Sjtug_Zhiyuan, "https://mirrors.sjtug.sjtu.edu.cn/cran/"}, + // {&Ali, "https://mirrors.aliyun.com/CRAN/"}, + {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/CRAN/"}, + // {&Sustech, "https://mirrors.sustech.edu.cn/CRAN"}, + // {&Bfsu, "https://mirrors.bfsu.edu.cn/CRAN/"}, + // {&Bjtu, "https://mirror.bjtu.edu.cn/cran/"}, +}; +def_sources_n(pl_r); + + +void +pl_r_getsrc (char *option) +{ + /** + * 或参考:https://zhuanlan.zhihu.com/p/585036231 + * + * options()$repos + * options()$BioC_mirror + */ + if (xy_on_windows) + { + chsrc_view_file ("~/Documents/.Rprofile"); + } + else + { + chsrc_view_file ("~/.Rprofile"); + } +} + +/** + * R 换源,参考:https://help.mirrors.cernet.edu.cn/CRAN/ + */ +void +pl_r_setsrc (char *option) +{ + SourceInfo source; + chsrc_yield_source (pl_r); + chsrc_confirm_source (&source); + + char *bioconductor_url = xy_str_delete_suffix (xy_str_delete_suffix (source.url, "cran/"), "CRAN/"); + bioconductor_url = xy_2strjoin(bioconductor_url, "bioconductor"); + + const char *towrite1 = xy_strjoin (3, "options(\"repos\" = c(CRAN=\"", source.url, "\"))" ); + const char *towrite2 = xy_strjoin (3, "options(BioC_mirror=\"", bioconductor_url, "\")" ); + + // 或者我们调用 r.exe --slave -e 上面的内容 + if (xy_on_windows) + { + chsrc_append_to_file (towrite1, "~/Documents/.Rprofile"); + chsrc_append_to_file (towrite2, "~/Documents/.Rprofile"); + } + else + { + chsrc_append_to_file (towrite1, "~/.Rprofile"); + chsrc_append_to_file (towrite2, "~/.Rprofile"); + } + chsrc_say_lastly (&source, ChsrcTypeAuto); +} + +def_target(pl_r);