From ae2d5c5da3e1a6dccc7e995cea9d87967767eca7 Mon Sep 17 00:00:00 2001 From: Aoran Zeng Date: Sun, 10 Sep 2023 17:01:20 +0800 Subject: [PATCH] Add support for `tex` Gitee close #I801A8 --- chsrc.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- chsrc.h | 2 +- 2 files changed, 77 insertions(+), 6 deletions(-) diff --git a/chsrc.c b/chsrc.c index 02ac182..8dde121 100644 --- a/chsrc.c +++ b/chsrc.c @@ -1442,6 +1442,76 @@ os_openkylin_setsrc (char* option) } + + + + + +void +_wr_tex_check_cmd (bool* tlmgr_exist, bool* mpm_exist) +{ + char* check_cmd = xy_str_to_quietcmd("tlmgr --version"); + *tlmgr_exist = does_the_program_exist (check_cmd, "tlmgr"); + + check_cmd = xy_str_to_quietcmd("mpm --version"); + *mpm_exist = does_the_program_exist (check_cmd, "mpm"); + + if (!*tlmgr_exist && !*mpm_exist) { + xy_error ("chsrc: 未找到 tlmgr 或 mpm 命令,请检查是否存在(其一)"); + exit(1); + } +} + +void +wr_tex_getsrc(char* option) +{ + bool tlmgr_exist, mpm_exist; + _wr_tex_check_cmd(&tlmgr_exist, &mpm_exist); + + if (tlmgr_exist) { + chsrc_runcmd("tlmgr option repository"); + } + if (mpm_exist) { + chsrc_runcmd("mpm --get-repository"); + } +} + +/** + * 参考 https://help.mirrors.cernet.edu.cn/CTAN/ + */ +void +wr_tex_setsrc(char* option) +{ + int index = 0; + bool tlmgr_exist, mpm_exist; + _wr_tex_check_cmd(&tlmgr_exist, &mpm_exist); + + if (NULL!=option) { + index = lets_find_mirror(wr_tex, option); + } else { + index = lets_test_speed(wr_tex); + } + + source_info source = wr_tex_sources[index]; + chsrc_say_selection (&source); + + char* cmd = NULL; + + if (tlmgr_exist) { + cmd = xy_2strjoin("tlmgr option repository ", source.url); + chsrc_runcmd(cmd); + } + + if (mpm_exist) { + char* miktex_url = xy_2strjoin(xy_str_delete_suffix(source.url, "texlive/tlnet"), "win32/miktex/tm/packages/"); + cmd = xy_2strjoin("mpm --set-repository=", miktex_url); + chsrc_runcmd(cmd); + } + + chsrc_say_thanks(&source); +} + + /************************************** Begin Target Matrix ****************************************/ def_target_info(pl_ruby); def_target_info(pl_python); @@ -1520,17 +1590,18 @@ static const char }; +def_target_info(wr_tex); + target_info wr_anaconda_target = {NULL, NULL, NULL, 0}, wr_emacs_target = {NULL, NULL, NULL, 0}, - wr_tex_target = {NULL, NULL, NULL, 0}, wr_brew_target = {NULL, NULL, NULL, 0}; static const char -*wr_anaconda[] = {"conda", "anaconda", NULL, targetinfo(&wr_anaconda_target)}, -*wr_emacs [] = {"emacs", NULL, targetinfo(&wr_emacs_target)}, -*wr_tex [] = {"latex", "ctan", "tex", NULL, targetinfo(&wr_tex_target) }, -*wr_brew [] = {"brew", "homebrew", NULL, targetinfo(&wr_brew_target)}, +*wr_anaconda[] = {"conda", "anaconda", NULL, targetinfo(&wr_anaconda_target)}, +*wr_emacs [] = {"emacs", NULL, targetinfo(&wr_emacs_target)}, +*wr_tex [] = {"latex", "ctan", "tex", "texlive", "miktex", "tlmgr", "mpm", NULL, targetinfo(&wr_tex_target)}, +*wr_brew [] = {"brew", "homebrew", NULL, targetinfo(&wr_brew_target)}, **wr_softwares[] = { wr_anaconda, wr_emacs, wr_tex, wr_brew diff --git a/chsrc.h b/chsrc.h index 8f0a17e..8e181d9 100644 --- a/chsrc.h +++ b/chsrc.h @@ -500,7 +500,7 @@ wr_tex_sources[] = { {&Lzuoss, "https://mirror.lzu.edu.cn/CTAN/systems/texlive/tlnet"}, {&Jlu, "https://mirrors.jlu.edu.cn/CTAN/systems/texlive/tlnet"}, {&Sustech, "https://mirrors.sustech.edu.cn/CTAN/systems/texlive/tlnet"} -} +};