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

Annotation of src/usr.bin/tmux/cmd-show-messages.c, Revision 1.10

1.10    ! nicm        1: /* $OpenBSD: cmd-show-messages.c,v 1.9 2014/02/14 13:59:01 nicm Exp $ */
1.1       nicm        2:
                      3: /*
                      4:  * Copyright (c) 2009 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 <string.h>
                     22: #include <time.h>
1.8       nicm       23: #include <unistd.h>
                     24: #include <vis.h>
1.1       nicm       25:
                     26: #include "tmux.h"
                     27:
                     28: /*
                     29:  * Show client message log.
                     30:  */
                     31:
1.6       nicm       32: enum cmd_retval         cmd_show_messages_exec(struct cmd *, struct cmd_q *);
1.1       nicm       33:
                     34: const struct cmd_entry cmd_show_messages_entry = {
                     35:        "show-messages", "showmsgs",
1.8       nicm       36:        "IJTt:", 0, 0,
                     37:        "[-IJT] " CMD_TARGET_CLIENT_USAGE,
1.3       nicm       38:        0,
                     39:        cmd_show_messages_exec
1.1       nicm       40: };
                     41:
1.8       nicm       42: const struct cmd_entry cmd_server_info_entry = {
                     43:        "server-info", "info",
                     44:        "", 0, 0,
                     45:        "",
                     46:        0,
                     47:        cmd_show_messages_exec
                     48: };
                     49:
1.9       nicm       50: void   cmd_show_messages_server(struct cmd_q *);
                     51: void   cmd_show_messages_terminals(struct cmd_q *);
                     52: void   cmd_show_messages_jobs(struct cmd_q *);
1.8       nicm       53:
                     54: void
1.9       nicm       55: cmd_show_messages_server(struct cmd_q *cmdq)
1.8       nicm       56: {
                     57:        char    *tim;
                     58:
                     59:        tim = ctime(&start_time);
                     60:        *strchr(tim, '\n') = '\0';
                     61:
                     62:        cmdq_print(cmdq, "started %s", tim);
                     63:        cmdq_print(cmdq, "socket path %s", socket_path);
                     64:        cmdq_print(cmdq, "debug level %d", debug_level);
                     65:        cmdq_print(cmdq, "protocol version %d", PROTOCOL_VERSION);
                     66: }
                     67:
                     68: void
1.9       nicm       69: cmd_show_messages_terminals(struct cmd_q *cmdq)
1.8       nicm       70: {
                     71:        struct tty_term                         *term;
                     72:        const struct tty_term_code_entry        *ent;
                     73:        struct tty_code                         *code;
                     74:        u_int                                    i, n;
                     75:        char                                     out[80];
                     76:
                     77:        n = 0;
                     78:        LIST_FOREACH(term, &tty_terms, entry) {
                     79:                cmdq_print(cmdq,
                     80:                    "Terminal %u: %s [references=%u, flags=0x%x]:",
                     81:                    n, term->name, term->references, term->flags);
                     82:                n++;
                     83:                for (i = 0; i < NTTYCODE; i++) {
                     84:                        ent = &tty_term_codes[i];
                     85:                        code = &term->codes[ent->code];
                     86:                        switch (code->type) {
                     87:                        case TTYCODE_NONE:
                     88:                                cmdq_print(cmdq, "%4u: %s: [missing]",
                     89:                                    ent->code, ent->name);
                     90:                                break;
                     91:                        case TTYCODE_STRING:
                     92:                                strnvis(out, code->value.string, sizeof out,
                     93:                                    VIS_OCTAL|VIS_TAB|VIS_NL);
                     94:                                cmdq_print(cmdq, "%4u: %s: (string) %s",
                     95:                                    ent->code, ent->name, out);
                     96:                                break;
                     97:                        case TTYCODE_NUMBER:
                     98:                                cmdq_print(cmdq, "%4u: %s: (number) %d",
                     99:                                    ent->code, ent->name, code->value.number);
                    100:                                break;
                    101:                        case TTYCODE_FLAG:
                    102:                                cmdq_print(cmdq, "%4u: %s: (flag) %s",
                    103:                                    ent->code, ent->name,
                    104:                                    code->value.flag ? "true" : "false");
                    105:                                break;
                    106:                        }
                    107:                }
                    108:        }
                    109: }
                    110:
                    111: void
1.9       nicm      112: cmd_show_messages_jobs(struct cmd_q *cmdq)
1.8       nicm      113: {
                    114:        struct job      *job;
                    115:        u_int            n;
                    116:
                    117:        n = 0;
                    118:        LIST_FOREACH(job, &all_jobs, lentry) {
                    119:                cmdq_print(cmdq,
                    120:                    "Job %u: %s [fd=%d, pid=%d, status=%d]",
                    121:                    n, job->cmd, job->fd, job->pid, job->status);
                    122:                n++;
                    123:        }
                    124: }
                    125:
1.4       nicm      126: enum cmd_retval
1.6       nicm      127: cmd_show_messages_exec(struct cmd *self, struct cmd_q *cmdq)
1.1       nicm      128: {
1.3       nicm      129:        struct args             *args = self->args;
                    130:        struct client           *c;
                    131:        struct message_entry    *msg;
                    132:        char                    *tim;
                    133:        u_int                    i;
1.8       nicm      134:        int                      done;
                    135:
                    136:        done = 0;
1.9       nicm      137:        if (args_has(args, 'I') || self->entry == &cmd_server_info_entry) {
                    138:                cmd_show_messages_server(cmdq);
1.8       nicm      139:                done = 1;
                    140:        }
1.9       nicm      141:        if (args_has(args, 'T') || self->entry == &cmd_server_info_entry) {
1.8       nicm      142:                if (done)
1.9       nicm      143:                        cmdq_print(cmdq, "%s", "");
                    144:                cmd_show_messages_terminals(cmdq);
1.8       nicm      145:                done = 1;
                    146:        }
1.9       nicm      147:        if (args_has(args, 'J') || self->entry == &cmd_server_info_entry) {
1.8       nicm      148:                if (done)
1.9       nicm      149:                        cmdq_print(cmdq, "%s", "");
                    150:                cmd_show_messages_jobs(cmdq);
1.8       nicm      151:                done = 1;
                    152:        }
                    153:        if (done)
                    154:                return (CMD_RETURN_NORMAL);
1.1       nicm      155:
1.6       nicm      156:        if ((c = cmd_find_client(cmdq, args_get(args, 't'), 0)) == NULL)
1.4       nicm      157:                return (CMD_RETURN_ERROR);
1.1       nicm      158:
                    159:        for (i = 0; i < ARRAY_LENGTH(&c->message_log); i++) {
                    160:                msg = &ARRAY_ITEM(&c->message_log, i);
                    161:
                    162:                tim = ctime(&msg->msg_time);
                    163:                *strchr(tim, '\n') = '\0';
1.2       nicm      164:
1.6       nicm      165:                cmdq_print(cmdq, "%s %s", tim, msg->msg);
1.1       nicm      166:        }
                    167:
1.4       nicm      168:        return (CMD_RETURN_NORMAL);
1.1       nicm      169: }