[BACK]Return to cmd-show-options.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tmux

Annotation of src/usr.bin/tmux/cmd-show-options.c, Revision 1.1

1.1     ! nicm        1: /* $OpenBSD$ */
        !             2:
        !             3: /*
        !             4:  * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
        !             5:  *
        !             6:  * Permission to use, copy, modify, and distribute this software for any
        !             7:  * purpose with or without fee is hereby granted, provided that the above
        !             8:  * copyright notice and this permission notice appear in all copies.
        !             9:  *
        !            10:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
        !            11:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
        !            12:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
        !            13:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
        !            14:  * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
        !            15:  * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
        !            16:  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
        !            17:  */
        !            18:
        !            19: #include <sys/types.h>
        !            20:
        !            21: #include <stdlib.h>
        !            22: #include <string.h>
        !            23:
        !            24: #include "tmux.h"
        !            25:
        !            26: /*
        !            27:  * Show options.
        !            28:  */
        !            29:
        !            30: int    cmd_show_options_exec(struct cmd *, struct cmd_ctx *);
        !            31:
        !            32: const struct cmd_entry cmd_show_options_entry = {
        !            33:        "show-options", "show",
        !            34:        "[-g] " CMD_TARGET_SESSION_USAGE,
        !            35:        CMD_GFLAG,
        !            36:        cmd_target_init,
        !            37:        cmd_target_parse,
        !            38:        cmd_show_options_exec,
        !            39:        cmd_target_send,
        !            40:        cmd_target_recv,
        !            41:        cmd_target_free,
        !            42:        cmd_target_print
        !            43: };
        !            44:
        !            45: int
        !            46: cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx)
        !            47: {
        !            48:        struct cmd_target_data          *data = self->data;
        !            49:        struct session                  *s;
        !            50:        struct options                  *oo;
        !            51:        const struct set_option_entry   *entry;
        !            52:        u_int                            i;
        !            53:        char                            *vs;
        !            54:        long long                        vn;
        !            55:
        !            56:        if (data->flags & CMD_GFLAG)
        !            57:                oo = &global_options;
        !            58:        else {
        !            59:                if ((s = cmd_find_session(ctx, data->target)) == NULL)
        !            60:                        return (-1);
        !            61:                oo = &s->options;
        !            62:        }
        !            63:
        !            64:        for (i = 0; i < NSETOPTION; i++) {
        !            65:                entry = &set_option_table[i];
        !            66:
        !            67:                if (options_find1(oo, entry->name) == NULL)
        !            68:                        continue;
        !            69:
        !            70:                switch (entry->type) {
        !            71:                case SET_OPTION_STRING:
        !            72:                        vs = options_get_string(oo, entry->name);
        !            73:                        ctx->print(ctx, "%s \"%s\"", entry->name, vs);
        !            74:                        break;
        !            75:                case SET_OPTION_NUMBER:
        !            76:                        vn = options_get_number(oo, entry->name);
        !            77:                        ctx->print(ctx, "%s %lld", entry->name, vn);
        !            78:                        break;
        !            79:                case SET_OPTION_KEY:
        !            80:                        vn = options_get_number(oo, entry->name);
        !            81:                        ctx->print(ctx, "%s %s",
        !            82:                            entry->name, key_string_lookup_key(vn));
        !            83:                        break;
        !            84:                case SET_OPTION_COLOUR:
        !            85:                        vn = options_get_number(oo, entry->name);
        !            86:                        ctx->print(ctx, "%s %s",
        !            87:                            entry->name, colour_tostring(vn));
        !            88:                        break;
        !            89:                case SET_OPTION_ATTRIBUTES:
        !            90:                        vn = options_get_number(oo, entry->name);
        !            91:                        ctx->print(ctx, "%s %s",
        !            92:                            entry->name, attributes_tostring(vn));
        !            93:                        break;
        !            94:                case SET_OPTION_FLAG:
        !            95:                        vn = options_get_number(oo, entry->name);
        !            96:                        if (vn)
        !            97:                                ctx->print(ctx, "%s on", entry->name);
        !            98:                        else
        !            99:                                ctx->print(ctx, "%s off", entry->name);
        !           100:                        break;
        !           101:                case SET_OPTION_CHOICE:
        !           102:                        vn = options_get_number(oo, entry->name);
        !           103:                        ctx->print(ctx, "%s %s",
        !           104:                            entry->name, entry->choices[vn]);
        !           105:                        break;
        !           106:                }
        !           107:        }
        !           108:
        !           109:        return (0);
        !           110: }