Annotation of embedaddon/tmux/cmd-show-messages.c, revision 1.1

1.1     ! misho       1: /* $OpenBSD$ */
        !             2: 
        !             3: /*
        !             4:  * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
        !             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>
        !            23: #include <unistd.h>
        !            24: 
        !            25: #include "tmux.h"
        !            26: 
        !            27: /*
        !            28:  * Show client message log.
        !            29:  */
        !            30: 
        !            31: static enum cmd_retval cmd_show_messages_exec(struct cmd *,
        !            32:                            struct cmdq_item *);
        !            33: 
        !            34: const struct cmd_entry cmd_show_messages_entry = {
        !            35:        .name = "show-messages",
        !            36:        .alias = "showmsgs",
        !            37: 
        !            38:        .args = { "JTt:", 0, 0 },
        !            39:        .usage = "[-JT] " CMD_TARGET_CLIENT_USAGE,
        !            40: 
        !            41:        .tflag = CMD_CLIENT,
        !            42: 
        !            43:        .flags = CMD_AFTERHOOK,
        !            44:        .exec = cmd_show_messages_exec
        !            45: };
        !            46: 
        !            47: static int     cmd_show_messages_terminals(struct cmdq_item *, int);
        !            48: static int     cmd_show_messages_jobs(struct cmdq_item *, int);
        !            49: 
        !            50: static int
        !            51: cmd_show_messages_terminals(struct cmdq_item *item, int blank)
        !            52: {
        !            53:        struct tty_term *term;
        !            54:        u_int            i, n;
        !            55: 
        !            56:        n = 0;
        !            57:        LIST_FOREACH(term, &tty_terms, entry) {
        !            58:                if (blank) {
        !            59:                        cmdq_print(item, "%s", "");
        !            60:                        blank = 0;
        !            61:                }
        !            62:                cmdq_print(item, "Terminal %u: %s [references=%u, flags=0x%x]:",
        !            63:                    n, term->name, term->references, term->flags);
        !            64:                n++;
        !            65:                for (i = 0; i < tty_term_ncodes(); i++)
        !            66:                        cmdq_print(item, "%s", tty_term_describe(term, i));
        !            67:        }
        !            68:        return (n != 0);
        !            69: }
        !            70: 
        !            71: static int
        !            72: cmd_show_messages_jobs(struct cmdq_item *item, int blank)
        !            73: {
        !            74:        struct job      *job;
        !            75:        u_int            n;
        !            76: 
        !            77:        n = 0;
        !            78:        LIST_FOREACH(job, &all_jobs, lentry) {
        !            79:                if (blank) {
        !            80:                        cmdq_print(item, "%s", "");
        !            81:                        blank = 0;
        !            82:                }
        !            83:                cmdq_print(item, "Job %u: %s [fd=%d, pid=%ld, status=%d]",
        !            84:                    n, job->cmd, job->fd, (long)job->pid, job->status);
        !            85:                n++;
        !            86:        }
        !            87:        return (n != 0);
        !            88: }
        !            89: 
        !            90: static enum cmd_retval
        !            91: cmd_show_messages_exec(struct cmd *self, struct cmdq_item *item)
        !            92: {
        !            93:        struct args             *args = self->args;
        !            94:        struct client           *c = item->state.c;
        !            95:        struct message_entry    *msg;
        !            96:        char                    *tim;
        !            97:        int                      done, blank;
        !            98: 
        !            99:        done = blank = 0;
        !           100:        if (args_has(args, 'T')) {
        !           101:                blank = cmd_show_messages_terminals(item, blank);
        !           102:                done = 1;
        !           103:        }
        !           104:        if (args_has(args, 'J')) {
        !           105:                cmd_show_messages_jobs(item, blank);
        !           106:                done = 1;
        !           107:        }
        !           108:        if (done)
        !           109:                return (CMD_RETURN_NORMAL);
        !           110: 
        !           111:        TAILQ_FOREACH(msg, &c->message_log, entry) {
        !           112:                tim = ctime(&msg->msg_time);
        !           113:                *strchr(tim, '\n') = '\0';
        !           114: 
        !           115:                cmdq_print(item, "%s %s", tim, msg->msg);
        !           116:        }
        !           117: 
        !           118:        return (CMD_RETURN_NORMAL);
        !           119: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>