introduced short option names

This commit is contained in:
valenok 2010-08-30 13:10:10 +01:00
parent bb21ffec12
commit 97f2155239
3 changed files with 20 additions and 24 deletions

17
main.c
View File

@ -91,29 +91,22 @@ static int mg_edit_passwords(const char *fname, const char *domain,
static void show_usage_and_exit(void) {
const char **names;
int i, len;
int i;
fprintf(stderr, "Mongoose version %s (c) Sergey Lyubka\n", mg_version());
fprintf(stderr, "Usage:\n");
fprintf(stderr, " mongoose -A <htpasswd_file> <realm> <user> <passwd>\n");
fprintf(stderr, " mongoose <config_file>\n");
fprintf(stderr, " mongoose [-option value ...]\n");
fprintf(stderr, "OPTIONS:\n ");
fprintf(stderr, "OPTIONS:\n");
names = mg_get_valid_option_names();
len = 2;
for (i = 0; names[i] != NULL; i++) {
len += strlen(names[i]) + 1;
if (len >= 80) {
len = strlen(names[i]) + 3;
fprintf(stderr, "%s", "\n ");
}
fprintf(stderr, "%s%c", names[i], names[i + 1] == NULL ? '\n' : ',');
for (i = 0; names[i] != NULL; i += 2) {
fprintf(stderr, " -%s %s\n", names[i], names[i + 1]);
}
fprintf(stderr, "See http://code.google.com/p/mongoose/wiki/MongooseManual"
" for more details.\n");
fprintf(stderr, "Example:\n mongoose -listening_ports 80,443s "
"-enable_directory_listing no\n");
fprintf(stderr, "Example:\n mongoose -s cert.pem -p 80,443s -d no\n");
exit(EXIT_FAILURE);
}

View File

@ -352,17 +352,19 @@ enum {
CGI_INTERPRETER, CGI_ENVIRONMENT, SSI_EXTENSIONS, AUTHENTICATION_DOMAIN,
URI_PROTECTION, GLOBAL_PASSWORDS_FILE, PUT_DELETE_PASSWORDS_FILE,
ACCESS_LOG_FILE, ERROR_LOG_FILE, ACCESS_CONTROL_LIST, RUN_AS_USER,
EXTRA_MIME_TYPES, ENABLE_DIRECTORY_LISTING, ENABLE_KEEP_ALIVE, NUM_THREADS,
EXTRA_MIME_TYPES, ENABLE_DIRECTORY_LISTING, NUM_THREADS,
NUM_OPTIONS
};
// There are two entries for each option: a short and a long version.
static const char *option_names[] = {
"document_root", "listening_ports", "index_files", "ssl_certificate",
"cgi_extensions", "cgi_interpreter", "cgi_environment", "ssi_extensions",
"authentication_domain", "protect_uri", "global_passwords_file",
"put_delete_passwords_file", "access_log_file", "error_log_file",
"access_control_list", "run_as_user", "extra_mime_types",
"enable_directory_listing", "enable_keep_alive", "num_threads",
"r", "document_root", "p", "listening_ports", "i", "index_files",
"s", "ssl_certificate", "C", "cgi_extensions", "I", "cgi_interpreter",
"E", "cgi_environment", "S", "ssi_extensions", "R", "authentication_domain",
"P", "protect_uri", "g", "global_passwords_file",
"G", "put_delete_passwords_file", "a", "access_log_file",
"e", "error_log_file", "l", "access_control_list", "u", "run_as_user",
"m", "extra_mime_types", "d", "enable_directory_listing", "t", "num_threads",
NULL
};
@ -410,9 +412,10 @@ static void *call_user(struct mg_connection *conn, enum mg_event event) {
static int get_option_index(const char *name) {
int i;
for (i = 0; option_names[i] != NULL; i++) {
if (strcmp(option_names[i], name) == 0) {
return i;
for (i = 0; option_names[i] != NULL; i += 2) {
if (strcmp(option_names[i], name) == 0 ||
strcmp(option_names[i + 1], name) == 0) {
return i / 2;
}
}
return -1;
@ -3788,7 +3791,6 @@ struct mg_context *mg_start(mg_callback_t user_callback, const char **options) {
ctx->config[DOCUMENT_ROOT] = mg_strdup(".");
ctx->config[LISTENING_PORTS] = mg_strdup("8080");
ctx->config[ENABLE_DIRECTORY_LISTING] = mg_strdup("yes");
ctx->config[ENABLE_KEEP_ALIVE] = mg_strdup("no");
ctx->config[AUTHENTICATION_DOMAIN] = mg_strdup("mydomain.com");
ctx->config[INDEX_FILES] = mg_strdup("index.html,index.htm,index.cgi");
ctx->config[CGI_EXTENSIONS] = mg_strdup(".cgi,.pl,.php");

View File

@ -118,7 +118,8 @@ void mg_stop(struct mg_context *);
const char *mg_get_option(const struct mg_context *ctx, const char *name);
// Return array of valid configuration options.
// Return array of valid configuration options. For each option, a short
// version and a long version is returned. Array is NULL terminated.
const char **mg_get_valid_option_names(void);