2008-11-16 13:28:59 +00:00
|
|
|
/* $Id: cmd-set-option.c,v 1.44 2008-11-16 13:28:59 nicm Exp $ */
|
2007-10-04 10:11:32 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "tmux.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set an option.
|
|
|
|
*/
|
|
|
|
|
2008-06-05 16:35:32 +00:00
|
|
|
int cmd_set_option_parse(struct cmd *, int, char **, char **);
|
|
|
|
void cmd_set_option_exec(struct cmd *, struct cmd_ctx *);
|
|
|
|
void cmd_set_option_send(struct cmd *, struct buffer *);
|
|
|
|
void cmd_set_option_recv(struct cmd *, struct buffer *);
|
|
|
|
void cmd_set_option_free(struct cmd *);
|
2008-06-05 17:12:11 +00:00
|
|
|
void cmd_set_option_print(struct cmd *, char *, size_t);
|
2007-10-04 10:11:32 +00:00
|
|
|
|
|
|
|
struct cmd_set_option_data {
|
2008-06-05 21:25:00 +00:00
|
|
|
char *target;
|
2008-06-03 21:42:37 +00:00
|
|
|
int flag_global;
|
2007-10-04 10:11:32 +00:00
|
|
|
char *option;
|
|
|
|
char *value;
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct cmd_entry cmd_set_option_entry = {
|
2008-06-02 18:08:17 +00:00
|
|
|
"set-option", "set",
|
2008-06-16 06:33:50 +00:00
|
|
|
"[-t target-session] option value",
|
2008-06-02 18:08:17 +00:00
|
|
|
0,
|
2008-06-05 21:25:00 +00:00
|
|
|
NULL,
|
2007-10-04 10:11:32 +00:00
|
|
|
cmd_set_option_parse,
|
2007-12-06 09:46:23 +00:00
|
|
|
cmd_set_option_exec,
|
2007-10-04 10:11:32 +00:00
|
|
|
cmd_set_option_send,
|
|
|
|
cmd_set_option_recv,
|
2008-06-03 05:35:51 +00:00
|
|
|
cmd_set_option_free,
|
2008-06-05 17:12:11 +00:00
|
|
|
cmd_set_option_print
|
2007-10-04 10:11:32 +00:00
|
|
|
};
|
|
|
|
|
2008-07-02 21:22:57 +00:00
|
|
|
const char *set_option_bell_action_list[] = {
|
|
|
|
"none", "any", "current", NULL
|
|
|
|
};
|
|
|
|
const char *set_option_mode_keys_list[] = {
|
2008-09-26 06:45:28 +00:00
|
|
|
"emacs", "vi", NULL
|
2008-07-02 21:22:57 +00:00
|
|
|
};
|
2008-06-23 07:41:21 +00:00
|
|
|
const struct set_option_entry set_option_table[NSETOPTION] = {
|
2008-07-02 21:22:57 +00:00
|
|
|
{ "bell-action", SET_OPTION_CHOICE, 0, 0, set_option_bell_action_list },
|
2008-06-23 22:12:29 +00:00
|
|
|
{ "buffer-limit", SET_OPTION_NUMBER, 1, INT_MAX, NULL },
|
|
|
|
{ "default-command", SET_OPTION_STRING, 0, 0, NULL },
|
|
|
|
{ "display-time", SET_OPTION_NUMBER, 1, INT_MAX, NULL },
|
|
|
|
{ "history-limit", SET_OPTION_NUMBER, 0, SHRT_MAX, NULL },
|
2008-07-02 21:22:57 +00:00
|
|
|
{ "mode-keys", SET_OPTION_CHOICE, 0, 0, set_option_mode_keys_list },
|
2008-06-23 22:12:29 +00:00
|
|
|
{ "prefix", SET_OPTION_KEY, 0, 0, NULL },
|
2008-06-29 07:04:31 +00:00
|
|
|
{ "remain-by-default", SET_OPTION_FLAG, 0, 0, NULL },
|
2008-06-23 22:12:29 +00:00
|
|
|
{ "set-titles", SET_OPTION_FLAG, 0, 0, NULL },
|
|
|
|
{ "status", SET_OPTION_FLAG, 0, 0, NULL },
|
|
|
|
{ "status-bg", SET_OPTION_COLOUR, 0, 0, NULL },
|
|
|
|
{ "status-fg", SET_OPTION_COLOUR, 0, 0, NULL },
|
|
|
|
{ "status-interval", SET_OPTION_NUMBER, 0, INT_MAX, NULL },
|
|
|
|
{ "status-left", SET_OPTION_STRING, 0, 0, NULL },
|
|
|
|
{ "status-right", SET_OPTION_STRING, 0, 0, NULL },
|
2008-11-16 13:28:59 +00:00
|
|
|
{ "utf8", SET_OPTION_FLAG, 0, 0, NULL },
|
2008-06-23 07:41:21 +00:00
|
|
|
};
|
|
|
|
|
2008-09-26 06:45:28 +00:00
|
|
|
void set_option_string(struct cmd_ctx *,
|
2008-06-23 22:12:29 +00:00
|
|
|
struct options *, const struct set_option_entry *, char *);
|
|
|
|
void set_option_number(struct cmd_ctx *,
|
|
|
|
struct options *, const struct set_option_entry *, char *);
|
|
|
|
void set_option_key(struct cmd_ctx *,
|
|
|
|
struct options *, const struct set_option_entry *, char *);
|
|
|
|
void set_option_colour(struct cmd_ctx *,
|
|
|
|
struct options *, const struct set_option_entry *, char *);
|
|
|
|
void set_option_flag(struct cmd_ctx *,
|
|
|
|
struct options *, const struct set_option_entry *, char *);
|
|
|
|
void set_option_choice(struct cmd_ctx *,
|
|
|
|
struct options *, const struct set_option_entry *, char *);
|
2008-06-23 07:41:21 +00:00
|
|
|
|
2007-10-04 10:11:32 +00:00
|
|
|
int
|
2008-06-05 16:35:32 +00:00
|
|
|
cmd_set_option_parse(struct cmd *self, int argc, char **argv, char **cause)
|
2007-10-04 10:11:32 +00:00
|
|
|
{
|
|
|
|
struct cmd_set_option_data *data;
|
|
|
|
int opt;
|
|
|
|
|
2008-06-05 16:35:32 +00:00
|
|
|
self->data = data = xmalloc(sizeof *data);
|
2008-06-05 21:25:00 +00:00
|
|
|
data->target = NULL;
|
2008-06-03 21:42:37 +00:00
|
|
|
data->flag_global = 1;
|
2007-10-04 10:11:32 +00:00
|
|
|
data->option = NULL;
|
|
|
|
data->value = NULL;
|
|
|
|
|
2008-09-25 23:28:15 +00:00
|
|
|
while ((opt = getopt(argc, argv, GETOPT_PREFIX "t:s:")) != EOF) {
|
2007-10-04 10:11:32 +00:00
|
|
|
switch (opt) {
|
2008-06-05 21:25:00 +00:00
|
|
|
case 't':
|
|
|
|
if (data->target == NULL)
|
|
|
|
data->target = xstrdup(optarg);
|
2008-06-03 21:42:37 +00:00
|
|
|
data->flag_global = 0;
|
|
|
|
break;
|
2007-10-04 10:11:32 +00:00
|
|
|
default:
|
|
|
|
goto usage;
|
|
|
|
}
|
2007-12-06 09:46:23 +00:00
|
|
|
}
|
2007-10-04 10:11:32 +00:00
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
if (argc != 1 && argc != 2)
|
|
|
|
goto usage;
|
|
|
|
|
|
|
|
data->option = xstrdup(argv[0]);
|
|
|
|
if (argc == 2)
|
|
|
|
data->value = xstrdup(argv[1]);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
usage:
|
2008-06-02 21:08:36 +00:00
|
|
|
xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
|
2007-10-04 10:11:32 +00:00
|
|
|
|
2008-06-05 16:35:32 +00:00
|
|
|
self->entry->free(self);
|
2007-10-04 10:11:32 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-06-23 07:41:21 +00:00
|
|
|
cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
|
2007-10-04 10:11:32 +00:00
|
|
|
{
|
2008-06-05 16:35:32 +00:00
|
|
|
struct cmd_set_option_data *data = self->data;
|
2008-06-03 21:42:37 +00:00
|
|
|
struct session *s;
|
2008-06-23 07:41:21 +00:00
|
|
|
struct client *c;
|
2008-06-03 21:42:37 +00:00
|
|
|
struct options *oo;
|
2008-06-23 07:41:21 +00:00
|
|
|
const struct set_option_entry *entry;
|
2007-10-30 10:59:43 +00:00
|
|
|
u_int i;
|
2007-10-04 10:11:32 +00:00
|
|
|
|
|
|
|
if (data == NULL)
|
|
|
|
return;
|
|
|
|
|
2008-06-03 21:42:37 +00:00
|
|
|
if (data->flag_global ||
|
2008-06-05 21:25:00 +00:00
|
|
|
((s = cmd_find_session(ctx, data->target))) == NULL)
|
2008-06-03 21:42:37 +00:00
|
|
|
oo = &global_options;
|
|
|
|
else
|
|
|
|
oo = &s->options;
|
|
|
|
|
2007-10-04 10:11:32 +00:00
|
|
|
if (*data->option == '\0') {
|
|
|
|
ctx->error(ctx, "invalid option");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-06-23 07:41:21 +00:00
|
|
|
entry = NULL;
|
|
|
|
for (i = 0; i < NSETOPTION; i++) {
|
|
|
|
if (strncmp(set_option_table[i].name,
|
|
|
|
data->option, strlen(data->option)) != 0)
|
|
|
|
continue;
|
|
|
|
if (entry != NULL) {
|
|
|
|
ctx->error(ctx, "ambiguous option: %s", data->option);
|
2007-10-12 12:08:51 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-06-23 07:41:21 +00:00
|
|
|
entry = &set_option_table[i];
|
2008-06-03 21:42:37 +00:00
|
|
|
|
2008-07-19 10:07:50 +00:00
|
|
|
/* Bail now if an exact match. */
|
|
|
|
if (strcmp(entry->name, data->option) == 0)
|
|
|
|
break;
|
2008-06-23 07:41:21 +00:00
|
|
|
}
|
|
|
|
if (entry == NULL) {
|
|
|
|
ctx->error(ctx, "unknown option: %s", data->option);
|
|
|
|
return;
|
|
|
|
}
|
2008-06-03 21:42:37 +00:00
|
|
|
|
2008-06-23 07:41:21 +00:00
|
|
|
switch (entry->type) {
|
|
|
|
case SET_OPTION_STRING:
|
2008-06-23 22:12:29 +00:00
|
|
|
set_option_string(ctx, oo, entry, data->value);
|
2008-06-23 07:41:21 +00:00
|
|
|
break;
|
|
|
|
case SET_OPTION_NUMBER:
|
2008-06-23 22:12:29 +00:00
|
|
|
set_option_number(ctx, oo, entry, data->value);
|
2008-06-23 07:41:21 +00:00
|
|
|
break;
|
|
|
|
case SET_OPTION_KEY:
|
2008-06-23 22:12:29 +00:00
|
|
|
set_option_key(ctx, oo, entry, data->value);
|
2008-06-23 07:41:21 +00:00
|
|
|
break;
|
2008-06-23 22:12:29 +00:00
|
|
|
case SET_OPTION_COLOUR:
|
|
|
|
set_option_colour(ctx, oo, entry, data->value);
|
2008-06-23 07:41:21 +00:00
|
|
|
break;
|
|
|
|
case SET_OPTION_FLAG:
|
2008-06-23 22:12:29 +00:00
|
|
|
set_option_flag(ctx, oo, entry, data->value);
|
2008-06-23 07:41:21 +00:00
|
|
|
break;
|
|
|
|
case SET_OPTION_CHOICE:
|
2008-06-23 22:12:29 +00:00
|
|
|
set_option_choice(ctx, oo, entry, data->value);
|
2008-06-23 07:41:21 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-06-03 21:42:37 +00:00
|
|
|
|
2008-06-23 07:41:21 +00:00
|
|
|
recalculate_sizes();
|
|
|
|
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
|
|
|
c = ARRAY_ITEM(&clients, i);
|
|
|
|
if (c != NULL && c->session != NULL)
|
|
|
|
server_redraw_client(c);
|
|
|
|
}
|
2008-06-03 21:42:37 +00:00
|
|
|
|
2008-06-23 07:41:21 +00:00
|
|
|
if (ctx->cmdclient != NULL)
|
|
|
|
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
set_option_string(struct cmd_ctx *ctx, struct options *oo,
|
2008-06-23 22:12:29 +00:00
|
|
|
const struct set_option_entry *entry, char *value)
|
2008-06-23 07:41:21 +00:00
|
|
|
{
|
|
|
|
if (value == NULL) {
|
|
|
|
ctx->error(ctx, "empty value");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-06-23 22:12:29 +00:00
|
|
|
options_set_string(oo, entry->name, "%s", value);
|
2008-06-23 07:41:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
set_option_number(struct cmd_ctx *ctx, struct options *oo,
|
2008-06-23 22:12:29 +00:00
|
|
|
const struct set_option_entry *entry, char *value)
|
2008-06-23 07:41:21 +00:00
|
|
|
{
|
|
|
|
long long number;
|
|
|
|
const char *errstr;
|
|
|
|
|
|
|
|
if (value == NULL) {
|
|
|
|
ctx->error(ctx, "empty value");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
number = strtonum(value, entry->minimum, entry->maximum, &errstr);
|
|
|
|
if (errstr != NULL) {
|
|
|
|
ctx->error(ctx, "value is %s: %s", errstr, value);
|
|
|
|
return;
|
|
|
|
}
|
2008-06-23 22:12:29 +00:00
|
|
|
options_set_number(oo, entry->name, number);
|
2008-06-23 07:41:21 +00:00
|
|
|
}
|
2008-09-26 06:45:28 +00:00
|
|
|
|
2008-06-23 07:41:21 +00:00
|
|
|
void
|
|
|
|
set_option_key(struct cmd_ctx *ctx, struct options *oo,
|
2008-06-23 22:12:29 +00:00
|
|
|
const struct set_option_entry *entry, char *value)
|
2008-06-23 07:41:21 +00:00
|
|
|
{
|
|
|
|
int key;
|
|
|
|
|
|
|
|
if (value == NULL) {
|
|
|
|
ctx->error(ctx, "empty value");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((key = key_string_lookup_string(value)) == KEYC_NONE) {
|
|
|
|
ctx->error(ctx, "unknown key: %s", value);
|
|
|
|
return;
|
|
|
|
}
|
2008-06-23 22:12:29 +00:00
|
|
|
options_set_number(oo, entry->name, key);
|
2008-09-26 06:45:28 +00:00
|
|
|
|
2008-06-23 07:41:21 +00:00
|
|
|
}
|
2008-09-26 06:45:28 +00:00
|
|
|
|
2008-06-23 07:41:21 +00:00
|
|
|
void
|
2008-06-23 22:12:29 +00:00
|
|
|
set_option_colour(struct cmd_ctx *ctx, struct options *oo,
|
|
|
|
const struct set_option_entry *entry, char *value)
|
2008-06-23 07:41:21 +00:00
|
|
|
{
|
2008-06-23 22:12:29 +00:00
|
|
|
u_char colour;
|
2008-06-23 07:41:21 +00:00
|
|
|
|
|
|
|
if (value == NULL) {
|
|
|
|
ctx->error(ctx, "empty value");
|
|
|
|
return;
|
|
|
|
}
|
2008-09-26 06:45:28 +00:00
|
|
|
|
2008-09-10 18:59:29 +00:00
|
|
|
if ((colour = colour_fromstring(value)) > 8) {
|
2008-06-23 07:41:21 +00:00
|
|
|
ctx->error(ctx, "bad colour: %s", value);
|
|
|
|
return;
|
|
|
|
}
|
2008-09-26 06:45:28 +00:00
|
|
|
|
|
|
|
options_set_number(oo, entry->name, colour);
|
2008-06-23 07:41:21 +00:00
|
|
|
}
|
2008-09-26 06:45:28 +00:00
|
|
|
|
2008-06-23 07:41:21 +00:00
|
|
|
void
|
|
|
|
set_option_flag(struct cmd_ctx *ctx, struct options *oo,
|
2008-06-23 22:12:29 +00:00
|
|
|
const struct set_option_entry *entry, char *value)
|
2008-06-23 07:41:21 +00:00
|
|
|
{
|
|
|
|
int flag;
|
2008-09-26 06:45:28 +00:00
|
|
|
|
2008-06-23 07:41:21 +00:00
|
|
|
if (value == NULL || *value == '\0')
|
2008-06-23 22:12:29 +00:00
|
|
|
flag = !options_get_number(oo, entry->name);
|
2008-06-23 07:41:21 +00:00
|
|
|
else {
|
|
|
|
if ((value[0] == '1' && value[1] == '\0') ||
|
|
|
|
strcasecmp(value, "on") == 0 ||
|
|
|
|
strcasecmp(value, "yes") == 0)
|
|
|
|
flag = 1;
|
|
|
|
else if ((value[0] == '0' && value[1] == '\0') ||
|
|
|
|
strcasecmp(value, "off") == 0 ||
|
|
|
|
strcasecmp(value, "no") == 0)
|
|
|
|
flag = 0;
|
2007-10-19 10:21:36 +00:00
|
|
|
else {
|
2008-06-23 07:41:21 +00:00
|
|
|
ctx->error(ctx, "bad value: %s", value);
|
2008-06-04 05:40:35 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-06-23 07:41:21 +00:00
|
|
|
}
|
2008-06-04 05:47:46 +00:00
|
|
|
|
2008-06-23 22:12:29 +00:00
|
|
|
options_set_number(oo, entry->name, flag);
|
2008-06-23 07:41:21 +00:00
|
|
|
}
|
2008-09-26 06:45:28 +00:00
|
|
|
|
2008-06-23 07:41:21 +00:00
|
|
|
void
|
|
|
|
set_option_choice(struct cmd_ctx *ctx, struct options *oo,
|
2008-06-23 22:12:29 +00:00
|
|
|
const struct set_option_entry *entry, char *value)
|
2008-06-23 07:41:21 +00:00
|
|
|
{
|
|
|
|
const char **choicep;
|
|
|
|
int n, choice = -1;
|
2008-06-04 05:47:46 +00:00
|
|
|
|
2008-06-23 07:41:21 +00:00
|
|
|
if (value == NULL) {
|
|
|
|
ctx->error(ctx, "empty value");
|
|
|
|
return;
|
|
|
|
}
|
2008-06-04 05:47:46 +00:00
|
|
|
|
2008-06-23 07:41:21 +00:00
|
|
|
n = 0;
|
|
|
|
for (choicep = entry->choices; *choicep != NULL; choicep++) {
|
|
|
|
n++;
|
|
|
|
if (strncmp(*choicep, value, strlen(value)) != 0)
|
|
|
|
continue;
|
2008-06-04 05:47:46 +00:00
|
|
|
|
2008-06-23 07:41:21 +00:00
|
|
|
if (choice != -1) {
|
|
|
|
ctx->error(ctx, "ambiguous option: %s", value);
|
2008-06-07 06:13:21 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-06-23 07:41:21 +00:00
|
|
|
choice = n - 1;
|
|
|
|
}
|
|
|
|
if (choice == -1) {
|
|
|
|
ctx->error(ctx, "unknown option: %s", value);
|
2007-10-04 10:11:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-06-23 22:12:29 +00:00
|
|
|
options_set_number(oo, entry->name, choice);
|
2007-10-04 10:11:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-06-05 16:35:32 +00:00
|
|
|
cmd_set_option_send(struct cmd *self, struct buffer *b)
|
2007-10-04 10:11:32 +00:00
|
|
|
{
|
2008-06-05 16:35:32 +00:00
|
|
|
struct cmd_set_option_data *data = self->data;
|
2007-10-04 10:11:32 +00:00
|
|
|
|
2008-06-03 21:42:37 +00:00
|
|
|
buffer_write(b, data, sizeof *data);
|
2008-06-05 21:25:00 +00:00
|
|
|
cmd_send_string(b, data->target);
|
2007-10-04 10:11:32 +00:00
|
|
|
cmd_send_string(b, data->option);
|
|
|
|
cmd_send_string(b, data->value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-06-05 16:35:32 +00:00
|
|
|
cmd_set_option_recv(struct cmd *self, struct buffer *b)
|
2007-10-04 10:11:32 +00:00
|
|
|
{
|
|
|
|
struct cmd_set_option_data *data;
|
|
|
|
|
2008-06-05 16:35:32 +00:00
|
|
|
self->data = data = xmalloc(sizeof *data);
|
2008-06-03 21:42:37 +00:00
|
|
|
buffer_read(b, data, sizeof *data);
|
2008-06-05 21:25:00 +00:00
|
|
|
data->target = cmd_recv_string(b);
|
2007-10-04 10:11:32 +00:00
|
|
|
data->option = cmd_recv_string(b);
|
|
|
|
data->value = cmd_recv_string(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-06-05 16:35:32 +00:00
|
|
|
cmd_set_option_free(struct cmd *self)
|
2007-10-04 10:11:32 +00:00
|
|
|
{
|
2008-06-05 16:35:32 +00:00
|
|
|
struct cmd_set_option_data *data = self->data;
|
2007-10-04 10:11:32 +00:00
|
|
|
|
2008-06-05 21:25:00 +00:00
|
|
|
if (data->target != NULL)
|
|
|
|
xfree(data->target);
|
2007-10-04 10:11:32 +00:00
|
|
|
if (data->option != NULL)
|
|
|
|
xfree(data->option);
|
|
|
|
if (data->value != NULL)
|
|
|
|
xfree(data->value);
|
|
|
|
xfree(data);
|
|
|
|
}
|
2008-06-05 17:12:11 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
cmd_set_option_print(struct cmd *self, char *buf, size_t len)
|
|
|
|
{
|
|
|
|
struct cmd_set_option_data *data = self->data;
|
|
|
|
size_t off = 0;
|
|
|
|
|
|
|
|
off += xsnprintf(buf, len, "%s", self->entry->name);
|
|
|
|
if (data == NULL)
|
|
|
|
return;
|
|
|
|
if (off < len && data->option != NULL)
|
|
|
|
off += xsnprintf(buf + off, len - off, " %s", data->option);
|
|
|
|
if (off < len && data->value != NULL)
|
2008-06-18 22:21:51 +00:00
|
|
|
off += xsnprintf(buf + off, len - off, " %s", data->value);
|
2008-06-05 17:12:11 +00:00
|
|
|
}
|