/* $OpenBSD$ */
/*
* Copyright (c) 2011 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 <sys/wait.h>
#include <ctype.h>
#include <errno.h>
#include <netdb.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "tmux.h"
/*
* Build a list of key-value pairs and use them to expand #{key} entries in a
* string.
*/
struct format_entry;
typedef void (*format_cb)(struct format_tree *, struct format_entry *);
void format_job_callback(struct job *);
const char *format_job_get(struct format_tree *, const char *);
void format_job_timer(int, short, void *);
void format_cb_host(struct format_tree *, struct format_entry *);
void format_cb_host_short(struct format_tree *, struct format_entry *);
void format_cb_pid(struct format_tree *, struct format_entry *);
void format_cb_session_alerts(struct format_tree *, struct format_entry *);
void format_cb_window_layout(struct format_tree *, struct format_entry *);
void format_cb_start_command(struct format_tree *, struct format_entry *);
void format_cb_current_command(struct format_tree *, struct format_entry *);
void format_cb_history_bytes(struct format_tree *, struct format_entry *);
void format_cb_pane_tabs(struct format_tree *, struct format_entry *);
void format_add_cb(struct format_tree *, const char *, format_cb);
int format_replace(struct format_tree *, const char *, size_t, char **,
size_t *, size_t *);
char *format_time_string(time_t);
void format_defaults_pane_tabs(struct format_tree *, struct window_pane *);
void format_defaults_session(struct format_tree *, struct session *);
void format_defaults_client(struct format_tree *, struct client *);
void format_defaults_winlink(struct format_tree *, struct session *,
struct winlink *);
/* Entry in format job tree. */
struct format_job {
const char *cmd;
time_t last;
char *out;
struct job *job;
int status;
RB_ENTRY(format_job) entry;
};
/* Format job tree. */
struct event format_job_event;
int format_job_cmp(struct format_job *, struct format_job *);
RB_HEAD(format_job_tree, format_job) format_jobs = RB_INITIALIZER();
RB_PROTOTYPE(format_job_tree, format_job, entry, format_job_cmp);
RB_GENERATE(format_job_tree, format_job, entry, format_job_cmp);
/* Format job tree comparison function. */
int
format_job_cmp(struct format_job *fj1, struct format_job *fj2)
{
return (strcmp(fj1->cmd, fj2->cmd));
}
/* Entry in format tree. */
struct format_entry {
char *key;
char *value;
format_cb cb;
RB_ENTRY(format_entry) entry;
};
/* Format entry tree. */
struct format_tree {
struct window *w;
struct session *s;
struct window_pane *wp;
int status;
RB_HEAD(format_entry_tree, format_entry) tree;
};
int format_entry_cmp(struct format_entry *, struct format_entry *);
RB_PROTOTYPE(format_entry_tree, format_entry, entry, format_entry_cmp);
RB_GENERATE(format_entry_tree, format_entry, entry, format_entry_cmp);
/* Format entry tree comparison function. */
int
format_entry_cmp(struct format_entry *fe1, struct format_entry