From f63b224b95789202a2b9653d6a48e6678888c0df Mon Sep 17 00:00:00 2001 From: Aoran Zeng Date: Thu, 31 Aug 2023 16:54:06 +0800 Subject: [PATCH] Add `xy_streql()` --- chsrc.c | 8 ++++---- helper.h | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/chsrc.c b/chsrc.c index d10e5b6..9483e2d 100644 --- a/chsrc.c +++ b/chsrc.c @@ -629,7 +629,7 @@ main (int argc, char const *argv[]) // 第一个参数 const char* target = NULL; - if (0==strcmp("-h",argv[1]) || 0==strcmp("--help",argv[1])) { + if (xy_streql("-h", argv[1]) || xy_streql("help", argv[1]) || xy_streql("--help", argv[1])) { print_help(); return 0; } else { target = argv[1]; @@ -655,7 +655,7 @@ main (int argc, char const *argv[]) int k = 0; const char* alias = packager[k]; while (NULL!=alias) { - if (0==strcmp(target, alias)) { + if (xy_streql(target, alias)) { // printf("matched: %s\n", alias); matched = 1; break; } @@ -677,7 +677,7 @@ main (int argc, char const *argv[]) const char* alias = system[k]; while (NULL!=alias) { // printf("%s matched: %s\n",target, alias); - if (0==strcmp(target, alias)) { + if (xy_streql(target, alias)) { // printf("matched: %s\n", alias); matched = 1; break; } @@ -699,7 +699,7 @@ main (int argc, char const *argv[]) const char* alias = ware[k]; while (NULL!=alias) { // printf("%s matched: %s\n",target, alias); - if (0==strcmp(target, alias)) { + if (xy_streql(target, alias)) { // printf("matched: %s\n", alias); matched = 1; break; } diff --git a/helper.h b/helper.h index b1cc0e2..68f968b 100644 --- a/helper.h +++ b/helper.h @@ -205,4 +205,10 @@ xy_strjoin (unsigned int count, ...) return ret; } + +bool +xy_streql(const char* str1, const char* str2) { + return strcmp(str1, str2) == 0 ? true : false; +} + #endif