Allow command line options from config file.
This commit is contained in:
@ -87,6 +87,18 @@ option_t *sb_find_option(const char *name)
|
||||
return find_option(&options, name);
|
||||
}
|
||||
|
||||
static void read_config_file(const char *filename)
|
||||
{
|
||||
/* read config options from file */
|
||||
FILE *fp = fopen(filename, "r");
|
||||
if (!fp) {
|
||||
perror(filename);
|
||||
} else {
|
||||
read_config(fp, &options);
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
|
||||
int set_option(const char *name, const char *value, sb_arg_type_t type)
|
||||
{
|
||||
option_t *opt;
|
||||
@ -120,6 +132,9 @@ int set_option(const char *name, const char *value, sb_arg_type_t type)
|
||||
add_value(&opt->values, tmp);
|
||||
free(tmp);
|
||||
break;
|
||||
case SB_ARG_TYPE_FILE:
|
||||
read_config_file(value);
|
||||
break;
|
||||
default:
|
||||
printf("Unknown argument type: %d", type);
|
||||
return 1;
|
||||
@ -163,6 +178,9 @@ void sb_print_options(sb_arg_t *opts)
|
||||
case SB_ARG_TYPE_STRING:
|
||||
fmt = "=STRING";
|
||||
break;
|
||||
case SB_ARG_TYPE_FILE:
|
||||
fmt = "=FILENAME";
|
||||
break;
|
||||
default:
|
||||
fmt = "<UNKNOWN>";
|
||||
}
|
||||
|
||||
@ -32,7 +32,8 @@ typedef enum
|
||||
SB_ARG_TYPE_SIZE,
|
||||
SB_ARG_TYPE_FLOAT,
|
||||
SB_ARG_TYPE_STRING,
|
||||
SB_ARG_TYPE_LIST
|
||||
SB_ARG_TYPE_LIST,
|
||||
SB_ARG_TYPE_FILE
|
||||
} sb_arg_type_t;
|
||||
|
||||
/* Test option definition */
|
||||
|
||||
@ -395,6 +395,9 @@ lua_State *sb_lua_new_state(const char *scriptname, int thread_id)
|
||||
/*FIXME: should be exported as tables */
|
||||
lua_pushnil(state);
|
||||
break;
|
||||
case SB_ARG_TYPE_FILE:
|
||||
/* FIXME: no need to export anything */
|
||||
break;
|
||||
default:
|
||||
log_text(LOG_WARNING, "Global option '%s' will not be exported, because"
|
||||
" the type is unknown", opt->name);
|
||||
|
||||
@ -148,6 +148,7 @@ sb_arg_t general_args[] =
|
||||
{"rand-seed", "seed for random number generator, ignored when 0", SB_ARG_TYPE_INT, "0"},
|
||||
{"rand-pareto-h", "parameter h for pareto distibution", SB_ARG_TYPE_FLOAT,
|
||||
"0.2"},
|
||||
{"config-file", "File containing command line options", SB_ARG_TYPE_FILE, NULL},
|
||||
{NULL, NULL, SB_ARG_TYPE_NULL, NULL}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user