Browse Source

update: structure of help message

master
Dnomd343 2 years ago
parent
commit
6a018e510c
  1. 8
      include/common.h
  2. 10
      src/common.c
  3. 7
      src/local.c
  4. 7
      src/server.c

8
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

10
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);
}
}

7
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));

7
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));

Loading…
Cancel
Save