Remove warning

This commit is contained in:
Aoran Zeng 2023-08-29 15:54:21 +08:00
parent f62353cbce
commit 6a79804df3
2 changed files with 27 additions and 16 deletions

39
chsrc.c
View File

@ -1,3 +1,14 @@
/* --------------------------------------------------------------
* File : chsrc.c
* Authors : Aoran Zeng <ccmywish@qq.com>
* Created on : <2023-08-28>
* Last modified : <2023-08-29>
*
* chsrc:
*
* Change Source
* -------------------------------------------------------------*/
#include <stdio.h> #include <stdio.h>
#include "helper.h" #include "helper.h"
@ -76,9 +87,9 @@ pl_chsrc_ruby (char* source_name)
free(cmd); free(cmd);
} }
#define arg(func) (const char const*)func #define cmdfunc(func) (const char const*)func
static const char const static const char const
*pl_ruby[] = {"gem", "ruby", "rb", NULL, arg(pl_chsrc_ruby)}, *pl_ruby[] = {"gem", "ruby", "rb", NULL, cmdfunc(pl_chsrc_ruby)},
*pl_python[] = {"pip", "python", "py", NULL}, *pl_python[] = {"pip", "python", "py", NULL},
*pl_nodejs[] = {"npm", "node", "nodejs", "js", NULL}, *pl_nodejs[] = {"npm", "node", "nodejs", "js", NULL},
*pl_perl[] = {"perl", "cpan", NULL}, *pl_perl[] = {"perl", "cpan", NULL},
@ -101,20 +112,20 @@ static const char const
static const char const* static const char const*
usage[] = { usage[] = {
"chsrc: Change Source " Chsrc_Version " by RubyMetric\n", "chsrc: Change Source " Chsrc_Version " by RubyMetric\n",
"Usage:\n" "使用:\n"
" chsrc <target> [source]\n", " chsrc <要换源的对象> [所换源名称]\n",
"Options:\n" "选项:\n"
" -h Print this help\n", " -h 打印该帮助\n",
"Supported:\n" "支持:\n"
}; };
void void
call_cmd (void* cmdptr, char* arg) call_cmd (void* cmdptr, const char* arg)
{ {
void (*cmd_func)(char*) = cmdptr; void (*cmd_func)(const char*) = cmdptr;
if (NULL==arg) { if (NULL==arg) {
puts("chsrc: Use the default"); puts("chsrc: Use the default");
} }
@ -123,7 +134,7 @@ call_cmd (void* cmdptr, char* arg)
int int
print_help() print_help ()
{ {
for (int i=0; i<ARRAY_SIZE(usage); i++) { for (int i=0; i<ARRAY_SIZE(usage); i++) {
puts(usage[i]); puts(usage[i]);
@ -132,7 +143,7 @@ print_help()
int int
main(int argc, char const *argv[]) main (int argc, char const *argv[])
{ {
// 未提供参数时 // 未提供参数时
if (argc<=1) { if (argc<=1) {
@ -140,15 +151,15 @@ main(int argc, char const *argv[])
} }
// 第一个参数 // 第一个参数
char* target = NULL; const char* target = NULL;
if (0==strcmp("-h",argv[1])) { if (0==strcmp("-h",argv[1])) {
print_help(); return 0; print_help(); return 0;
} else { } else {
target = argv[1]; target = argv[1];
} }
char* option = NULL; const char* option = NULL;
char* cmdarg = NULL; const char* cmdarg = NULL;
// 第二个参数 // 第二个参数
if (argc>=2) if (argc>=2)
{ {

View File

@ -2,7 +2,7 @@
* File : helper.h * File : helper.h
* Authors : Aoran Zeng <ccmywish@qq.com> * Authors : Aoran Zeng <ccmywish@qq.com>
* Created on : <2023-08-28> * Created on : <2023-08-28>
* Last modified : <2023-08-28> * Last modified : <2023-08-29>
* *
* helper: * helper:
* *
@ -15,7 +15,7 @@
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
char* char*
xy_strjoin(const char* str1, const char* str2) xy_strjoin (const char* str1, const char* str2)
{ {
size_t len = strlen(str1) + strlen(str2) + 1; size_t len = strlen(str1) + strlen(str2) + 1;
char* ret = malloc(len); char* ret = malloc(len);