mirror of
https://github.com/tmate-io/tmate.git
synced 2024-11-23 08:33:17 +01:00
Sync OpenBSD patchset 339:
Move common code from show-options and show-window-options into a function.
This commit is contained in:
parent
b6bc8a6828
commit
649b7c132d
@ -1,4 +1,4 @@
|
|||||||
/* $Id: cmd-show-options.c,v 1.16 2009-07-28 22:12:16 tcunha Exp $ */
|
/* $Id: cmd-show-options.c,v 1.17 2009-09-22 13:56:02 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -46,9 +46,9 @@ cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
struct cmd_target_data *data = self->data;
|
struct cmd_target_data *data = self->data;
|
||||||
struct session *s;
|
struct session *s;
|
||||||
struct options *oo;
|
struct options *oo;
|
||||||
|
struct options_entry *o;
|
||||||
const struct set_option_entry *entry;
|
const struct set_option_entry *entry;
|
||||||
char *vs;
|
const char *optval;
|
||||||
long long vn;
|
|
||||||
|
|
||||||
if (data->chflags & CMD_CHFLAG('g'))
|
if (data->chflags & CMD_CHFLAG('g'))
|
||||||
oo = &global_s_options;
|
oo = &global_s_options;
|
||||||
@ -59,46 +59,10 @@ cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (entry = set_option_table; entry->name != NULL; entry++) {
|
for (entry = set_option_table; entry->name != NULL; entry++) {
|
||||||
if (options_find1(oo, entry->name) == NULL)
|
if ((o = options_find1(oo, entry->name)) == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
optval = set_option_print(entry, o);
|
||||||
switch (entry->type) {
|
ctx->print(ctx, "%s %s", entry->name, optval);
|
||||||
case SET_OPTION_STRING:
|
|
||||||
vs = options_get_string(oo, entry->name);
|
|
||||||
ctx->print(ctx, "%s \"%s\"", entry->name, vs);
|
|
||||||
break;
|
|
||||||
case SET_OPTION_NUMBER:
|
|
||||||
vn = options_get_number(oo, entry->name);
|
|
||||||
ctx->print(ctx, "%s %lld", entry->name, vn);
|
|
||||||
break;
|
|
||||||
case SET_OPTION_KEY:
|
|
||||||
vn = options_get_number(oo, entry->name);
|
|
||||||
ctx->print(ctx, "%s %s",
|
|
||||||
entry->name, key_string_lookup_key(vn));
|
|
||||||
break;
|
|
||||||
case SET_OPTION_COLOUR:
|
|
||||||
vn = options_get_number(oo, entry->name);
|
|
||||||
ctx->print(ctx, "%s %s",
|
|
||||||
entry->name, colour_tostring(vn));
|
|
||||||
break;
|
|
||||||
case SET_OPTION_ATTRIBUTES:
|
|
||||||
vn = options_get_number(oo, entry->name);
|
|
||||||
ctx->print(ctx, "%s %s",
|
|
||||||
entry->name, attributes_tostring(vn));
|
|
||||||
break;
|
|
||||||
case SET_OPTION_FLAG:
|
|
||||||
vn = options_get_number(oo, entry->name);
|
|
||||||
if (vn)
|
|
||||||
ctx->print(ctx, "%s on", entry->name);
|
|
||||||
else
|
|
||||||
ctx->print(ctx, "%s off", entry->name);
|
|
||||||
break;
|
|
||||||
case SET_OPTION_CHOICE:
|
|
||||||
vn = options_get_number(oo, entry->name);
|
|
||||||
ctx->print(ctx, "%s %s",
|
|
||||||
entry->name, entry->choices[vn]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $Id: cmd-show-window-options.c,v 1.12 2009-07-28 22:12:16 tcunha Exp $ */
|
/* $Id: cmd-show-window-options.c,v 1.13 2009-09-22 13:56:02 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -46,9 +46,9 @@ cmd_show_window_options_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
struct cmd_target_data *data = self->data;
|
struct cmd_target_data *data = self->data;
|
||||||
struct winlink *wl;
|
struct winlink *wl;
|
||||||
struct options *oo;
|
struct options *oo;
|
||||||
|
struct options_entry *o;
|
||||||
const struct set_option_entry *entry;
|
const struct set_option_entry *entry;
|
||||||
char *vs;
|
const char *optval;
|
||||||
long long vn;
|
|
||||||
|
|
||||||
if (data->chflags & CMD_CHFLAG('g'))
|
if (data->chflags & CMD_CHFLAG('g'))
|
||||||
oo = &global_w_options;
|
oo = &global_w_options;
|
||||||
@ -59,46 +59,10 @@ cmd_show_window_options_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (entry = set_window_option_table; entry->name != NULL; entry++) {
|
for (entry = set_window_option_table; entry->name != NULL; entry++) {
|
||||||
if (options_find1(oo, entry->name) == NULL)
|
if ((o = options_find1(oo, entry->name)) == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
optval = set_option_print(entry, o);
|
||||||
switch (entry->type) {
|
ctx->print(ctx, "%s %s", entry->name, optval);
|
||||||
case SET_OPTION_STRING:
|
|
||||||
vs = options_get_string(oo, entry->name);
|
|
||||||
ctx->print(ctx, "%s \"%s\"", entry->name, vs);
|
|
||||||
break;
|
|
||||||
case SET_OPTION_NUMBER:
|
|
||||||
vn = options_get_number(oo, entry->name);
|
|
||||||
ctx->print(ctx, "%s %lld", entry->name, vn);
|
|
||||||
break;
|
|
||||||
case SET_OPTION_KEY:
|
|
||||||
vn = options_get_number(oo, entry->name);
|
|
||||||
ctx->print(ctx, "%s %s",
|
|
||||||
entry->name, key_string_lookup_key(vn));
|
|
||||||
break;
|
|
||||||
case SET_OPTION_COLOUR:
|
|
||||||
vn = options_get_number(oo, entry->name);
|
|
||||||
ctx->print(ctx, "%s %s",
|
|
||||||
entry->name, colour_tostring(vn));
|
|
||||||
break;
|
|
||||||
case SET_OPTION_ATTRIBUTES:
|
|
||||||
vn = options_get_number(oo, entry->name);
|
|
||||||
ctx->print(ctx, "%s %s",
|
|
||||||
entry->name, attributes_tostring(vn));
|
|
||||||
break;
|
|
||||||
case SET_OPTION_FLAG:
|
|
||||||
vn = options_get_number(oo, entry->name);
|
|
||||||
if (vn)
|
|
||||||
ctx->print(ctx, "%s on", entry->name);
|
|
||||||
else
|
|
||||||
ctx->print(ctx, "%s off", entry->name);
|
|
||||||
break;
|
|
||||||
case SET_OPTION_CHOICE:
|
|
||||||
vn = options_get_number(oo, entry->name);
|
|
||||||
ctx->print(ctx, "%s %s",
|
|
||||||
entry->name, entry->choices[vn]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $Id: options-cmd.c,v 1.5 2009-08-09 16:48:34 tcunha Exp $ */
|
/* $Id: options-cmd.c,v 1.6 2009-09-22 13:56:02 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -23,6 +23,46 @@
|
|||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
|
const char *
|
||||||
|
set_option_print(const struct set_option_entry *entry, struct options_entry *o)
|
||||||
|
{
|
||||||
|
static char out[BUFSIZ];
|
||||||
|
const char *s;
|
||||||
|
|
||||||
|
*out = '\0';
|
||||||
|
switch (entry->type) {
|
||||||
|
case SET_OPTION_STRING:
|
||||||
|
xsnprintf(out, sizeof out, "\"%s\"", o->str);
|
||||||
|
break;
|
||||||
|
case SET_OPTION_NUMBER:
|
||||||
|
xsnprintf(out, sizeof out, "%lld", o->num);
|
||||||
|
break;
|
||||||
|
case SET_OPTION_KEY:
|
||||||
|
s = key_string_lookup_key(o->num);
|
||||||
|
xsnprintf(out, sizeof out, "%s", s);
|
||||||
|
break;
|
||||||
|
case SET_OPTION_COLOUR:
|
||||||
|
s = colour_tostring(o->num);
|
||||||
|
xsnprintf(out, sizeof out, "%s", s);
|
||||||
|
break;
|
||||||
|
case SET_OPTION_ATTRIBUTES:
|
||||||
|
s = attributes_tostring(o->num);
|
||||||
|
xsnprintf(out, sizeof out, "%s", s);
|
||||||
|
break;
|
||||||
|
case SET_OPTION_FLAG:
|
||||||
|
if (o->num)
|
||||||
|
strlcpy(out, "on", sizeof out);
|
||||||
|
else
|
||||||
|
strlcpy(out, "off", sizeof out);
|
||||||
|
break;
|
||||||
|
case SET_OPTION_CHOICE:
|
||||||
|
s = entry->choices[o->num];
|
||||||
|
xsnprintf(out, sizeof out, "%s", s);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return (out);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
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)
|
||||||
|
4
tmux.h
4
tmux.h
@ -1,4 +1,4 @@
|
|||||||
/* $Id: tmux.h,v 1.447 2009-09-22 13:49:13 tcunha Exp $ */
|
/* $Id: tmux.h,v 1.448 2009-09-22 13:56:02 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -1236,6 +1236,8 @@ void tty_keys_free(struct tty *);
|
|||||||
int tty_keys_next(struct tty *, int *, u_char *);
|
int tty_keys_next(struct tty *, int *, u_char *);
|
||||||
|
|
||||||
/* options-cmd.c */
|
/* options-cmd.c */
|
||||||
|
const char *set_option_print(
|
||||||
|
const struct set_option_entry *, struct options_entry *);
|
||||||
void set_option_string(struct cmd_ctx *,
|
void set_option_string(struct cmd_ctx *,
|
||||||
struct options *, const struct set_option_entry *, char *, int);
|
struct options *, const struct set_option_entry *, char *, int);
|
||||||
void set_option_number(struct cmd_ctx *,
|
void set_option_number(struct cmd_ctx *,
|
||||||
|
Loading…
Reference in New Issue
Block a user