version 1.3, 2009/09/21 14:46:47 |
version 1.4, 2009/09/21 14:56:03 |
|
|
set_option_string(struct cmd_ctx *ctx, struct options *oo, |
set_option_string(struct cmd_ctx *ctx, struct options *oo, |
const struct set_option_entry *entry, char *value, int append) |
const struct set_option_entry *entry, char *value, int append) |
{ |
{ |
char *oldvalue, *newvalue; |
struct options_entry *o; |
|
char *oldvalue, *newvalue; |
|
|
if (value == NULL) { |
if (value == NULL) { |
ctx->error(ctx, "empty value"); |
ctx->error(ctx, "empty value"); |
|
|
} else |
} else |
newvalue = value; |
newvalue = value; |
|
|
options_set_string(oo, entry->name, "%s", newvalue); |
o = options_set_string(oo, entry->name, "%s", newvalue); |
ctx->info(ctx, "set option: %s -> %s", entry->name, newvalue); |
ctx->info( |
|
ctx, "set option: %s -> %s", o->name, set_option_print(entry, o)); |
|
|
if (newvalue != value) |
if (newvalue != value) |
xfree(newvalue); |
xfree(newvalue); |
|
|
set_option_number(struct cmd_ctx *ctx, struct options *oo, |
set_option_number(struct cmd_ctx *ctx, struct options *oo, |
const struct set_option_entry *entry, char *value) |
const struct set_option_entry *entry, char *value) |
{ |
{ |
long long number; |
struct options_entry *o; |
const char *errstr; |
long long number; |
|
const char *errstr; |
|
|
if (value == NULL) { |
if (value == NULL) { |
ctx->error(ctx, "empty value"); |
ctx->error(ctx, "empty value"); |
|
|
ctx->error(ctx, "value is %s: %s", errstr, value); |
ctx->error(ctx, "value is %s: %s", errstr, value); |
return; |
return; |
} |
} |
options_set_number(oo, entry->name, number); |
|
ctx->info(ctx, "set option: %s -> %lld", entry->name, number); |
o = options_set_number(oo, entry->name, number); |
|
ctx->info( |
|
ctx, "set option: %s -> %s", o->name, set_option_print(entry, o)); |
} |
} |
|
|
void |
void |
set_option_key(struct cmd_ctx *ctx, struct options *oo, |
set_option_key(struct cmd_ctx *ctx, struct options *oo, |
const struct set_option_entry *entry, char *value) |
const struct set_option_entry *entry, char *value) |
{ |
{ |
int key; |
struct options_entry *o; |
|
int key; |
|
|
if (value == NULL) { |
if (value == NULL) { |
ctx->error(ctx, "empty value"); |
ctx->error(ctx, "empty value"); |
|
|
ctx->error(ctx, "unknown key: %s", value); |
ctx->error(ctx, "unknown key: %s", value); |
return; |
return; |
} |
} |
options_set_number(oo, entry->name, key); |
|
ctx->info(ctx, |
o = options_set_number(oo, entry->name, key); |
"set option: %s -> %s", entry->name, key_string_lookup_key(key)); |
ctx->info( |
|
ctx, "set option: %s -> %s", o->name, set_option_print(entry, o)); |
} |
} |
|
|
void |
void |
set_option_colour(struct cmd_ctx *ctx, struct options *oo, |
set_option_colour(struct cmd_ctx *ctx, struct options *oo, |
const struct set_option_entry *entry, char *value) |
const struct set_option_entry *entry, char *value) |
{ |
{ |
int colour; |
struct options_entry *o; |
|
int colour; |
|
|
if (value == NULL) { |
if (value == NULL) { |
ctx->error(ctx, "empty value"); |
ctx->error(ctx, "empty value"); |
|
|
return; |
return; |
} |
} |
|
|
options_set_number(oo, entry->name, colour); |
o = options_set_number(oo, entry->name, colour); |
ctx->info(ctx, |
ctx->info( |
"set option: %s -> %s", entry->name, colour_tostring(colour)); |
ctx, "set option: %s -> %s", o->name, set_option_print(entry, o)); |
} |
} |
|
|
void |
void |
set_option_attributes(struct cmd_ctx *ctx, struct options *oo, |
set_option_attributes(struct cmd_ctx *ctx, struct options *oo, |
const struct set_option_entry *entry, char *value) |
const struct set_option_entry *entry, char *value) |
{ |
{ |
int attr; |
struct options_entry *o; |
|
int attr; |
|
|
if (value == NULL) { |
if (value == NULL) { |
ctx->error(ctx, "empty value"); |
ctx->error(ctx, "empty value"); |
|
|
return; |
return; |
} |
} |
|
|
options_set_number(oo, entry->name, attr); |
o = options_set_number(oo, entry->name, attr); |
ctx->info(ctx, |
ctx->info( |
"set option: %s -> %s", entry->name, attributes_tostring(attr)); |
ctx, "set option: %s -> %s", o->name, set_option_print(entry, o)); |
} |
} |
|
|
void |
void |
set_option_flag(struct cmd_ctx *ctx, struct options *oo, |
set_option_flag(struct cmd_ctx *ctx, struct options *oo, |
const struct set_option_entry *entry, char *value) |
const struct set_option_entry *entry, char *value) |
{ |
{ |
int flag; |
struct options_entry *o; |
|
int flag; |
|
|
if (value == NULL || *value == '\0') |
if (value == NULL || *value == '\0') |
flag = !options_get_number(oo, entry->name); |
flag = !options_get_number(oo, entry->name); |
|
|
} |
} |
} |
} |
|
|
options_set_number(oo, entry->name, flag); |
o = options_set_number(oo, entry->name, flag); |
ctx->info(ctx, |
ctx->info( |
"set option: %s -> %s", entry->name, flag ? "on" : "off"); |
ctx, "set option: %s -> %s", o->name, set_option_print(entry, o)); |
} |
} |
|
|
void |
void |
set_option_choice(struct cmd_ctx *ctx, struct options *oo, |
set_option_choice(struct cmd_ctx *ctx, struct options *oo, |
const struct set_option_entry *entry, char *value) |
const struct set_option_entry *entry, char *value) |
{ |
{ |
const char **choicep; |
struct options_entry *o; |
int n, choice = -1; |
const char **choicep; |
|
int n, choice = -1; |
|
|
if (value == NULL) { |
if (value == NULL) { |
ctx->error(ctx, "empty value"); |
ctx->error(ctx, "empty value"); |
|
|
return; |
return; |
} |
} |
|
|
options_set_number(oo, entry->name, choice); |
o = options_set_number(oo, entry->name, choice); |
ctx->info(ctx, |
ctx->info( |
"set option: %s -> %s", entry->name, entry->choices[choice]); |
ctx, "set option: %s -> %s", o->name, set_option_print(entry, o)); |
} |
} |