From 6a018e510c0c18f095c4ed3d0dcd67fb9a07e6de Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sun, 2 Oct 2022 17:18:54 +0800 Subject: [PATCH] update: structure of help message --- include/common.h | 8 ++++---- src/common.c | 10 +++++----- src/local.c | 7 +++---- src/server.c | 7 +++---- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/include/common.h b/include/common.h index d870a4e..a9bab28 100644 --- a/include/common.h +++ b/include/common.h @@ -6,12 +6,12 @@ #define RANDOM_PORT_START 41952 #define RANDOM_PORT_END 65535 -void init(int argc, char **argv, char *help_msg); +void init(int argc, char **argv, const char *help_msg); -char* new_string(char *str); char* int_to_string(int num); -char* read_file(char *file_name); +char* new_string(const char *str); +char* read_file(const char *file_name); char* string_list_join(char **string_list); -char** string_list_append(char **string_list, char *data); +char** string_list_append(char **string_list, const char *data); #endif diff --git a/src/common.c b/src/common.c index 038598c..c6fac13 100644 --- a/src/common.c +++ b/src/common.c @@ -4,7 +4,7 @@ #include "logger.h" #include "common.h" -char* new_string(char *str) { +char* new_string(const char *str) { return strcpy((char*)malloc(strlen(str) + 1), str); } @@ -23,7 +23,7 @@ char* int_to_string(int num) { // int -> string return str; } -char** string_list_append(char **string_list, char *data) { +char** string_list_append(char **string_list, const char *data) { int num = 0; while(string_list[num++] != NULL); // get string list size string_list = (char**)realloc(string_list, sizeof(char*) * (num + 1)); @@ -42,7 +42,7 @@ char* string_list_join(char **string_list) { // combine string list -> `str_1` ` return join_str; } -char* read_file(char *file_name) { // read file content +char* read_file(const char *file_name) { // read file content log_debug("Start read file -> %s", file_name); FILE *pfile = fopen(file_name, "rb"); if (pfile == NULL) { // file open failed @@ -62,7 +62,7 @@ char* read_file(char *file_name) { // read file content return file_content; } -void init(int argc, char **argv, char *help_msg) { +void init(int argc, char **argv, const char *help_msg) { if (argc <= 1) { // with only one argument printf(help_msg, VERSION); exit(0); @@ -72,7 +72,7 @@ void init(int argc, char **argv, char *help_msg) { LOG_LEVEL = LOG_DEBUG; } if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { // include `-h` or `--help` - printf(help_msg, VERSION); + printf(help_msg, VERSION); // show help message exit(0); } } diff --git a/src/local.c b/src/local.c index b8f5db1..649ae7c 100644 --- a/src/local.c +++ b/src/local.c @@ -3,7 +3,7 @@ #include "common.h" #include "process.h" -char *help_msg = "\n\ +#define HELP_MSG "\n\ ss-bootstrap-local (%s)\n\ \n\ A simple program to make the original shadowsocks support SIP003 plugins.\n\ @@ -24,11 +24,10 @@ ss-bootstrap-local (%s)\n\ --no-udp Do not use UDP proxy.\n\ --debug Enable debug mode.\n\ -h, --help Print this message.\n\ -\n\ -"; +\n" int main(int argc, char *argv[]) { - init(argc, argv, help_msg); + init(argc, argv, HELP_MSG); log_info("Shadowsocks bootstrap local (%s)", VERSION); bootstrap *info = load_info(argc, argv); start_bootstrap(1, load_sip003("sslocal", info)); diff --git a/src/server.c b/src/server.c index 1a79a97..7d21142 100644 --- a/src/server.c +++ b/src/server.c @@ -3,7 +3,7 @@ #include "common.h" #include "process.h" -char *help_msg = "\n\ +#define HELP_MSG "\n\ ss-bootstrap-server (%s)\n\ \n\ A simple program to make the original shadowsocks support SIP003 plugins.\n\ @@ -24,11 +24,10 @@ ss-bootstrap-server (%s)\n\ --no-udp Do not use UDP proxy.\n\ --debug Enable debug mode.\n\ -h, --help Print this message.\n\ -\n\ -"; +\n" int main(int argc, char *argv[]) { - init(argc, argv, help_msg); + init(argc, argv, HELP_MSG); log_info("Shadowsocks bootstrap server (%s)", VERSION); bootstrap *info = load_info(argc, argv); start_bootstrap(0, load_sip003("ssserver", info));