Merge branch 'obsd-master'

This commit is contained in:
Thomas 2014-01-20 10:48:12 +00:00
commit d02c4bda3a
19 changed files with 192 additions and 122 deletions

View File

@ -20,6 +20,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "tmux.h"
@ -77,7 +78,6 @@ struct args *
args_parse(const char *template, int argc, char **argv)
{
struct args *args;
char *ptr;
int opt;
args = xcalloc(1, sizeof *args);
@ -88,7 +88,7 @@ args_parse(const char *template, int argc, char **argv)
while ((opt = getopt(argc, argv, template)) != -1) {
if (opt < 0)
continue;
if (opt == '?' || (ptr = strchr(template, opt)) == NULL) {
if (opt == '?' || strchr(template, opt) == NULL) {
args_free(args);
return (NULL);
}
@ -204,19 +204,15 @@ args_set(struct args *args, u_char ch, const char *value)
/* Replace existing argument. */
if ((entry = args_find(args, ch)) != NULL) {
free(entry->value);
if (value != NULL)
entry->value = xstrdup(value);
else
entry->value = NULL;
return;
}
} else {
entry = xcalloc(1, sizeof *entry);
entry->flag = ch;
RB_INSERT(args_tree, &args->tree, entry);
}
if (value != NULL)
entry->value = xstrdup(value);
RB_INSERT(args_tree, &args->tree, entry);
}
/* Get argument value. Will be NULL if it isn't present. */

View File

@ -118,10 +118,15 @@ retry:
close(fd);
xasprintf(&lockfile, "%s.lock", path);
if ((lockfd = client_get_lock(lockfile)) == -1)
if ((lockfd = client_get_lock(lockfile)) == -1) {
free(lockfile);
goto retry;
if (unlink(path) != 0 && errno != ENOENT)
}
if (unlink(path) != 0 && errno != ENOENT) {
free(lockfile);
close(lockfd);
return (-1);
}
fd = server_start(lockfd, lockfile);
free(lockfile);
close(lockfd);
@ -232,7 +237,8 @@ client_main(int argc, char **argv, int flags)
/* Initialise the client socket and start the server. */
fd = client_connect(socket_path, cmdflags & CMD_STARTSERVER);
if (fd == -1) {
fprintf(stderr, "failed to connect to server\n");
fprintf(stderr, "failed to connect to server: %s\n",
strerror(errno));
return (1);
}

View File

@ -47,6 +47,9 @@ cmd_attach_session(struct cmd_q *cmdq, const char *tflag, int dflag, int rflag,
{
struct session *s;
struct client *c;
struct winlink *wl = NULL;
struct window *w = NULL;
struct window_pane *wp = NULL;
const char *update;
char *cause;
u_int i;
@ -59,12 +62,31 @@ cmd_attach_session(struct cmd_q *cmdq, const char *tflag, int dflag, int rflag,
return (CMD_RETURN_ERROR);
}
if (tflag == NULL) {
if ((s = cmd_find_session(cmdq, tflag, 1)) == NULL)
return (CMD_RETURN_ERROR);
} else if (tflag[strcspn(tflag, ":.")] != '\0') {
if ((wl = cmd_find_pane(cmdq, tflag, &s, &wp)) == NULL)
return (CMD_RETURN_ERROR);
} else {
if ((s = cmd_find_session(cmdq, tflag, 1)) == NULL)
return (CMD_RETURN_ERROR);
w = cmd_lookup_windowid(tflag);
if (w == NULL && (wp = cmd_lookup_paneid(tflag)) != NULL)
w = wp->window;
if (w != NULL)
wl = winlink_find_by_window(&s->windows, w);
}
if (cmdq->client == NULL)
return (CMD_RETURN_NORMAL);
if (wl != NULL) {
if (wp != NULL)
window_set_active_pane(wp->window, wp);
session_set_current(s, wl);
}
if (cmdq->client->session != NULL) {
if (dflag) {
/*

View File

@ -107,6 +107,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
cp = format_expand(ft, args_get(args, 'c'));
format_free(ft);
if (cp != NULL && *cp != '\0') {
fd = open(cp, O_RDONLY|O_DIRECTORY);
free(cp);
if (fd == -1) {
@ -114,6 +115,8 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
strerror(errno));
return (CMD_RETURN_ERROR);
}
} else if (cp != NULL)
free(cp);
cwd = fd;
} else if (c != NULL && c->session == NULL)
cwd = c->cwd;

View File

@ -82,6 +82,37 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq)
}
detached = args_has(args, 'd');
if (args->argc == 0)
cmd = options_get_string(&s->options, "default-command");
else
cmd = args->argv[0];
if (args_has(args, 'c')) {
ft = format_create();
if ((c = cmd_find_client(cmdq, NULL, 1)) != NULL)
format_client(ft, c);
format_session(ft, s);
format_winlink(ft, s, s->curw);
format_window_pane(ft, s->curw->window->active);
cp = format_expand(ft, args_get(args, 'c'));
format_free(ft);
if (cp != NULL && *cp != '\0') {
fd = open(cp, O_RDONLY|O_DIRECTORY);
free(cp);
if (fd == -1) {
cmdq_error(cmdq, "bad working directory: %s",
strerror(errno));
return (CMD_RETURN_ERROR);
}
} else if (cp != NULL)
free(cp);
cwd = fd;
} else if (cmdq->client != NULL && cmdq->client->session == NULL)
cwd = cmdq->client->cwd;
else
cwd = s->cwd;
wl = NULL;
if (idx != -1)
wl = winlink_find_by_index(&s->windows, idx);
@ -102,34 +133,6 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq)
}
}
if (args->argc == 0)
cmd = options_get_string(&s->options, "default-command");
else
cmd = args->argv[0];
if (args_has(args, 'c')) {
ft = format_create();
if ((c = cmd_find_client(cmdq, NULL, 1)) != NULL)
format_client(ft, c);
format_session(ft, s);
format_winlink(ft, s, s->curw);
format_window_pane(ft, s->curw->window->active);
cp = format_expand(ft, args_get(args, 'c'));
format_free(ft);
fd = open(cp, O_RDONLY|O_DIRECTORY);
free(cp);
if (fd == -1) {
cmdq_error(cmdq, "bad working directory: %s",
strerror(errno));
return (CMD_RETURN_ERROR);
}
cwd = fd;
} else if (cmdq->client != NULL && cmdq->client->session == NULL)
cwd = cmdq->client->cwd;
else
cwd = s->cwd;
if (idx == -1)
idx = -1 - options_get_number(&s->options, "base-index");
wl = session_new(s, args_get(args, 'n'), cmd, cwd, idx, &cause);

View File

@ -69,9 +69,7 @@ cmdq_print(struct cmd_q *cmdq, const char *fmt, ...)
if (c == NULL)
/* nothing */;
else if (c->session == NULL || (c->flags & CLIENT_CONTROL)) {
va_start(ap, fmt);
evbuffer_add_vprintf(c->stdout_data, fmt, ap);
va_end(ap);
evbuffer_add(c->stdout_data, "\n", 1);
server_push_stdout(c);
@ -104,9 +102,7 @@ cmdq_info(struct cmd_q *cmdq, const char *fmt, ...)
if (c == NULL)
/* nothing */;
else if (c->session == NULL || (c->flags & CLIENT_CONTROL)) {
va_start(ap, fmt);
evbuffer_add_vprintf(c->stdout_data, fmt, ap);
va_end(ap);
evbuffer_add(c->stdout_data, "\n", 1);
server_push_stdout(c);

View File

@ -94,6 +94,7 @@ cmd_split_window_exec(struct cmd *self, struct cmd_q *cmdq)
cp = format_expand(ft, args_get(args, 'c'));
format_free(ft);
if (cp != NULL && *cp != '\0') {
fd = open(cp, O_RDONLY|O_DIRECTORY);
free(cp);
if (fd == -1) {
@ -101,6 +102,8 @@ cmd_split_window_exec(struct cmd *self, struct cmd_q *cmdq)
strerror(errno));
return (CMD_RETURN_ERROR);
}
} else if (cp != NULL)
free(cp);
cwd = fd;
} else if (cmdq->client != NULL && cmdq->client->session == NULL)
cwd = cmdq->client->cwd;

View File

@ -62,6 +62,10 @@ cmd_switch_client_exec(struct cmd *self, struct cmd_q *cmdq)
struct args *args = self->args;
struct client *c;
struct session *s;
struct winlink *wl = NULL;
struct window *w = NULL;
struct window_pane *wp = NULL;
const char *tflag;
if ((c = cmd_find_client(cmdq, args_get(args, 'c'), 0)) == NULL)
return (CMD_RETURN_ERROR);
@ -76,7 +80,7 @@ cmd_switch_client_exec(struct cmd *self, struct cmd_q *cmdq)
}
}
s = NULL;
tflag = args_get(args, 't');
if (args_has(args, 'n')) {
if ((s = session_next_session(c->session)) == NULL) {
cmdq_error(cmdq, "can't find next session");
@ -94,10 +98,33 @@ cmd_switch_client_exec(struct cmd *self, struct cmd_q *cmdq)
cmdq_error(cmdq, "can't find last session");
return (CMD_RETURN_ERROR);
}
} else
s = cmd_find_session(cmdq, args_get(args, 't'), 0);
if (s == NULL)
} else {
if (tflag == NULL) {
if ((s = cmd_find_session(cmdq, tflag, 1)) == NULL)
return (CMD_RETURN_ERROR);
} else if (tflag[strcspn(tflag, ":.")] != '\0') {
if ((wl = cmd_find_pane(cmdq, tflag, &s, &wp)) == NULL)
return (CMD_RETURN_ERROR);
} else {
if ((s = cmd_find_session(cmdq, tflag, 1)) == NULL)
return (CMD_RETURN_ERROR);
w = cmd_lookup_windowid(tflag);
if (w == NULL &&
(wp = cmd_lookup_paneid(tflag)) != NULL)
w = wp->window;
if (w != NULL)
wl = winlink_find_by_window(&s->windows, w);
}
if (cmdq->client == NULL)
return (CMD_RETURN_NORMAL);
if (wl != NULL) {
if (wp != NULL)
window_set_active_pane(wp->window, wp);
session_set_current(s, wl);
}
}
if (c->session != NULL)
c->last_session = c->session;

2
cmd.c
View File

@ -125,9 +125,7 @@ struct session *cmd_lookup_session(const char *, int *);
struct session *cmd_lookup_session_id(const char *);
struct winlink *cmd_lookup_window(struct session *, const char *, int *);
int cmd_lookup_index(struct session *, const char *, int *);
struct window_pane *cmd_lookup_paneid(const char *);
struct winlink *cmd_lookup_winlink_windowid(struct session *, const char *);
struct window *cmd_lookup_windowid(const char *);
struct session *cmd_window_session(struct cmd_q *, struct window *,
struct winlink **);
struct winlink *cmd_find_window_offset(const char *, struct session *, int *);

View File

@ -321,6 +321,13 @@ format_expand(struct format_tree *ft, const char *fmt)
break;
fmt += n + 1;
continue;
case '#':
while (len - off < 2) {
buf = xrealloc(buf, 2, len);
len *= 2;
}
buf[off++] = '#';
continue;
default:
s = NULL;
if (ch >= 'A' && ch <= 'Z')

2
grid.c
View File

@ -124,7 +124,7 @@ grid_compare(struct grid *ga, struct grid *gb)
struct grid_cell *gca, *gcb;
u_int xx, yy;
if (ga->sx != gb->sx || ga->sy != ga->sy)
if (ga->sx != gb->sx || ga->sy != gb->sy)
return (1);
for (yy = 0; yy < ga->sy; yy++) {

View File

@ -26,7 +26,7 @@
/*
* Option handling; each option has a name, type and value and is stored in
* a splay tree.
* a red-black tree.
*/
RB_GENERATE(options_tree, options_entry, entry, options_cmp);

View File

@ -111,12 +111,8 @@ screen_set_cursor_colour(struct screen *s, const char *colour_string)
void
screen_set_title(struct screen *s, const char *title)
{
char tmp[BUFSIZ];
strlcpy(tmp, title, sizeof tmp);
free(s->title);
s->title = xstrdup(tmp);
s->title = xstrdup(title);
}
/* Resize screen. */

3
tmux.1
View File

@ -3015,6 +3015,9 @@ for example
.Ql #{session_name} .
Some variables also have an shorter alias such as
.Ql #S .
.Ql ##
is replaced by a single
.Ql # .
Conditionals are also accepted by prefixing with
.Ql \&?
and separating two alternatives with a comma;

13
tmux.c
View File

@ -205,8 +205,9 @@ int
main(int argc, char **argv)
{
struct passwd *pw;
char *s, *path, *label, *home, **var, tmp[MAXPATHLEN];
char *s, *path, *label, **var, tmp[MAXPATHLEN];
char in[256];
const char *home;
long long pid;
int opt, flags, quiet, keys, session;
@ -331,13 +332,17 @@ main(int argc, char **argv)
pw = getpwuid(getuid());
if (pw != NULL)
home = pw->pw_dir;
else
home = NULL;
}
if (home != NULL) {
xasprintf(&cfg_file, "%s/.tmux.conf", home);
if (access(cfg_file, R_OK) != 0 && errno == ENOENT) {
free(cfg_file);
cfg_file = NULL;
}
}
}
/* Get path from environment. */
s = getenv("TMUX");
@ -367,7 +372,11 @@ main(int argc, char **argv)
}
}
free(label);
strlcpy(socket_path, path, sizeof socket_path);
if (strlcpy(socket_path, path, sizeof socket_path) >= sizeof socket_path) {
fprintf(stderr, "socket path too long: %s\n", path);
exit(1);
}
free(path);
#ifdef HAVE_SETPROCTITLE

2
tmux.h
View File

@ -1732,6 +1732,8 @@ int cmd_find_index(struct cmd_q *, const char *,
struct winlink *cmd_find_pane(struct cmd_q *, const char *, struct session **,
struct window_pane **);
char *cmd_template_replace(const char *, const char *, int);
struct window *cmd_lookup_windowid(const char *);
struct window_pane *cmd_lookup_paneid(const char *);
extern const struct cmd_entry *cmd_table[];
extern const struct cmd_entry cmd_attach_session_entry;
extern const struct cmd_entry cmd_bind_key_entry;

View File

@ -30,38 +30,38 @@ struct tty_acs_entry {
const char *string;
};
const struct tty_acs_entry tty_acs_table[] = {
{ '+', "\342\206\222" },
{ ',', "\342\206\220" },
{ '-', "\342\206\221" },
{ '.', "\342\206\223" },
{ '0', "\342\226\256" },
{ '`', "\342\227\206" },
{ 'a', "\342\226\222" },
{ 'f', "\302\260" },
{ 'g', "\302\261" },
{ 'h', "\342\226\222" },
{ 'i', "\342\230\203" },
{ 'j', "\342\224\230" },
{ 'k', "\342\224\220" },
{ 'l', "\342\224\214" },
{ 'm', "\342\224\224" },
{ 'n', "\342\224\274" },
{ 'o', "\342\216\272" },
{ 'p', "\342\216\273" },
{ 'q', "\342\224\200" },
{ 'r', "\342\216\274" },
{ 's', "\342\216\275" },
{ 't', "\342\224\234" },
{ 'u', "\342\224\244" },
{ 'v', "\342\224\264" },
{ 'w', "\342\224\254" },
{ 'x', "\342\224\202" },
{ 'y', "\342\211\244" },
{ 'z', "\342\211\245" },
{ '{', "\317\200" },
{ '|', "\342\211\240" },
{ '}', "\302\243" },
{ '~', "\302\267" }
{ '+', "\342\206\222" }, /* arrow pointing right */
{ ',', "\342\206\220" }, /* arrow pointing left */
{ '-', "\342\206\221" }, /* arrow pointing up */
{ '.', "\342\206\223" }, /* arrow pointing down */
{ '0', "\342\226\256" }, /* solid square block */
{ '`', "\342\227\206" }, /* diamond */
{ 'a', "\342\226\222" }, /* checker board (stipple) */
{ 'f', "\302\260" }, /* degree symbol */
{ 'g', "\302\261" }, /* plus/minus */
{ 'h', "\342\226\222" }, /* board of squares */
{ 'i', "\342\230\203" }, /* lantern symbol */
{ 'j', "\342\224\230" }, /* lower right corner */
{ 'k', "\342\224\220" }, /* upper right corner */
{ 'l', "\342\224\214" }, /* upper left corner */
{ 'm', "\342\224\224" }, /* lower left corner */
{ 'n', "\342\224\274" }, /* large plus or crossover */
{ 'o', "\342\216\272" }, /* scan line 1 */
{ 'p', "\342\216\273" }, /* scan line 3 */
{ 'q', "\342\224\200" }, /* horizontal line */
{ 'r', "\342\216\274" }, /* scan line 7 */
{ 's', "\342\216\275" }, /* scan line 9 */
{ 't', "\342\224\234" }, /* tee pointing right */
{ 'u', "\342\224\244" }, /* tee pointing left */
{ 'v', "\342\224\264" }, /* tee pointing up */
{ 'w', "\342\224\254" }, /* tee pointing down */
{ 'x', "\342\224\202" }, /* vertical line */
{ 'y', "\342\211\244" }, /* less-than-or-equal-to */
{ 'z', "\342\211\245" }, /* greater-than-or-equal-to */
{ '{', "\317\200" }, /* greek pi */
{ '|', "\342\211\240" }, /* not-equal */
{ '}', "\302\243" }, /* UK pound sign */
{ '~', "\302\267" } /* bullet */
};
int

View File

@ -345,8 +345,7 @@ window_choose_collapse(struct window_pane *wp, struct session *s)
* assign the actual result we want to render and copy the new one over
* the top of it.
*/
for (i = 0; i < ARRAY_LENGTH(&data->list); i++)
{
for (i = 0; i < ARRAY_LENGTH(&data->list); i++) {
item = &ARRAY_ITEM(&data->list, i);
wcd = item->wcd;

View File

@ -1030,7 +1030,7 @@ window_copy_search_up(struct window_pane *wp, const char *searchstr)
cis = 1;
for (ptr = searchstr; *ptr != '\0'; ptr++) {
if (*ptr != tolower(*ptr)) {
if (*ptr != tolower((u_char)*ptr)) {
cis = 0;
break;
}
@ -1097,7 +1097,7 @@ window_copy_search_down(struct window_pane *wp, const char *searchstr)
cis = 1;
for (ptr = searchstr; *ptr != '\0'; ptr++) {
if (*ptr != tolower(*ptr)) {
if (*ptr != tolower((u_char)*ptr)) {
cis = 0;
break;
}