Merge branch 'master' of ssh://git.code.sf.net/p/tmux/tmux-code

This commit is contained in:
Nicholas Marriott 2014-03-08 16:28:56 +00:00
commit 77603c4f2d
13 changed files with 145 additions and 180 deletions

2
TODO
View File

@ -132,5 +132,3 @@
binding to a command that says "next key from $othertable" and so
on. means -n can go away as well
* customizable command aliases
* get_cwd for cgywin

View File

@ -53,6 +53,9 @@ cmd_set_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
psize = 0;
pdata = NULL;
pb = NULL;
buffer = -1;
if (args_has(args, 'b')) {
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
if (cause != NULL) {
@ -65,13 +68,17 @@ cmd_set_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
cmdq_error(cmdq, "no buffer %d", buffer);
return (CMD_RETURN_ERROR);
}
if (args_has(args, 'a')) {
psize = pb->size;
pdata = xmalloc(psize);
memcpy(pdata, pb->data, psize);
}
} else
buffer = -1;
} else if (args_has(args, 'a')) {
pb = paste_get_top(&global_buffers);
if (pb != NULL)
buffer = 0;
}
if (args_has(args, 'a') && pb != NULL) {
psize = pb->size;
pdata = xmalloc(psize);
memcpy(pdata, pb->data, psize);
}
newsize = strlen(args->argv[0]);

View File

@ -501,6 +501,10 @@ case "$host_os" in
AC_MSG_RESULT(hpux)
PLATFORM=hpux
;;
*cygwin*)
AC_MSG_RESULT(cygwin)
PLATFORM=cygwin
;;
*)
AC_MSG_RESULT(unknown)
PLATFORM=unknown

View File

@ -59,8 +59,6 @@ grid_view_clear_history(struct grid *gd)
struct grid_line *gl;
u_int yy, last;
GRID_DEBUG(gd, "");
/* Find the last used line. */
last = 0;
for (yy = 0; yy < gd->sy; yy++) {
@ -82,8 +80,6 @@ grid_view_clear_history(struct grid *gd)
void
grid_view_clear(struct grid *gd, u_int px, u_int py, u_int nx, u_int ny)
{
GRID_DEBUG(gd, "px=%u, py=%u, nx=%u, ny=%u", px, py, nx, ny);
px = grid_view_x(gd, px);
py = grid_view_y(gd, py);
@ -94,8 +90,6 @@ grid_view_clear(struct grid *gd, u_int px, u_int py, u_int nx, u_int ny)
void
grid_view_scroll_region_up(struct grid *gd, u_int rupper, u_int rlower)
{
GRID_DEBUG(gd, "rupper=%u, rlower=%u", rupper, rlower);
if (gd->flags & GRID_HISTORY) {
grid_collect_history(gd);
if (rupper == 0 && rlower == gd->sy - 1)
@ -116,8 +110,6 @@ grid_view_scroll_region_up(struct grid *gd, u_int rupper, u_int rlower)
void
grid_view_scroll_region_down(struct grid *gd, u_int rupper, u_int rlower)
{
GRID_DEBUG(gd, "rupper=%u, rlower=%u", rupper, rlower);
rupper = grid_view_y(gd, rupper);
rlower = grid_view_y(gd, rlower);
@ -130,8 +122,6 @@ grid_view_insert_lines(struct grid *gd, u_int py, u_int ny)
{
u_int sy;
GRID_DEBUG(gd, "py=%u, ny=%u", py, ny);
py = grid_view_y(gd, py);
sy = grid_view_y(gd, gd->sy);
@ -145,8 +135,6 @@ grid_view_insert_lines_region(struct grid *gd, u_int rlower, u_int py, u_int ny)
{
u_int ny2;
GRID_DEBUG(gd, "rlower=%u, py=%u, ny=%u", rlower, py, ny);
rlower = grid_view_y(gd, rlower);
py = grid_view_y(gd, py);
@ -162,8 +150,6 @@ grid_view_delete_lines(struct grid *gd, u_int py, u_int ny)
{
u_int sy;
GRID_DEBUG(gd, "py=%u, ny=%u", py, ny);
py = grid_view_y(gd, py);
sy = grid_view_y(gd, gd->sy);
@ -178,8 +164,6 @@ grid_view_delete_lines_region(struct grid *gd, u_int rlower, u_int py, u_int ny)
{
u_int ny2;
GRID_DEBUG(gd, "rlower=%u, py=%u, ny=%u", rlower, py, ny);
rlower = grid_view_y(gd, rlower);
py = grid_view_y(gd, py);
@ -195,8 +179,6 @@ grid_view_insert_cells(struct grid *gd, u_int px, u_int py, u_int nx)
{
u_int sx;
GRID_DEBUG(gd, "px=%u, py=%u, nx=%u", px, py, nx);
px = grid_view_x(gd, px);
py = grid_view_y(gd, py);
@ -214,8 +196,6 @@ grid_view_delete_cells(struct grid *gd, u_int px, u_int py, u_int nx)
{
u_int sx;
GRID_DEBUG(gd, "px=%u, py=%u, nx=%u", px, py, nx);
px = grid_view_x(gd, px);
py = grid_view_y(gd, py);
@ -229,8 +209,6 @@ grid_view_delete_cells(struct grid *gd, u_int px, u_int py, u_int nx)
char *
grid_view_string_cells(struct grid *gd, u_int px, u_int py, u_int nx)
{
GRID_DEBUG(gd, "px=%u, py=%u, nx=%u", px, py, nx);
px = grid_view_x(gd, px);
py = grid_view_y(gd, py);

18
grid.c
View File

@ -151,8 +151,6 @@ grid_collect_history(struct grid *gd)
{
u_int yy;
GRID_DEBUG(gd, "");
if (gd->hsize < gd->hlimit)
return;
@ -173,8 +171,6 @@ grid_scroll_history(struct grid *gd)
{
u_int yy;
GRID_DEBUG(gd, "");
yy = gd->hsize + gd->sy;
gd->linedata = xrealloc(gd->linedata, yy + 1, sizeof *gd->linedata);
memset(&gd->linedata[yy], 0, sizeof gd->linedata[yy]);
@ -189,8 +185,6 @@ grid_scroll_history_region(struct grid *gd, u_int upper, u_int lower)
struct grid_line *gl_history, *gl_upper, *gl_lower;
u_int yy;
GRID_DEBUG(gd, "upper=%u, lower=%u", upper, lower);
/* Create a space for a new line. */
yy = gd->hsize + gd->sy;
gd->linedata = xrealloc(gd->linedata, yy + 1, sizeof *gd->linedata);
@ -282,8 +276,6 @@ grid_clear(struct grid *gd, u_int px, u_int py, u_int nx, u_int ny)
{
u_int xx, yy;
GRID_DEBUG(gd, "px=%u, py=%u, nx=%u, ny=%u", px, py, nx, ny);
if (nx == 0 || ny == 0)
return;
@ -319,8 +311,6 @@ grid_clear_lines(struct grid *gd, u_int py, u_int ny)
struct grid_line *gl;
u_int yy;
GRID_DEBUG(gd, "py=%u, ny=%u", py, ny);
if (ny == 0)
return;
@ -342,8 +332,6 @@ grid_move_lines(struct grid *gd, u_int dy, u_int py, u_int ny)
{
u_int yy;
GRID_DEBUG(gd, "dy=%u, py=%u, ny=%u", dy, py, ny);
if (ny == 0 || py == dy)
return;
@ -381,8 +369,6 @@ grid_move_cells(struct grid *gd, u_int dx, u_int px, u_int py, u_int nx)
struct grid_line *gl;
u_int xx;
GRID_DEBUG(gd, "dx=%u, px=%u, py=%u, nx=%u", dx, px, py, nx);
if (nx == 0 || px == dx)
return;
@ -592,8 +578,6 @@ grid_string_cells(struct grid *gd, u_int px, u_int py, u_int nx,
u_int xx;
const struct grid_line *gl;
GRID_DEBUG(gd, "px=%u, py=%u, nx=%u", px, py, nx);
if (lastgc != NULL && *lastgc == NULL) {
memcpy(&lastgc1, &grid_default_cell, sizeof lastgc1);
*lastgc = &lastgc1;
@ -661,8 +645,6 @@ grid_duplicate_lines(struct grid *dst, u_int dy, struct grid *src, u_int sy,
struct grid_line *dstl, *srcl;
u_int yy;
GRID_DEBUG(src, "dy=%u, sy=%u, ny=%u", dy, sy, ny);
if (dy + ny > dst->hsize + dst->sy)
ny = dst->hsize + dst->sy - dy;
if (sy + ny > src->hsize + src->sy)

View File

@ -142,7 +142,7 @@ input_key(struct window_pane *wp, int key)
char *out;
u_char ch;
log_debug2("writing key 0x%x", key);
log_debug("writing key 0x%x", key);
/*
* If this is a normal 7-bit key, just send it, with a leading escape
@ -185,11 +185,11 @@ input_key(struct window_pane *wp, int key)
break;
}
if (i == nitems(input_keys)) {
log_debug2("key 0x%x missing", key);
log_debug("key 0x%x missing", key);
return;
}
dlen = strlen(ike->data);
log_debug2("found key 0x%x: \"%s\"", key, ike->data);
log_debug("found key 0x%x: \"%s\"", key, ike->data);
/* Prefix a \033 for escape. */
if (key & KEYC_ESCAPE)

116
log.c
View File

@ -22,36 +22,28 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <time.h>
#include "tmux.h"
/* Log file, if needed. */
FILE *log_file;
FILE *log_file;
/* Debug level. */
int log_level = 0;
void log_event_cb(int, const char *);
void log_vwrite(const char *, va_list);
__dead void log_vfatal(const char *, va_list);
void log_event_cb(int, const char *);
void log_vwrite(const char *, va_list);
/* Log callback for libevent. */
void
log_event_cb(unused int severity, const char *msg)
{
log_warnx("%s", msg);
log_debug("%s", msg);
}
/* Open logging to file. */
void
log_open(int level, const char *path)
log_open(const char *path)
{
log_file = fopen(path, "w");
if (log_file == NULL)
return;
log_level = level;
setlinebuf(log_file);
event_set_log_callback(log_event_cb);
@ -65,6 +57,7 @@ log_close(void)
{
if (log_file != NULL)
fclose(log_file);
log_file = NULL;
event_set_log_callback(NULL);
}
@ -86,24 +79,9 @@ log_vwrite(const char *msg, va_list ap)
free(fmt);
}
/* Log a warning with error string. */
/* Log a debug message. */
void printflike1
log_warn(const char *msg, ...)
{
va_list ap;
char *fmt;
va_start(ap, msg);
if (asprintf(&fmt, "%s: %s", msg, strerror(errno)) == -1)
exit(1);
log_vwrite(fmt, ap);
free(fmt);
va_end(ap);
}
/* Log a warning. */
void printflike1
log_warnx(const char *msg, ...)
log_debug(const char *msg, ...)
{
va_list ap;
@ -112,82 +90,30 @@ log_warnx(const char *msg, ...)
va_end(ap);
}
/* Log an informational message. */
void printflike1
log_info(const char *msg, ...)
{
va_list ap;
if (log_level > -1) {
va_start(ap, msg);
log_vwrite(msg, ap);
va_end(ap);
}
}
/* Log a debug message. */
void printflike1
log_debug(const char *msg, ...)
{
va_list ap;
if (log_level > 0) {
va_start(ap, msg);
log_vwrite(msg, ap);
va_end(ap);
}
}
/* Log a debug message at level 2. */
void printflike1
log_debug2(const char *msg, ...)
{
va_list ap;
if (log_level > 1) {
va_start(ap, msg);
log_vwrite(msg, ap);
va_end(ap);
}
}
/* Log a critical error, with error string if necessary, and die. */
__dead void
log_vfatal(const char *msg, va_list ap)
{
char *fmt;
if (errno != 0) {
if (asprintf(&fmt, "fatal: %s: %s", msg, strerror(errno)) == -1)
exit(1);
log_vwrite(fmt, ap);
} else {
if (asprintf(&fmt, "fatal: %s", msg) == -1)
exit(1);
log_vwrite(fmt, ap);
}
free(fmt);
exit(1);
}
/* Log a critical error, with error string, and die. */
/* Log a critical error with error string and die. */
__dead void printflike1
log_fatal(const char *msg, ...)
{
va_list ap;
char *fmt;
va_list ap;
va_start(ap, msg);
log_vfatal(msg, ap);
if (asprintf(&fmt, "fatal: %s: %s", msg, strerror(errno)) == -1)
exit(1);
log_vwrite(fmt, ap);
exit(1);
}
/* Log a critical error and die. */
__dead void printflike1
log_fatalx(const char *msg, ...)
{
va_list ap;
char *fmt;
va_list ap;
errno = 0;
va_start(ap, msg);
log_vfatal(msg, ap);
if (asprintf(&fmt, "fatal: %s", msg) == -1)
exit(1);
log_vwrite(fmt, ap);
exit(1);
}

View File

@ -80,6 +80,13 @@ const struct options_table_entry server_options_table[] = {
.default_num = 0
},
{ .name = "message-limit",
.type = OPTIONS_TABLE_NUMBER,
.minimum = 0,
.maximum = INT_MAX,
.default_num = 100
},
{ .name = "quiet",
.type = OPTIONS_TABLE_FLAG,
.default_num = 0 /* overridden in main() */
@ -234,13 +241,6 @@ const struct options_table_entry session_options_table[] = {
.style = "message-style"
},
{ .name = "message-limit",
.type = OPTIONS_TABLE_NUMBER,
.minimum = 0,
.maximum = INT_MAX,
.default_num = 20
},
{ .name = "message-style",
.type = OPTIONS_TABLE_STYLE,
.default_str = "bg=yellow,fg=black"

88
osdep-cygwin.c Normal file
View File

@ -0,0 +1,88 @@
/* $Id$ */
/*
* Copyright (c) 2009 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/stat.h>
#include <event.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "tmux.h"
char *
osdep_get_name(int fd, unused char *tty)
{
FILE *f;
char *path, *buf;
size_t len;
int ch;
pid_t pgrp;
if ((pgrp = tcgetpgrp(fd)) == -1)
return (NULL);
xasprintf(&path, "/proc/%lld/cmdline", (long long) pgrp);
if ((f = fopen(path, "r")) == NULL) {
free(path);
return (NULL);
}
free(path);
len = 0;
buf = NULL;
while ((ch = fgetc(f)) != EOF) {
if (ch == '\0')
break;
buf = xrealloc(buf, 1, len + 2);
buf[len++] = ch;
}
if (buf != NULL)
buf[len] = '\0';
fclose(f);
return (buf);
}
char *
osdep_get_cwd(int fd)
{
static char target[MAXPATHLEN + 1];
char *path;
pid_t pgrp;
ssize_t n;
if ((pgrp = tcgetpgrp(fd)) == -1)
return (NULL);
xasprintf(&path, "/proc/%lld/cwd", (long long) pgrp);
n = readlink(path, target, MAXPATHLEN);
free(path);
if (n > 0) {
target[n] = '\0';
return (target);
}
return (NULL);
}
struct event_base *
osdep_event_init(void)
{
return (event_init());
}

View File

@ -655,7 +655,6 @@ void printflike2
status_message_set(struct client *c, const char *fmt, ...)
{
struct timeval tv;
struct session *s = c->session;
struct message_entry *msg;
va_list ap;
int delay;
@ -673,10 +672,7 @@ status_message_set(struct client *c, const char *fmt, ...)
msg->msg_time = time(NULL);
msg->msg = xstrdup(c->message_string);
if (s == NULL)
limit = 0;
else
limit = options_get_number(&s->options, "message-limit");
limit = options_get_number(&global_options, "message-limit");
if (ARRAY_LENGTH(&c->message_log) > limit) {
limit = ARRAY_LENGTH(&c->message_log) - limit;
for (i = 0; i < limit; i++) {

10
tmux.1
View File

@ -782,7 +782,7 @@ Show client messages or server information.
Any messages displayed on the status line are saved in a per-client message
log, up to a maximum of the limit set by the
.Ar message-limit
session option for the session attached to that client.
server option.
With
.Fl t ,
display the log for
@ -2138,6 +2138,10 @@ passed through to applications running in
.Nm .
Attached clients should be detached and attached again after changing this
option.
.It Ic message-limit Ar number
Set the number of error or information messages to save in the message log for
each client.
The default is 100.
.It Xo Ic quiet
.Op Ic on | off
.Xc
@ -2359,10 +2363,6 @@ With the
flag to the
.Ic set-option
command the new style is added otherwise the existing style is replaced.
.It Ic message-limit Ar number
Set the number of error or information messages to save in the message log for
each client.
The default is 20.
.It Ic message-style Ar style
Set status line message style.
For how to specify

2
tmux.c
View File

@ -73,7 +73,7 @@ logfile(const char *name)
if (debug_level > 0) {
xasprintf(&path, "tmux-%s-%ld.log", name, (long) getpid());
log_open(debug_level, path);
log_open(path);
free(path);
}
}

16
tmux.h
View File

@ -660,16 +660,6 @@ struct utf8_data {
u_int width;
};
/* Grid output. */
#if defined(DEBUG) && \
((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
(defined(__GNUC__) && __GNUC__ >= 3))
#define GRID_DEBUG(gd, fmt, ...) log_debug2("%s: (sx=%u, sy=%u, hsize=%u) " \
fmt, __func__, (gd)->sx, (gd)->sy, (gd)->hsize, ## __VA_ARGS__)
#else
#define GRID_DEBUG(...)
#endif
/* Grid attributes. */
#define GRID_ATTR_BRIGHT 0x1
#define GRID_ATTR_DIM 0x2
@ -2340,13 +2330,9 @@ char *osdep_get_cwd(int);
struct event_base *osdep_event_init(void);
/* log.c */
void log_open(int, const char *);
void log_open(const char *);
void log_close(void);
void printflike1 log_warn(const char *, ...);
void printflike1 log_warnx(const char *, ...);
void printflike1 log_info(const char *, ...);
void printflike1 log_debug(const char *, ...);
void printflike1 log_debug2(const char *, ...);
__dead void printflike1 log_fatal(const char *, ...);
__dead void printflike1 log_fatalx(const char *, ...);