mirror of
https://github.com/lammertb/libhttp.git
synced 2025-09-04 12:42:09 +03:00
Better usage description in main
This commit is contained in:
41
src/main.c
41
src/main.c
@@ -138,7 +138,7 @@ static void die(const char *fmt, ...)
|
|||||||
static int MakeConsole();
|
static int MakeConsole();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void show_usage_and_exit(void)
|
static void show_usage_and_exit(const char *exeName)
|
||||||
{
|
{
|
||||||
const struct mg_option *options;
|
const struct mg_option *options;
|
||||||
int i;
|
int i;
|
||||||
@@ -147,12 +147,20 @@ static void show_usage_and_exit(void)
|
|||||||
MakeConsole();
|
MakeConsole();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (exeName==0 || *exeName==0) {
|
||||||
|
exeName = "civetweb";
|
||||||
|
}
|
||||||
|
|
||||||
fprintf(stderr, "Civetweb v%s, built on %s\n",
|
fprintf(stderr, "Civetweb v%s, built on %s\n",
|
||||||
mg_version(), __DATE__);
|
mg_version(), __DATE__);
|
||||||
fprintf(stderr, "Usage:\n");
|
fprintf(stderr, "Usage:\n");
|
||||||
fprintf(stderr, " civetweb -A <htpasswd_file> <realm> <user> <passwd>\n");
|
fprintf(stderr, " Start server with a set of options:\n");
|
||||||
fprintf(stderr, " civetweb [config_file]\n");
|
fprintf(stderr, " %s [config_file]\n", exeName);
|
||||||
fprintf(stderr, " civetweb [-option value ...]\n");
|
fprintf(stderr, " %s [-option value ...]\n", exeName);
|
||||||
|
fprintf(stderr, " Add user/change password:\n");
|
||||||
|
fprintf(stderr, " %s -A <htpasswd_file> <realm> <user> <passwd>\n", exeName);
|
||||||
|
fprintf(stderr, " Remove user:\n");
|
||||||
|
fprintf(stderr, " %s -R <htpasswd_file> <realm> <user>\n", exeName);
|
||||||
fprintf(stderr, "\nOPTIONS:\n");
|
fprintf(stderr, "\nOPTIONS:\n");
|
||||||
|
|
||||||
options = mg_get_valid_options();
|
options = mg_get_valid_options();
|
||||||
@@ -432,7 +440,7 @@ static void process_command_line_arguments(char *argv[], char **options)
|
|||||||
They override config file and default settings. */
|
They override config file and default settings. */
|
||||||
for (i = cmd_line_opts_start; argv[i] != NULL; i += 2) {
|
for (i = cmd_line_opts_start; argv[i] != NULL; i += 2) {
|
||||||
if (argv[i][0] != '-' || argv[i + 1] == NULL) {
|
if (argv[i][0] != '-' || argv[i + 1] == NULL) {
|
||||||
show_usage_and_exit();
|
show_usage_and_exit(argv[0]);
|
||||||
}
|
}
|
||||||
if (!set_option(options, &argv[i][1], argv[i + 1])) {
|
if (!set_option(options, &argv[i][1], argv[i + 1])) {
|
||||||
printf("command line option is invalid, ignoring it:\n %s %s\n",
|
printf("command line option is invalid, ignoring it:\n %s %s\n",
|
||||||
@@ -561,15 +569,24 @@ static void start_civetweb(int argc, char *argv[])
|
|||||||
char *options[2*MAX_OPTIONS+1];
|
char *options[2*MAX_OPTIONS+1];
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* Edit passwords file, if -A option is specified */
|
/* Edit passwords file: Add user or change password, if -A option is specified */
|
||||||
if (argc > 1 && !strcmp(argv[1], "-A")) {
|
if (argc > 1 && !strcmp(argv[1], "-A")) {
|
||||||
if (argc != 6) {
|
if (argc != 6) {
|
||||||
show_usage_and_exit();
|
show_usage_and_exit(argv[0]);
|
||||||
}
|
}
|
||||||
exit(mg_modify_passwords_file(argv[2], argv[3], argv[4], argv[5]) ?
|
exit(mg_modify_passwords_file(argv[2], argv[3], argv[4], argv[5]) ?
|
||||||
EXIT_SUCCESS : EXIT_FAILURE);
|
EXIT_SUCCESS : EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Edit passwords file: Remove user, if -R option is specified */
|
||||||
|
if (argc > 1 && !strcmp(argv[1], "-R")) {
|
||||||
|
if (argc != 5) {
|
||||||
|
show_usage_and_exit(argv[0]);
|
||||||
|
}
|
||||||
|
exit(mg_modify_passwords_file(argv[2], argv[3], argv[4], NULL) ?
|
||||||
|
EXIT_SUCCESS : EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
/* Call Lua with additional Civetweb specific Lua functions, if -L option is specified */
|
/* Call Lua with additional Civetweb specific Lua functions, if -L option is specified */
|
||||||
if (argc > 1 && !strcmp(argv[1], "-L")) {
|
if (argc > 1 && !strcmp(argv[1], "-L")) {
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
@@ -582,8 +599,8 @@ static void start_civetweb(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Show usage if -h or --help options are specified */
|
/* Show usage if -h or --help options are specified */
|
||||||
if (argc == 2 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))) {
|
if (argc == 2 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "-H") || !strcmp(argv[1], "--help"))) {
|
||||||
show_usage_and_exit();
|
show_usage_and_exit(argv[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
options[0] = NULL;
|
options[0] = NULL;
|
||||||
@@ -1501,9 +1518,9 @@ static int MakeConsole() {
|
|||||||
|
|
||||||
ok = (GetConsoleWindow() != NULL);
|
ok = (GetConsoleWindow() != NULL);
|
||||||
if (ok) {
|
if (ok) {
|
||||||
freopen("CONIN$", "r", stdin);
|
freopen("CONIN$", "r", stdin);
|
||||||
freopen("CONOUT$", "w", stdout);
|
freopen("CONOUT$", "w", stdout);
|
||||||
freopen("CONOUT$", "w", stderr);
|
freopen("CONOUT$", "w", stderr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user