diff --git a/src/chsrc.h b/include/chsrc.h similarity index 100% rename from src/chsrc.h rename to include/chsrc.h diff --git a/src/source.h b/include/source.h similarity index 78% rename from src/source.h rename to include/source.h index eb09c9c..3e61bfd 100644 --- a/src/source.h +++ b/include/source.h @@ -7,12 +7,12 @@ * Contributors : Shengwei Chen <414685209@qq.com> * | * Created on : <2023-08-29> - * Last modified : <2024-08-09> + * Last modified : <2024-08-16> * * 镜像站与换源信息 * ------------------------------------------------------------*/ -typedef struct { +typedef struct MirrorSite_t { const char *code; // 用于用户指定镜像站 const char *abbr; const char *name; @@ -116,13 +116,49 @@ MirrorSite UserDefine = {"user", "用户自定义", "用户自定义", NULL, NULL}; - - -typedef struct { +typedef struct SourceInfo_t { const MirrorSite *mirror; const char *url; } SourceInfo; - - #define def_sources_n(t) const size_t t##_sources_n = xy_arylen(t##_sources) + + +/* Target Feature Info */ +typedef struct FeatInfo_t { + bool can_get; + bool can_reset; // 有的reset不是暂时没有实现,而是现在的实现根本就无法重置 + + bool can_english; + char *locally; + bool can_user_define; // 用户自定义换源URL + + char *note; +} FeatInfo; + +/* Target Info */ +typedef struct TargetInfo_t { + void (*getfn) (char *option); + void (*setfn) (char *option); + void (*resetfn) (char *option); + + FeatInfo (*featfn) (char *option); + + SourceInfo *sources; + size_t sources_n; +} TargetInfo; + + +#define def_target_inner_s(t) NULL, t##_setsrc, NULL, NULL +#define def_target_inner_gs(t) t##_getsrc, t##_setsrc, NULL, NULL +#define def_target_inner_gsr(t) t##_getsrc, t##_setsrc, t##_resetsrc, NULL +#define def_target_inner_gsf(t) t##_getsrc, t##_setsrc, NULL, t##_feat +#define def_target_inner_gsrf(t) t##_getsrc, t##_setsrc, t##_resetsrc, t##_feat + +#define def_target_sourcesn(t) t##_sources, t##_sources_n + +// 大部分target还不支持reset,所以暂时先默认设置为NULL来过渡 +#define def_target(t) TargetInfo t##_target = {def_target_inner_gs(t),def_target_sourcesn(t)} +#define def_target_gsr(t) TargetInfo t##_target = {def_target_inner_gsr(t),def_target_sourcesn(t)} +#define def_target_gsrf(t) TargetInfo t##_target = {def_target_inner_gsrf(t),def_target_sourcesn(t)} +#define def_target_s(t) TargetInfo t##_target = {def_target_inner_s(t),def_target_sourcesn(t)} diff --git a/src/chsrc.c b/src/chsrc.c index 3f48c3f..267543d 100644 --- a/src/chsrc.c +++ b/src/chsrc.c @@ -3,11 +3,11 @@ * Copyright © 2023-2024 Aoran Zeng, Heng Guo * ------------------------------------------------------------- * Project Authors : Aoran Zeng - * | Heng Guo <2085471348@qq.com> + * | Heng Guo <2085471348@qq.com> * Contributors : Aaron Ruan - * | Rui Chen + * | Rui Chen * | Shengwei Chen <414685209@qq.com> - * | BlockLune + * | BlockLune * | * Created On : <2023-08-28> * Last Modified : <2024-08-16> @@ -198,7 +198,7 @@ print_supported_wr () * 用于 chsrc list */ void -print_supported_sources_for_target (SourceInfo sources[], size_t size) +cli_print_target_available_sources (SourceInfo sources[], size_t size) { for (int i=0;iresetfn) target->resetfn(option); else chsrc_error (xy_strjoin (3, "暂未对 ", input, " 实现reset功能,邀您帮助: chsrc issue")); - // puts ("将重置并恢复上游默认使用的源"); } else if (TargetOp_Get_Source==code) { @@ -352,11 +376,15 @@ get_target (const char *input, TargetOp code, char *option) } else if (TargetOp_List_Source==code) { - chsrc_info (xy_strjoin (3, "对 ", input, " 支持以下镜像站")); chsrc_info (xy_strjoin (3, "下方 code 列,可用于指定使用某源,请使用 chsrc set ", input, " \n")); printf (" %-14s%-35s%-43s ", "code", "镜像站简写", "换源URL"); puts ("镜像站名称"); puts ("--------- -------------- ----------------------------------------------- ---------------------"); - print_supported_sources_for_target (target->sources, target->sources_n); + cli_print_target_available_sources (target->sources, target->sources_n); + if (target->featfn) + { + FeatInfo fi = target->featfn(""); + cli_print_target_features (fi); + } } else if (TargetOp_Cesu_Source==code) { @@ -372,7 +400,7 @@ main (int argc, char const *argv[]) { xy_useutf8 (); argc -= 1; - if (argc==0) + if (0==argc) { cli_print_version (); cli_print_help (); @@ -391,7 +419,7 @@ main (int argc, char const *argv[]) // chsrc set -ipv6 target mirror // 1 2 3 4 // argc = 4 - for (int i=2; i<=argc ;i++) + for (int i=2; i<=argc; i++) { if (xy_str_start_with (argv[i], "-")) {