Skip to content

Commit 653ac67

Browse files
author
Mikachu2333
committed
replace original function
1 parent 05b9672 commit 653ac67

6 files changed

Lines changed: 61 additions & 60 deletions

File tree

lib/xy.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ bool xy_enable_color = true;
9494
#define xy_useutf8()
9595
#endif
9696

97-
#define assert_str(a, b) assert (xy_streql ((a), (b)))
97+
#define assert_str(a, b) assert (xy_streql_ic ((a), (b)))
9898

9999
#define xy_unsupported() assert(!"Unsuppoted")
100100
#define xy_unimplemented() assert(!"Unimplemented temporarily")
@@ -379,7 +379,8 @@ xy_streql (const char *str1, const char *str2)
379379
return strcmp (str1, str2) == 0 ? true : false;
380380
}
381381

382-
static bool xy_streql_ic(const char *str1, const char *str2) {
382+
static bool
383+
xy_streql_ic(const char *str1, const char *str2) {
383384
if (NULL == str1 || NULL == str2) {
384385
return false;
385386
}

src/chsrc-main.c

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ iterate_targets_ (const char ***array, size_t size, const char *input, const cha
402402
alias = target[k];
403403
while (NULL!=alias)
404404
{
405-
if (xy_streql (input, alias))
405+
if (xy_streql_ic (input, alias))
406406
{
407407
matched = 1; break;
408408
}
@@ -572,36 +572,36 @@ main (int argc, char const *argv[])
572572
{
573573
if (xy_str_start_with (argv[i], "-"))
574574
{
575-
if (xy_streql (argv[i], "-ipv6"))
575+
if (xy_streql_ic (argv[i], "-ipv6"))
576576
{
577577
ProgMode.Ipv6Mode = true;
578578
}
579-
else if (xy_streql (argv[i], "-local"))
579+
else if (xy_streql_ic (argv[i], "-local"))
580580
{
581581
ProgMode.LocalMode = true;
582582
}
583-
else if (xy_streql (argv[i], "-en") || xy_streql (argv[i], "-english"))
583+
else if (xy_streql_ic (argv[i], "-en") || xy_streql_ic (argv[i], "-english"))
584584
{
585585
ProgMode.EnglishMode = true;
586586
}
587-
else if (xy_streql (argv[i], "-dry"))
587+
else if (xy_streql_ic (argv[i], "-dry"))
588588
{
589589
ProgMode.DryRunMode = true;
590590
}
591-
else if (xy_streql (argv[i], "-no-color") || xy_streql (argv[i], "-no-colour"))
591+
else if (xy_streql_ic (argv[i], "-no-color") || xy_streql_ic (argv[i], "-no-colour"))
592592
{
593593
ProgMode.NoColorMode = true;
594594
xy_enable_color = false;
595595
}
596-
else if ( xy_streql (argv[i], "-h")
597-
|| xy_streql (argv[i], "-help")
598-
|| xy_streql (argv[i], "--help"))
596+
else if ( xy_streql_ic (argv[i], "-h")
597+
|| xy_streql_ic (argv[i], "-help")
598+
|| xy_streql_ic (argv[i], "--help"))
599599
{
600600
command = "help"; /* 交到下方处理 */
601601
}
602-
else if ( xy_streql (argv[i], "-v")
603-
|| xy_streql (command, "-version")
604-
|| xy_streql (command, "--version"))
602+
else if ( xy_streql_ic (argv[i], "-v")
603+
|| xy_streql_ic (command, "-version")
604+
|| xy_streql_ic (command, "--version"))
605605
{
606606
command = "version"; /* 交到下方处理 */
607607
}
@@ -628,31 +628,31 @@ main (int argc, char const *argv[])
628628
}
629629

630630
/* chsrc help */
631-
if ( xy_streql (command, "h")
632-
|| xy_streql (command, "-h")
633-
|| xy_streql (command, "help")
634-
|| xy_streql (command, "-help")
635-
|| xy_streql (command, "--help"))
631+
if ( xy_streql_ic (command, "h")
632+
|| xy_streql_ic (command, "-h")
633+
|| xy_streql_ic (command, "help")
634+
|| xy_streql_ic (command, "-help")
635+
|| xy_streql_ic (command, "--help"))
636636
{
637637
cli_print_help ();
638638
return Exit_OK;
639639
}
640640

641641
/* chsrc -v */
642-
else if ( xy_streql (command, "-v")
643-
|| xy_streql (command, "-version")
644-
|| xy_streql (command, "--version")
645-
|| xy_streql (command, "ver")
646-
|| xy_streql (command, "version"))
642+
else if ( xy_streql_ic (command, "-v")
643+
|| xy_streql_ic (command, "-version")
644+
|| xy_streql_ic (command, "--version")
645+
|| xy_streql_ic (command, "ver")
646+
|| xy_streql_ic (command, "version"))
647647
{
648648
cli_print_version ();
649649
return Exit_OK;
650650
}
651651

652652
/* chsrc list */
653-
else if ( xy_streql (command, "list")
654-
|| xy_streql (command, "l")
655-
|| xy_streql (command, "ls"))
653+
else if ( xy_streql_ic (command, "list")
654+
|| xy_streql_ic (command, "l")
655+
|| xy_streql_ic (command, "ls"))
656656
{
657657
if (argc < cli_arg_Target_pos)
658658
{
@@ -663,23 +663,23 @@ main (int argc, char const *argv[])
663663
else
664664
{
665665
target = argv[cli_arg_Target_pos];
666-
if (xy_streql (target, "mirrors") || xy_streql (target, "mirror"))
666+
if (xy_streql_ic (target, "mirrors") || xy_streql_ic (target, "mirror"))
667667
{
668668
cli_print_available_mirrors (); return Exit_OK;
669669
}
670-
else if (xy_streql (target, "targets") || xy_streql (target, "target"))
670+
else if (xy_streql_ic (target, "targets") || xy_streql_ic (target, "target"))
671671
{
672672
cli_print_supported_targets (); return Exit_OK;
673673
}
674-
else if (xy_streql (target, "os"))
674+
else if (xy_streql_ic (target, "os"))
675675
{
676676
cli_print_supported_os (); return Exit_OK;
677677
}
678-
else if (xy_streql (target, "lang") || xy_streql (target, "pl") || xy_streql (target, "language"))
678+
else if (xy_streql_ic (target, "lang") || xy_streql_ic (target, "pl") || xy_streql_ic (target, "language"))
679679
{
680680
cli_print_supported_pl(); return Exit_OK;
681681
}
682-
else if (xy_streql (target, "ware") || xy_streql (target, "software"))
682+
else if (xy_streql_ic (target, "ware") || xy_streql_ic (target, "software"))
683683
{
684684
cli_print_supported_wr (); return Exit_OK;
685685
}
@@ -694,12 +694,12 @@ main (int argc, char const *argv[])
694694
#define MSG_CN_USE_LIST_TARGETS "使用 chsrc list targets 查看所有支持的目标"
695695

696696
/* chsrc measure */
697-
else if ( xy_streql (command, "measure")
698-
|| xy_streql (command, "mea")
699-
|| xy_streql (command, "m")
700-
|| xy_streql (command, "cesu")
701-
|| xy_streql (command, "ce")
702-
|| xy_streql (command, "c"))
697+
else if ( xy_streql_ic (command, "measure")
698+
|| xy_streql_ic (command, "mea")
699+
|| xy_streql_ic (command, "m")
700+
|| xy_streql_ic (command, "cesu")
701+
|| xy_streql_ic (command, "ce")
702+
|| xy_streql_ic (command, "c"))
703703
{
704704
if (argc < cli_arg_Target_pos)
705705
{
@@ -717,8 +717,8 @@ main (int argc, char const *argv[])
717717

718718

719719
/* chsrc get */
720-
else if ( xy_streql (command, "get")
721-
|| xy_streql (command, "g"))
720+
else if ( xy_streql_ic (command, "get")
721+
|| xy_streql_ic (command, "g"))
722722
{
723723
if (argc < cli_arg_Target_pos)
724724
{
@@ -734,8 +734,8 @@ main (int argc, char const *argv[])
734734
}
735735

736736
/* chsrc set */
737-
else if ( xy_streql (command, "set")
738-
|| xy_streql (command, "s"))
737+
else if ( xy_streql_ic (command, "set")
738+
|| xy_streql_ic (command, "s"))
739739
{
740740
if (argc < cli_arg_Target_pos)
741741
{
@@ -758,9 +758,9 @@ main (int argc, char const *argv[])
758758
}
759759

760760
/* chsrc reset */
761-
else if ( xy_streql (command, "reset")
762-
|| xy_streql (command, "rest")
763-
|| xy_streql (command, "r"))
761+
else if ( xy_streql_ic (command, "reset")
762+
|| xy_streql_ic (command, "rest")
763+
|| xy_streql_ic (command, "r"))
764764
{
765765
if (argc < cli_arg_Target_pos)
766766
{
@@ -778,10 +778,10 @@ main (int argc, char const *argv[])
778778
}
779779

780780
/* chsrc issue */
781-
else if ( xy_streql (command, "issue")
782-
|| xy_streql (command, "issues")
783-
|| xy_streql (command, "isue")
784-
|| xy_streql (command, "i"))
781+
else if ( xy_streql_ic (command, "issue")
782+
|| xy_streql_ic (command, "issues")
783+
|| xy_streql_ic (command, "isue")
784+
|| xy_streql_ic (command, "i"))
785785
{
786786
cli_print_issues ();
787787
return Exit_OK;

src/framework/core.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ query_provider_exist (Source_t *sources, size_t size, char *target, char *input)
488488
exit (Exit_MaintainerCause);
489489
}
490490

491-
/* if (xy_streql ("reset", input)) 不再使用这种方式 */
491+
/* if (xy_streql_ic ("reset", input)) 不再使用这种方式 */
492492
if (chsrc_in_reset_mode())
493493
{
494494
char *msg = ENGLISH ? "Will reset to the upstream's default source" : "将重置为上游默认源";
@@ -506,7 +506,7 @@ query_provider_exist (Source_t *sources, size_t size, char *target, char *input)
506506
chsrc_succ (xy_strjoin (4, name, msg1, target, msg2));
507507
}
508508

509-
if (xy_streql ("first", input))
509+
if (xy_streql_ic ("first", input))
510510
{
511511
char *msg = ENGLISH ? "Will use the first speedy source measured by maintainers" : "将使用维护团队测速第一的源";
512512
say (msg);
@@ -520,7 +520,7 @@ query_provider_exist (Source_t *sources, size_t size, char *target, char *input)
520520
for (int i=0; i<size; i++)
521521
{
522522
src = sources[i];
523-
if (xy_streql (src.mirror->code, input))
523+
if (xy_streql_ic (src.mirror->code, input))
524524
{
525525
idx = i;
526526
exist = true;
@@ -750,7 +750,7 @@ measure_speed_for_every_source (Source_t sources[], int size, double speed_recor
750750

751751
if (provider_skip && !has_dedicated_speed_url)
752752
{
753-
if (xy_streql ("upstream", provider->code))
753+
if (xy_streql_ic ("upstream", provider->code))
754754
{
755755
/* 上游源不测速,但不置0,因为要避免这么一种情况: 可能其他镜像站测速都为0,最后反而选择了该 upstream */
756756
speed = -1024*1024*1024;
@@ -760,7 +760,7 @@ measure_speed_for_every_source (Source_t sources[], int size, double speed_recor
760760
psmi.skip_reason_EN = "Lack of URL to measure upstream default source provider, please help to add";
761761
}
762762
}
763-
else if (xy_streql ("user", provider->code))
763+
else if (xy_streql_ic ("user", provider->code))
764764
{
765765
/* 代码不会执行至此 */
766766
speed = 1024*1024*1024;
@@ -804,7 +804,7 @@ measure_speed_for_every_source (Source_t sources[], int size, double speed_recor
804804
char *accurate_msg = CHINESE ? (is_accurate ? bdblue(faint("[精准测速]")) : faint("[模糊测速]"))
805805
: (is_accurate ? bdblue(faint("[accurate]")) : faint("[rough]"));
806806

807-
if (xy_streql ("upstream", provider->code))
807+
if (xy_streql_ic ("upstream", provider->code))
808808
{
809809
measure_msgs[i] = xy_strjoin (7, faint(" ^ "), msg, " (", src.url, ") ", accurate_msg, faint(" ... "));
810810
}
@@ -981,13 +981,13 @@ select_mirror_autoly (Source_t *sources, size_t size, const char *target_name)
981981
bool
982982
source_is_upstream (Source_t *source)
983983
{
984-
return xy_streql (source->mirror->code, "upstream");
984+
return xy_streql_ic (source->mirror->code, "upstream");
985985
}
986986

987987
bool
988988
source_is_userdefine (Source_t *source)
989989
{
990-
return xy_streql (source->mirror->code, "user");
990+
return xy_streql_ic (source->mirror->code, "user");
991991
}
992992

993993
bool

src/recipe/os/BSD/FreeBSD.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ os_freebsd_setsrc (char *option)
6969
bool git_exist = query_program_exist (xy_str_to_quietcmd ("git version"), "git", Noisy_When_Exist|Noisy_When_NonExist);
7070
if (git_exist)
7171
{
72-
if (xy_streql("nju",source.mirror->code))
72+
if (xy_streql_ic("nju",source.mirror->code))
7373
{
7474
source = os_freebsd_sources[index-1]; // 使用NJU的前一个源,即USTC源
7575
}

src/recipe/ware/Docker-Hub/Docker-Hub.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ wr_dockerhub_setsrc (char *option)
8787
cmd = xy_str_gsub (cmd, "@2@", WR_DockerHub_ConfigFile);
8888

8989
char *result = xy_run (cmd, 0);
90-
if (result && !xy_streql (result, "null"))
90+
if (result && !xy_streql_ic (result, "null"))
9191
{
9292
chsrc_alert2 ("已存在源,无需重复添加");
9393
}

test/fw.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
int
1717
main (int argc, char const *argv[])
1818
{
19-
if (argc == 2 && xy_streql (argv[1], "--version"))
19+
if (argc == 2 && xy_streql_ic (argv[1], "--version"))
2020
{
2121
say (Chsrc_Version);
2222
return 0;

0 commit comments

Comments
 (0)