Import tmux
We have to use SOCK_SEQPACKET instead of SOCK_STREAM for client/server communication, because UDS does things with control messages that tmux does not expect. Change-Id: I3edb1875d61fb976cf6485c650f4fd4b82fa354c
This commit is contained in:
parent
5d259c7f93
commit
eda6f5931d
159 changed files with 39630 additions and 2 deletions
|
@ -516,6 +516,7 @@
|
||||||
./usr/bin/tget minix-sys
|
./usr/bin/tget minix-sys
|
||||||
./usr/bin/tic minix-sys
|
./usr/bin/tic minix-sys
|
||||||
./usr/bin/time minix-sys
|
./usr/bin/time minix-sys
|
||||||
|
./usr/bin/tmux minix-sys
|
||||||
./usr/bin/top minix-sys
|
./usr/bin/top minix-sys
|
||||||
./usr/bin/toproto minix-sys
|
./usr/bin/toproto minix-sys
|
||||||
./usr/bin/touch minix-sys
|
./usr/bin/touch minix-sys
|
||||||
|
@ -2555,6 +2556,7 @@
|
||||||
./usr/man/man1/tget.1 minix-sys
|
./usr/man/man1/tget.1 minix-sys
|
||||||
./usr/man/man1/tic.1 minix-sys
|
./usr/man/man1/tic.1 minix-sys
|
||||||
./usr/man/man1/time.1 minix-sys
|
./usr/man/man1/time.1 minix-sys
|
||||||
|
./usr/man/man1/tmux.1 minix-sys
|
||||||
./usr/man/man1/touch.1 minix-sys
|
./usr/man/man1/touch.1 minix-sys
|
||||||
./usr/man/man1/tput.1 minix-sys
|
./usr/man/man1/tput.1 minix-sys
|
||||||
./usr/man/man1/tr.1 minix-sys
|
./usr/man/man1/tr.1 minix-sys
|
||||||
|
@ -5344,6 +5346,8 @@
|
||||||
./usr/share/examples/lutok/hello.cpp minix-sys kyua
|
./usr/share/examples/lutok/hello.cpp minix-sys kyua
|
||||||
./usr/share/examples/lutok/interpreter.cpp minix-sys kyua
|
./usr/share/examples/lutok/interpreter.cpp minix-sys kyua
|
||||||
./usr/share/examples/lutok/raii.cpp minix-sys kyua
|
./usr/share/examples/lutok/raii.cpp minix-sys kyua
|
||||||
|
./usr/share/examples/tmux minix-sys
|
||||||
|
./usr/share/examples/tmux/screen-keys.conf minix-sys
|
||||||
./usr/share/games minix-sys
|
./usr/share/games minix-sys
|
||||||
./usr/share/games/fish.instr minix-sys
|
./usr/share/games/fish.instr minix-sys
|
||||||
./usr/share/games/fortune minix-sys
|
./usr/share/games/fortune minix-sys
|
||||||
|
|
|
@ -117,6 +117,8 @@
|
||||||
./usr/share/doc/psd/19.curses
|
./usr/share/doc/psd/19.curses
|
||||||
./usr/share/doc/usd
|
./usr/share/doc/usd
|
||||||
./usr/share/doc/usd/03.shell
|
./usr/share/doc/usd/03.shell
|
||||||
|
./usr/share/examples
|
||||||
|
./usr/share/examples/tmux
|
||||||
./usr/share/info
|
./usr/share/info
|
||||||
./usr/share/games
|
./usr/share/games
|
||||||
./usr/share/games/fortune
|
./usr/share/games/fortune
|
||||||
|
|
|
@ -162,7 +162,6 @@
|
||||||
./usr/share/doc/kyua-atf-compat
|
./usr/share/doc/kyua-atf-compat
|
||||||
./usr/share/doc/kyua-cli
|
./usr/share/doc/kyua-cli
|
||||||
./usr/share/doc/kyua-testers
|
./usr/share/doc/kyua-testers
|
||||||
./usr/share/examples
|
|
||||||
./usr/share/examples/atf
|
./usr/share/examples/atf
|
||||||
./usr/share/examples/kyua-cli
|
./usr/share/examples/kyua-cli
|
||||||
./usr/share/examples/lutok
|
./usr/share/examples/lutok
|
||||||
|
|
2
external/bsd/Makefile
vendored
2
external/bsd/Makefile
vendored
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
SUBDIR= byacc file flex less \
|
SUBDIR= byacc file flex less \
|
||||||
libarchive libevent mdocml \
|
libarchive libevent mdocml \
|
||||||
|
tmux
|
||||||
|
|
||||||
.if (${MKATF} != "no")
|
.if (${MKATF} != "no")
|
||||||
SUBDIR+= atf
|
SUBDIR+= atf
|
||||||
|
|
5
external/bsd/tmux/Makefile
vendored
Normal file
5
external/bsd/tmux/Makefile
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# $NetBSD: Makefile,v 1.1 2011/03/10 09:18:00 jmmv Exp $
|
||||||
|
|
||||||
|
SUBDIR= share usr.bin
|
||||||
|
|
||||||
|
.include <bsd.subdir.mk>
|
15
external/bsd/tmux/README
vendored
Normal file
15
external/bsd/tmux/README
vendored
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
To update tmux to a new version:
|
||||||
|
|
||||||
|
- Build the package from pkgsrc and write down all -D flags passed to the
|
||||||
|
compiler. Autoconf is not generating a config.h file, so this is the
|
||||||
|
best we can do to get the build-time settings in place.
|
||||||
|
- Use prepare-import.sh to regenerate the dist directory.
|
||||||
|
- Update usr.bin/tmux/Makefile to sync the CPPFLAGS to the list of -D flags
|
||||||
|
gathered earlier on.
|
||||||
|
- Update the list of source files in usr.bin/tmux/Makefile with the new
|
||||||
|
dist/*.c listing.
|
||||||
|
- cvs import the contents of the new dist directory.
|
||||||
|
- Fix merge conflicts, if any.
|
||||||
|
- Commit the changes to the reachover Makefiles.
|
||||||
|
- Update doc/3RDPARTY with the new tmux version.
|
||||||
|
- Add a note to doc/CHANGES about the new version.
|
222
external/bsd/tmux/dist/arguments.c
vendored
Normal file
222
external/bsd/tmux/dist/arguments.c
vendored
Normal file
|
@ -0,0 +1,222 @@
|
||||||
|
/* $Id: arguments.c,v 1.1.1.1 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2010 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 <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/* Create an arguments set with no flags. */
|
||||||
|
struct args *
|
||||||
|
args_create(int argc, ...)
|
||||||
|
{
|
||||||
|
struct args *args;
|
||||||
|
va_list ap;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
args = xcalloc(1, sizeof *args);
|
||||||
|
if ((args->flags = bit_alloc(SCHAR_MAX)) == NULL)
|
||||||
|
fatal("bit_alloc failed");
|
||||||
|
|
||||||
|
args->argc = argc;
|
||||||
|
if (argc == 0)
|
||||||
|
args->argv = NULL;
|
||||||
|
else
|
||||||
|
args->argv = xcalloc(argc, sizeof *args->argv);
|
||||||
|
|
||||||
|
va_start(ap, argc);
|
||||||
|
for (i = 0; i < argc; i++)
|
||||||
|
args->argv[i] = xstrdup(va_arg(ap, char *));
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
return (args);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Parse an argv and argc into a new argument set. */
|
||||||
|
struct args *
|
||||||
|
args_parse(const char *template, int argc, char **argv)
|
||||||
|
{
|
||||||
|
struct args *args;
|
||||||
|
char *ptr;
|
||||||
|
int opt;
|
||||||
|
|
||||||
|
args = xcalloc(1, sizeof *args);
|
||||||
|
if ((args->flags = bit_alloc(SCHAR_MAX)) == NULL)
|
||||||
|
fatal("bit_alloc failed");
|
||||||
|
|
||||||
|
optreset = 1;
|
||||||
|
optind = 1;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, template)) != -1) {
|
||||||
|
if (opt < 0 || opt >= SCHAR_MAX)
|
||||||
|
continue;
|
||||||
|
if (opt == '?' || (ptr = strchr(template, opt)) == NULL) {
|
||||||
|
xfree(args->flags);
|
||||||
|
xfree(args);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
bit_set(args->flags, opt);
|
||||||
|
if (ptr[1] == ':') {
|
||||||
|
if (args->values[opt] != NULL)
|
||||||
|
xfree(args->values[opt]);
|
||||||
|
args->values[opt] = xstrdup(optarg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
argc -= optind;
|
||||||
|
argv += optind;
|
||||||
|
|
||||||
|
args->argc = argc;
|
||||||
|
args->argv = cmd_copy_argv(argc, argv);
|
||||||
|
|
||||||
|
return (args);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Free an arguments set. */
|
||||||
|
void
|
||||||
|
args_free(struct args *args)
|
||||||
|
{
|
||||||
|
u_int i;
|
||||||
|
|
||||||
|
cmd_free_argv(args->argc, args->argv);
|
||||||
|
|
||||||
|
for (i = 0; i < SCHAR_MAX; i++) {
|
||||||
|
if (args->values[i] != NULL)
|
||||||
|
xfree(args->values[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
xfree(args->flags);
|
||||||
|
xfree(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Print a set of arguments. */
|
||||||
|
size_t
|
||||||
|
args_print(struct args *args, char *buf, size_t len)
|
||||||
|
{
|
||||||
|
size_t off;
|
||||||
|
int i;
|
||||||
|
const char *quotes;
|
||||||
|
|
||||||
|
/* There must be at least one byte at the start. */
|
||||||
|
if (len == 0)
|
||||||
|
return (0);
|
||||||
|
off = 0;
|
||||||
|
|
||||||
|
/* Process the flags first. */
|
||||||
|
buf[off++] = '-';
|
||||||
|
for (i = 0; i < SCHAR_MAX; i++) {
|
||||||
|
if (!bit_test(args->flags, i) || args->values[i] != NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (off == len - 1) {
|
||||||
|
buf[off] = '\0';
|
||||||
|
return (len);
|
||||||
|
}
|
||||||
|
buf[off++] = i;
|
||||||
|
buf[off] = '\0';
|
||||||
|
}
|
||||||
|
if (off == 1)
|
||||||
|
buf[--off] = '\0';
|
||||||
|
|
||||||
|
/* Then the flags with arguments. */
|
||||||
|
for (i = 0; i < SCHAR_MAX; i++) {
|
||||||
|
if (!bit_test(args->flags, i) || args->values[i] == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (off >= len) {
|
||||||
|
/* snprintf will have zero terminated. */
|
||||||
|
return (len);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strchr(args->values[i], ' ') != NULL)
|
||||||
|
quotes = "\"";
|
||||||
|
else
|
||||||
|
quotes = "";
|
||||||
|
off += xsnprintf(buf + off, len - off, "%s-%c %s%s%s",
|
||||||
|
off != 0 ? " " : "", i, quotes, args->values[i], quotes);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* And finally the argument vector. */
|
||||||
|
for (i = 0; i < args->argc; i++) {
|
||||||
|
if (off >= len) {
|
||||||
|
/* snprintf will have zero terminated. */
|
||||||
|
return (len);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strchr(args->argv[i], ' ') != NULL)
|
||||||
|
quotes = "\"";
|
||||||
|
else
|
||||||
|
quotes = "";
|
||||||
|
off += xsnprintf(buf + off, len - off, "%s%s%s%s",
|
||||||
|
off != 0 ? " " : "", quotes, args->argv[i], quotes);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (off);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return if an argument is present. */
|
||||||
|
int
|
||||||
|
args_has(struct args *args, u_char ch)
|
||||||
|
{
|
||||||
|
return (bit_test(args->flags, ch));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set argument value. */
|
||||||
|
void
|
||||||
|
args_set(struct args *args, u_char ch, const char *value)
|
||||||
|
{
|
||||||
|
if (args->values[ch] != NULL)
|
||||||
|
xfree(args->values[ch]);
|
||||||
|
if (value != NULL)
|
||||||
|
args->values[ch] = xstrdup(value);
|
||||||
|
else
|
||||||
|
args->values[ch] = NULL;
|
||||||
|
bit_set(args->flags, ch);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get argument value. Will be NULL if it isn't present. */
|
||||||
|
const char *
|
||||||
|
args_get(struct args *args, u_char ch)
|
||||||
|
{
|
||||||
|
return (args->values[ch]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Convert an argument value to a number. */
|
||||||
|
long long
|
||||||
|
args_strtonum(struct args *args,
|
||||||
|
u_char ch, long long minval, long long maxval, char **cause)
|
||||||
|
{
|
||||||
|
const char *errstr;
|
||||||
|
long long ll;
|
||||||
|
|
||||||
|
if (!args_has(args, ch)) {
|
||||||
|
*cause = xstrdup("missing");
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
ll = strtonum(args->values[ch], minval, maxval, &errstr);
|
||||||
|
if (errstr != NULL) {
|
||||||
|
*cause = xstrdup(errstr);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
*cause = NULL;
|
||||||
|
return (ll);
|
||||||
|
}
|
121
external/bsd/tmux/dist/array.h
vendored
Normal file
121
external/bsd/tmux/dist/array.h
vendored
Normal file
|
@ -0,0 +1,121 @@
|
||||||
|
/* $Id: array.h,v 1.1.1.2 2011/08/17 18:40:05 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2006 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ARRAY_H
|
||||||
|
#define ARRAY_H
|
||||||
|
|
||||||
|
#define ARRAY_INITIALIZER { NULL, 0, 0 }
|
||||||
|
|
||||||
|
#define ARRAY_DECL(n, c) \
|
||||||
|
struct n { \
|
||||||
|
c *list; \
|
||||||
|
u_int num; \
|
||||||
|
size_t space; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define ARRAY_ITEM(a, i) ((a)->list[i])
|
||||||
|
#define ARRAY_ITEMSIZE(a) (sizeof *(a)->list)
|
||||||
|
#define ARRAY_INITIALSPACE(a) (10 * ARRAY_ITEMSIZE(a))
|
||||||
|
|
||||||
|
#define ARRAY_ENSURE(a, n) do { \
|
||||||
|
if (UINT_MAX - (n) < (a)->num) \
|
||||||
|
fatalx("number too big"); \
|
||||||
|
if (SIZE_MAX / ((a)->num + (n)) < ARRAY_ITEMSIZE(a)) \
|
||||||
|
fatalx("size too big"); \
|
||||||
|
if ((a)->space == 0) { \
|
||||||
|
(a)->space = ARRAY_INITIALSPACE(a); \
|
||||||
|
(a)->list = xrealloc((a)->list, 1, (a)->space); \
|
||||||
|
} \
|
||||||
|
while ((a)->space <= ((a)->num + (n)) * ARRAY_ITEMSIZE(a)) { \
|
||||||
|
(a)->list = xrealloc((a)->list, 2, (a)->space); \
|
||||||
|
(a)->space *= 2; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define ARRAY_EMPTY(a) (((void *) (a)) == NULL || (a)->num == 0)
|
||||||
|
#define ARRAY_LENGTH(a) ((a)->num)
|
||||||
|
#define ARRAY_DATA(a) ((a)->list)
|
||||||
|
|
||||||
|
#define ARRAY_FIRST(a) ARRAY_ITEM(a, 0)
|
||||||
|
#define ARRAY_LAST(a) ARRAY_ITEM(a, (a)->num - 1)
|
||||||
|
|
||||||
|
#define ARRAY_INIT(a) do { \
|
||||||
|
(a)->num = 0; \
|
||||||
|
(a)->list = NULL; \
|
||||||
|
(a)->space = 0; \
|
||||||
|
} while (0)
|
||||||
|
#define ARRAY_CLEAR(a) do { \
|
||||||
|
(a)->num = 0; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define ARRAY_SET(a, i, s) do { \
|
||||||
|
(a)->list[i] = s; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define ARRAY_ADD(a, s) do { \
|
||||||
|
ARRAY_ENSURE(a, 1); \
|
||||||
|
(a)->list[(a)->num] = s; \
|
||||||
|
(a)->num++; \
|
||||||
|
} while (0)
|
||||||
|
#define ARRAY_INSERT(a, i, s) do { \
|
||||||
|
ARRAY_ENSURE(a, 1); \
|
||||||
|
if ((i) < (a)->num) { \
|
||||||
|
memmove((a)->list + (i) + 1, (a)->list + (i), \
|
||||||
|
ARRAY_ITEMSIZE(a) * ((a)->num - (i))); \
|
||||||
|
} \
|
||||||
|
(a)->list[i] = s; \
|
||||||
|
(a)->num++; \
|
||||||
|
} while (0)
|
||||||
|
#define ARRAY_REMOVE(a, i) do { \
|
||||||
|
if ((i) < (a)->num - 1) { \
|
||||||
|
memmove((a)->list + (i), (a)->list + (i) + 1, \
|
||||||
|
ARRAY_ITEMSIZE(a) * ((a)->num - (i) - 1)); \
|
||||||
|
} \
|
||||||
|
(a)->num--; \
|
||||||
|
if ((a)->num == 0) \
|
||||||
|
ARRAY_FREE(a); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define ARRAY_EXPAND(a, n) do { \
|
||||||
|
ARRAY_ENSURE(a, n); \
|
||||||
|
(a)->num += n; \
|
||||||
|
} while (0)
|
||||||
|
#define ARRAY_TRUNC(a, n) do { \
|
||||||
|
if ((a)->num > n) \
|
||||||
|
(a)->num -= n; \
|
||||||
|
else \
|
||||||
|
ARRAY_FREE(a); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define ARRAY_CONCAT(a, b) do { \
|
||||||
|
ARRAY_ENSURE(a, (b)->num); \
|
||||||
|
memcpy((a)->list + (a)->num, (b)->list, (b)->num * ARRAY_ITEMSIZE(a)); \
|
||||||
|
(a)->num += (b)->num; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define ARRAY_FREE(a) do { \
|
||||||
|
if ((a)->list != NULL) \
|
||||||
|
xfree((a)->list); \
|
||||||
|
ARRAY_INIT(a); \
|
||||||
|
} while (0)
|
||||||
|
#define ARRAY_FREEALL(a) do { \
|
||||||
|
ARRAY_FREE(a); \
|
||||||
|
xfree(a); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#endif
|
93
external/bsd/tmux/dist/attributes.c
vendored
Normal file
93
external/bsd/tmux/dist/attributes.c
vendored
Normal file
|
@ -0,0 +1,93 @@
|
||||||
|
/* $Id: attributes.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2009 Joshua Elsasser <josh@elsasser.org>
|
||||||
|
*
|
||||||
|
* 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 <string.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
const char *
|
||||||
|
attributes_tostring(u_char attr)
|
||||||
|
{
|
||||||
|
static char buf[128];
|
||||||
|
|
||||||
|
if (attr == 0)
|
||||||
|
return ("none");
|
||||||
|
|
||||||
|
buf[0] = '\0';
|
||||||
|
if (attr & GRID_ATTR_BRIGHT)
|
||||||
|
strlcat(buf, "bright,", sizeof (buf));
|
||||||
|
if (attr & GRID_ATTR_DIM)
|
||||||
|
strlcat(buf, "dim,", sizeof (buf));
|
||||||
|
if (attr & GRID_ATTR_UNDERSCORE)
|
||||||
|
strlcat(buf, "underscore,", sizeof (buf));
|
||||||
|
if (attr & GRID_ATTR_BLINK)
|
||||||
|
strlcat(buf, "blink,", sizeof (buf));
|
||||||
|
if (attr & GRID_ATTR_REVERSE)
|
||||||
|
strlcat(buf, "reverse,", sizeof (buf));
|
||||||
|
if (attr & GRID_ATTR_HIDDEN)
|
||||||
|
strlcat(buf, "hidden,", sizeof (buf));
|
||||||
|
if (attr & GRID_ATTR_ITALICS)
|
||||||
|
strlcat(buf, "italics,", sizeof (buf));
|
||||||
|
if (*buf != '\0')
|
||||||
|
*(strrchr(buf, ',')) = '\0';
|
||||||
|
|
||||||
|
return (buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
attributes_fromstring(const char *str)
|
||||||
|
{
|
||||||
|
const char delimiters[] = " ,|";
|
||||||
|
u_char attr;
|
||||||
|
size_t end;
|
||||||
|
|
||||||
|
if (*str == '\0' || strcspn(str, delimiters) == 0)
|
||||||
|
return (-1);
|
||||||
|
if (strchr(delimiters, str[strlen(str) - 1]) != NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
if (strcasecmp(str, "default") == 0 || strcasecmp(str, "none") == 0)
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
attr = 0;
|
||||||
|
do {
|
||||||
|
end = strcspn(str, delimiters);
|
||||||
|
if ((end == 6 && strncasecmp(str, "bright", end) == 0) ||
|
||||||
|
(end == 4 && strncasecmp(str, "bold", end) == 0))
|
||||||
|
attr |= GRID_ATTR_BRIGHT;
|
||||||
|
else if (end == 3 && strncasecmp(str, "dim", end) == 0)
|
||||||
|
attr |= GRID_ATTR_DIM;
|
||||||
|
else if (end == 10 && strncasecmp(str, "underscore", end) == 0)
|
||||||
|
attr |= GRID_ATTR_UNDERSCORE;
|
||||||
|
else if (end == 5 && strncasecmp(str, "blink", end) == 0)
|
||||||
|
attr |= GRID_ATTR_BLINK;
|
||||||
|
else if (end == 7 && strncasecmp(str, "reverse", end) == 0)
|
||||||
|
attr |= GRID_ATTR_REVERSE;
|
||||||
|
else if (end == 6 && strncasecmp(str, "hidden", end) == 0)
|
||||||
|
attr |= GRID_ATTR_HIDDEN;
|
||||||
|
else if (end == 7 && strncasecmp(str, "italics", end) == 0)
|
||||||
|
attr |= GRID_ATTR_ITALICS;
|
||||||
|
else
|
||||||
|
return (-1);
|
||||||
|
str += end + strspn(str + end, delimiters);
|
||||||
|
} while (*str != '\0');
|
||||||
|
|
||||||
|
return (attr);
|
||||||
|
}
|
143
external/bsd/tmux/dist/cfg.c
vendored
Normal file
143
external/bsd/tmux/dist/cfg.c
vendored
Normal file
|
@ -0,0 +1,143 @@
|
||||||
|
/* $Id: cfg.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008 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 <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Config file parser. Pretty quick and simple, each line is parsed into a
|
||||||
|
* argv array and executed as a command.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void printflike2 cfg_print(struct cmd_ctx *, const char *, ...);
|
||||||
|
void printflike2 cfg_error(struct cmd_ctx *, const char *, ...);
|
||||||
|
|
||||||
|
char *cfg_cause;
|
||||||
|
int cfg_finished;
|
||||||
|
struct causelist cfg_causes = ARRAY_INITIALIZER;
|
||||||
|
|
||||||
|
/* ARGSUSED */
|
||||||
|
void printflike2
|
||||||
|
cfg_print(unused struct cmd_ctx *ctx, unused const char *fmt, ...)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ARGSUSED */
|
||||||
|
void printflike2
|
||||||
|
cfg_error(unused struct cmd_ctx *ctx, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
xvasprintf(&cfg_cause, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
void printflike2
|
||||||
|
cfg_add_cause(struct causelist *causes, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
char *cause;
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
xvasprintf(&cause, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
ARRAY_ADD(causes, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Load configuration file. Returns -1 for an error with a list of messages in
|
||||||
|
* causes. Note that causes must be initialised by the caller!
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes)
|
||||||
|
{
|
||||||
|
FILE *f;
|
||||||
|
u_int n;
|
||||||
|
char *buf, *line, *cause;
|
||||||
|
size_t len;
|
||||||
|
struct cmd_list *cmdlist;
|
||||||
|
struct cmd_ctx ctx;
|
||||||
|
int retval;
|
||||||
|
|
||||||
|
if ((f = fopen(path, "rb")) == NULL) {
|
||||||
|
cfg_add_cause(causes, "%s: %s", path, strerror(errno));
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
n = 0;
|
||||||
|
|
||||||
|
line = NULL;
|
||||||
|
retval = 0;
|
||||||
|
while ((buf = fgetln(f, &len))) {
|
||||||
|
if (buf[len - 1] == '\n')
|
||||||
|
buf[len - 1] = '\0';
|
||||||
|
else {
|
||||||
|
line = xrealloc(line, 1, len + 1);
|
||||||
|
memcpy(line, buf, len);
|
||||||
|
line[len] = '\0';
|
||||||
|
buf = line;
|
||||||
|
}
|
||||||
|
n++;
|
||||||
|
|
||||||
|
if (cmd_string_parse(buf, &cmdlist, &cause) != 0) {
|
||||||
|
if (cause == NULL)
|
||||||
|
continue;
|
||||||
|
cfg_add_cause(causes, "%s: %u: %s", path, n, cause);
|
||||||
|
xfree(cause);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (cmdlist == NULL)
|
||||||
|
continue;
|
||||||
|
cfg_cause = NULL;
|
||||||
|
|
||||||
|
if (ctxin == NULL) {
|
||||||
|
ctx.msgdata = NULL;
|
||||||
|
ctx.curclient = NULL;
|
||||||
|
ctx.cmdclient = NULL;
|
||||||
|
} else {
|
||||||
|
ctx.msgdata = ctxin->msgdata;
|
||||||
|
ctx.curclient = ctxin->curclient;
|
||||||
|
ctx.cmdclient = ctxin->cmdclient;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.error = cfg_error;
|
||||||
|
ctx.print = cfg_print;
|
||||||
|
ctx.info = cfg_print;
|
||||||
|
|
||||||
|
cfg_cause = NULL;
|
||||||
|
if (cmd_list_exec(cmdlist, &ctx) == 1)
|
||||||
|
retval = 1;
|
||||||
|
cmd_list_free(cmdlist);
|
||||||
|
if (cfg_cause != NULL) {
|
||||||
|
cfg_add_cause(causes, "%s: %d: %s", path, n, cfg_cause);
|
||||||
|
xfree(cfg_cause);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (line != NULL)
|
||||||
|
xfree(line);
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
|
return (retval);
|
||||||
|
}
|
512
external/bsd/tmux/dist/client.c
vendored
Normal file
512
external/bsd/tmux/dist/client.c
vendored
Normal file
|
@ -0,0 +1,512 @@
|
||||||
|
/* $Id: client.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 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/socket.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/un.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <event.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <pwd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
struct imsgbuf client_ibuf;
|
||||||
|
struct event client_event;
|
||||||
|
const char *client_exitmsg;
|
||||||
|
int client_exitval;
|
||||||
|
enum msgtype client_exittype;
|
||||||
|
int client_attached;
|
||||||
|
|
||||||
|
int client_connect(char *, int);
|
||||||
|
void client_send_identify(int);
|
||||||
|
void client_send_environ(void);
|
||||||
|
void client_write_server(enum msgtype, void *, size_t);
|
||||||
|
void client_update_event(void);
|
||||||
|
void client_signal(int, short, void *);
|
||||||
|
void client_callback(int, short, void *);
|
||||||
|
int client_dispatch_attached(void);
|
||||||
|
int client_dispatch_wait(void *);
|
||||||
|
|
||||||
|
/* Connect client to server. */
|
||||||
|
int
|
||||||
|
client_connect(char *path, int start_server)
|
||||||
|
{
|
||||||
|
struct sockaddr_un sa;
|
||||||
|
size_t size;
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
memset(&sa, 0, sizeof sa);
|
||||||
|
sa.sun_family = AF_UNIX;
|
||||||
|
size = strlcpy(sa.sun_path, path, sizeof sa.sun_path);
|
||||||
|
if (size >= sizeof sa.sun_path) {
|
||||||
|
errno = ENAMETOOLONG;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef __minix
|
||||||
|
if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
|
||||||
|
#else
|
||||||
|
if ((fd = socket(AF_UNIX, SOCK_SEQPACKET, 0)) == -1)
|
||||||
|
#endif
|
||||||
|
fatal("socket failed");
|
||||||
|
|
||||||
|
if (connect(fd, (struct sockaddr *) &sa, SUN_LEN(&sa)) == -1) {
|
||||||
|
if (!start_server)
|
||||||
|
goto failed;
|
||||||
|
switch (errno) {
|
||||||
|
case ECONNREFUSED:
|
||||||
|
if (unlink(path) != 0)
|
||||||
|
goto failed;
|
||||||
|
/* FALLTHROUGH */
|
||||||
|
case ENOENT:
|
||||||
|
if ((fd = server_start()) == -1)
|
||||||
|
goto failed;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
goto failed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setblocking(fd, 0);
|
||||||
|
return (fd);
|
||||||
|
|
||||||
|
failed:
|
||||||
|
close(fd);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Client main loop. */
|
||||||
|
int
|
||||||
|
client_main(int argc, char **argv, int flags)
|
||||||
|
{
|
||||||
|
struct cmd *cmd;
|
||||||
|
struct cmd_list *cmdlist;
|
||||||
|
struct msg_command_data cmddata;
|
||||||
|
int cmdflags, fd;
|
||||||
|
pid_t ppid;
|
||||||
|
enum msgtype msg;
|
||||||
|
char *cause;
|
||||||
|
|
||||||
|
/* Set up the initial command. */
|
||||||
|
cmdflags = 0;
|
||||||
|
if (shell_cmd != NULL) {
|
||||||
|
msg = MSG_SHELL;
|
||||||
|
cmdflags = CMD_STARTSERVER;
|
||||||
|
} else if (argc == 0) {
|
||||||
|
msg = MSG_COMMAND;
|
||||||
|
cmdflags = CMD_STARTSERVER|CMD_SENDENVIRON|CMD_CANTNEST;
|
||||||
|
} else {
|
||||||
|
msg = MSG_COMMAND;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* It sucks parsing the command string twice (in client and
|
||||||
|
* later in server) but it is necessary to get the start server
|
||||||
|
* flag.
|
||||||
|
*/
|
||||||
|
if ((cmdlist = cmd_list_parse(argc, argv, &cause)) == NULL) {
|
||||||
|
log_warnx("%s", cause);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
cmdflags &= ~CMD_STARTSERVER;
|
||||||
|
TAILQ_FOREACH(cmd, &cmdlist->list, qentry) {
|
||||||
|
if (cmd->entry->flags & CMD_STARTSERVER)
|
||||||
|
cmdflags |= CMD_STARTSERVER;
|
||||||
|
if (cmd->entry->flags & CMD_SENDENVIRON)
|
||||||
|
cmdflags |= CMD_SENDENVIRON;
|
||||||
|
if (cmd->entry->flags & CMD_CANTNEST)
|
||||||
|
cmdflags |= CMD_CANTNEST;
|
||||||
|
}
|
||||||
|
cmd_list_free(cmdlist);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check if this could be a nested session, if the command can't nest:
|
||||||
|
* if the socket path matches $TMUX, this is probably the same server.
|
||||||
|
*/
|
||||||
|
if (shell_cmd == NULL && environ_path != NULL &&
|
||||||
|
cmdflags & CMD_CANTNEST && strcmp(socket_path, environ_path) == 0) {
|
||||||
|
log_warnx("sessions should be nested with care. "
|
||||||
|
"unset $TMUX to force.");
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Initialise the client socket and start the server. */
|
||||||
|
fd = client_connect(socket_path, cmdflags & CMD_STARTSERVER);
|
||||||
|
if (fd == -1) {
|
||||||
|
log_warn("failed to connect to server");
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set process title, log and signals now this is the client. */
|
||||||
|
#ifdef HAVE_SETPROCTITLE
|
||||||
|
setproctitle("client (%s)", socket_path);
|
||||||
|
#endif
|
||||||
|
logfile("client");
|
||||||
|
|
||||||
|
/* Create imsg. */
|
||||||
|
imsg_init(&client_ibuf, fd);
|
||||||
|
event_set(&client_event, fd, EV_READ, client_callback, shell_cmd);
|
||||||
|
|
||||||
|
/* Establish signal handlers. */
|
||||||
|
set_signals(client_signal);
|
||||||
|
|
||||||
|
/* Send initial environment. */
|
||||||
|
if (cmdflags & CMD_SENDENVIRON)
|
||||||
|
client_send_environ();
|
||||||
|
client_send_identify(flags);
|
||||||
|
|
||||||
|
/* Send first command. */
|
||||||
|
if (msg == MSG_COMMAND) {
|
||||||
|
/* Fill in command line arguments. */
|
||||||
|
cmddata.pid = environ_pid;
|
||||||
|
cmddata.idx = environ_idx;
|
||||||
|
|
||||||
|
/* Prepare command for server. */
|
||||||
|
cmddata.argc = argc;
|
||||||
|
if (cmd_pack_argv(
|
||||||
|
argc, argv, cmddata.argv, sizeof cmddata.argv) != 0) {
|
||||||
|
log_warnx("command too long");
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
client_write_server(msg, &cmddata, sizeof cmddata);
|
||||||
|
} else if (msg == MSG_SHELL)
|
||||||
|
client_write_server(msg, NULL, 0);
|
||||||
|
|
||||||
|
/* Set the event and dispatch. */
|
||||||
|
client_update_event();
|
||||||
|
event_dispatch();
|
||||||
|
|
||||||
|
/* Print the exit message, if any, and exit. */
|
||||||
|
if (client_attached) {
|
||||||
|
if (client_exitmsg != NULL && !login_shell)
|
||||||
|
printf("[%s]\n", client_exitmsg);
|
||||||
|
|
||||||
|
ppid = getppid();
|
||||||
|
if (client_exittype == MSG_DETACHKILL && ppid > 1)
|
||||||
|
kill(ppid, SIGHUP);
|
||||||
|
}
|
||||||
|
return (client_exitval);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Send identify message to server with the file descriptors. */
|
||||||
|
void
|
||||||
|
client_send_identify(int flags)
|
||||||
|
{
|
||||||
|
struct msg_identify_data data;
|
||||||
|
char *term;
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
data.flags = flags;
|
||||||
|
|
||||||
|
if (getcwd(data.cwd, sizeof data.cwd) == NULL)
|
||||||
|
*data.cwd = '\0';
|
||||||
|
|
||||||
|
term = getenv("TERM");
|
||||||
|
if (term == NULL ||
|
||||||
|
strlcpy(data.term, term, sizeof data.term) >= sizeof data.term)
|
||||||
|
*data.term = '\0';
|
||||||
|
|
||||||
|
if ((fd = dup(STDIN_FILENO)) == -1)
|
||||||
|
fatal("dup failed");
|
||||||
|
imsg_compose(&client_ibuf,
|
||||||
|
MSG_IDENTIFY, PROTOCOL_VERSION, -1, fd, &data, sizeof data);
|
||||||
|
|
||||||
|
if ((fd = dup(STDOUT_FILENO)) == -1)
|
||||||
|
fatal("dup failed");
|
||||||
|
imsg_compose(&client_ibuf,
|
||||||
|
MSG_STDOUT, PROTOCOL_VERSION, -1, fd, NULL, 0);
|
||||||
|
|
||||||
|
if ((fd = dup(STDERR_FILENO)) == -1)
|
||||||
|
fatal("dup failed");
|
||||||
|
imsg_compose(&client_ibuf,
|
||||||
|
MSG_STDERR, PROTOCOL_VERSION, -1, fd, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Forward entire environment to server. */
|
||||||
|
void
|
||||||
|
client_send_environ(void)
|
||||||
|
{
|
||||||
|
struct msg_environ_data data;
|
||||||
|
char **var;
|
||||||
|
|
||||||
|
for (var = environ; *var != NULL; var++) {
|
||||||
|
if (strlcpy(data.var, *var, sizeof data.var) >= sizeof data.var)
|
||||||
|
continue;
|
||||||
|
client_write_server(MSG_ENVIRON, &data, sizeof data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Write a message to the server without a file descriptor. */
|
||||||
|
void
|
||||||
|
client_write_server(enum msgtype type, void *buf, size_t len)
|
||||||
|
{
|
||||||
|
imsg_compose(&client_ibuf, type, PROTOCOL_VERSION, -1, -1, buf, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Update client event based on whether it needs to read or read and write. */
|
||||||
|
void
|
||||||
|
client_update_event(void)
|
||||||
|
{
|
||||||
|
short events;
|
||||||
|
|
||||||
|
event_del(&client_event);
|
||||||
|
events = EV_READ;
|
||||||
|
if (client_ibuf.w.queued > 0)
|
||||||
|
events |= EV_WRITE;
|
||||||
|
event_set(
|
||||||
|
&client_event, client_ibuf.fd, events, client_callback, shell_cmd);
|
||||||
|
event_add(&client_event, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Callback to handle signals in the client. */
|
||||||
|
/* ARGSUSED */
|
||||||
|
void
|
||||||
|
client_signal(int sig, unused short events, unused void *data)
|
||||||
|
{
|
||||||
|
struct sigaction sigact;
|
||||||
|
int status;
|
||||||
|
|
||||||
|
if (!client_attached) {
|
||||||
|
switch (sig) {
|
||||||
|
case SIGCHLD:
|
||||||
|
waitpid(WAIT_ANY, &status, WNOHANG);
|
||||||
|
break;
|
||||||
|
case SIGTERM:
|
||||||
|
event_loopexit(NULL);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
switch (sig) {
|
||||||
|
case SIGHUP:
|
||||||
|
client_exitmsg = "lost tty";
|
||||||
|
client_exitval = 1;
|
||||||
|
client_write_server(MSG_EXITING, NULL, 0);
|
||||||
|
break;
|
||||||
|
case SIGTERM:
|
||||||
|
client_exitmsg = "terminated";
|
||||||
|
client_exitval = 1;
|
||||||
|
client_write_server(MSG_EXITING, NULL, 0);
|
||||||
|
break;
|
||||||
|
case SIGWINCH:
|
||||||
|
client_write_server(MSG_RESIZE, NULL, 0);
|
||||||
|
break;
|
||||||
|
case SIGCONT:
|
||||||
|
memset(&sigact, 0, sizeof sigact);
|
||||||
|
sigemptyset(&sigact.sa_mask);
|
||||||
|
sigact.sa_flags = SA_RESTART;
|
||||||
|
sigact.sa_handler = SIG_IGN;
|
||||||
|
if (sigaction(SIGTSTP, &sigact, NULL) != 0)
|
||||||
|
fatal("sigaction failed");
|
||||||
|
client_write_server(MSG_WAKEUP, NULL, 0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
client_update_event();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Callback for client imsg read events. */
|
||||||
|
/* ARGSUSED */
|
||||||
|
void
|
||||||
|
client_callback(unused int fd, short events, void *data)
|
||||||
|
{
|
||||||
|
ssize_t n;
|
||||||
|
int retval;
|
||||||
|
|
||||||
|
if (events & EV_READ) {
|
||||||
|
if ((n = imsg_read(&client_ibuf)) == -1 || n == 0)
|
||||||
|
goto lost_server;
|
||||||
|
if (client_attached)
|
||||||
|
retval = client_dispatch_attached();
|
||||||
|
else
|
||||||
|
retval = client_dispatch_wait(data);
|
||||||
|
if (retval != 0) {
|
||||||
|
event_loopexit(NULL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (events & EV_WRITE) {
|
||||||
|
if (msgbuf_write(&client_ibuf.w) < 0)
|
||||||
|
goto lost_server;
|
||||||
|
}
|
||||||
|
|
||||||
|
client_update_event();
|
||||||
|
return;
|
||||||
|
|
||||||
|
lost_server:
|
||||||
|
client_exitmsg = "lost server";
|
||||||
|
client_exitval = 1;
|
||||||
|
event_loopexit(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Dispatch imsgs when in wait state (before MSG_READY). */
|
||||||
|
int
|
||||||
|
client_dispatch_wait(void *data)
|
||||||
|
{
|
||||||
|
struct imsg imsg;
|
||||||
|
ssize_t n, datalen;
|
||||||
|
struct msg_shell_data shelldata;
|
||||||
|
struct msg_exit_data exitdata;
|
||||||
|
const char *shellcmd = data;
|
||||||
|
|
||||||
|
if ((n = imsg_read(&client_ibuf)) == -1 || n == 0)
|
||||||
|
fatalx("imsg_read failed");
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
if ((n = imsg_get(&client_ibuf, &imsg)) == -1)
|
||||||
|
fatalx("imsg_get failed");
|
||||||
|
if (n == 0)
|
||||||
|
return (0);
|
||||||
|
datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
|
||||||
|
|
||||||
|
switch (imsg.hdr.type) {
|
||||||
|
case MSG_EXIT:
|
||||||
|
case MSG_SHUTDOWN:
|
||||||
|
if (datalen != sizeof exitdata) {
|
||||||
|
if (datalen != 0)
|
||||||
|
fatalx("bad MSG_EXIT size");
|
||||||
|
} else {
|
||||||
|
memcpy(&exitdata, imsg.data, sizeof exitdata);
|
||||||
|
client_exitval = exitdata.retcode;
|
||||||
|
}
|
||||||
|
imsg_free(&imsg);
|
||||||
|
return (-1);
|
||||||
|
case MSG_READY:
|
||||||
|
if (datalen != 0)
|
||||||
|
fatalx("bad MSG_READY size");
|
||||||
|
|
||||||
|
client_attached = 1;
|
||||||
|
break;
|
||||||
|
case MSG_VERSION:
|
||||||
|
if (datalen != 0)
|
||||||
|
fatalx("bad MSG_VERSION size");
|
||||||
|
|
||||||
|
log_warnx("protocol version mismatch (client %u, "
|
||||||
|
"server %u)", PROTOCOL_VERSION, imsg.hdr.peerid);
|
||||||
|
client_exitval = 1;
|
||||||
|
|
||||||
|
imsg_free(&imsg);
|
||||||
|
return (-1);
|
||||||
|
case MSG_SHELL:
|
||||||
|
if (datalen != sizeof shelldata)
|
||||||
|
fatalx("bad MSG_SHELL size");
|
||||||
|
memcpy(&shelldata, imsg.data, sizeof shelldata);
|
||||||
|
shelldata.shell[(sizeof shelldata.shell) - 1] = '\0';
|
||||||
|
|
||||||
|
clear_signals(0);
|
||||||
|
|
||||||
|
shell_exec(shelldata.shell, shellcmd);
|
||||||
|
/* NOTREACHED */
|
||||||
|
default:
|
||||||
|
fatalx("unexpected message");
|
||||||
|
}
|
||||||
|
|
||||||
|
imsg_free(&imsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Dispatch imsgs in attached state (after MSG_READY). */
|
||||||
|
/* ARGSUSED */
|
||||||
|
int
|
||||||
|
client_dispatch_attached(void)
|
||||||
|
{
|
||||||
|
struct imsg imsg;
|
||||||
|
struct msg_lock_data lockdata;
|
||||||
|
struct sigaction sigact;
|
||||||
|
ssize_t n, datalen;
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
if ((n = imsg_get(&client_ibuf, &imsg)) == -1)
|
||||||
|
fatalx("imsg_get failed");
|
||||||
|
if (n == 0)
|
||||||
|
return (0);
|
||||||
|
datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
|
||||||
|
|
||||||
|
log_debug("client got %d", imsg.hdr.type);
|
||||||
|
switch (imsg.hdr.type) {
|
||||||
|
case MSG_DETACHKILL:
|
||||||
|
case MSG_DETACH:
|
||||||
|
if (datalen != 0)
|
||||||
|
fatalx("bad MSG_DETACH size");
|
||||||
|
|
||||||
|
client_exittype = imsg.hdr.type;
|
||||||
|
if (imsg.hdr.type == MSG_DETACHKILL)
|
||||||
|
client_exitmsg = "detached and SIGHUP";
|
||||||
|
else
|
||||||
|
client_exitmsg = "detached";
|
||||||
|
client_write_server(MSG_EXITING, NULL, 0);
|
||||||
|
break;
|
||||||
|
case MSG_EXIT:
|
||||||
|
if (datalen != 0 &&
|
||||||
|
datalen != sizeof (struct msg_exit_data))
|
||||||
|
fatalx("bad MSG_EXIT size");
|
||||||
|
|
||||||
|
client_write_server(MSG_EXITING, NULL, 0);
|
||||||
|
client_exitmsg = "exited";
|
||||||
|
break;
|
||||||
|
case MSG_EXITED:
|
||||||
|
if (datalen != 0)
|
||||||
|
fatalx("bad MSG_EXITED size");
|
||||||
|
|
||||||
|
imsg_free(&imsg);
|
||||||
|
return (-1);
|
||||||
|
case MSG_SHUTDOWN:
|
||||||
|
if (datalen != 0)
|
||||||
|
fatalx("bad MSG_SHUTDOWN size");
|
||||||
|
|
||||||
|
client_write_server(MSG_EXITING, NULL, 0);
|
||||||
|
client_exitmsg = "server exited";
|
||||||
|
client_exitval = 1;
|
||||||
|
break;
|
||||||
|
case MSG_SUSPEND:
|
||||||
|
if (datalen != 0)
|
||||||
|
fatalx("bad MSG_SUSPEND size");
|
||||||
|
|
||||||
|
memset(&sigact, 0, sizeof sigact);
|
||||||
|
sigemptyset(&sigact.sa_mask);
|
||||||
|
sigact.sa_flags = SA_RESTART;
|
||||||
|
sigact.sa_handler = SIG_DFL;
|
||||||
|
if (sigaction(SIGTSTP, &sigact, NULL) != 0)
|
||||||
|
fatal("sigaction failed");
|
||||||
|
kill(getpid(), SIGTSTP);
|
||||||
|
break;
|
||||||
|
case MSG_LOCK:
|
||||||
|
if (datalen != sizeof lockdata)
|
||||||
|
fatalx("bad MSG_LOCK size");
|
||||||
|
memcpy(&lockdata, imsg.data, sizeof lockdata);
|
||||||
|
|
||||||
|
lockdata.cmd[(sizeof lockdata.cmd) - 1] = '\0';
|
||||||
|
system(lockdata.cmd);
|
||||||
|
client_write_server(MSG_UNLOCK, NULL, 0);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fatalx("unexpected message");
|
||||||
|
}
|
||||||
|
|
||||||
|
imsg_free(&imsg);
|
||||||
|
}
|
||||||
|
}
|
159
external/bsd/tmux/dist/clock.c
vendored
Normal file
159
external/bsd/tmux/dist/clock.c
vendored
Normal file
|
@ -0,0 +1,159 @@
|
||||||
|
/* $Id: clock.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
const char clock_table[14][5][5] = {
|
||||||
|
{ { 1,1,1,1,1 }, /* 0 */
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 } },
|
||||||
|
{ { 0,0,0,0,1 }, /* 1 */
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 0,0,0,0,1 } },
|
||||||
|
{ { 1,1,1,1,1 }, /* 2 */
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 },
|
||||||
|
{ 1,0,0,0,0 },
|
||||||
|
{ 1,1,1,1,1 } },
|
||||||
|
{ { 1,1,1,1,1 }, /* 3 */
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 },
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 } },
|
||||||
|
{ { 1,0,0,0,1 }, /* 4 */
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 },
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 0,0,0,0,1 } },
|
||||||
|
{ { 1,1,1,1,1 }, /* 5 */
|
||||||
|
{ 1,0,0,0,0 },
|
||||||
|
{ 1,1,1,1,1 },
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 } },
|
||||||
|
{ { 1,1,1,1,1 }, /* 6 */
|
||||||
|
{ 1,0,0,0,0 },
|
||||||
|
{ 1,1,1,1,1 },
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 } },
|
||||||
|
{ { 1,1,1,1,1 }, /* 7 */
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 0,0,0,0,1 } },
|
||||||
|
{ { 1,1,1,1,1 }, /* 8 */
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 },
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 } },
|
||||||
|
{ { 1,1,1,1,1 }, /* 9 */
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 },
|
||||||
|
{ 0,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 } },
|
||||||
|
{ { 0,0,0,0,0 }, /* : */
|
||||||
|
{ 0,0,1,0,0 },
|
||||||
|
{ 0,0,0,0,0 },
|
||||||
|
{ 0,0,1,0,0 },
|
||||||
|
{ 0,0,0,0,0 } },
|
||||||
|
{ { 1,1,1,1,1 }, /* A */
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 },
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,0,0,0,1 } },
|
||||||
|
{ { 1,1,1,1,1 }, /* P */
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,1,1,1,1 },
|
||||||
|
{ 1,0,0,0,0 },
|
||||||
|
{ 1,0,0,0,0 } },
|
||||||
|
{ { 1,0,0,0,1 }, /* M */
|
||||||
|
{ 1,1,0,1,1 },
|
||||||
|
{ 1,0,1,0,1 },
|
||||||
|
{ 1,0,0,0,1 },
|
||||||
|
{ 1,0,0,0,1 } },
|
||||||
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
clock_draw(struct screen_write_ctx *ctx, int colour, int style)
|
||||||
|
{
|
||||||
|
struct screen *s = ctx->s;
|
||||||
|
struct grid_cell gc;
|
||||||
|
char tim[64], *ptr;
|
||||||
|
time_t t;
|
||||||
|
u_int i, j, x, y, idx;
|
||||||
|
|
||||||
|
t = time(NULL);
|
||||||
|
if (style == 0)
|
||||||
|
strftime(tim, sizeof tim, "%l:%M %p", localtime(&t));
|
||||||
|
else
|
||||||
|
strftime(tim, sizeof tim, "%H:%M", localtime(&t));
|
||||||
|
|
||||||
|
screen_write_clearscreen(ctx);
|
||||||
|
|
||||||
|
if (screen_size_x(s) < 6 * strlen(tim) || screen_size_y(s) < 6) {
|
||||||
|
if (screen_size_x(s) >= strlen(tim) && screen_size_y(s) != 0) {
|
||||||
|
x = (screen_size_x(s) / 2) - (strlen(tim) / 2);
|
||||||
|
y = screen_size_y(s) / 2;
|
||||||
|
screen_write_cursormove(ctx, x, y);
|
||||||
|
|
||||||
|
memcpy(&gc, &grid_default_cell, sizeof gc);
|
||||||
|
colour_set_fg(&gc, colour);
|
||||||
|
screen_write_puts(ctx, &gc, "%s", tim);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
x = (screen_size_x(s) / 2) - 3 * strlen(tim);
|
||||||
|
y = (screen_size_y(s) / 2) - 3;
|
||||||
|
|
||||||
|
memcpy(&gc, &grid_default_cell, sizeof gc);
|
||||||
|
colour_set_bg(&gc, colour);
|
||||||
|
for (ptr = tim; *ptr != '\0'; ptr++) {
|
||||||
|
if (*ptr >= '0' && *ptr <= '9')
|
||||||
|
idx = *ptr - '0';
|
||||||
|
else if (*ptr == ':')
|
||||||
|
idx = 10;
|
||||||
|
else if (*ptr == 'A')
|
||||||
|
idx = 11;
|
||||||
|
else if (*ptr == 'P')
|
||||||
|
idx = 12;
|
||||||
|
else if (*ptr == 'M')
|
||||||
|
idx = 13;
|
||||||
|
else {
|
||||||
|
x += 6;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (j = 0; j < 5; j++) {
|
||||||
|
for (i = 0; i < 5; i++) {
|
||||||
|
screen_write_cursormove(ctx, x + i, y + j);
|
||||||
|
if (clock_table[idx][j][i])
|
||||||
|
screen_write_putc(ctx, &gc, ' ');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
x += 6;
|
||||||
|
}
|
||||||
|
}
|
112
external/bsd/tmux/dist/cmd-attach-session.c
vendored
Normal file
112
external/bsd/tmux/dist/cmd-attach-session.c
vendored
Normal file
|
@ -0,0 +1,112 @@
|
||||||
|
/* $Id: cmd-attach-session.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 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 "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Attach existing session to the current terminal.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_attach_session_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_attach_session_entry = {
|
||||||
|
"attach-session", "attach",
|
||||||
|
"drt:", 0, 0,
|
||||||
|
"[-dr] " CMD_TARGET_SESSION_USAGE,
|
||||||
|
CMD_CANTNEST|CMD_STARTSERVER|CMD_SENDENVIRON,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_attach_session_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct session *s;
|
||||||
|
struct client *c;
|
||||||
|
const char *update;
|
||||||
|
char *overrides, *cause;
|
||||||
|
u_int i;
|
||||||
|
|
||||||
|
if (RB_EMPTY(&sessions)) {
|
||||||
|
ctx->error(ctx, "no sessions");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((s = cmd_find_session(ctx, args_get(args, 't'), 1)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
if (ctx->cmdclient == NULL && ctx->curclient == NULL)
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
if (ctx->cmdclient == NULL) {
|
||||||
|
if (args_has(self->args, 'd')) {
|
||||||
|
/*
|
||||||
|
* Can't use server_write_session in case attaching to
|
||||||
|
* the same session as currently attached to.
|
||||||
|
*/
|
||||||
|
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||||
|
c = ARRAY_ITEM(&clients, i);
|
||||||
|
if (c == NULL || c->session != s)
|
||||||
|
continue;
|
||||||
|
if (c == ctx->curclient)
|
||||||
|
continue;
|
||||||
|
server_write_client(c, MSG_DETACH, NULL, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx->curclient->session = s;
|
||||||
|
session_update_activity(s);
|
||||||
|
server_redraw_client(ctx->curclient);
|
||||||
|
} else {
|
||||||
|
if (!(ctx->cmdclient->flags & CLIENT_TERMINAL)) {
|
||||||
|
ctx->error(ctx, "not a terminal");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
overrides =
|
||||||
|
options_get_string(&s->options, "terminal-overrides");
|
||||||
|
if (tty_open(&ctx->cmdclient->tty, overrides, &cause) != 0) {
|
||||||
|
ctx->error(ctx, "terminal open failed: %s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args_has(self->args, 'r'))
|
||||||
|
ctx->cmdclient->flags |= CLIENT_READONLY;
|
||||||
|
|
||||||
|
if (args_has(self->args, 'd'))
|
||||||
|
server_write_session(s, MSG_DETACH, NULL, 0);
|
||||||
|
|
||||||
|
ctx->cmdclient->session = s;
|
||||||
|
session_update_activity(s);
|
||||||
|
server_write_client(ctx->cmdclient, MSG_READY, NULL, 0);
|
||||||
|
|
||||||
|
update = options_get_string(&s->options, "update-environment");
|
||||||
|
environ_update(update, &ctx->cmdclient->environ, &s->environ);
|
||||||
|
|
||||||
|
server_redraw_client(ctx->cmdclient);
|
||||||
|
}
|
||||||
|
recalculate_sizes();
|
||||||
|
server_update_socket();
|
||||||
|
|
||||||
|
return (1); /* 1 means don't tell command client to exit */
|
||||||
|
}
|
120
external/bsd/tmux/dist/cmd-bind-key.c
vendored
Normal file
120
external/bsd/tmux/dist/cmd-bind-key.c
vendored
Normal file
|
@ -0,0 +1,120 @@
|
||||||
|
/* $Id: cmd-bind-key.c,v 1.1.1.2 2011/08/17 18:40:03 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 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 <string.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Bind a key to a command, this recurses through cmd_*.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_bind_key_check(struct args *);
|
||||||
|
int cmd_bind_key_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
int cmd_bind_key_table(struct cmd *, struct cmd_ctx *, int);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_bind_key_entry = {
|
||||||
|
"bind-key", "bind",
|
||||||
|
"cnrt:", 1, -1,
|
||||||
|
"[-cnr] [-t key-table] key command [arguments]",
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
cmd_bind_key_check,
|
||||||
|
cmd_bind_key_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_bind_key_check(struct args *args)
|
||||||
|
{
|
||||||
|
if (args_has(args, 't')) {
|
||||||
|
if (args->argc != 2)
|
||||||
|
return (-1);
|
||||||
|
} else {
|
||||||
|
if (args->argc < 2)
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_bind_key_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
char *cause;
|
||||||
|
struct cmd_list *cmdlist;
|
||||||
|
int key;
|
||||||
|
|
||||||
|
key = key_string_lookup_string(args->argv[0]);
|
||||||
|
if (key == KEYC_NONE) {
|
||||||
|
ctx->error(ctx, "unknown key: %s", args->argv[0]);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args_has(args, 't'))
|
||||||
|
return (cmd_bind_key_table(self, ctx, key));
|
||||||
|
|
||||||
|
cmdlist = cmd_list_parse(args->argc - 1, args->argv + 1, &cause);
|
||||||
|
if (cmdlist == NULL) {
|
||||||
|
ctx->error(ctx, "%s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!args_has(args, 'n'))
|
||||||
|
key |= KEYC_PREFIX;
|
||||||
|
key_bindings_add(key, args_has(args, 'r'), cmdlist);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_bind_key_table(struct cmd *self, struct cmd_ctx *ctx, int key)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
const char *tablename;
|
||||||
|
const struct mode_key_table *mtab;
|
||||||
|
struct mode_key_binding *mbind, mtmp;
|
||||||
|
enum mode_key_cmd cmd;
|
||||||
|
|
||||||
|
tablename = args_get(args, 't');
|
||||||
|
if ((mtab = mode_key_findtable(tablename)) == NULL) {
|
||||||
|
ctx->error(ctx, "unknown key table: %s", tablename);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd = mode_key_fromstring(mtab->cmdstr, args->argv[1]);
|
||||||
|
if (cmd == MODEKEY_NONE) {
|
||||||
|
ctx->error(ctx, "unknown command: %s", args->argv[1]);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
mtmp.key = key;
|
||||||
|
mtmp.mode = !!args_has(args, 'c');
|
||||||
|
if ((mbind = SPLAY_FIND(mode_key_tree, mtab->tree, &mtmp)) != NULL) {
|
||||||
|
mbind->cmd = cmd;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
mbind = xmalloc(sizeof *mbind);
|
||||||
|
mbind->key = mtmp.key;
|
||||||
|
mbind->mode = mtmp.mode;
|
||||||
|
mbind->cmd = cmd;
|
||||||
|
SPLAY_INSERT(mode_key_tree, mtab->tree, mbind);
|
||||||
|
return (0);
|
||||||
|
}
|
89
external/bsd/tmux/dist/cmd-break-pane.c
vendored
Normal file
89
external/bsd/tmux/dist/cmd-break-pane.c
vendored
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
/* $Id: cmd-break-pane.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 <stdlib.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Break pane off into a window.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_break_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_break_pane_entry = {
|
||||||
|
"break-pane", "breakp",
|
||||||
|
"dt:", 0, 0,
|
||||||
|
"[-d] " CMD_TARGET_PANE_USAGE,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_break_pane_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_break_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct winlink *wl;
|
||||||
|
struct session *s;
|
||||||
|
struct window_pane *wp;
|
||||||
|
struct window *w;
|
||||||
|
char *cause;
|
||||||
|
int base_idx;
|
||||||
|
|
||||||
|
if ((wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
if (window_count_panes(wl->window) == 1) {
|
||||||
|
ctx->error(ctx, "can't break with only one pane");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
w = wl->window;
|
||||||
|
TAILQ_REMOVE(&w->panes, wp, entry);
|
||||||
|
if (wp == w->active) {
|
||||||
|
w->active = w->last;
|
||||||
|
w->last = NULL;
|
||||||
|
if (w->active == NULL) {
|
||||||
|
w->active = TAILQ_PREV(wp, window_panes, entry);
|
||||||
|
if (w->active == NULL)
|
||||||
|
w->active = TAILQ_NEXT(wp, entry);
|
||||||
|
}
|
||||||
|
} else if (wp == w->last)
|
||||||
|
w->last = NULL;
|
||||||
|
layout_close_pane(wp);
|
||||||
|
|
||||||
|
w = wp->window = window_create1(s->sx, s->sy);
|
||||||
|
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
||||||
|
w->active = wp;
|
||||||
|
w->name = default_window_name(w);
|
||||||
|
layout_init(w);
|
||||||
|
|
||||||
|
base_idx = options_get_number(&s->options, "base-index");
|
||||||
|
wl = session_attach(s, w, -1 - base_idx, &cause); /* can't fail */
|
||||||
|
if (!args_has(self->args, 'd'))
|
||||||
|
session_select(s, wl->idx);
|
||||||
|
|
||||||
|
server_redraw_session(s);
|
||||||
|
server_status_session_group(s);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
123
external/bsd/tmux/dist/cmd-capture-pane.c
vendored
Normal file
123
external/bsd/tmux/dist/cmd-capture-pane.c
vendored
Normal file
|
@ -0,0 +1,123 @@
|
||||||
|
/* $Id: cmd-capture-pane.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2009 Jonathan Alvarado <radobobo@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 <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Write the entire contents of a pane to a buffer.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_capture_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_capture_pane_entry = {
|
||||||
|
"capture-pane", "capturep",
|
||||||
|
"b:E:S:t:", 0, 0,
|
||||||
|
"[-b buffer-index] [-E end-line] [-S start-line] [-t target-pane]",
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_capture_pane_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_capture_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct window_pane *wp;
|
||||||
|
char *buf, *line, *cause;
|
||||||
|
struct screen *s;
|
||||||
|
struct grid *gd;
|
||||||
|
int buffer, n;
|
||||||
|
u_int i, limit, top, bottom, tmp;
|
||||||
|
size_t len, linelen;
|
||||||
|
|
||||||
|
if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL)
|
||||||
|
return (-1);
|
||||||
|
s = &wp->base;
|
||||||
|
gd = s->grid;
|
||||||
|
|
||||||
|
buf = NULL;
|
||||||
|
len = 0;
|
||||||
|
|
||||||
|
n = args_strtonum(args, 'S', SHRT_MIN, SHRT_MAX, &cause);
|
||||||
|
if (cause != NULL) {
|
||||||
|
top = gd->hsize;
|
||||||
|
xfree(cause);
|
||||||
|
} else if (n < 0 && (u_int) -n > gd->hsize)
|
||||||
|
top = 0;
|
||||||
|
else
|
||||||
|
top = gd->hsize + n;
|
||||||
|
if (top > gd->hsize + gd->sy - 1)
|
||||||
|
top = gd->hsize + gd->sy - 1;
|
||||||
|
|
||||||
|
n = args_strtonum(args, 'E', SHRT_MIN, SHRT_MAX, &cause);
|
||||||
|
if (cause != NULL) {
|
||||||
|
bottom = gd->hsize + gd->sy - 1;
|
||||||
|
xfree(cause);
|
||||||
|
} else if (n < 0 && (u_int) -n > gd->hsize)
|
||||||
|
bottom = 0;
|
||||||
|
else
|
||||||
|
bottom = gd->hsize + n;
|
||||||
|
if (bottom > gd->hsize + gd->sy - 1)
|
||||||
|
bottom = gd->hsize + gd->sy - 1;
|
||||||
|
|
||||||
|
if (bottom < top) {
|
||||||
|
tmp = bottom;
|
||||||
|
bottom = top;
|
||||||
|
top = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = top; i <= bottom; i++) {
|
||||||
|
line = grid_string_cells(s->grid, 0, i, screen_size_x(s));
|
||||||
|
linelen = strlen(line);
|
||||||
|
|
||||||
|
buf = xrealloc(buf, 1, len + linelen + 1);
|
||||||
|
memcpy(buf + len, line, linelen);
|
||||||
|
len += linelen;
|
||||||
|
buf[len++] = '\n';
|
||||||
|
|
||||||
|
xfree(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
limit = options_get_number(&global_options, "buffer-limit");
|
||||||
|
|
||||||
|
if (!args_has(args, 'b')) {
|
||||||
|
paste_add(&global_buffers, buf, len, limit);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
|
||||||
|
if (cause != NULL) {
|
||||||
|
ctx->error(ctx, "buffer %s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (paste_replace(&global_buffers, buffer, buf, len) != 0) {
|
||||||
|
ctx->error(ctx, "no buffer %d", buffer);
|
||||||
|
xfree(buf);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
143
external/bsd/tmux/dist/cmd-choose-buffer.c
vendored
Normal file
143
external/bsd/tmux/dist/cmd-choose-buffer.c
vendored
Normal file
|
@ -0,0 +1,143 @@
|
||||||
|
/* $Id: cmd-choose-buffer.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2010 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 <ctype.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Enter choice mode to choose a buffer.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_choose_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
void cmd_choose_buffer_callback(void *, int);
|
||||||
|
void cmd_choose_buffer_free(void *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_choose_buffer_entry = {
|
||||||
|
"choose-buffer", NULL,
|
||||||
|
"t:", 0, 1,
|
||||||
|
CMD_TARGET_WINDOW_USAGE " [template]",
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_choose_buffer_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
struct cmd_choose_buffer_data {
|
||||||
|
struct client *client;
|
||||||
|
char *template;
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_choose_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct cmd_choose_buffer_data *cdata;
|
||||||
|
struct winlink *wl;
|
||||||
|
struct paste_buffer *pb;
|
||||||
|
u_int idx;
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
|
if (ctx->curclient == NULL) {
|
||||||
|
ctx->error(ctx, "must be run interactively");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
if (paste_get_top(&global_buffers) == NULL)
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
idx = 0;
|
||||||
|
while ((pb = paste_walk_stack(&global_buffers, &idx)) != NULL) {
|
||||||
|
tmp = paste_print(pb, 50);
|
||||||
|
window_choose_add(wl->window->active, idx - 1,
|
||||||
|
"%u: %zu bytes: \"%s\"", idx - 1, pb->size, tmp);
|
||||||
|
xfree(tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
cdata = xmalloc(sizeof *cdata);
|
||||||
|
if (args->argc != 0)
|
||||||
|
cdata->template = xstrdup(args->argv[0]);
|
||||||
|
else
|
||||||
|
cdata->template = xstrdup("paste-buffer -b '%%'");
|
||||||
|
cdata->client = ctx->curclient;
|
||||||
|
cdata->client->references++;
|
||||||
|
|
||||||
|
window_choose_ready(wl->window->active,
|
||||||
|
0, cmd_choose_buffer_callback, cmd_choose_buffer_free, cdata);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_choose_buffer_callback(void *data, int idx)
|
||||||
|
{
|
||||||
|
struct cmd_choose_buffer_data *cdata = data;
|
||||||
|
struct cmd_list *cmdlist;
|
||||||
|
struct cmd_ctx ctx;
|
||||||
|
char *template, *cause, tmp[16];
|
||||||
|
|
||||||
|
if (idx == -1)
|
||||||
|
return;
|
||||||
|
if (cdata->client->flags & CLIENT_DEAD)
|
||||||
|
return;
|
||||||
|
|
||||||
|
xsnprintf(tmp, sizeof tmp, "%u", idx);
|
||||||
|
template = cmd_template_replace(cdata->template, tmp, 1);
|
||||||
|
|
||||||
|
if (cmd_string_parse(template, &cmdlist, &cause) != 0) {
|
||||||
|
if (cause != NULL) {
|
||||||
|
*cause = toupper((u_char) *cause);
|
||||||
|
status_message_set(cdata->client, "%s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
}
|
||||||
|
xfree(template);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
xfree(template);
|
||||||
|
|
||||||
|
ctx.msgdata = NULL;
|
||||||
|
ctx.curclient = cdata->client;
|
||||||
|
|
||||||
|
ctx.error = key_bindings_error;
|
||||||
|
ctx.print = key_bindings_print;
|
||||||
|
ctx.info = key_bindings_info;
|
||||||
|
|
||||||
|
ctx.cmdclient = NULL;
|
||||||
|
|
||||||
|
cmd_list_exec(cmdlist, &ctx);
|
||||||
|
cmd_list_free(cmdlist);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_choose_buffer_free(void *data)
|
||||||
|
{
|
||||||
|
struct cmd_choose_buffer_data *cdata = data;
|
||||||
|
|
||||||
|
cdata->client->references--;
|
||||||
|
xfree(cdata->template);
|
||||||
|
xfree(cdata);
|
||||||
|
}
|
151
external/bsd/tmux/dist/cmd-choose-client.c
vendored
Normal file
151
external/bsd/tmux/dist/cmd-choose-client.c
vendored
Normal file
|
@ -0,0 +1,151 @@
|
||||||
|
/* $Id: cmd-choose-client.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 <ctype.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Enter choice mode to choose a client.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_choose_client_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
void cmd_choose_client_callback(void *, int);
|
||||||
|
void cmd_choose_client_free(void *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_choose_client_entry = {
|
||||||
|
"choose-client", NULL,
|
||||||
|
"t:", 0, 1,
|
||||||
|
CMD_TARGET_WINDOW_USAGE " [template]",
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_choose_client_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
struct cmd_choose_client_data {
|
||||||
|
struct client *client;
|
||||||
|
char *template;
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_choose_client_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct cmd_choose_client_data *cdata;
|
||||||
|
struct winlink *wl;
|
||||||
|
struct client *c;
|
||||||
|
u_int i, idx, cur;
|
||||||
|
|
||||||
|
if (ctx->curclient == NULL) {
|
||||||
|
ctx->error(ctx, "must be run interactively");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
cur = idx = 0;
|
||||||
|
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||||
|
c = ARRAY_ITEM(&clients, i);
|
||||||
|
if (c == NULL || c->session == NULL)
|
||||||
|
continue;
|
||||||
|
if (c == ctx->curclient)
|
||||||
|
cur = idx;
|
||||||
|
idx++;
|
||||||
|
|
||||||
|
window_choose_add(wl->window->active, i,
|
||||||
|
"%s: %s [%ux%u %s]%s", c->tty.path,
|
||||||
|
c->session->name, c->tty.sx, c->tty.sy,
|
||||||
|
c->tty.termname, c->tty.flags & TTY_UTF8 ? " (utf8)" : "");
|
||||||
|
}
|
||||||
|
|
||||||
|
cdata = xmalloc(sizeof *cdata);
|
||||||
|
if (args->argc != 0)
|
||||||
|
cdata->template = xstrdup(args->argv[0]);
|
||||||
|
else
|
||||||
|
cdata->template = xstrdup("detach-client -t '%%'");
|
||||||
|
cdata->client = ctx->curclient;
|
||||||
|
cdata->client->references++;
|
||||||
|
|
||||||
|
window_choose_ready(wl->window->active,
|
||||||
|
cur, cmd_choose_client_callback, cmd_choose_client_free, cdata);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_choose_client_callback(void *data, int idx)
|
||||||
|
{
|
||||||
|
struct cmd_choose_client_data *cdata = data;
|
||||||
|
struct client *c;
|
||||||
|
struct cmd_list *cmdlist;
|
||||||
|
struct cmd_ctx ctx;
|
||||||
|
char *template, *cause;
|
||||||
|
|
||||||
|
if (idx == -1)
|
||||||
|
return;
|
||||||
|
if (cdata->client->flags & CLIENT_DEAD)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if ((u_int) idx > ARRAY_LENGTH(&clients) - 1)
|
||||||
|
return;
|
||||||
|
c = ARRAY_ITEM(&clients, idx);
|
||||||
|
if (c == NULL || c->session == NULL)
|
||||||
|
return;
|
||||||
|
template = cmd_template_replace(cdata->template, c->tty.path, 1);
|
||||||
|
|
||||||
|
if (cmd_string_parse(template, &cmdlist, &cause) != 0) {
|
||||||
|
if (cause != NULL) {
|
||||||
|
*cause = toupper((u_char) *cause);
|
||||||
|
status_message_set(c, "%s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
}
|
||||||
|
xfree(template);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
xfree(template);
|
||||||
|
|
||||||
|
ctx.msgdata = NULL;
|
||||||
|
ctx.curclient = cdata->client;
|
||||||
|
|
||||||
|
ctx.error = key_bindings_error;
|
||||||
|
ctx.print = key_bindings_print;
|
||||||
|
ctx.info = key_bindings_info;
|
||||||
|
|
||||||
|
ctx.cmdclient = NULL;
|
||||||
|
|
||||||
|
cmd_list_exec(cmdlist, &ctx);
|
||||||
|
cmd_list_free(cmdlist);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_choose_client_free(void *data)
|
||||||
|
{
|
||||||
|
struct cmd_choose_client_data *cdata = data;
|
||||||
|
|
||||||
|
cdata->client->references--;
|
||||||
|
xfree(cdata->template);
|
||||||
|
xfree(cdata);
|
||||||
|
}
|
156
external/bsd/tmux/dist/cmd-choose-session.c
vendored
Normal file
156
external/bsd/tmux/dist/cmd-choose-session.c
vendored
Normal file
|
@ -0,0 +1,156 @@
|
||||||
|
/* $Id: cmd-choose-session.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 <ctype.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Enter choice mode to choose a session.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_choose_session_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
void cmd_choose_session_callback(void *, int);
|
||||||
|
void cmd_choose_session_free(void *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_choose_session_entry = {
|
||||||
|
"choose-session", NULL,
|
||||||
|
"t:", 0, 1,
|
||||||
|
CMD_TARGET_WINDOW_USAGE " [template]",
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_choose_session_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
struct cmd_choose_session_data {
|
||||||
|
struct client *client;
|
||||||
|
char *template;
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_choose_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct cmd_choose_session_data *cdata;
|
||||||
|
struct winlink *wl;
|
||||||
|
struct session *s;
|
||||||
|
struct session_group *sg;
|
||||||
|
u_int idx, sgidx, cur;
|
||||||
|
char tmp[64];
|
||||||
|
|
||||||
|
if (ctx->curclient == NULL) {
|
||||||
|
ctx->error(ctx, "must be run interactively");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
cur = idx = 0;
|
||||||
|
RB_FOREACH(s, sessions, &sessions) {
|
||||||
|
if (s == ctx->curclient->session)
|
||||||
|
cur = idx;
|
||||||
|
idx++;
|
||||||
|
|
||||||
|
sg = session_group_find(s);
|
||||||
|
if (sg == NULL)
|
||||||
|
*tmp = '\0';
|
||||||
|
else {
|
||||||
|
sgidx = session_group_index(sg);
|
||||||
|
xsnprintf(tmp, sizeof tmp, " (group %u)", sgidx);
|
||||||
|
}
|
||||||
|
|
||||||
|
window_choose_add(wl->window->active, s->idx,
|
||||||
|
"%s: %u windows [%ux%u]%s%s", s->name,
|
||||||
|
winlink_count(&s->windows), s->sx, s->sy,
|
||||||
|
tmp, s->flags & SESSION_UNATTACHED ? "" : " (attached)");
|
||||||
|
}
|
||||||
|
|
||||||
|
cdata = xmalloc(sizeof *cdata);
|
||||||
|
if (args->argc != 0)
|
||||||
|
cdata->template = xstrdup(args->argv[0]);
|
||||||
|
else
|
||||||
|
cdata->template = xstrdup("switch-client -t '%%'");
|
||||||
|
cdata->client = ctx->curclient;
|
||||||
|
cdata->client->references++;
|
||||||
|
|
||||||
|
window_choose_ready(wl->window->active,
|
||||||
|
cur, cmd_choose_session_callback, cmd_choose_session_free, cdata);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_choose_session_callback(void *data, int idx)
|
||||||
|
{
|
||||||
|
struct cmd_choose_session_data *cdata = data;
|
||||||
|
struct session *s;
|
||||||
|
struct cmd_list *cmdlist;
|
||||||
|
struct cmd_ctx ctx;
|
||||||
|
char *template, *cause;
|
||||||
|
|
||||||
|
if (idx == -1)
|
||||||
|
return;
|
||||||
|
if (cdata->client->flags & CLIENT_DEAD)
|
||||||
|
return;
|
||||||
|
|
||||||
|
s = session_find_by_index(idx);
|
||||||
|
if (s == NULL)
|
||||||
|
return;
|
||||||
|
template = cmd_template_replace(cdata->template, s->name, 1);
|
||||||
|
|
||||||
|
if (cmd_string_parse(template, &cmdlist, &cause) != 0) {
|
||||||
|
if (cause != NULL) {
|
||||||
|
*cause = toupper((u_char) *cause);
|
||||||
|
status_message_set(cdata->client, "%s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
}
|
||||||
|
xfree(template);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
xfree(template);
|
||||||
|
|
||||||
|
ctx.msgdata = NULL;
|
||||||
|
ctx.curclient = cdata->client;
|
||||||
|
|
||||||
|
ctx.error = key_bindings_error;
|
||||||
|
ctx.print = key_bindings_print;
|
||||||
|
ctx.info = key_bindings_info;
|
||||||
|
|
||||||
|
ctx.cmdclient = NULL;
|
||||||
|
|
||||||
|
cmd_list_exec(cmdlist, &ctx);
|
||||||
|
cmd_list_free(cmdlist);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_choose_session_free(void *data)
|
||||||
|
{
|
||||||
|
struct cmd_choose_session_data *cdata = data;
|
||||||
|
|
||||||
|
cdata->client->references--;
|
||||||
|
xfree(cdata->template);
|
||||||
|
xfree(cdata);
|
||||||
|
}
|
169
external/bsd/tmux/dist/cmd-choose-window.c
vendored
Normal file
169
external/bsd/tmux/dist/cmd-choose-window.c
vendored
Normal file
|
@ -0,0 +1,169 @@
|
||||||
|
/* $Id: cmd-choose-window.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 <ctype.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Enter choice mode to choose a window.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_choose_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
void cmd_choose_window_callback(void *, int);
|
||||||
|
void cmd_choose_window_free(void *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_choose_window_entry = {
|
||||||
|
"choose-window", NULL,
|
||||||
|
"t:", 0, 1,
|
||||||
|
CMD_TARGET_WINDOW_USAGE " [template]",
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_choose_window_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
struct cmd_choose_window_data {
|
||||||
|
struct client *client;
|
||||||
|
struct session *session;
|
||||||
|
char *template;
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_choose_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct cmd_choose_window_data *cdata;
|
||||||
|
struct session *s;
|
||||||
|
struct winlink *wl, *wm;
|
||||||
|
struct window *w;
|
||||||
|
u_int idx, cur;
|
||||||
|
char *flags, *title;
|
||||||
|
const char *left, *right;
|
||||||
|
|
||||||
|
if (ctx->curclient == NULL) {
|
||||||
|
ctx->error(ctx, "must be run interactively");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
s = ctx->curclient->session;
|
||||||
|
|
||||||
|
if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
cur = idx = 0;
|
||||||
|
RB_FOREACH(wm, winlinks, &s->windows) {
|
||||||
|
w = wm->window;
|
||||||
|
|
||||||
|
if (wm == s->curw)
|
||||||
|
cur = idx;
|
||||||
|
idx++;
|
||||||
|
|
||||||
|
flags = window_printable_flags(s, wm);
|
||||||
|
title = w->active->screen->title;
|
||||||
|
if (wm == wl)
|
||||||
|
title = w->active->base.title;
|
||||||
|
left = " \"";
|
||||||
|
right = "\"";
|
||||||
|
if (*title == '\0')
|
||||||
|
left = right = "";
|
||||||
|
|
||||||
|
window_choose_add(wl->window->active,
|
||||||
|
wm->idx, "%3d: %s%s [%ux%u] (%u panes%s)%s%s%s",
|
||||||
|
wm->idx, w->name, flags, w->sx, w->sy, window_count_panes(w),
|
||||||
|
w->active->fd == -1 ? ", dead" : "",
|
||||||
|
left, title, right);
|
||||||
|
|
||||||
|
xfree(flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
cdata = xmalloc(sizeof *cdata);
|
||||||
|
if (args->argc != 0)
|
||||||
|
cdata->template = xstrdup(args->argv[0]);
|
||||||
|
else
|
||||||
|
cdata->template = xstrdup("select-window -t '%%'");
|
||||||
|
cdata->session = s;
|
||||||
|
cdata->session->references++;
|
||||||
|
cdata->client = ctx->curclient;
|
||||||
|
cdata->client->references++;
|
||||||
|
|
||||||
|
window_choose_ready(wl->window->active,
|
||||||
|
cur, cmd_choose_window_callback, cmd_choose_window_free, cdata);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_choose_window_callback(void *data, int idx)
|
||||||
|
{
|
||||||
|
struct cmd_choose_window_data *cdata = data;
|
||||||
|
struct session *s = cdata->session;
|
||||||
|
struct cmd_list *cmdlist;
|
||||||
|
struct cmd_ctx ctx;
|
||||||
|
char *target, *template, *cause;
|
||||||
|
|
||||||
|
if (idx == -1)
|
||||||
|
return;
|
||||||
|
if (!session_alive(s))
|
||||||
|
return;
|
||||||
|
if (cdata->client->flags & CLIENT_DEAD)
|
||||||
|
return;
|
||||||
|
|
||||||
|
xasprintf(&target, "%s:%d", s->name, idx);
|
||||||
|
template = cmd_template_replace(cdata->template, target, 1);
|
||||||
|
xfree(target);
|
||||||
|
|
||||||
|
if (cmd_string_parse(template, &cmdlist, &cause) != 0) {
|
||||||
|
if (cause != NULL) {
|
||||||
|
*cause = toupper((u_char) *cause);
|
||||||
|
status_message_set(cdata->client, "%s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
}
|
||||||
|
xfree(template);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
xfree(template);
|
||||||
|
|
||||||
|
ctx.msgdata = NULL;
|
||||||
|
ctx.curclient = cdata->client;
|
||||||
|
|
||||||
|
ctx.error = key_bindings_error;
|
||||||
|
ctx.print = key_bindings_print;
|
||||||
|
ctx.info = key_bindings_info;
|
||||||
|
|
||||||
|
ctx.cmdclient = NULL;
|
||||||
|
|
||||||
|
cmd_list_exec(cmdlist, &ctx);
|
||||||
|
cmd_list_free(cmdlist);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_choose_window_free(void *data)
|
||||||
|
{
|
||||||
|
struct cmd_choose_window_data *cdata = data;
|
||||||
|
|
||||||
|
cdata->session->references--;
|
||||||
|
cdata->client->references--;
|
||||||
|
xfree(cdata->template);
|
||||||
|
xfree(cdata);
|
||||||
|
}
|
54
external/bsd/tmux/dist/cmd-clear-history.c
vendored
Normal file
54
external/bsd/tmux/dist/cmd-clear-history.c
vendored
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
/* $Id: cmd-clear-history.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Clear pane history.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_clear_history_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_clear_history_entry = {
|
||||||
|
"clear-history", "clearhist",
|
||||||
|
"t:", 0, 0,
|
||||||
|
CMD_TARGET_PANE_USAGE,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_clear_history_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_clear_history_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct window_pane *wp;
|
||||||
|
struct grid *gd;
|
||||||
|
|
||||||
|
if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL)
|
||||||
|
return (-1);
|
||||||
|
gd = wp->base.grid;
|
||||||
|
|
||||||
|
grid_move_lines(gd, 0, gd->hsize, gd->sy);
|
||||||
|
gd->hsize = 0;
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
51
external/bsd/tmux/dist/cmd-clock-mode.c
vendored
Normal file
51
external/bsd/tmux/dist/cmd-clock-mode.c
vendored
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
/* $Id: cmd-clock-mode.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Enter clock mode.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_clock_mode_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_clock_mode_entry = {
|
||||||
|
"clock-mode", NULL,
|
||||||
|
"t:", 0, 0,
|
||||||
|
CMD_TARGET_PANE_USAGE,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_clock_mode_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_clock_mode_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct window_pane *wp;
|
||||||
|
|
||||||
|
if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
window_pane_set_mode(wp, &window_clock_mode);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
215
external/bsd/tmux/dist/cmd-command-prompt.c
vendored
Normal file
215
external/bsd/tmux/dist/cmd-command-prompt.c
vendored
Normal file
|
@ -0,0 +1,215 @@
|
||||||
|
/* $Id: cmd-command-prompt.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008 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 <ctype.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Prompt for command in client.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void cmd_command_prompt_key_binding(struct cmd *, int);
|
||||||
|
int cmd_command_prompt_check(struct args *);
|
||||||
|
int cmd_command_prompt_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
int cmd_command_prompt_callback(void *, const char *);
|
||||||
|
void cmd_command_prompt_free(void *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_command_prompt_entry = {
|
||||||
|
"command-prompt", NULL,
|
||||||
|
"I:p:t:", 0, 1,
|
||||||
|
"[-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE " [template]",
|
||||||
|
0,
|
||||||
|
cmd_command_prompt_key_binding,
|
||||||
|
NULL,
|
||||||
|
cmd_command_prompt_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
struct cmd_command_prompt_cdata {
|
||||||
|
struct client *c;
|
||||||
|
char *inputs;
|
||||||
|
char *next_input;
|
||||||
|
char *next_prompt;
|
||||||
|
char *prompts;
|
||||||
|
char *template;
|
||||||
|
int idx;
|
||||||
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_command_prompt_key_binding(struct cmd *self, int key)
|
||||||
|
{
|
||||||
|
switch (key) {
|
||||||
|
case '$':
|
||||||
|
self->args = args_create(1, "rename-session '%%'");
|
||||||
|
args_set(self->args, 'I', "#S");
|
||||||
|
break;
|
||||||
|
case ',':
|
||||||
|
self->args = args_create(1, "rename-window '%%'");
|
||||||
|
args_set(self->args, 'I', "#W");
|
||||||
|
break;
|
||||||
|
case '.':
|
||||||
|
self->args = args_create(1, "move-window -t '%%'");
|
||||||
|
break;
|
||||||
|
case 'f':
|
||||||
|
self->args = args_create(1, "find-window '%%'");
|
||||||
|
break;
|
||||||
|
case '\'':
|
||||||
|
self->args = args_create(1, "select-window -t ':%%'");
|
||||||
|
args_set(self->args, 'p', "index");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
self->args = args_create(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_command_prompt_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
const char *inputs, *prompts;
|
||||||
|
struct cmd_command_prompt_cdata *cdata;
|
||||||
|
struct client *c;
|
||||||
|
char *prompt, *ptr, *input = NULL;
|
||||||
|
size_t n;
|
||||||
|
|
||||||
|
if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
if (c->prompt_string != NULL)
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
cdata = xmalloc(sizeof *cdata);
|
||||||
|
cdata->c = c;
|
||||||
|
cdata->idx = 1;
|
||||||
|
cdata->inputs = NULL;
|
||||||
|
cdata->next_input = NULL;
|
||||||
|
cdata->next_prompt = NULL;
|
||||||
|
cdata->prompts = NULL;
|
||||||
|
cdata->template = NULL;
|
||||||
|
|
||||||
|
if (args->argc != 0)
|
||||||
|
cdata->template = xstrdup(args->argv[0]);
|
||||||
|
else
|
||||||
|
cdata->template = xstrdup("%1");
|
||||||
|
|
||||||
|
if ((prompts = args_get(args, 'p')) != NULL)
|
||||||
|
cdata->prompts = xstrdup(prompts);
|
||||||
|
else if (args->argc != 0) {
|
||||||
|
n = strcspn(cdata->template, " ,");
|
||||||
|
xasprintf(&cdata->prompts, "(%.*s) ", (int) n, cdata->template);
|
||||||
|
} else
|
||||||
|
cdata->prompts = xstrdup(":");
|
||||||
|
|
||||||
|
/* Get first prompt. */
|
||||||
|
cdata->next_prompt = cdata->prompts;
|
||||||
|
ptr = strsep(&cdata->next_prompt, ",");
|
||||||
|
if (prompts == NULL)
|
||||||
|
prompt = xstrdup(ptr);
|
||||||
|
else
|
||||||
|
xasprintf(&prompt, "%s ", ptr);
|
||||||
|
|
||||||
|
/* Get initial prompt input. */
|
||||||
|
if ((inputs = args_get(args, 'I')) != NULL) {
|
||||||
|
cdata->inputs = xstrdup(inputs);
|
||||||
|
cdata->next_input = cdata->inputs;
|
||||||
|
input = strsep(&cdata->next_input, ",");
|
||||||
|
}
|
||||||
|
|
||||||
|
status_prompt_set(c, prompt, input, cmd_command_prompt_callback,
|
||||||
|
cmd_command_prompt_free, cdata, 0);
|
||||||
|
xfree(prompt);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_command_prompt_callback(void *data, const char *s)
|
||||||
|
{
|
||||||
|
struct cmd_command_prompt_cdata *cdata = data;
|
||||||
|
struct client *c = cdata->c;
|
||||||
|
struct cmd_list *cmdlist;
|
||||||
|
struct cmd_ctx ctx;
|
||||||
|
char *cause, *new_template, *prompt, *ptr;
|
||||||
|
char *input = NULL;
|
||||||
|
|
||||||
|
if (s == NULL)
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
new_template = cmd_template_replace(cdata->template, s, cdata->idx);
|
||||||
|
xfree(cdata->template);
|
||||||
|
cdata->template = new_template;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check if there are more prompts; if so, get its respective input
|
||||||
|
* and update the prompt data.
|
||||||
|
*/
|
||||||
|
if ((ptr = strsep(&cdata->next_prompt, ",")) != NULL) {
|
||||||
|
xasprintf(&prompt, "%s ", ptr);
|
||||||
|
input = strsep(&cdata->next_input, ",");
|
||||||
|
status_prompt_update(c, prompt, input);
|
||||||
|
|
||||||
|
xfree(prompt);
|
||||||
|
cdata->idx++;
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cmd_string_parse(new_template, &cmdlist, &cause) != 0) {
|
||||||
|
if (cause != NULL) {
|
||||||
|
*cause = toupper((u_char) *cause);
|
||||||
|
status_message_set(c, "%s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.msgdata = NULL;
|
||||||
|
ctx.curclient = c;
|
||||||
|
|
||||||
|
ctx.error = key_bindings_error;
|
||||||
|
ctx.print = key_bindings_print;
|
||||||
|
ctx.info = key_bindings_info;
|
||||||
|
|
||||||
|
ctx.cmdclient = NULL;
|
||||||
|
|
||||||
|
cmd_list_exec(cmdlist, &ctx);
|
||||||
|
cmd_list_free(cmdlist);
|
||||||
|
|
||||||
|
if (c->prompt_callbackfn != (void *) &cmd_command_prompt_callback)
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_command_prompt_free(void *data)
|
||||||
|
{
|
||||||
|
struct cmd_command_prompt_cdata *cdata = data;
|
||||||
|
|
||||||
|
if (cdata->inputs != NULL)
|
||||||
|
xfree(cdata->inputs);
|
||||||
|
if (cdata->prompts != NULL)
|
||||||
|
xfree(cdata->prompts);
|
||||||
|
if (cdata->template != NULL)
|
||||||
|
xfree(cdata->template);
|
||||||
|
xfree(cdata);
|
||||||
|
}
|
150
external/bsd/tmux/dist/cmd-confirm-before.c
vendored
Normal file
150
external/bsd/tmux/dist/cmd-confirm-before.c
vendored
Normal file
|
@ -0,0 +1,150 @@
|
||||||
|
/* $Id: cmd-confirm-before.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
||||||
|
*
|
||||||
|
* 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 <ctype.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Asks for confirmation before executing a command.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void cmd_confirm_before_key_binding(struct cmd *, int);
|
||||||
|
int cmd_confirm_before_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
int cmd_confirm_before_callback(void *, const char *);
|
||||||
|
void cmd_confirm_before_free(void *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_confirm_before_entry = {
|
||||||
|
"confirm-before", "confirm",
|
||||||
|
"p:t:", 1, 1,
|
||||||
|
"[-p prompt] " CMD_TARGET_CLIENT_USAGE " command",
|
||||||
|
0,
|
||||||
|
cmd_confirm_before_key_binding,
|
||||||
|
NULL,
|
||||||
|
cmd_confirm_before_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
struct cmd_confirm_before_data {
|
||||||
|
struct client *c;
|
||||||
|
char *cmd;
|
||||||
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_confirm_before_key_binding(struct cmd *self, int key)
|
||||||
|
{
|
||||||
|
switch (key) {
|
||||||
|
case '&':
|
||||||
|
self->args = args_create(1, "kill-window");
|
||||||
|
args_set(self->args, 'p', "kill-window #W? (y/n)");
|
||||||
|
break;
|
||||||
|
case 'x':
|
||||||
|
self->args = args_create(1, "kill-pane");
|
||||||
|
args_set(self->args, 'p', "kill-pane #P? (y/n)");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
self->args = args_create(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_confirm_before_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct cmd_confirm_before_data *cdata;
|
||||||
|
struct client *c;
|
||||||
|
char *cmd, *copy, *new_prompt, *ptr;
|
||||||
|
const char *prompt;
|
||||||
|
|
||||||
|
if (ctx->curclient == NULL) {
|
||||||
|
ctx->error(ctx, "must be run interactively");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
if ((prompt = args_get(args, 'p')) != NULL)
|
||||||
|
xasprintf(&new_prompt, "%s ", prompt);
|
||||||
|
else {
|
||||||
|
ptr = copy = xstrdup(args->argv[0]);
|
||||||
|
cmd = strsep(&ptr, " \t");
|
||||||
|
xasprintf(&new_prompt, "Confirm '%s'? (y/n) ", cmd);
|
||||||
|
xfree(copy);
|
||||||
|
}
|
||||||
|
|
||||||
|
cdata = xmalloc(sizeof *cdata);
|
||||||
|
cdata->cmd = xstrdup(args->argv[0]);
|
||||||
|
cdata->c = c;
|
||||||
|
status_prompt_set(cdata->c, new_prompt, NULL,
|
||||||
|
cmd_confirm_before_callback, cmd_confirm_before_free, cdata,
|
||||||
|
PROMPT_SINGLE);
|
||||||
|
|
||||||
|
xfree(new_prompt);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_confirm_before_callback(void *data, const char *s)
|
||||||
|
{
|
||||||
|
struct cmd_confirm_before_data *cdata = data;
|
||||||
|
struct client *c = cdata->c;
|
||||||
|
struct cmd_list *cmdlist;
|
||||||
|
struct cmd_ctx ctx;
|
||||||
|
char *cause;
|
||||||
|
|
||||||
|
if (s == NULL || *s == '\0')
|
||||||
|
return (0);
|
||||||
|
if (tolower((u_char) s[0]) != 'y' || s[1] != '\0')
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
if (cmd_string_parse(cdata->cmd, &cmdlist, &cause) != 0) {
|
||||||
|
if (cause != NULL) {
|
||||||
|
*cause = toupper((u_char) *cause);
|
||||||
|
status_message_set(c, "%s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.msgdata = NULL;
|
||||||
|
ctx.curclient = c;
|
||||||
|
|
||||||
|
ctx.error = key_bindings_error;
|
||||||
|
ctx.print = key_bindings_print;
|
||||||
|
ctx.info = key_bindings_info;
|
||||||
|
|
||||||
|
ctx.cmdclient = NULL;
|
||||||
|
|
||||||
|
cmd_list_exec(cmdlist, &ctx);
|
||||||
|
cmd_list_free(cmdlist);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_confirm_before_free(void *data)
|
||||||
|
{
|
||||||
|
struct cmd_confirm_before_data *cdata = data;
|
||||||
|
|
||||||
|
if (cdata->cmd != NULL)
|
||||||
|
xfree(cdata->cmd);
|
||||||
|
xfree(cdata);
|
||||||
|
}
|
64
external/bsd/tmux/dist/cmd-copy-mode.c
vendored
Normal file
64
external/bsd/tmux/dist/cmd-copy-mode.c
vendored
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
/* $Id: cmd-copy-mode.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 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 "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Enter copy mode.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void cmd_copy_mode_key_binding(struct cmd *, int);
|
||||||
|
int cmd_copy_mode_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_copy_mode_entry = {
|
||||||
|
"copy-mode", NULL,
|
||||||
|
"t:u", 0, 0,
|
||||||
|
"[-u] " CMD_TARGET_PANE_USAGE,
|
||||||
|
0,
|
||||||
|
cmd_copy_mode_key_binding,
|
||||||
|
NULL,
|
||||||
|
cmd_copy_mode_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_copy_mode_key_binding(struct cmd *self, int key)
|
||||||
|
{
|
||||||
|
self->args = args_create(0);
|
||||||
|
if (key == KEYC_PPAGE)
|
||||||
|
args_set(self->args, 'u', NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_copy_mode_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct window_pane *wp;
|
||||||
|
|
||||||
|
if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
if (window_pane_set_mode(wp, &window_copy_mode) != 0)
|
||||||
|
return (0);
|
||||||
|
window_copy_init_from_pane(wp);
|
||||||
|
if (wp->mode == &window_copy_mode && args_has(self->args, 'u'))
|
||||||
|
window_copy_pageup(wp);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
66
external/bsd/tmux/dist/cmd-delete-buffer.c
vendored
Normal file
66
external/bsd/tmux/dist/cmd-delete-buffer.c
vendored
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
/* $Id: cmd-delete-buffer.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 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 <stdlib.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Delete a paste buffer.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_delete_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_delete_buffer_entry = {
|
||||||
|
"delete-buffer", "deleteb",
|
||||||
|
"b:", 0, 0,
|
||||||
|
CMD_BUFFER_USAGE,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_delete_buffer_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_delete_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
char *cause;
|
||||||
|
int buffer;
|
||||||
|
|
||||||
|
if (!args_has(args, 'b')) {
|
||||||
|
paste_free_top(&global_buffers);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
|
||||||
|
if (cause != NULL) {
|
||||||
|
ctx->error(ctx, "buffer %s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (paste_free_index(&global_buffers, buffer) != 0) {
|
||||||
|
ctx->error(ctx, "no buffer %d", buffer);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
72
external/bsd/tmux/dist/cmd-detach-client.c
vendored
Normal file
72
external/bsd/tmux/dist/cmd-detach-client.c
vendored
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
/* $Id: cmd-detach-client.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 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 "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Detach a client.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_detach_client_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_detach_client_entry = {
|
||||||
|
"detach-client", "detach",
|
||||||
|
"s:t:P", 0, 0,
|
||||||
|
"[-P] [-s target-session] " CMD_TARGET_CLIENT_USAGE,
|
||||||
|
CMD_READONLY,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_detach_client_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_detach_client_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct client *c;
|
||||||
|
struct session *s;
|
||||||
|
enum msgtype msgtype;
|
||||||
|
u_int i;
|
||||||
|
|
||||||
|
if (args_has(args, 'P'))
|
||||||
|
msgtype = MSG_DETACHKILL;
|
||||||
|
else
|
||||||
|
msgtype = MSG_DETACH;
|
||||||
|
|
||||||
|
if (args_has(args, 's')) {
|
||||||
|
s = cmd_find_session(ctx, args_get(args, 's'), 0);
|
||||||
|
if (s == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||||
|
c = ARRAY_ITEM(&clients, i);
|
||||||
|
if (c != NULL && c->session == s)
|
||||||
|
server_write_client(c, msgtype, NULL, 0);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
c = cmd_find_client(ctx, args_get(args, 't'));
|
||||||
|
if (c == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
server_write_client(c, msgtype, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
78
external/bsd/tmux/dist/cmd-display-message.c
vendored
Normal file
78
external/bsd/tmux/dist/cmd-display-message.c
vendored
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
/* $Id: cmd-display-message.c,v 1.2 2011/08/19 09:06:05 christos Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
||||||
|
*
|
||||||
|
* 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 <time.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Displays a message in the status line.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_display_message_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_display_message_entry = {
|
||||||
|
"display-message", "display",
|
||||||
|
"c:pt:", 0, 1,
|
||||||
|
"[-p] [-c target-client] [-t target-pane] [message]",
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_display_message_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_display_message_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct client *c;
|
||||||
|
struct session *s;
|
||||||
|
struct winlink *wl;
|
||||||
|
struct window_pane *wp;
|
||||||
|
const char *template;
|
||||||
|
char *msg;
|
||||||
|
|
||||||
|
if ((c = cmd_find_client(ctx, args_get(args, 'c'))) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
if (args_has(args, 't') != 0) {
|
||||||
|
wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp);
|
||||||
|
if (wl == NULL)
|
||||||
|
return (-1);
|
||||||
|
} else {
|
||||||
|
s = NULL;
|
||||||
|
wl = NULL;
|
||||||
|
wp = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args->argc == 0)
|
||||||
|
template = "[#S] #I:#W, current pane #P - (%H:%M %d-%b-%Y)";
|
||||||
|
else
|
||||||
|
template = args->argv[0];
|
||||||
|
|
||||||
|
msg = status_replace(c, s, wl, wp, template, time(NULL), 0);
|
||||||
|
if (args_has(self->args, 'p'))
|
||||||
|
ctx->print(ctx, "%s", msg);
|
||||||
|
else
|
||||||
|
status_message_set(c, "%s", msg);
|
||||||
|
xfree(msg);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
51
external/bsd/tmux/dist/cmd-display-panes.c
vendored
Normal file
51
external/bsd/tmux/dist/cmd-display-panes.c
vendored
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
/* $Id: cmd-display-panes.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Display panes on a client.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_display_panes_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_display_panes_entry = {
|
||||||
|
"display-panes", "displayp",
|
||||||
|
"t:", 0, 0,
|
||||||
|
CMD_TARGET_CLIENT_USAGE,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_display_panes_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_display_panes_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct client *c;
|
||||||
|
|
||||||
|
if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
server_set_identify(c);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
176
external/bsd/tmux/dist/cmd-find-window.c
vendored
Normal file
176
external/bsd/tmux/dist/cmd-find-window.c
vendored
Normal file
|
@ -0,0 +1,176 @@
|
||||||
|
/* $Id: cmd-find-window.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 <fnmatch.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Find window containing text.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_find_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
void cmd_find_window_callback(void *, int);
|
||||||
|
void cmd_find_window_free(void *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_find_window_entry = {
|
||||||
|
"find-window", "findw",
|
||||||
|
"t:", 1, 1,
|
||||||
|
CMD_TARGET_WINDOW_USAGE " match-string",
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_find_window_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
struct cmd_find_window_data {
|
||||||
|
struct session *session;
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct cmd_find_window_data *cdata;
|
||||||
|
struct session *s;
|
||||||
|
struct winlink *wl, *wm;
|
||||||
|
struct window *w;
|
||||||
|
struct window_pane *wp;
|
||||||
|
ARRAY_DECL(, u_int) list_idx;
|
||||||
|
ARRAY_DECL(, char *) list_ctx;
|
||||||
|
char *str, *sres, *sctx, *searchstr;
|
||||||
|
u_int i, line;
|
||||||
|
|
||||||
|
if (ctx->curclient == NULL) {
|
||||||
|
ctx->error(ctx, "must be run interactively");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
s = ctx->curclient->session;
|
||||||
|
|
||||||
|
if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
str = args->argv[0];
|
||||||
|
|
||||||
|
ARRAY_INIT(&list_idx);
|
||||||
|
ARRAY_INIT(&list_ctx);
|
||||||
|
|
||||||
|
xasprintf(&searchstr, "*%s*", str);
|
||||||
|
RB_FOREACH(wm, winlinks, &s->windows) {
|
||||||
|
i = 0;
|
||||||
|
TAILQ_FOREACH(wp, &wm->window->panes, entry) {
|
||||||
|
i++;
|
||||||
|
|
||||||
|
if (fnmatch(searchstr, wm->window->name, 0) == 0)
|
||||||
|
sctx = xstrdup("");
|
||||||
|
else {
|
||||||
|
sres = window_pane_search(wp, str, &line);
|
||||||
|
if (sres == NULL &&
|
||||||
|
fnmatch(searchstr, wp->base.title, 0) != 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (sres == NULL) {
|
||||||
|
xasprintf(&sctx,
|
||||||
|
"pane %u title: \"%s\"", i - 1,
|
||||||
|
wp->base.title);
|
||||||
|
} else {
|
||||||
|
xasprintf(&sctx,
|
||||||
|
"pane %u line %u: \"%s\"", i - 1,
|
||||||
|
line + 1, sres);
|
||||||
|
xfree(sres);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ARRAY_ADD(&list_idx, wm->idx);
|
||||||
|
ARRAY_ADD(&list_ctx, sctx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
xfree(searchstr);
|
||||||
|
|
||||||
|
if (ARRAY_LENGTH(&list_idx) == 0) {
|
||||||
|
ctx->error(ctx, "no windows matching: %s", str);
|
||||||
|
ARRAY_FREE(&list_idx);
|
||||||
|
ARRAY_FREE(&list_ctx);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ARRAY_LENGTH(&list_idx) == 1) {
|
||||||
|
if (session_select(s, ARRAY_FIRST(&list_idx)) == 0)
|
||||||
|
server_redraw_session(s);
|
||||||
|
recalculate_sizes();
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
for (i = 0; i < ARRAY_LENGTH(&list_idx); i++) {
|
||||||
|
wm = winlink_find_by_index(
|
||||||
|
&s->windows, ARRAY_ITEM(&list_idx, i));
|
||||||
|
w = wm->window;
|
||||||
|
|
||||||
|
sctx = ARRAY_ITEM(&list_ctx, i);
|
||||||
|
window_choose_add(wl->window->active,
|
||||||
|
wm->idx, "%3d: %s [%ux%u] (%u panes) %s", wm->idx, w->name,
|
||||||
|
w->sx, w->sy, window_count_panes(w), sctx);
|
||||||
|
xfree(sctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
cdata = xmalloc(sizeof *cdata);
|
||||||
|
cdata->session = s;
|
||||||
|
cdata->session->references++;
|
||||||
|
|
||||||
|
window_choose_ready(wl->window->active,
|
||||||
|
0, cmd_find_window_callback, cmd_find_window_free, cdata);
|
||||||
|
|
||||||
|
out:
|
||||||
|
ARRAY_FREE(&list_idx);
|
||||||
|
ARRAY_FREE(&list_ctx);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_find_window_callback(void *data, int idx)
|
||||||
|
{
|
||||||
|
struct cmd_find_window_data *cdata = data;
|
||||||
|
struct session *s = cdata->session;
|
||||||
|
|
||||||
|
if (idx == -1)
|
||||||
|
return;
|
||||||
|
if (!session_alive(s))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (session_select(s, idx) == 0) {
|
||||||
|
server_redraw_session(s);
|
||||||
|
recalculate_sizes();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_find_window_free(void *data)
|
||||||
|
{
|
||||||
|
struct cmd_find_window_data *cdata = data;
|
||||||
|
|
||||||
|
cdata->session->references--;
|
||||||
|
xfree(cdata);
|
||||||
|
}
|
48
external/bsd/tmux/dist/cmd-has-session.c
vendored
Normal file
48
external/bsd/tmux/dist/cmd-has-session.c
vendored
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
/* $Id: cmd-has-session.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 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 "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Cause client to report an error and exit with 1 if session doesn't exist.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_has_session_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_has_session_entry = {
|
||||||
|
"has-session", "has",
|
||||||
|
"t:", 0, 0,
|
||||||
|
CMD_TARGET_SESSION_USAGE,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_has_session_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_has_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
|
||||||
|
if (cmd_find_session(ctx, args_get(args, 't'), 0) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
110
external/bsd/tmux/dist/cmd-if-shell.c
vendored
Normal file
110
external/bsd/tmux/dist/cmd-if-shell.c
vendored
Normal file
|
@ -0,0 +1,110 @@
|
||||||
|
/* $Id: cmd-if-shell.c,v 1.2 2013/10/20 03:00:02 christos Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
||||||
|
* Copyright (c) 2009 Nicholas Marriott <nicm@openbsd.org>
|
||||||
|
*
|
||||||
|
* 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 <string.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Executes a tmux command if a shell command returns true.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_if_shell_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
void cmd_if_shell_callback(struct job *);
|
||||||
|
void cmd_if_shell_free(void *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_if_shell_entry = {
|
||||||
|
"if-shell", "if",
|
||||||
|
"", 2, 2,
|
||||||
|
"shell-command command",
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_if_shell_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
struct cmd_if_shell_data {
|
||||||
|
char *cmd;
|
||||||
|
struct cmd_ctx ctx;
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_if_shell_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct cmd_if_shell_data *cdata;
|
||||||
|
const char *shellcmd = args->argv[0];
|
||||||
|
|
||||||
|
cdata = xmalloc(sizeof *cdata);
|
||||||
|
cdata->cmd = xstrdup(args->argv[1]);
|
||||||
|
memcpy(&cdata->ctx, ctx, sizeof cdata->ctx);
|
||||||
|
|
||||||
|
if (ctx->cmdclient != NULL)
|
||||||
|
ctx->cmdclient->references++;
|
||||||
|
if (ctx->curclient != NULL)
|
||||||
|
ctx->curclient->references++;
|
||||||
|
|
||||||
|
job_run(shellcmd, cmd_if_shell_callback, cmd_if_shell_free, cdata);
|
||||||
|
|
||||||
|
return (1); /* don't let client exit */
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_if_shell_callback(struct job *job)
|
||||||
|
{
|
||||||
|
struct cmd_if_shell_data *cdata = job->data;
|
||||||
|
struct cmd_ctx *ctx = &cdata->ctx;
|
||||||
|
struct cmd_list *cmdlist;
|
||||||
|
char *cause;
|
||||||
|
|
||||||
|
if (!WIFEXITED(job->status) || WEXITSTATUS(job->status) != 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (cmd_string_parse(cdata->cmd, &cmdlist, &cause) != 0) {
|
||||||
|
if (cause != NULL) {
|
||||||
|
ctx->error(ctx, "%s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd_list_exec(cmdlist, ctx);
|
||||||
|
cmd_list_free(cmdlist);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_if_shell_free(void *data)
|
||||||
|
{
|
||||||
|
struct cmd_if_shell_data *cdata = data;
|
||||||
|
struct cmd_ctx *ctx = &cdata->ctx;
|
||||||
|
|
||||||
|
if (ctx->cmdclient != NULL) {
|
||||||
|
ctx->cmdclient->references--;
|
||||||
|
ctx->cmdclient->flags |= CLIENT_EXIT;
|
||||||
|
}
|
||||||
|
if (ctx->curclient != NULL)
|
||||||
|
ctx->curclient->references--;
|
||||||
|
|
||||||
|
xfree(cdata->cmd);
|
||||||
|
xfree(cdata);
|
||||||
|
}
|
145
external/bsd/tmux/dist/cmd-join-pane.c
vendored
Normal file
145
external/bsd/tmux/dist/cmd-join-pane.c
vendored
Normal file
|
@ -0,0 +1,145 @@
|
||||||
|
/* $Id: cmd-join-pane.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Join a pane into another (like split/swap/kill).
|
||||||
|
*/
|
||||||
|
|
||||||
|
void cmd_join_pane_key_binding(struct cmd *, int);
|
||||||
|
int cmd_join_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_join_pane_entry = {
|
||||||
|
"join-pane", "joinp",
|
||||||
|
"dhvp:l:s:t:", 0, 0,
|
||||||
|
"[-dhv] [-p percentage|-l size] [-s src-pane] [-t dst-pane]",
|
||||||
|
0,
|
||||||
|
cmd_join_pane_key_binding,
|
||||||
|
NULL,
|
||||||
|
cmd_join_pane_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_join_pane_key_binding(struct cmd *self, int key)
|
||||||
|
{
|
||||||
|
switch (key) {
|
||||||
|
case '%':
|
||||||
|
self->args = args_create(0);
|
||||||
|
args_set(self->args, 'h', NULL);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
self->args = args_create(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_join_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct session *dst_s;
|
||||||
|
struct winlink *src_wl, *dst_wl;
|
||||||
|
struct window *src_w, *dst_w;
|
||||||
|
struct window_pane *src_wp, *dst_wp;
|
||||||
|
char *cause;
|
||||||
|
int size, percentage, dst_idx;
|
||||||
|
enum layout_type type;
|
||||||
|
struct layout_cell *lc;
|
||||||
|
|
||||||
|
dst_wl = cmd_find_pane(ctx, args_get(args, 't'), &dst_s, &dst_wp);
|
||||||
|
if (dst_wl == NULL)
|
||||||
|
return (-1);
|
||||||
|
dst_w = dst_wl->window;
|
||||||
|
dst_idx = dst_wl->idx;
|
||||||
|
|
||||||
|
src_wl = cmd_find_pane(ctx, args_get(args, 's'), NULL, &src_wp);
|
||||||
|
if (src_wl == NULL)
|
||||||
|
return (-1);
|
||||||
|
src_w = src_wl->window;
|
||||||
|
|
||||||
|
if (src_w == dst_w) {
|
||||||
|
ctx->error(ctx, "can't join a pane to its own window");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
type = LAYOUT_TOPBOTTOM;
|
||||||
|
if (args_has(args, 'h'))
|
||||||
|
type = LAYOUT_LEFTRIGHT;
|
||||||
|
|
||||||
|
size = -1;
|
||||||
|
if (args_has(args, 'l')) {
|
||||||
|
size = args_strtonum(args, 'l', 0, INT_MAX, &cause);
|
||||||
|
if (cause != NULL) {
|
||||||
|
ctx->error(ctx, "size %s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
} else if (args_has(args, 'p')) {
|
||||||
|
percentage = args_strtonum(args, 'p', 0, 100, &cause);
|
||||||
|
if (cause != NULL) {
|
||||||
|
ctx->error(ctx, "percentage %s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
if (type == LAYOUT_TOPBOTTOM)
|
||||||
|
size = (dst_wp->sy * percentage) / 100;
|
||||||
|
else
|
||||||
|
size = (dst_wp->sx * percentage) / 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((lc = layout_split_pane(dst_wp, type, size)) == NULL) {
|
||||||
|
ctx->error(ctx, "create pane failed: pane too small");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
layout_close_pane(src_wp);
|
||||||
|
|
||||||
|
if (src_w->active == src_wp) {
|
||||||
|
src_w->active = TAILQ_PREV(src_wp, window_panes, entry);
|
||||||
|
if (src_w->active == NULL)
|
||||||
|
src_w->active = TAILQ_NEXT(src_wp, entry);
|
||||||
|
}
|
||||||
|
TAILQ_REMOVE(&src_w->panes, src_wp, entry);
|
||||||
|
|
||||||
|
if (window_count_panes(src_w) == 0)
|
||||||
|
server_kill_window(src_w);
|
||||||
|
|
||||||
|
src_wp->window = dst_w;
|
||||||
|
TAILQ_INSERT_AFTER(&dst_w->panes, dst_wp, src_wp, entry);
|
||||||
|
layout_assign_pane(lc, src_wp);
|
||||||
|
|
||||||
|
recalculate_sizes();
|
||||||
|
|
||||||
|
server_redraw_window(src_w);
|
||||||
|
server_redraw_window(dst_w);
|
||||||
|
|
||||||
|
if (!args_has(args, 'd')) {
|
||||||
|
window_set_active_pane(dst_w, src_wp);
|
||||||
|
session_select(dst_s, dst_idx);
|
||||||
|
server_redraw_session(dst_s);
|
||||||
|
} else
|
||||||
|
server_status_session(dst_s);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
75
external/bsd/tmux/dist/cmd-kill-pane.c
vendored
Normal file
75
external/bsd/tmux/dist/cmd-kill-pane.c
vendored
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
/* $Id: cmd-kill-pane.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 <stdlib.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Kill pane.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_kill_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_kill_pane_entry = {
|
||||||
|
"kill-pane", "killp",
|
||||||
|
"at:", 0, 0,
|
||||||
|
"[-a] " CMD_TARGET_PANE_USAGE,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_kill_pane_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_kill_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct winlink *wl;
|
||||||
|
struct window_pane *loopwp, *nextwp, *wp;
|
||||||
|
|
||||||
|
if ((wl = cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
if (window_count_panes(wl->window) == 1) {
|
||||||
|
/* Only one pane, kill the window. */
|
||||||
|
server_kill_window(wl->window);
|
||||||
|
recalculate_sizes();
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args_has(self->args, 'a')) {
|
||||||
|
loopwp = TAILQ_FIRST(&wl->window->panes);
|
||||||
|
while (loopwp != NULL) {
|
||||||
|
nextwp = TAILQ_NEXT(loopwp, entry);
|
||||||
|
if (loopwp != wp) {
|
||||||
|
layout_close_pane(loopwp);
|
||||||
|
window_remove_pane(wl->window, loopwp);
|
||||||
|
}
|
||||||
|
loopwp = nextwp;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
layout_close_pane(wp);
|
||||||
|
window_remove_pane(wl->window, wp);
|
||||||
|
}
|
||||||
|
server_redraw_window(wl->window);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
49
external/bsd/tmux/dist/cmd-kill-server.c
vendored
Normal file
49
external/bsd/tmux/dist/cmd-kill-server.c
vendored
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
/* $Id: cmd-kill-server.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 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 <signal.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Kill the server and do nothing else.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_kill_server_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_kill_server_entry = {
|
||||||
|
"kill-server", NULL,
|
||||||
|
"", 0, 0,
|
||||||
|
"",
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_kill_server_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ARGSUSED */
|
||||||
|
int
|
||||||
|
cmd_kill_server_exec(unused struct cmd *self, unused struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
kill(getpid(), SIGTERM);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
55
external/bsd/tmux/dist/cmd-kill-session.c
vendored
Normal file
55
external/bsd/tmux/dist/cmd-kill-session.c
vendored
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
/* $Id: cmd-kill-session.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 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 "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Destroy session, detaching all clients attached to it and destroying any
|
||||||
|
* windows linked only to this session.
|
||||||
|
*
|
||||||
|
* Note this deliberately has no alias to make it hard to hit by accident.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_kill_session_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_kill_session_entry = {
|
||||||
|
"kill-session", NULL,
|
||||||
|
"t:", 0, 0,
|
||||||
|
CMD_TARGET_SESSION_USAGE,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_kill_session_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_kill_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct session *s;
|
||||||
|
|
||||||
|
if ((s = cmd_find_session(ctx, args_get(args, 't'), 0)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
server_destroy_session(s);
|
||||||
|
session_destroy(s);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
52
external/bsd/tmux/dist/cmd-kill-window.c
vendored
Normal file
52
external/bsd/tmux/dist/cmd-kill-window.c
vendored
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
/* $Id: cmd-kill-window.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 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 "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Destroy window.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_kill_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_kill_window_entry = {
|
||||||
|
"kill-window", "killw",
|
||||||
|
"t:", 0, 0,
|
||||||
|
CMD_TARGET_WINDOW_USAGE,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_kill_window_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_kill_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct winlink *wl;
|
||||||
|
|
||||||
|
if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
server_kill_window(wl->window);
|
||||||
|
recalculate_sizes();
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
65
external/bsd/tmux/dist/cmd-link-window.c
vendored
Normal file
65
external/bsd/tmux/dist/cmd-link-window.c
vendored
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
/* $Id: cmd-link-window.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 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 <stdlib.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Link a window into another session.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_link_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_link_window_entry = {
|
||||||
|
"link-window", "linkw",
|
||||||
|
"dks:t:", 0, 0,
|
||||||
|
"[-dk] " CMD_SRCDST_WINDOW_USAGE,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_link_window_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct session *src, *dst;
|
||||||
|
struct winlink *wl;
|
||||||
|
char *cause;
|
||||||
|
int idx, kflag, dflag;
|
||||||
|
|
||||||
|
if ((wl = cmd_find_window(ctx, args_get(args, 's'), &src)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
if ((idx = cmd_find_index(ctx, args_get(args, 't'), &dst)) == -2)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
kflag = args_has(self->args, 'k');
|
||||||
|
dflag = args_has(self->args, 'd');
|
||||||
|
if (server_link_window(src, wl, dst, idx, kflag, !dflag, &cause) != 0) {
|
||||||
|
ctx->error(ctx, "can't link window: %s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
recalculate_sizes();
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
58
external/bsd/tmux/dist/cmd-list-buffers.c
vendored
Normal file
58
external/bsd/tmux/dist/cmd-list-buffers.c
vendored
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
/* $Id: cmd-list-buffers.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 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 <string.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* List paste buffers.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_list_buffers_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_list_buffers_entry = {
|
||||||
|
"list-buffers", "lsb",
|
||||||
|
"", 0, 0,
|
||||||
|
"",
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_list_buffers_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ARGSUSED */
|
||||||
|
int
|
||||||
|
cmd_list_buffers_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct paste_buffer *pb;
|
||||||
|
u_int idx;
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
|
idx = 0;
|
||||||
|
while ((pb = paste_walk_stack(&global_buffers, &idx)) != NULL) {
|
||||||
|
tmp = paste_print(pb, 50);
|
||||||
|
ctx->print(ctx,
|
||||||
|
"%u: %zu bytes: \"%s\"", idx - 1, pb->size, tmp);
|
||||||
|
xfree(tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
77
external/bsd/tmux/dist/cmd-list-clients.c
vendored
Normal file
77
external/bsd/tmux/dist/cmd-list-clients.c
vendored
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
/* $Id: cmd-list-clients.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 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 <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* List all clients.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_list_clients_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_list_clients_entry = {
|
||||||
|
"list-clients", "lsc",
|
||||||
|
"t:", 0, 0,
|
||||||
|
CMD_TARGET_SESSION_USAGE,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_list_clients_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ARGSUSED */
|
||||||
|
int
|
||||||
|
cmd_list_clients_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct client *c;
|
||||||
|
struct session *s;
|
||||||
|
u_int i;
|
||||||
|
const char *s_utf8;
|
||||||
|
|
||||||
|
if (args_has(args, 't')) {
|
||||||
|
s = cmd_find_session(ctx, args_get(args, 't'), 0);
|
||||||
|
if (s == NULL)
|
||||||
|
return (-1);
|
||||||
|
} else
|
||||||
|
s = NULL;
|
||||||
|
|
||||||
|
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||||
|
c = ARRAY_ITEM(&clients, i);
|
||||||
|
if (c == NULL || c->session == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (c->tty.flags & TTY_UTF8)
|
||||||
|
s_utf8 = " (utf8)";
|
||||||
|
else
|
||||||
|
s_utf8 = "";
|
||||||
|
|
||||||
|
if (s != NULL && s != c->session)
|
||||||
|
continue;
|
||||||
|
ctx->print(ctx, "%s: %s [%ux%u %s]%s", c->tty.path,
|
||||||
|
c->session->name, c->tty.sx, c->tty.sy,
|
||||||
|
c->tty.termname, s_utf8);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
49
external/bsd/tmux/dist/cmd-list-commands.c
vendored
Normal file
49
external/bsd/tmux/dist/cmd-list-commands.c
vendored
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
/* $Id: cmd-list-commands.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 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 "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* List all commands with usages.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_list_commands_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_list_commands_entry = {
|
||||||
|
"list-commands", "lscm",
|
||||||
|
"", 0, 0,
|
||||||
|
"",
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_list_commands_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ARGSUSED */
|
||||||
|
int
|
||||||
|
cmd_list_commands_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
const struct cmd_entry **entryp;
|
||||||
|
|
||||||
|
for (entryp = cmd_table; *entryp != NULL; entryp++)
|
||||||
|
ctx->print(ctx, "%s %s", (*entryp)->name, (*entryp)->usage);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
149
external/bsd/tmux/dist/cmd-list-keys.c
vendored
Normal file
149
external/bsd/tmux/dist/cmd-list-keys.c
vendored
Normal file
|
@ -0,0 +1,149 @@
|
||||||
|
/* $Id: cmd-list-keys.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 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 <string.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* List key bindings.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_list_keys_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
int cmd_list_keys_table(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_list_keys_entry = {
|
||||||
|
"list-keys", "lsk",
|
||||||
|
"t:", 0, 0,
|
||||||
|
"[-t key-table]",
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_list_keys_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_list_keys_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct key_binding *bd;
|
||||||
|
const char *key;
|
||||||
|
char tmp[BUFSIZ], flags[8];
|
||||||
|
size_t used;
|
||||||
|
int width, keywidth;
|
||||||
|
|
||||||
|
if (args_has(args, 't'))
|
||||||
|
return (cmd_list_keys_table(self, ctx));
|
||||||
|
|
||||||
|
width = 0;
|
||||||
|
*flags = '\0';
|
||||||
|
|
||||||
|
SPLAY_FOREACH(bd, key_bindings, &key_bindings) {
|
||||||
|
key = key_string_lookup_key(bd->key & ~KEYC_PREFIX);
|
||||||
|
if (key == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
keywidth = strlen(key);
|
||||||
|
if (!(bd->key & KEYC_PREFIX)) {
|
||||||
|
if (bd->can_repeat)
|
||||||
|
keywidth += 4;
|
||||||
|
else
|
||||||
|
keywidth += 3;
|
||||||
|
} else if (bd->can_repeat)
|
||||||
|
keywidth += 3;
|
||||||
|
if (keywidth > width)
|
||||||
|
width = keywidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
SPLAY_FOREACH(bd, key_bindings, &key_bindings) {
|
||||||
|
key = key_string_lookup_key(bd->key & ~KEYC_PREFIX);
|
||||||
|
if (key == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!(bd->key & KEYC_PREFIX)) {
|
||||||
|
if (bd->can_repeat)
|
||||||
|
xsnprintf(flags, sizeof flags, "-rn ");
|
||||||
|
else
|
||||||
|
xsnprintf(flags, sizeof flags, "-n ");
|
||||||
|
} else if (bd->can_repeat)
|
||||||
|
xsnprintf(flags, sizeof flags, "-r ");
|
||||||
|
|
||||||
|
used = xsnprintf(tmp, sizeof tmp, "%s%*s ",
|
||||||
|
flags, (int) (width - strlen(flags)), key);
|
||||||
|
if (used >= sizeof tmp)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
cmd_list_print(bd->cmdlist, tmp + used, (sizeof tmp) - used);
|
||||||
|
ctx->print(ctx, "bind-key %s", tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_list_keys_table(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
const char *tablename;
|
||||||
|
const struct mode_key_table *mtab;
|
||||||
|
struct mode_key_binding *mbind;
|
||||||
|
const char *key, *cmdstr, *mode;
|
||||||
|
int width, keywidth, any_mode;
|
||||||
|
|
||||||
|
tablename = args_get(args, 't');
|
||||||
|
if ((mtab = mode_key_findtable(tablename)) == NULL) {
|
||||||
|
ctx->error(ctx, "unknown key table: %s", tablename);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
width = 0;
|
||||||
|
any_mode = 0;
|
||||||
|
SPLAY_FOREACH(mbind, mode_key_tree, mtab->tree) {
|
||||||
|
key = key_string_lookup_key(mbind->key);
|
||||||
|
if (key == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (mbind->mode != 0)
|
||||||
|
any_mode = 1;
|
||||||
|
|
||||||
|
keywidth = strlen(key);
|
||||||
|
if (keywidth > width)
|
||||||
|
width = keywidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
SPLAY_FOREACH(mbind, mode_key_tree, mtab->tree) {
|
||||||
|
key = key_string_lookup_key(mbind->key);
|
||||||
|
if (key == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
mode = "";
|
||||||
|
if (mbind->mode != 0)
|
||||||
|
mode = "c";
|
||||||
|
cmdstr = mode_key_tostring(mtab->cmdstr, mbind->cmd);
|
||||||
|
if (cmdstr != NULL) {
|
||||||
|
ctx->print(ctx, "bind-key -%st %s%s %*s %s",
|
||||||
|
mode, any_mode && *mode == '\0' ? " " : "",
|
||||||
|
mtab->name, (int) width, key, cmdstr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
137
external/bsd/tmux/dist/cmd-list-panes.c
vendored
Normal file
137
external/bsd/tmux/dist/cmd-list-panes.c
vendored
Normal file
|
@ -0,0 +1,137 @@
|
||||||
|
/* $Id: cmd-list-panes.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 <unistd.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* List panes on given window.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_list_panes_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
void cmd_list_panes_server(struct cmd_ctx *);
|
||||||
|
void cmd_list_panes_session(struct session *, struct cmd_ctx *, int);
|
||||||
|
void cmd_list_panes_window(
|
||||||
|
struct session *, struct winlink *, struct cmd_ctx *, int);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_list_panes_entry = {
|
||||||
|
"list-panes", "lsp",
|
||||||
|
"ast:", 0, 0,
|
||||||
|
"[-as] [-t target]",
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_list_panes_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_list_panes_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct session *s;
|
||||||
|
struct winlink *wl;
|
||||||
|
|
||||||
|
if (args_has(args, 'a'))
|
||||||
|
cmd_list_panes_server(ctx);
|
||||||
|
else if (args_has(args, 's')) {
|
||||||
|
s = cmd_find_session(ctx, args_get(args, 't'), 0);
|
||||||
|
if (s == NULL)
|
||||||
|
return (-1);
|
||||||
|
cmd_list_panes_session(s, ctx, 1);
|
||||||
|
} else {
|
||||||
|
wl = cmd_find_window(ctx, args_get(args, 't'), &s);
|
||||||
|
if (wl == NULL)
|
||||||
|
return (-1);
|
||||||
|
cmd_list_panes_window(s, wl, ctx, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_list_panes_server(struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct session *s;
|
||||||
|
|
||||||
|
RB_FOREACH(s, sessions, &sessions)
|
||||||
|
cmd_list_panes_session(s, ctx, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_list_panes_session(struct session *s, struct cmd_ctx *ctx, int type)
|
||||||
|
{
|
||||||
|
struct winlink *wl;
|
||||||
|
|
||||||
|
RB_FOREACH(wl, winlinks, &s->windows)
|
||||||
|
cmd_list_panes_window(s, wl, ctx, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_list_panes_window(
|
||||||
|
struct session *s, struct winlink *wl, struct cmd_ctx *ctx, int type)
|
||||||
|
{
|
||||||
|
struct window_pane *wp;
|
||||||
|
struct grid *gd;
|
||||||
|
struct grid_line *gl;
|
||||||
|
u_int i, n;
|
||||||
|
unsigned long long size;
|
||||||
|
|
||||||
|
n = 0;
|
||||||
|
TAILQ_FOREACH(wp, &wl->window->panes, entry) {
|
||||||
|
gd = wp->base.grid;
|
||||||
|
|
||||||
|
size = 0;
|
||||||
|
for (i = 0; i < gd->hsize; i++) {
|
||||||
|
gl = &gd->linedata[i];
|
||||||
|
size += gl->cellsize * sizeof *gl->celldata;
|
||||||
|
size += gl->utf8size * sizeof *gl->utf8data;
|
||||||
|
}
|
||||||
|
size += gd->hsize * sizeof *gd->linedata;
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case 0:
|
||||||
|
ctx->print(ctx,
|
||||||
|
"%u: [%ux%u] [history %u/%u, %llu bytes] %%%u%s%s",
|
||||||
|
n, wp->sx, wp->sy, gd->hsize, gd->hlimit, size,
|
||||||
|
wp->id, wp == wp->window->active ? " (active)" : "",
|
||||||
|
wp->fd == -1 ? " (dead)" : "");
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
ctx->print(ctx,
|
||||||
|
"%d.%u: [%ux%u] [history %u/%u, %llu bytes] "
|
||||||
|
"%%%u%s%s", wl->idx,
|
||||||
|
n, wp->sx, wp->sy, gd->hsize, gd->hlimit, size,
|
||||||
|
wp->id, wp == wp->window->active ? " (active)" : "",
|
||||||
|
wp->fd == -1 ? " (dead)" : "");
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
ctx->print(ctx,
|
||||||
|
"%s:%d.%u: [%ux%u] [history %u/%u, %llu bytes] "
|
||||||
|
"%%%u%s%s", s->name, wl->idx,
|
||||||
|
n, wp->sx, wp->sy, gd->hsize, gd->hlimit, size,
|
||||||
|
wp->id, wp == wp->window->active ? " (active)" : "",
|
||||||
|
wp->fd == -1 ? " (dead)" : "");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
}
|
71
external/bsd/tmux/dist/cmd-list-sessions.c
vendored
Normal file
71
external/bsd/tmux/dist/cmd-list-sessions.c
vendored
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
/* $Id: cmd-list-sessions.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 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 <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* List all sessions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_list_sessions_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_list_sessions_entry = {
|
||||||
|
"list-sessions", "ls",
|
||||||
|
"", 0, 0,
|
||||||
|
"",
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_list_sessions_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ARGSUSED */
|
||||||
|
int
|
||||||
|
cmd_list_sessions_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct session *s;
|
||||||
|
struct session_group *sg;
|
||||||
|
char *tim, tmp[64];
|
||||||
|
u_int idx;
|
||||||
|
time_t t;
|
||||||
|
|
||||||
|
RB_FOREACH(s, sessions, &sessions) {
|
||||||
|
sg = session_group_find(s);
|
||||||
|
if (sg == NULL)
|
||||||
|
*tmp = '\0';
|
||||||
|
else {
|
||||||
|
idx = session_group_index(sg);
|
||||||
|
xsnprintf(tmp, sizeof tmp, " (group %u)", idx);
|
||||||
|
}
|
||||||
|
|
||||||
|
t = s->creation_time.tv_sec;
|
||||||
|
tim = ctime(&t);
|
||||||
|
*strchr(tim, '\n') = '\0';
|
||||||
|
|
||||||
|
ctx->print(ctx, "%s: %u windows (created %s) [%ux%u]%s%s",
|
||||||
|
s->name, winlink_count(&s->windows), tim, s->sx, s->sy,
|
||||||
|
tmp, s->flags & SESSION_UNATTACHED ? "" : " (attached)");
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
92
external/bsd/tmux/dist/cmd-list-windows.c
vendored
Normal file
92
external/bsd/tmux/dist/cmd-list-windows.c
vendored
Normal file
|
@ -0,0 +1,92 @@
|
||||||
|
/* $Id: cmd-list-windows.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 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 <unistd.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* List windows on given session.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_list_windows_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
void cmd_list_windows_server(struct cmd_ctx *);
|
||||||
|
void cmd_list_windows_session(struct session *, struct cmd_ctx *, int);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_list_windows_entry = {
|
||||||
|
"list-windows", "lsw",
|
||||||
|
"at:", 0, 0,
|
||||||
|
"[-a] " CMD_TARGET_SESSION_USAGE,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_list_windows_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_list_windows_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct session *s;
|
||||||
|
|
||||||
|
if (args_has(args, 'a'))
|
||||||
|
cmd_list_windows_server(ctx);
|
||||||
|
else {
|
||||||
|
s = cmd_find_session(ctx, args_get(args, 't'), 0);
|
||||||
|
if (s == NULL)
|
||||||
|
return (-1);
|
||||||
|
cmd_list_windows_session(s, ctx, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_list_windows_server(struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct session *s;
|
||||||
|
|
||||||
|
RB_FOREACH(s, sessions, &sessions)
|
||||||
|
cmd_list_windows_session(s, ctx, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_list_windows_session(struct session *s, struct cmd_ctx *ctx, int type)
|
||||||
|
{
|
||||||
|
struct winlink *wl;
|
||||||
|
char *layout;
|
||||||
|
|
||||||
|
RB_FOREACH(wl, winlinks, &s->windows) {
|
||||||
|
layout = layout_dump(wl->window);
|
||||||
|
if (type) {
|
||||||
|
ctx->print(ctx, "%s:%d: %s [%ux%u] [layout %s]%s",
|
||||||
|
s->name, wl->idx, wl->window->name, wl->window->sx,
|
||||||
|
wl->window->sy, layout,
|
||||||
|
wl == s->curw ? " (active)" : "");
|
||||||
|
} else {
|
||||||
|
ctx->print(ctx, "%d: %s [%ux%u] [layout %s]%s",
|
||||||
|
wl->idx, wl->window->name, wl->window->sx,
|
||||||
|
wl->window->sy, layout,
|
||||||
|
wl == s->curw ? " (active)" : "");
|
||||||
|
}
|
||||||
|
xfree(layout);
|
||||||
|
}
|
||||||
|
}
|
150
external/bsd/tmux/dist/cmd-list.c
vendored
Normal file
150
external/bsd/tmux/dist/cmd-list.c
vendored
Normal file
|
@ -0,0 +1,150 @@
|
||||||
|
/* $Id: cmd-list.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 <string.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
struct cmd_list *
|
||||||
|
cmd_list_parse(int argc, char **argv, char **cause)
|
||||||
|
{
|
||||||
|
struct cmd_list *cmdlist;
|
||||||
|
struct cmd *cmd;
|
||||||
|
int i, lastsplit;
|
||||||
|
size_t arglen, new_argc;
|
||||||
|
char **copy_argv, **new_argv;
|
||||||
|
|
||||||
|
copy_argv = cmd_copy_argv(argc, argv);
|
||||||
|
|
||||||
|
cmdlist = xmalloc(sizeof *cmdlist);
|
||||||
|
cmdlist->references = 1;
|
||||||
|
TAILQ_INIT(&cmdlist->list);
|
||||||
|
|
||||||
|
lastsplit = 0;
|
||||||
|
for (i = 0; i < argc; i++) {
|
||||||
|
arglen = strlen(copy_argv[i]);
|
||||||
|
if (arglen == 0 || copy_argv[i][arglen - 1] != ';')
|
||||||
|
continue;
|
||||||
|
copy_argv[i][arglen - 1] = '\0';
|
||||||
|
|
||||||
|
if (arglen > 1 && copy_argv[i][arglen - 2] == '\\') {
|
||||||
|
copy_argv[i][arglen - 2] = ';';
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
new_argc = i - lastsplit;
|
||||||
|
new_argv = copy_argv + lastsplit;
|
||||||
|
if (arglen != 1)
|
||||||
|
new_argc++;
|
||||||
|
|
||||||
|
cmd = cmd_parse(new_argc, new_argv, cause);
|
||||||
|
if (cmd == NULL)
|
||||||
|
goto bad;
|
||||||
|
TAILQ_INSERT_TAIL(&cmdlist->list, cmd, qentry);
|
||||||
|
|
||||||
|
lastsplit = i + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lastsplit != argc) {
|
||||||
|
cmd = cmd_parse(argc - lastsplit, copy_argv + lastsplit, cause);
|
||||||
|
if (cmd == NULL)
|
||||||
|
goto bad;
|
||||||
|
TAILQ_INSERT_TAIL(&cmdlist->list, cmd, qentry);
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd_free_argv(argc, copy_argv);
|
||||||
|
return (cmdlist);
|
||||||
|
|
||||||
|
bad:
|
||||||
|
cmd_list_free(cmdlist);
|
||||||
|
cmd_free_argv(argc, copy_argv);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_list_exec(struct cmd_list *cmdlist, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd *cmd;
|
||||||
|
int n, retval;
|
||||||
|
|
||||||
|
retval = 0;
|
||||||
|
TAILQ_FOREACH(cmd, &cmdlist->list, qentry) {
|
||||||
|
if ((n = cmd_exec(cmd, ctx)) == -1)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* A 1 return value means the command client is being attached
|
||||||
|
* (sent MSG_READY).
|
||||||
|
*/
|
||||||
|
if (n == 1) {
|
||||||
|
retval = 1;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The command client has been attached, so mangle the
|
||||||
|
* context to treat any following commands as if they
|
||||||
|
* were called from inside.
|
||||||
|
*/
|
||||||
|
if (ctx->curclient == NULL) {
|
||||||
|
ctx->curclient = ctx->cmdclient;
|
||||||
|
ctx->cmdclient = NULL;
|
||||||
|
|
||||||
|
ctx->error = key_bindings_error;
|
||||||
|
ctx->print = key_bindings_print;
|
||||||
|
ctx->info = key_bindings_info;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (retval);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_list_free(struct cmd_list *cmdlist)
|
||||||
|
{
|
||||||
|
struct cmd *cmd;
|
||||||
|
|
||||||
|
if (--cmdlist->references != 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
while (!TAILQ_EMPTY(&cmdlist->list)) {
|
||||||
|
cmd = TAILQ_FIRST(&cmdlist->list);
|
||||||
|
TAILQ_REMOVE(&cmdlist->list, cmd, qentry);
|
||||||
|
cmd_free(cmd);
|
||||||
|
}
|
||||||
|
xfree(cmdlist);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
cmd_list_print(struct cmd_list *cmdlist, char *buf, size_t len)
|
||||||
|
{
|
||||||
|
struct cmd *cmd;
|
||||||
|
size_t off;
|
||||||
|
|
||||||
|
off = 0;
|
||||||
|
TAILQ_FOREACH(cmd, &cmdlist->list, qentry) {
|
||||||
|
if (off >= len)
|
||||||
|
break;
|
||||||
|
off += cmd_print(cmd, buf + off, len - off);
|
||||||
|
if (off >= len)
|
||||||
|
break;
|
||||||
|
if (TAILQ_NEXT(cmd, qentry) != NULL)
|
||||||
|
off += xsnprintf(buf + off, len - off, " ; ");
|
||||||
|
}
|
||||||
|
return (off);
|
||||||
|
}
|
174
external/bsd/tmux/dist/cmd-load-buffer.c
vendored
Normal file
174
external/bsd/tmux/dist/cmd-load-buffer.c
vendored
Normal file
|
@ -0,0 +1,174 @@
|
||||||
|
/* $Id: cmd-load-buffer.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
||||||
|
*
|
||||||
|
* 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 <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Loads a session paste buffer from a file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_load_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
void cmd_load_buffer_callback(struct client *, void *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_load_buffer_entry = {
|
||||||
|
"load-buffer", "loadb",
|
||||||
|
"b:", 1, 1,
|
||||||
|
CMD_BUFFER_USAGE " path",
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_load_buffer_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_load_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct client *c = ctx->cmdclient;
|
||||||
|
FILE *f;
|
||||||
|
const char *path;
|
||||||
|
char *pdata, *new_pdata, *cause;
|
||||||
|
size_t psize;
|
||||||
|
u_int limit;
|
||||||
|
int ch, buffer;
|
||||||
|
int *buffer_ptr;
|
||||||
|
|
||||||
|
if (!args_has(args, 'b'))
|
||||||
|
buffer = -1;
|
||||||
|
else {
|
||||||
|
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
|
||||||
|
if (cause != NULL) {
|
||||||
|
ctx->error(ctx, "buffer %s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
path = args->argv[0];
|
||||||
|
if (strcmp(path, "-") == 0) {
|
||||||
|
if (c == NULL) {
|
||||||
|
ctx->error(ctx, "%s: can't read from stdin", path);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
if (c->flags & CLIENT_TERMINAL) {
|
||||||
|
ctx->error(ctx, "%s: stdin is a tty", path);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
if (c->stdin_fd == -1) {
|
||||||
|
ctx->error(ctx, "%s: can't read from stdin", path);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer_ptr = xmalloc(sizeof *buffer_ptr);
|
||||||
|
*buffer_ptr = buffer;
|
||||||
|
|
||||||
|
c->stdin_data = buffer_ptr;
|
||||||
|
c->stdin_callback = cmd_load_buffer_callback;
|
||||||
|
|
||||||
|
c->references++;
|
||||||
|
bufferevent_enable(c->stdin_event, EV_READ);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((f = fopen(path, "rb")) == NULL) {
|
||||||
|
ctx->error(ctx, "%s: %s", path, strerror(errno));
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
pdata = NULL;
|
||||||
|
psize = 0;
|
||||||
|
while ((ch = getc(f)) != EOF) {
|
||||||
|
/* Do not let the server die due to memory exhaustion. */
|
||||||
|
if ((new_pdata = realloc(pdata, psize + 2)) == NULL) {
|
||||||
|
ctx->error(ctx, "realloc error: %s", strerror(errno));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
pdata = new_pdata;
|
||||||
|
pdata[psize++] = ch;
|
||||||
|
}
|
||||||
|
if (ferror(f)) {
|
||||||
|
ctx->error(ctx, "%s: read error", path);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
if (pdata != NULL)
|
||||||
|
pdata[psize] = '\0';
|
||||||
|
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
|
limit = options_get_number(&global_options, "buffer-limit");
|
||||||
|
if (buffer == -1) {
|
||||||
|
paste_add(&global_buffers, pdata, psize, limit);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
if (paste_replace(&global_buffers, buffer, pdata, psize) != 0) {
|
||||||
|
ctx->error(ctx, "no buffer %d", buffer);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
error:
|
||||||
|
if (pdata != NULL)
|
||||||
|
xfree(pdata);
|
||||||
|
if (f != NULL)
|
||||||
|
fclose(f);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_load_buffer_callback(struct client *c, void *data)
|
||||||
|
{
|
||||||
|
int *buffer = data;
|
||||||
|
char *pdata;
|
||||||
|
size_t psize;
|
||||||
|
u_int limit;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Event callback has already checked client is not dead and reduced
|
||||||
|
* its reference count. But tell it to exit.
|
||||||
|
*/
|
||||||
|
c->flags |= CLIENT_EXIT;
|
||||||
|
|
||||||
|
psize = EVBUFFER_LENGTH(c->stdin_event->input);
|
||||||
|
if (psize == 0 || (pdata = malloc(psize + 1)) == NULL) {
|
||||||
|
xfree(data);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
bufferevent_read(c->stdin_event, pdata, psize);
|
||||||
|
pdata[psize] = '\0';
|
||||||
|
|
||||||
|
limit = options_get_number(&global_options, "buffer-limit");
|
||||||
|
if (*buffer == -1)
|
||||||
|
paste_add(&global_buffers, pdata, psize, limit);
|
||||||
|
else if (paste_replace(&global_buffers, *buffer, pdata, psize) != 0) {
|
||||||
|
/* No context so can't use server_client_msg_error. */
|
||||||
|
evbuffer_add_printf(
|
||||||
|
c->stderr_event->output, "no buffer %d\n", *buffer);
|
||||||
|
bufferevent_enable(c->stderr_event, EV_WRITE);
|
||||||
|
}
|
||||||
|
|
||||||
|
xfree(data);
|
||||||
|
}
|
85
external/bsd/tmux/dist/cmd-lock-server.c
vendored
Normal file
85
external/bsd/tmux/dist/cmd-lock-server.c
vendored
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
/* $Id: cmd-lock-server.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008 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 <pwd.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Lock commands.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_lock_server_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_lock_server_entry = {
|
||||||
|
"lock-server", "lock",
|
||||||
|
"", 0, 0,
|
||||||
|
"",
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_lock_server_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_lock_session_entry = {
|
||||||
|
"lock-session", "locks",
|
||||||
|
"t:", 0, 0,
|
||||||
|
CMD_TARGET_SESSION_USAGE,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_lock_server_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_lock_client_entry = {
|
||||||
|
"lock-client", "lockc",
|
||||||
|
"t:", 0, 0,
|
||||||
|
CMD_TARGET_CLIENT_USAGE,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_lock_server_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ARGSUSED */
|
||||||
|
int
|
||||||
|
cmd_lock_server_exec(struct cmd *self, unused struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct client *c;
|
||||||
|
struct session *s;
|
||||||
|
|
||||||
|
if (self->entry == &cmd_lock_server_entry)
|
||||||
|
server_lock();
|
||||||
|
else if (self->entry == &cmd_lock_session_entry) {
|
||||||
|
if ((s = cmd_find_session(ctx, args_get(args, 't'), 0)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
server_lock_session(s);
|
||||||
|
} else {
|
||||||
|
if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
|
||||||
|
return (-1);
|
||||||
|
server_lock_client(c);
|
||||||
|
}
|
||||||
|
recalculate_sizes();
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
66
external/bsd/tmux/dist/cmd-move-window.c
vendored
Normal file
66
external/bsd/tmux/dist/cmd-move-window.c
vendored
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
/* $Id: cmd-move-window.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008 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 <stdlib.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Move a window.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_move_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_move_window_entry = {
|
||||||
|
"move-window", "movew",
|
||||||
|
"dks:t:", 0, 0,
|
||||||
|
"[-dk] " CMD_SRCDST_WINDOW_USAGE,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_move_window_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_move_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct session *src, *dst;
|
||||||
|
struct winlink *wl;
|
||||||
|
char *cause;
|
||||||
|
int idx, kflag, dflag;
|
||||||
|
|
||||||
|
if ((wl = cmd_find_window(ctx, args_get(args, 's'), &src)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
if ((idx = cmd_find_index(ctx, args_get(args, 't'), &dst)) == -2)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
kflag = args_has(self->args, 'k');
|
||||||
|
dflag = args_has(self->args, 'd');
|
||||||
|
if (server_link_window(src, wl, dst, idx, kflag, !dflag, &cause) != 0) {
|
||||||
|
ctx->error(ctx, "can't move window: %s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
server_unlink_window(src, wl);
|
||||||
|
recalculate_sizes();
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
277
external/bsd/tmux/dist/cmd-new-session.c
vendored
Normal file
277
external/bsd/tmux/dist/cmd-new-session.c
vendored
Normal file
|
@ -0,0 +1,277 @@
|
||||||
|
/* $Id: cmd-new-session.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 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 <pwd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <termios.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create a new session and attach to the current terminal unless -d is given.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_new_session_check(struct args *);
|
||||||
|
int cmd_new_session_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_new_session_entry = {
|
||||||
|
"new-session", "new",
|
||||||
|
"dn:s:t:x:y:", 0, 1,
|
||||||
|
"[-d] [-n window-name] [-s session-name] [-t target-session] "
|
||||||
|
"[-x width] [-y height] [command]",
|
||||||
|
CMD_STARTSERVER|CMD_CANTNEST|CMD_SENDENVIRON,
|
||||||
|
NULL,
|
||||||
|
cmd_new_session_check,
|
||||||
|
cmd_new_session_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_new_session_check(struct args *args)
|
||||||
|
{
|
||||||
|
if (args_has(args, 't') && (args->argc != 0 || args_has(args, 'n')))
|
||||||
|
return (-1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct session *s, *old_s, *groupwith;
|
||||||
|
struct window *w;
|
||||||
|
struct window_pane *wp;
|
||||||
|
struct environ env;
|
||||||
|
struct termios tio, *tiop;
|
||||||
|
struct passwd *pw;
|
||||||
|
const char *newname, *target, *update, *cwd, *errstr;
|
||||||
|
char *overrides, *cmd, *cause;
|
||||||
|
int detached, idx;
|
||||||
|
u_int sx, sy, i;
|
||||||
|
|
||||||
|
newname = args_get(args, 's');
|
||||||
|
if (newname != NULL) {
|
||||||
|
if (!session_check_name(newname)) {
|
||||||
|
ctx->error(ctx, "bad session name: %s", newname);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
if (session_find(newname) != NULL) {
|
||||||
|
ctx->error(ctx, "duplicate session: %s", newname);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
target = args_get(args, 't');
|
||||||
|
if (target != NULL) {
|
||||||
|
groupwith = cmd_find_session(ctx, target, 0);
|
||||||
|
if (groupwith == NULL)
|
||||||
|
return (-1);
|
||||||
|
} else
|
||||||
|
groupwith = NULL;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* There are three cases:
|
||||||
|
*
|
||||||
|
* 1. If cmdclient is non-NULL, new-session has been called from the
|
||||||
|
* command-line - cmdclient is to become a new attached, interactive
|
||||||
|
* client. Unless -d is given, the terminal must be opened and then
|
||||||
|
* the client sent MSG_READY.
|
||||||
|
*
|
||||||
|
* 2. If cmdclient is NULL, new-session has been called from an
|
||||||
|
* existing client (such as a key binding).
|
||||||
|
*
|
||||||
|
* 3. Both are NULL, the command was in the configuration file. Treat
|
||||||
|
* this as if -d was given even if it was not.
|
||||||
|
*
|
||||||
|
* In all cases, a new additional session needs to be created and
|
||||||
|
* (unless -d) set as the current session for the client.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Set -d if no client. */
|
||||||
|
detached = args_has(args, 'd');
|
||||||
|
if (ctx->cmdclient == NULL && ctx->curclient == NULL)
|
||||||
|
detached = 1;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Save the termios settings, part of which is used for new windows in
|
||||||
|
* this session.
|
||||||
|
*
|
||||||
|
* This is read again with tcgetattr() rather than using tty.tio as if
|
||||||
|
* detached, tty_open won't be called. Because of this, it must be done
|
||||||
|
* before opening the terminal as that calls tcsetattr() to prepare for
|
||||||
|
* tmux taking over.
|
||||||
|
*/
|
||||||
|
if (ctx->cmdclient != NULL && ctx->cmdclient->tty.fd != -1) {
|
||||||
|
if (tcgetattr(ctx->cmdclient->tty.fd, &tio) != 0)
|
||||||
|
fatal("tcgetattr failed");
|
||||||
|
tiop = &tio;
|
||||||
|
} else
|
||||||
|
tiop = NULL;
|
||||||
|
|
||||||
|
/* Open the terminal if necessary. */
|
||||||
|
if (!detached && ctx->cmdclient != NULL) {
|
||||||
|
if (!(ctx->cmdclient->flags & CLIENT_TERMINAL)) {
|
||||||
|
ctx->error(ctx, "not a terminal");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
overrides =
|
||||||
|
options_get_string(&global_s_options, "terminal-overrides");
|
||||||
|
if (tty_open(&ctx->cmdclient->tty, overrides, &cause) != 0) {
|
||||||
|
ctx->error(ctx, "open terminal failed: %s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get the new session working directory. */
|
||||||
|
if (ctx->cmdclient != NULL && ctx->cmdclient->cwd != NULL)
|
||||||
|
cwd = ctx->cmdclient->cwd;
|
||||||
|
else {
|
||||||
|
pw = getpwuid(getuid());
|
||||||
|
if (pw->pw_dir != NULL && *pw->pw_dir != '\0')
|
||||||
|
cwd = pw->pw_dir;
|
||||||
|
else
|
||||||
|
cwd = "/";
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Find new session size. */
|
||||||
|
if (detached) {
|
||||||
|
sx = 80;
|
||||||
|
sy = 24;
|
||||||
|
if (args_has(args, 'x')) {
|
||||||
|
sx = strtonum(
|
||||||
|
args_get(args, 'x'), 1, USHRT_MAX, &errstr);
|
||||||
|
if (errstr != NULL) {
|
||||||
|
ctx->error(ctx, "width %s", errstr);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (args_has(args, 'y')) {
|
||||||
|
sy = strtonum(
|
||||||
|
args_get(args, 'y'), 1, USHRT_MAX, &errstr);
|
||||||
|
if (errstr != NULL) {
|
||||||
|
ctx->error(ctx, "height %s", errstr);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (ctx->cmdclient != NULL) {
|
||||||
|
sx = ctx->cmdclient->tty.sx;
|
||||||
|
sy = ctx->cmdclient->tty.sy;
|
||||||
|
} else {
|
||||||
|
sx = ctx->curclient->tty.sx;
|
||||||
|
sy = ctx->curclient->tty.sy;
|
||||||
|
}
|
||||||
|
if (sy > 0 && options_get_number(&global_s_options, "status"))
|
||||||
|
sy--;
|
||||||
|
if (sx == 0)
|
||||||
|
sx = 1;
|
||||||
|
if (sy == 0)
|
||||||
|
sy = 1;
|
||||||
|
|
||||||
|
/* Figure out the command for the new window. */
|
||||||
|
if (target != NULL)
|
||||||
|
cmd = NULL;
|
||||||
|
else if (args->argc != 0)
|
||||||
|
cmd = args->argv[0];
|
||||||
|
else
|
||||||
|
cmd = options_get_string(&global_s_options, "default-command");
|
||||||
|
|
||||||
|
/* Construct the environment. */
|
||||||
|
environ_init(&env);
|
||||||
|
update = options_get_string(&global_s_options, "update-environment");
|
||||||
|
if (ctx->cmdclient != NULL)
|
||||||
|
environ_update(update, &ctx->cmdclient->environ, &env);
|
||||||
|
|
||||||
|
/* Create the new session. */
|
||||||
|
idx = -1 - options_get_number(&global_s_options, "base-index");
|
||||||
|
s = session_create(newname, cmd, cwd, &env, tiop, idx, sx, sy, &cause);
|
||||||
|
if (s == NULL) {
|
||||||
|
ctx->error(ctx, "create session failed: %s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
environ_free(&env);
|
||||||
|
|
||||||
|
/* Set the initial window name if one given. */
|
||||||
|
if (cmd != NULL && args_has(args, 'n')) {
|
||||||
|
w = s->curw->window;
|
||||||
|
|
||||||
|
xfree(w->name);
|
||||||
|
w->name = xstrdup(args_get(args, 'n'));
|
||||||
|
|
||||||
|
options_set_number(&w->options, "automatic-rename", 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If a target session is given, this is to be part of a session group,
|
||||||
|
* so add it to the group and synchronize.
|
||||||
|
*/
|
||||||
|
if (groupwith != NULL) {
|
||||||
|
session_group_add(groupwith, s);
|
||||||
|
session_group_synchronize_to(s);
|
||||||
|
session_select(s, RB_ROOT(&s->windows)->idx);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set the client to the new session. If a command client exists, it is
|
||||||
|
* taking this session and needs to get MSG_READY and stay around.
|
||||||
|
*/
|
||||||
|
if (!detached) {
|
||||||
|
if (ctx->cmdclient != NULL) {
|
||||||
|
server_write_client(ctx->cmdclient, MSG_READY, NULL, 0);
|
||||||
|
|
||||||
|
old_s = ctx->cmdclient->session;
|
||||||
|
if (old_s != NULL)
|
||||||
|
ctx->cmdclient->last_session = old_s;
|
||||||
|
ctx->cmdclient->session = s;
|
||||||
|
session_update_activity(s);
|
||||||
|
server_redraw_client(ctx->cmdclient);
|
||||||
|
} else {
|
||||||
|
old_s = ctx->curclient->session;
|
||||||
|
if (old_s != NULL)
|
||||||
|
ctx->curclient->last_session = old_s;
|
||||||
|
ctx->curclient->session = s;
|
||||||
|
session_update_activity(s);
|
||||||
|
server_redraw_client(ctx->curclient);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
recalculate_sizes();
|
||||||
|
server_update_socket();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If there are still configuration file errors to display, put the new
|
||||||
|
* session's current window into more mode and display them now.
|
||||||
|
*/
|
||||||
|
if (cfg_finished && !ARRAY_EMPTY(&cfg_causes)) {
|
||||||
|
wp = s->curw->window->active;
|
||||||
|
window_pane_set_mode(wp, &window_copy_mode);
|
||||||
|
window_copy_init_for_output(wp);
|
||||||
|
for (i = 0; i < ARRAY_LENGTH(&cfg_causes); i++) {
|
||||||
|
cause = ARRAY_ITEM(&cfg_causes, i);
|
||||||
|
window_copy_add(wp, "%s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
}
|
||||||
|
ARRAY_FREE(&cfg_causes);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (!detached); /* 1 means don't tell command client to exit */
|
||||||
|
}
|
126
external/bsd/tmux/dist/cmd-new-window.c
vendored
Normal file
126
external/bsd/tmux/dist/cmd-new-window.c
vendored
Normal file
|
@ -0,0 +1,126 @@
|
||||||
|
/* $Id: cmd-new-window.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 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 <stdlib.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create a new window.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_new_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_new_window_entry = {
|
||||||
|
"new-window", "neww",
|
||||||
|
"adkn:Pt:", 0, 1,
|
||||||
|
"[-adk] [-n window-name] [-t target-window] [command]",
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_new_window_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct session *s;
|
||||||
|
struct winlink *wl;
|
||||||
|
char *cmd, *cwd, *cause;
|
||||||
|
int idx, last, detached;
|
||||||
|
|
||||||
|
if (args_has(args, 'a')) {
|
||||||
|
wl = cmd_find_window(ctx, args_get(args, 't'), &s);
|
||||||
|
if (wl == NULL)
|
||||||
|
return (-1);
|
||||||
|
idx = wl->idx + 1;
|
||||||
|
|
||||||
|
/* Find the next free index. */
|
||||||
|
for (last = idx; last < INT_MAX; last++) {
|
||||||
|
if (winlink_find_by_index(&s->windows, last) == NULL)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (last == INT_MAX) {
|
||||||
|
ctx->error(ctx, "no free window indexes");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Move everything from last - 1 to idx up a bit. */
|
||||||
|
for (; last > idx; last--) {
|
||||||
|
wl = winlink_find_by_index(&s->windows, last - 1);
|
||||||
|
server_link_window(s, wl, s, last, 0, 0, NULL);
|
||||||
|
server_unlink_window(s, wl);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ((idx = cmd_find_index(ctx, args_get(args, 't'), &s)) == -2)
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
detached = args_has(args, 'd');
|
||||||
|
|
||||||
|
wl = NULL;
|
||||||
|
if (idx != -1)
|
||||||
|
wl = winlink_find_by_index(&s->windows, idx);
|
||||||
|
if (wl != NULL && args_has(args, 'k')) {
|
||||||
|
/*
|
||||||
|
* Can't use session_detach as it will destroy session if this
|
||||||
|
* makes it empty.
|
||||||
|
*/
|
||||||
|
wl->flags &= ~WINLINK_ALERTFLAGS;
|
||||||
|
winlink_stack_remove(&s->lastw, wl);
|
||||||
|
winlink_remove(&s->windows, wl);
|
||||||
|
|
||||||
|
/* Force select/redraw if current. */
|
||||||
|
if (wl == s->curw) {
|
||||||
|
detached = 0;
|
||||||
|
s->curw = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args->argc == 0)
|
||||||
|
cmd = options_get_string(&s->options, "default-command");
|
||||||
|
else
|
||||||
|
cmd = args->argv[0];
|
||||||
|
cwd = options_get_string(&s->options, "default-path");
|
||||||
|
if (*cwd == '\0') {
|
||||||
|
if (ctx->cmdclient != NULL && ctx->cmdclient->cwd != NULL)
|
||||||
|
cwd = ctx->cmdclient->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);
|
||||||
|
if (wl == NULL) {
|
||||||
|
ctx->error(ctx, "create window failed: %s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
if (!detached) {
|
||||||
|
session_select(s, wl->idx);
|
||||||
|
server_redraw_session_group(s);
|
||||||
|
} else
|
||||||
|
server_status_session_group(s);
|
||||||
|
|
||||||
|
if (args_has(args, 'P'))
|
||||||
|
ctx->print(ctx, "%s:%u", s->name, wl->idx);
|
||||||
|
return (0);
|
||||||
|
}
|
121
external/bsd/tmux/dist/cmd-paste-buffer.c
vendored
Normal file
121
external/bsd/tmux/dist/cmd-paste-buffer.c
vendored
Normal file
|
@ -0,0 +1,121 @@
|
||||||
|
/* $Id: cmd-paste-buffer.c,v 1.3 2011/08/17 18:48:35 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 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 <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Paste paste buffer if present.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_paste_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
void cmd_paste_buffer_filter(
|
||||||
|
struct window_pane *, const char *, size_t, const char *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_paste_buffer_entry = {
|
||||||
|
"paste-buffer", "pasteb",
|
||||||
|
"db:rs:t:", 0, 0,
|
||||||
|
"[-dr] [-s separator] [-b buffer-index] [-t target-pane]",
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_paste_buffer_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct window_pane *wp;
|
||||||
|
struct session *s;
|
||||||
|
struct paste_buffer *pb;
|
||||||
|
const char *sepstr;
|
||||||
|
char *cause;
|
||||||
|
int buffer;
|
||||||
|
|
||||||
|
if (cmd_find_pane(ctx, args_get(args, 't'), &s, &wp) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
if (!args_has(args, 'b'))
|
||||||
|
buffer = -1;
|
||||||
|
else {
|
||||||
|
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
|
||||||
|
if (cause != NULL) {
|
||||||
|
ctx->error(ctx, "buffer %s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buffer == -1)
|
||||||
|
pb = paste_get_top(&global_buffers);
|
||||||
|
else {
|
||||||
|
pb = paste_get_index(&global_buffers, buffer);
|
||||||
|
if (pb == NULL) {
|
||||||
|
ctx->error(ctx, "no buffer %d", buffer);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pb != NULL) {
|
||||||
|
sepstr = args_get(args, 's');
|
||||||
|
if (sepstr == NULL) {
|
||||||
|
if (args_has(args, 'r'))
|
||||||
|
sepstr = "\n";
|
||||||
|
else
|
||||||
|
sepstr = "\r";
|
||||||
|
}
|
||||||
|
cmd_paste_buffer_filter(wp, pb->data, pb->size, sepstr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Delete the buffer if -d. */
|
||||||
|
if (args_has(args, 'd')) {
|
||||||
|
if (buffer == -1)
|
||||||
|
paste_free_top(&global_buffers);
|
||||||
|
else
|
||||||
|
paste_free_index(&global_buffers, buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Add bytes to a buffer and filter '\n' according to separator. */
|
||||||
|
void
|
||||||
|
cmd_paste_buffer_filter(
|
||||||
|
struct window_pane *wp, const char *data, size_t size, const char *sep)
|
||||||
|
{
|
||||||
|
const char *end = data + size;
|
||||||
|
const char *lf;
|
||||||
|
size_t seplen;
|
||||||
|
|
||||||
|
seplen = strlen(sep);
|
||||||
|
while ((lf = memchr(data, '\n', end - data)) != NULL) {
|
||||||
|
if (lf != data)
|
||||||
|
bufferevent_write(wp->event, data, lf - data);
|
||||||
|
bufferevent_write(wp->event, sep, seplen);
|
||||||
|
data = lf + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (end != data)
|
||||||
|
bufferevent_write(wp->event, data, end - data);
|
||||||
|
}
|
145
external/bsd/tmux/dist/cmd-pipe-pane.c
vendored
Normal file
145
external/bsd/tmux/dist/cmd-pipe-pane.c
vendored
Normal file
|
@ -0,0 +1,145 @@
|
||||||
|
/* $Id: cmd-pipe-pane.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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/socket.h>
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Open pipe to redirect pane output. If already open, close first.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_pipe_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
void cmd_pipe_pane_error_callback(struct bufferevent *, short, void *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_pipe_pane_entry = {
|
||||||
|
"pipe-pane", "pipep",
|
||||||
|
"ot:", 0, 1,
|
||||||
|
CMD_TARGET_PANE_USAGE "[-o] [command]",
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_pipe_pane_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct client *c;
|
||||||
|
struct window_pane *wp;
|
||||||
|
char *command;
|
||||||
|
int old_fd, pipe_fd[2], null_fd;
|
||||||
|
|
||||||
|
if ((c = cmd_find_client(ctx, NULL)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
/* Destroy the old pipe. */
|
||||||
|
old_fd = wp->pipe_fd;
|
||||||
|
if (wp->pipe_fd != -1) {
|
||||||
|
bufferevent_free(wp->pipe_event);
|
||||||
|
close(wp->pipe_fd);
|
||||||
|
wp->pipe_fd = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If no pipe command, that is enough. */
|
||||||
|
if (args->argc == 0 || *args->argv[0] == '\0')
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* With -o, only open the new pipe if there was no previous one. This
|
||||||
|
* allows a pipe to be toggled with a single key, for example:
|
||||||
|
*
|
||||||
|
* bind ^p pipep -o 'cat >>~/output'
|
||||||
|
*/
|
||||||
|
if (args_has(self->args, 'o') && old_fd != -1)
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
/* Open the new pipe. */
|
||||||
|
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_fd) != 0) {
|
||||||
|
ctx->error(ctx, "socketpair error: %s", strerror(errno));
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Fork the child. */
|
||||||
|
switch (fork()) {
|
||||||
|
case -1:
|
||||||
|
ctx->error(ctx, "fork error: %s", strerror(errno));
|
||||||
|
return (-1);
|
||||||
|
case 0:
|
||||||
|
/* Child process. */
|
||||||
|
close(pipe_fd[0]);
|
||||||
|
clear_signals(1);
|
||||||
|
|
||||||
|
if (dup2(pipe_fd[1], STDIN_FILENO) == -1)
|
||||||
|
_exit(1);
|
||||||
|
if (pipe_fd[1] != STDIN_FILENO)
|
||||||
|
close(pipe_fd[1]);
|
||||||
|
|
||||||
|
null_fd = open(_PATH_DEVNULL, O_WRONLY, 0);
|
||||||
|
if (dup2(null_fd, STDOUT_FILENO) == -1)
|
||||||
|
_exit(1);
|
||||||
|
if (dup2(null_fd, STDERR_FILENO) == -1)
|
||||||
|
_exit(1);
|
||||||
|
if (null_fd != STDOUT_FILENO && null_fd != STDERR_FILENO)
|
||||||
|
close(null_fd);
|
||||||
|
|
||||||
|
closefrom(STDERR_FILENO + 1);
|
||||||
|
|
||||||
|
command = status_replace(
|
||||||
|
c, NULL, NULL, NULL, args->argv[0], time(NULL), 0);
|
||||||
|
execl(_PATH_BSHELL, "sh", "-c", command, (char *) NULL);
|
||||||
|
_exit(1);
|
||||||
|
default:
|
||||||
|
/* Parent process. */
|
||||||
|
close(pipe_fd[1]);
|
||||||
|
|
||||||
|
wp->pipe_fd = pipe_fd[0];
|
||||||
|
wp->pipe_off = EVBUFFER_LENGTH(wp->event->input);
|
||||||
|
|
||||||
|
wp->pipe_event = bufferevent_new(wp->pipe_fd,
|
||||||
|
NULL, NULL, cmd_pipe_pane_error_callback, wp);
|
||||||
|
bufferevent_enable(wp->pipe_event, EV_WRITE);
|
||||||
|
|
||||||
|
setblocking(wp->pipe_fd, 0);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ARGSUSED */
|
||||||
|
void
|
||||||
|
cmd_pipe_pane_error_callback(
|
||||||
|
unused struct bufferevent *bufev, unused short what, void *data)
|
||||||
|
{
|
||||||
|
struct window_pane *wp = data;
|
||||||
|
|
||||||
|
bufferevent_free(wp->pipe_event);
|
||||||
|
close(wp->pipe_fd);
|
||||||
|
wp->pipe_fd = -1;
|
||||||
|
}
|
51
external/bsd/tmux/dist/cmd-refresh-client.c
vendored
Normal file
51
external/bsd/tmux/dist/cmd-refresh-client.c
vendored
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
/* $Id: cmd-refresh-client.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 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 "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Refresh client.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_refresh_client_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_refresh_client_entry = {
|
||||||
|
"refresh-client", "refresh",
|
||||||
|
"t:", 0, 0,
|
||||||
|
CMD_TARGET_CLIENT_USAGE,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_refresh_client_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_refresh_client_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct client *c;
|
||||||
|
|
||||||
|
if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
server_redraw_client(c);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
69
external/bsd/tmux/dist/cmd-rename-session.c
vendored
Normal file
69
external/bsd/tmux/dist/cmd-rename-session.c
vendored
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
/* $Id: cmd-rename-session.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 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 <stdlib.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Change session name.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_rename_session_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_rename_session_entry = {
|
||||||
|
"rename-session", "rename",
|
||||||
|
"t:", 1, 1,
|
||||||
|
CMD_TARGET_SESSION_USAGE " new-name",
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_rename_session_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_rename_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct session *s;
|
||||||
|
const char *newname;
|
||||||
|
|
||||||
|
newname = args->argv[0];
|
||||||
|
if (!session_check_name(newname)) {
|
||||||
|
ctx->error(ctx, "bad session name: %s", newname);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
if (session_find(newname) != NULL) {
|
||||||
|
ctx->error(ctx, "duplicate session: %s", newname);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((s = cmd_find_session(ctx, args_get(args, 't'), 0)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
RB_REMOVE(sessions, &sessions, s);
|
||||||
|
xfree(s->name);
|
||||||
|
s->name = xstrdup(newname);
|
||||||
|
RB_INSERT(sessions, &sessions, s);
|
||||||
|
|
||||||
|
server_status_session(s);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
58
external/bsd/tmux/dist/cmd-rename-window.c
vendored
Normal file
58
external/bsd/tmux/dist/cmd-rename-window.c
vendored
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
/* $Id: cmd-rename-window.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 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 <stdlib.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Rename a window.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_rename_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_rename_window_entry = {
|
||||||
|
"rename-window", "renamew",
|
||||||
|
"t:", 1, 1,
|
||||||
|
CMD_TARGET_WINDOW_USAGE " new-name",
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_rename_window_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_rename_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct session *s;
|
||||||
|
struct winlink *wl;
|
||||||
|
|
||||||
|
if ((wl = cmd_find_window(ctx, args_get(args, 't'), &s)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
xfree(wl->window->name);
|
||||||
|
wl->window->name = xstrdup(args->argv[0]);
|
||||||
|
options_set_number(&wl->window->options, "automatic-rename", 0);
|
||||||
|
|
||||||
|
server_status_window(wl->window);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
117
external/bsd/tmux/dist/cmd-resize-pane.c
vendored
Normal file
117
external/bsd/tmux/dist/cmd-resize-pane.c
vendored
Normal file
|
@ -0,0 +1,117 @@
|
||||||
|
/* $Id: cmd-resize-pane.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 <stdlib.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Increase or decrease pane size.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void cmd_resize_pane_key_binding(struct cmd *, int);
|
||||||
|
int cmd_resize_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_resize_pane_entry = {
|
||||||
|
"resize-pane", "resizep",
|
||||||
|
"DLRt:U", 0, 1,
|
||||||
|
"[-DLRU] " CMD_TARGET_PANE_USAGE " [adjustment]",
|
||||||
|
0,
|
||||||
|
cmd_resize_pane_key_binding,
|
||||||
|
NULL,
|
||||||
|
cmd_resize_pane_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_resize_pane_key_binding(struct cmd *self, int key)
|
||||||
|
{
|
||||||
|
switch (key) {
|
||||||
|
case KEYC_UP | KEYC_CTRL:
|
||||||
|
self->args = args_create(0);
|
||||||
|
args_set(self->args, 'U', NULL);
|
||||||
|
break;
|
||||||
|
case KEYC_DOWN | KEYC_CTRL:
|
||||||
|
self->args = args_create(0);
|
||||||
|
args_set(self->args, 'D', NULL);
|
||||||
|
break;
|
||||||
|
case KEYC_LEFT | KEYC_CTRL:
|
||||||
|
self->args = args_create(0);
|
||||||
|
args_set(self->args, 'L', NULL);
|
||||||
|
break;
|
||||||
|
case KEYC_RIGHT | KEYC_CTRL:
|
||||||
|
self->args = args_create(0);
|
||||||
|
args_set(self->args, 'R', NULL);
|
||||||
|
break;
|
||||||
|
case KEYC_UP | KEYC_ESCAPE:
|
||||||
|
self->args = args_create(1, "5");
|
||||||
|
args_set(self->args, 'U', NULL);
|
||||||
|
break;
|
||||||
|
case KEYC_DOWN | KEYC_ESCAPE:
|
||||||
|
self->args = args_create(1, "5");
|
||||||
|
args_set(self->args, 'D', NULL);
|
||||||
|
break;
|
||||||
|
case KEYC_LEFT | KEYC_ESCAPE:
|
||||||
|
self->args = args_create(1, "5");
|
||||||
|
args_set(self->args, 'L', NULL);
|
||||||
|
break;
|
||||||
|
case KEYC_RIGHT | KEYC_ESCAPE:
|
||||||
|
self->args = args_create(1, "5");
|
||||||
|
args_set(self->args, 'R', NULL);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
self->args = args_create(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_resize_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct winlink *wl;
|
||||||
|
const char *errstr;
|
||||||
|
struct window_pane *wp;
|
||||||
|
u_int adjust;
|
||||||
|
|
||||||
|
if ((wl = cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
if (args->argc == 0)
|
||||||
|
adjust = 1;
|
||||||
|
else {
|
||||||
|
adjust = strtonum(args->argv[0], 1, INT_MAX, &errstr);
|
||||||
|
if (errstr != NULL) {
|
||||||
|
ctx->error(ctx, "adjustment %s", errstr);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args_has(self->args, 'L'))
|
||||||
|
layout_resize_pane(wp, LAYOUT_LEFTRIGHT, -adjust);
|
||||||
|
else if (args_has(self->args, 'R'))
|
||||||
|
layout_resize_pane(wp, LAYOUT_LEFTRIGHT, adjust);
|
||||||
|
else if (args_has(self->args, 'U'))
|
||||||
|
layout_resize_pane(wp, LAYOUT_TOPBOTTOM, -adjust);
|
||||||
|
else if (args_has(self->args, 'D'))
|
||||||
|
layout_resize_pane(wp, LAYOUT_TOPBOTTOM, adjust);
|
||||||
|
server_redraw_window(wl->window);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
88
external/bsd/tmux/dist/cmd-respawn-pane.c
vendored
Normal file
88
external/bsd/tmux/dist/cmd-respawn-pane.c
vendored
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
/* $Id: cmd-respawn-pane.c,v 1.1.1.1 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
|
* Copyright (c) 2011 Marcel P. Partap <mpartap@gmx.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 <unistd.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Respawn a pane (restart the command). Kill existing if -k given.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_respawn_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_respawn_pane_entry = {
|
||||||
|
"respawn-pane", "respawnp",
|
||||||
|
"kt:", 0, 1,
|
||||||
|
"[-k] " CMD_TARGET_PANE_USAGE " [command]",
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_respawn_pane_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_respawn_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct winlink *wl;
|
||||||
|
struct window *w;
|
||||||
|
struct window_pane *wp;
|
||||||
|
struct session *s;
|
||||||
|
struct environ env;
|
||||||
|
const char *cmd;
|
||||||
|
char *cause;
|
||||||
|
|
||||||
|
if ((wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
w = wl->window;
|
||||||
|
|
||||||
|
if (!args_has(self->args, 'k') && wp->fd != -1) {
|
||||||
|
ctx->error(ctx, "pane still active: %s:%u.%u",
|
||||||
|
s->name, wl->idx, window_pane_index(w, wp));
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
environ_init(&env);
|
||||||
|
environ_copy(&global_environ, &env);
|
||||||
|
environ_copy(&s->environ, &env);
|
||||||
|
server_fill_environ(s, &env);
|
||||||
|
|
||||||
|
window_pane_reset_mode(wp);
|
||||||
|
screen_reinit(&wp->base);
|
||||||
|
input_init(wp);
|
||||||
|
|
||||||
|
if (args->argc != 0)
|
||||||
|
cmd = args->argv[0];
|
||||||
|
else
|
||||||
|
cmd = NULL;
|
||||||
|
if (window_pane_spawn(wp, cmd, NULL, NULL, &env, s->tio, &cause) != 0) {
|
||||||
|
ctx->error(ctx, "respawn pane failed: %s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
environ_free(&env);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
wp->flags |= PANE_REDRAW;
|
||||||
|
server_status_window(w);
|
||||||
|
|
||||||
|
environ_free(&env);
|
||||||
|
return (0);
|
||||||
|
}
|
100
external/bsd/tmux/dist/cmd-respawn-window.c
vendored
Normal file
100
external/bsd/tmux/dist/cmd-respawn-window.c
vendored
Normal file
|
@ -0,0 +1,100 @@
|
||||||
|
/* $Id: cmd-respawn-window.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008 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 <unistd.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Respawn a window (restart the command). Kill existing if -k given.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_respawn_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_respawn_window_entry = {
|
||||||
|
"respawn-window", "respawnw",
|
||||||
|
"kt:", 0, 1,
|
||||||
|
"[-k] " CMD_TARGET_WINDOW_USAGE " [command]",
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_respawn_window_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_respawn_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct winlink *wl;
|
||||||
|
struct window *w;
|
||||||
|
struct window_pane *wp;
|
||||||
|
struct session *s;
|
||||||
|
struct environ env;
|
||||||
|
const char *cmd;
|
||||||
|
char *cause;
|
||||||
|
|
||||||
|
if ((wl = cmd_find_window(ctx, args_get(args, 't'), &s)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
w = wl->window;
|
||||||
|
|
||||||
|
if (!args_has(self->args, 'k')) {
|
||||||
|
TAILQ_FOREACH(wp, &w->panes, entry) {
|
||||||
|
if (wp->fd == -1)
|
||||||
|
continue;
|
||||||
|
ctx->error(ctx,
|
||||||
|
"window still active: %s:%d", s->name, wl->idx);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
environ_init(&env);
|
||||||
|
environ_copy(&global_environ, &env);
|
||||||
|
environ_copy(&s->environ, &env);
|
||||||
|
server_fill_environ(s, &env);
|
||||||
|
|
||||||
|
wp = TAILQ_FIRST(&w->panes);
|
||||||
|
TAILQ_REMOVE(&w->panes, wp, entry);
|
||||||
|
layout_free(w);
|
||||||
|
window_destroy_panes(w);
|
||||||
|
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
||||||
|
window_pane_resize(wp, w->sx, w->sy);
|
||||||
|
if (args->argc != 0)
|
||||||
|
cmd = args->argv[0];
|
||||||
|
else
|
||||||
|
cmd = NULL;
|
||||||
|
if (window_pane_spawn(wp, cmd, NULL, NULL, &env, s->tio, &cause) != 0) {
|
||||||
|
ctx->error(ctx, "respawn window failed: %s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
environ_free(&env);
|
||||||
|
server_destroy_pane(wp);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
layout_init(w);
|
||||||
|
window_pane_reset_mode(wp);
|
||||||
|
screen_reinit(&wp->base);
|
||||||
|
input_init(wp);
|
||||||
|
window_set_active_pane(w, wp);
|
||||||
|
|
||||||
|
recalculate_sizes();
|
||||||
|
server_redraw_window(w);
|
||||||
|
|
||||||
|
environ_free(&env);
|
||||||
|
return (0);
|
||||||
|
}
|
119
external/bsd/tmux/dist/cmd-rotate-window.c
vendored
Normal file
119
external/bsd/tmux/dist/cmd-rotate-window.c
vendored
Normal file
|
@ -0,0 +1,119 @@
|
||||||
|
/* $Id: cmd-rotate-window.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Rotate the panes in a window.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void cmd_rotate_window_key_binding(struct cmd *, int);
|
||||||
|
int cmd_rotate_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_rotate_window_entry = {
|
||||||
|
"rotate-window", "rotatew",
|
||||||
|
"Dt:U", 0, 0,
|
||||||
|
"[-DU] " CMD_TARGET_WINDOW_USAGE,
|
||||||
|
0,
|
||||||
|
cmd_rotate_window_key_binding,
|
||||||
|
NULL,
|
||||||
|
cmd_rotate_window_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_rotate_window_key_binding(struct cmd *self, int key)
|
||||||
|
{
|
||||||
|
self->args = args_create(0);
|
||||||
|
if (key == ('o' | KEYC_ESCAPE))
|
||||||
|
args_set(self->args, 'D', NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_rotate_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct winlink *wl;
|
||||||
|
struct window *w;
|
||||||
|
struct window_pane *wp, *wp2;
|
||||||
|
struct layout_cell *lc;
|
||||||
|
u_int sx, sy, xoff, yoff;
|
||||||
|
|
||||||
|
if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
w = wl->window;
|
||||||
|
|
||||||
|
if (args_has(self->args, 'D')) {
|
||||||
|
wp = TAILQ_LAST(&w->panes, window_panes);
|
||||||
|
TAILQ_REMOVE(&w->panes, wp, entry);
|
||||||
|
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
||||||
|
|
||||||
|
lc = wp->layout_cell;
|
||||||
|
xoff = wp->xoff; yoff = wp->yoff;
|
||||||
|
sx = wp->sx; sy = wp->sy;
|
||||||
|
TAILQ_FOREACH(wp, &w->panes, entry) {
|
||||||
|
if ((wp2 = TAILQ_NEXT(wp, entry)) == NULL)
|
||||||
|
break;
|
||||||
|
wp->layout_cell = wp2->layout_cell;
|
||||||
|
if (wp->layout_cell != NULL)
|
||||||
|
wp->layout_cell->wp = wp;
|
||||||
|
wp->xoff = wp2->xoff; wp->yoff = wp2->yoff;
|
||||||
|
window_pane_resize(wp, wp2->sx, wp2->sy);
|
||||||
|
}
|
||||||
|
wp->layout_cell = lc;
|
||||||
|
if (wp->layout_cell != NULL)
|
||||||
|
wp->layout_cell->wp = wp;
|
||||||
|
wp->xoff = xoff; wp->yoff = yoff;
|
||||||
|
window_pane_resize(wp, sx, sy);
|
||||||
|
|
||||||
|
if ((wp = TAILQ_PREV(w->active, window_panes, entry)) == NULL)
|
||||||
|
wp = TAILQ_LAST(&w->panes, window_panes);
|
||||||
|
window_set_active_pane(w, wp);
|
||||||
|
server_redraw_window(w);
|
||||||
|
} else {
|
||||||
|
wp = TAILQ_FIRST(&w->panes);
|
||||||
|
TAILQ_REMOVE(&w->panes, wp, entry);
|
||||||
|
TAILQ_INSERT_TAIL(&w->panes, wp, entry);
|
||||||
|
|
||||||
|
lc = wp->layout_cell;
|
||||||
|
xoff = wp->xoff; yoff = wp->yoff;
|
||||||
|
sx = wp->sx; sy = wp->sy;
|
||||||
|
TAILQ_FOREACH_REVERSE(wp, &w->panes, window_panes, entry) {
|
||||||
|
if ((wp2 = TAILQ_PREV(wp, window_panes, entry)) == NULL)
|
||||||
|
break;
|
||||||
|
wp->layout_cell = wp2->layout_cell;
|
||||||
|
if (wp->layout_cell != NULL)
|
||||||
|
wp->layout_cell->wp = wp;
|
||||||
|
wp->xoff = wp2->xoff; wp->yoff = wp2->yoff;
|
||||||
|
window_pane_resize(wp, wp2->sx, wp2->sy);
|
||||||
|
}
|
||||||
|
wp->layout_cell = lc;
|
||||||
|
if (wp->layout_cell != NULL)
|
||||||
|
wp->layout_cell->wp = wp;
|
||||||
|
wp->xoff = xoff; wp->yoff = yoff;
|
||||||
|
window_pane_resize(wp, sx, sy);
|
||||||
|
|
||||||
|
if ((wp = TAILQ_NEXT(w->active, entry)) == NULL)
|
||||||
|
wp = TAILQ_FIRST(&w->panes);
|
||||||
|
window_set_active_pane(w, wp);
|
||||||
|
server_redraw_window(w);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
141
external/bsd/tmux/dist/cmd-run-shell.c
vendored
Normal file
141
external/bsd/tmux/dist/cmd-run-shell.c
vendored
Normal file
|
@ -0,0 +1,141 @@
|
||||||
|
/* $Id: cmd-run-shell.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
||||||
|
* Copyright (c) 2009 Nicholas Marriott <nicm@openbsd.org>
|
||||||
|
*
|
||||||
|
* 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 <string.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Runs a command without a window.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_run_shell_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
void cmd_run_shell_callback(struct job *);
|
||||||
|
void cmd_run_shell_free(void *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_run_shell_entry = {
|
||||||
|
"run-shell", "run",
|
||||||
|
"", 1, 1,
|
||||||
|
"command",
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_run_shell_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
struct cmd_run_shell_data {
|
||||||
|
char *cmd;
|
||||||
|
struct cmd_ctx ctx;
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_run_shell_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct cmd_run_shell_data *cdata;
|
||||||
|
const char *shellcmd = args->argv[0];
|
||||||
|
|
||||||
|
cdata = xmalloc(sizeof *cdata);
|
||||||
|
cdata->cmd = xstrdup(args->argv[0]);
|
||||||
|
memcpy(&cdata->ctx, ctx, sizeof cdata->ctx);
|
||||||
|
|
||||||
|
if (ctx->cmdclient != NULL)
|
||||||
|
ctx->cmdclient->references++;
|
||||||
|
if (ctx->curclient != NULL)
|
||||||
|
ctx->curclient->references++;
|
||||||
|
|
||||||
|
job_run(shellcmd, cmd_run_shell_callback, cmd_run_shell_free, cdata);
|
||||||
|
|
||||||
|
return (1); /* don't let client exit */
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_run_shell_callback(struct job *job)
|
||||||
|
{
|
||||||
|
struct cmd_run_shell_data *cdata = job->data;
|
||||||
|
struct cmd_ctx *ctx = &cdata->ctx;
|
||||||
|
char *cmd, *msg, *line;
|
||||||
|
size_t size;
|
||||||
|
int retcode;
|
||||||
|
u_int lines;
|
||||||
|
|
||||||
|
if (ctx->cmdclient != NULL && ctx->cmdclient->flags & CLIENT_DEAD)
|
||||||
|
return;
|
||||||
|
if (ctx->curclient != NULL && ctx->curclient->flags & CLIENT_DEAD)
|
||||||
|
return;
|
||||||
|
|
||||||
|
lines = 0;
|
||||||
|
do {
|
||||||
|
if ((line = evbuffer_readline(job->event->input)) != NULL) {
|
||||||
|
ctx->print(ctx, "%s", line);
|
||||||
|
lines++;
|
||||||
|
}
|
||||||
|
} while (line != NULL);
|
||||||
|
|
||||||
|
size = EVBUFFER_LENGTH(job->event->input);
|
||||||
|
if (size != 0) {
|
||||||
|
line = xmalloc(size + 1);
|
||||||
|
memcpy(line, EVBUFFER_DATA(job->event->input), size);
|
||||||
|
line[size] = '\0';
|
||||||
|
|
||||||
|
ctx->print(ctx, "%s", line);
|
||||||
|
lines++;
|
||||||
|
|
||||||
|
xfree(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd = cdata->cmd;
|
||||||
|
|
||||||
|
msg = NULL;
|
||||||
|
if (WIFEXITED(job->status)) {
|
||||||
|
if ((retcode = WEXITSTATUS(job->status)) != 0)
|
||||||
|
xasprintf(&msg, "'%s' returned %d", cmd, retcode);
|
||||||
|
} else if (WIFSIGNALED(job->status)) {
|
||||||
|
retcode = WTERMSIG(job->status);
|
||||||
|
xasprintf(&msg, "'%s' terminated by signal %d", cmd, retcode);
|
||||||
|
}
|
||||||
|
if (msg != NULL) {
|
||||||
|
if (lines != 0)
|
||||||
|
ctx->print(ctx, "%s", msg);
|
||||||
|
else
|
||||||
|
ctx->info(ctx, "%s", msg);
|
||||||
|
xfree(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_run_shell_free(void *data)
|
||||||
|
{
|
||||||
|
struct cmd_run_shell_data *cdata = data;
|
||||||
|
struct cmd_ctx *ctx = &cdata->ctx;
|
||||||
|
|
||||||
|
if (ctx->cmdclient != NULL) {
|
||||||
|
ctx->cmdclient->references--;
|
||||||
|
ctx->cmdclient->flags |= CLIENT_EXIT;
|
||||||
|
}
|
||||||
|
if (ctx->curclient != NULL)
|
||||||
|
ctx->curclient->references--;
|
||||||
|
|
||||||
|
xfree(cdata->cmd);
|
||||||
|
xfree(cdata);
|
||||||
|
}
|
102
external/bsd/tmux/dist/cmd-save-buffer.c
vendored
Normal file
102
external/bsd/tmux/dist/cmd-save-buffer.c
vendored
Normal file
|
@ -0,0 +1,102 @@
|
||||||
|
/* $Id: cmd-save-buffer.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
||||||
|
*
|
||||||
|
* 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 <errno.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Saves a session paste buffer to a file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_save_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_save_buffer_entry = {
|
||||||
|
"save-buffer", "saveb",
|
||||||
|
"ab:", 1, 1,
|
||||||
|
"[-a] " CMD_BUFFER_USAGE,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_save_buffer_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_save_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct client *c = ctx->cmdclient;
|
||||||
|
struct paste_buffer *pb;
|
||||||
|
const char *path;
|
||||||
|
char *cause;
|
||||||
|
int buffer;
|
||||||
|
mode_t mask;
|
||||||
|
FILE *f;
|
||||||
|
|
||||||
|
if (!args_has(args, 'b')) {
|
||||||
|
if ((pb = paste_get_top(&global_buffers)) == NULL) {
|
||||||
|
ctx->error(ctx, "no buffers");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
|
||||||
|
if (cause != NULL) {
|
||||||
|
ctx->error(ctx, "buffer %s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
pb = paste_get_index(&global_buffers, buffer);
|
||||||
|
if (pb == NULL) {
|
||||||
|
ctx->error(ctx, "no buffer %d", buffer);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
path = args->argv[0];
|
||||||
|
if (strcmp(path, "-") == 0) {
|
||||||
|
if (c == NULL) {
|
||||||
|
ctx->error(ctx, "%s: can't write to stdout", path);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
bufferevent_write(c->stdout_event, pb->data, pb->size);
|
||||||
|
} else {
|
||||||
|
mask = umask(S_IRWXG | S_IRWXO);
|
||||||
|
if (args_has(self->args, 'a'))
|
||||||
|
f = fopen(path, "ab");
|
||||||
|
else
|
||||||
|
f = fopen(path, "wb");
|
||||||
|
umask(mask);
|
||||||
|
if (f == NULL) {
|
||||||
|
ctx->error(ctx, "%s: %s", path, strerror(errno));
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
if (fwrite(pb->data, 1, pb->size, f) != pb->size) {
|
||||||
|
ctx->error(ctx, "%s: fwrite error", path);
|
||||||
|
fclose(f);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
fclose(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
133
external/bsd/tmux/dist/cmd-select-layout.c
vendored
Normal file
133
external/bsd/tmux/dist/cmd-select-layout.c
vendored
Normal file
|
@ -0,0 +1,133 @@
|
||||||
|
/* $Id: cmd-select-layout.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Switch window to selected layout.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void cmd_select_layout_key_binding(struct cmd *, int);
|
||||||
|
int cmd_select_layout_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_select_layout_entry = {
|
||||||
|
"select-layout", "selectl",
|
||||||
|
"npt:", 0, 1,
|
||||||
|
"[-np] " CMD_TARGET_WINDOW_USAGE " [layout-name]",
|
||||||
|
0,
|
||||||
|
cmd_select_layout_key_binding,
|
||||||
|
NULL,
|
||||||
|
cmd_select_layout_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_next_layout_entry = {
|
||||||
|
"next-layout", "nextl",
|
||||||
|
"t:", 0, 0,
|
||||||
|
CMD_TARGET_WINDOW_USAGE,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_select_layout_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_previous_layout_entry = {
|
||||||
|
"previous-layout", "prevl",
|
||||||
|
"t:", 0, 0,
|
||||||
|
CMD_TARGET_WINDOW_USAGE,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_select_layout_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_select_layout_key_binding(struct cmd *self, int key)
|
||||||
|
{
|
||||||
|
switch (key) {
|
||||||
|
case '1' | KEYC_ESCAPE:
|
||||||
|
self->args = args_create(1, "even-horizontal");
|
||||||
|
break;
|
||||||
|
case '2' | KEYC_ESCAPE:
|
||||||
|
self->args = args_create(1, "even-vertical");
|
||||||
|
break;
|
||||||
|
case '3' | KEYC_ESCAPE:
|
||||||
|
self->args = args_create(1, "main-horizontal");
|
||||||
|
break;
|
||||||
|
case '4' | KEYC_ESCAPE:
|
||||||
|
self->args = args_create(1, "main-vertical");
|
||||||
|
break;
|
||||||
|
case '5' | KEYC_ESCAPE:
|
||||||
|
self->args = args_create(1, "tiled");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
self->args = args_create(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_select_layout_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct winlink *wl;
|
||||||
|
const char *layoutname;
|
||||||
|
int next, previous, layout;
|
||||||
|
|
||||||
|
if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
next = self->entry == &cmd_next_layout_entry;
|
||||||
|
if (args_has(self->args, 'n'))
|
||||||
|
next = 1;
|
||||||
|
previous = self->entry == &cmd_previous_layout_entry;
|
||||||
|
if (args_has(self->args, 'p'))
|
||||||
|
previous = 1;
|
||||||
|
|
||||||
|
if (next || previous) {
|
||||||
|
if (next)
|
||||||
|
layout = layout_set_next(wl->window);
|
||||||
|
else
|
||||||
|
layout = layout_set_previous(wl->window);
|
||||||
|
ctx->info(ctx, "arranging in: %s", layout_set_name(layout));
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args->argc == 0)
|
||||||
|
layout = wl->window->lastlayout;
|
||||||
|
else
|
||||||
|
layout = layout_set_lookup(args->argv[0]);
|
||||||
|
if (layout != -1) {
|
||||||
|
layout = layout_set_select(wl->window, layout);
|
||||||
|
ctx->info(ctx, "arranging in: %s", layout_set_name(layout));
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args->argc != 0) {
|
||||||
|
layoutname = args->argv[0];
|
||||||
|
if (layout_parse(wl->window, layoutname) == -1) {
|
||||||
|
ctx->error(ctx, "can't set layout: %s", layoutname);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
ctx->info(ctx, "arranging in: %s", layoutname);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
116
external/bsd/tmux/dist/cmd-select-pane.c
vendored
Normal file
116
external/bsd/tmux/dist/cmd-select-pane.c
vendored
Normal file
|
@ -0,0 +1,116 @@
|
||||||
|
/* $Id: cmd-select-pane.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Select pane.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void cmd_select_pane_key_binding(struct cmd *, int);
|
||||||
|
int cmd_select_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_select_pane_entry = {
|
||||||
|
"select-pane", "selectp",
|
||||||
|
"lDLRt:U", 0, 0,
|
||||||
|
"[-lDLRU] " CMD_TARGET_PANE_USAGE,
|
||||||
|
0,
|
||||||
|
cmd_select_pane_key_binding,
|
||||||
|
NULL,
|
||||||
|
cmd_select_pane_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_last_pane_entry = {
|
||||||
|
"last-pane", "lastp",
|
||||||
|
"t:", 0, 0,
|
||||||
|
CMD_TARGET_WINDOW_USAGE,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_select_pane_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_select_pane_key_binding(struct cmd *self, int key)
|
||||||
|
{
|
||||||
|
self->args = args_create(0);
|
||||||
|
if (key == KEYC_UP)
|
||||||
|
args_set(self->args, 'U', NULL);
|
||||||
|
if (key == KEYC_DOWN)
|
||||||
|
args_set(self->args, 'D', NULL);
|
||||||
|
if (key == KEYC_LEFT)
|
||||||
|
args_set(self->args, 'L', NULL);
|
||||||
|
if (key == KEYC_RIGHT)
|
||||||
|
args_set(self->args, 'R', NULL);
|
||||||
|
if (key == 'o')
|
||||||
|
args_set(self->args, 't', ":.+");
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_select_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct winlink *wl;
|
||||||
|
struct window_pane *wp;
|
||||||
|
|
||||||
|
if (self->entry == &cmd_last_pane_entry || args_has(args, 'l')) {
|
||||||
|
wl = cmd_find_window(ctx, args_get(args, 't'), NULL);
|
||||||
|
if (wl == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
if (wl->window->last == NULL) {
|
||||||
|
ctx->error(ctx, "no last pane");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
window_set_active_pane(wl->window, wl->window->last);
|
||||||
|
server_status_window(wl->window);
|
||||||
|
server_redraw_window_borders(wl->window);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((wl = cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
if (!window_pane_visible(wp)) {
|
||||||
|
ctx->error(ctx, "pane not visible");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args_has(self->args, 'L'))
|
||||||
|
wp = window_pane_find_left(wp);
|
||||||
|
else if (args_has(self->args, 'R'))
|
||||||
|
wp = window_pane_find_right(wp);
|
||||||
|
else if (args_has(self->args, 'U'))
|
||||||
|
wp = window_pane_find_up(wp);
|
||||||
|
else if (args_has(self->args, 'D'))
|
||||||
|
wp = window_pane_find_down(wp);
|
||||||
|
if (wp == NULL) {
|
||||||
|
ctx->error(ctx, "pane not found");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
window_set_active_pane(wl->window, wp);
|
||||||
|
server_status_window(wl->window);
|
||||||
|
server_redraw_window_borders(wl->window);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
139
external/bsd/tmux/dist/cmd-select-window.c
vendored
Normal file
139
external/bsd/tmux/dist/cmd-select-window.c
vendored
Normal file
|
@ -0,0 +1,139 @@
|
||||||
|
/* $Id: cmd-select-window.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 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 <stdlib.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Select window by index.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void cmd_select_window_key_binding(struct cmd *, int);
|
||||||
|
int cmd_select_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_select_window_entry = {
|
||||||
|
"select-window", "selectw",
|
||||||
|
"lnpt:", 0, 0,
|
||||||
|
"[-lnp] " CMD_TARGET_WINDOW_USAGE,
|
||||||
|
0,
|
||||||
|
cmd_select_window_key_binding,
|
||||||
|
NULL,
|
||||||
|
cmd_select_window_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_next_window_entry = {
|
||||||
|
"next-window", "next",
|
||||||
|
"at:", 0, 0,
|
||||||
|
"[-a] " CMD_TARGET_SESSION_USAGE,
|
||||||
|
0,
|
||||||
|
cmd_select_window_key_binding,
|
||||||
|
NULL,
|
||||||
|
cmd_select_window_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_previous_window_entry = {
|
||||||
|
"previous-window", "prev",
|
||||||
|
"at:", 0, 0,
|
||||||
|
"[-a] " CMD_TARGET_SESSION_USAGE,
|
||||||
|
0,
|
||||||
|
cmd_select_window_key_binding,
|
||||||
|
NULL,
|
||||||
|
cmd_select_window_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_last_window_entry = {
|
||||||
|
"last-window", "last",
|
||||||
|
"t:", 0, 0,
|
||||||
|
CMD_TARGET_SESSION_USAGE,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_select_window_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_select_window_key_binding(struct cmd *self, int key)
|
||||||
|
{
|
||||||
|
char tmp[16];
|
||||||
|
|
||||||
|
self->args = args_create(0);
|
||||||
|
if (key >= '0' && key <= '9') {
|
||||||
|
xsnprintf(tmp, sizeof tmp, ":%d", key - '0');
|
||||||
|
args_set(self->args, 't', tmp);
|
||||||
|
}
|
||||||
|
if (key == ('n' | KEYC_ESCAPE) || key == ('p' | KEYC_ESCAPE))
|
||||||
|
args_set(self->args, 'a', NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_select_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct winlink *wl;
|
||||||
|
struct session *s;
|
||||||
|
int next, previous, last, activity;
|
||||||
|
|
||||||
|
next = self->entry == &cmd_next_window_entry;
|
||||||
|
if (args_has(self->args, 'n'))
|
||||||
|
next = 1;
|
||||||
|
previous = self->entry == &cmd_previous_window_entry;
|
||||||
|
if (args_has(self->args, 'p'))
|
||||||
|
previous = 1;
|
||||||
|
last = self->entry == &cmd_last_window_entry;
|
||||||
|
if (args_has(self->args, 'l'))
|
||||||
|
last = 1;
|
||||||
|
|
||||||
|
if (next || previous || last) {
|
||||||
|
s = cmd_find_session(ctx, args_get(args, 't'), 0);
|
||||||
|
if (s == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
activity = args_has(self->args, 'a');
|
||||||
|
if (next) {
|
||||||
|
if (session_next(s, activity) != 0) {
|
||||||
|
ctx->error(ctx, "no next window");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
} else if (previous) {
|
||||||
|
if (session_previous(s, activity) != 0) {
|
||||||
|
ctx->error(ctx, "no previous window");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (session_last(s) != 0) {
|
||||||
|
ctx->error(ctx, "no last window");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
server_redraw_session(s);
|
||||||
|
} else {
|
||||||
|
wl = cmd_find_window(ctx, args_get(args, 't'), &s);
|
||||||
|
if (wl == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
if (session_select(s, wl->idx) == 0)
|
||||||
|
server_redraw_session(s);
|
||||||
|
}
|
||||||
|
recalculate_sizes();
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
65
external/bsd/tmux/dist/cmd-send-keys.c
vendored
Normal file
65
external/bsd/tmux/dist/cmd-send-keys.c
vendored
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
/* $Id: cmd-send-keys.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008 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 <stdlib.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Send keys to client.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_send_keys_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_send_keys_entry = {
|
||||||
|
"send-keys", "send",
|
||||||
|
"t:", 0, -1,
|
||||||
|
"[-t target-pane] key ...",
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_send_keys_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_send_keys_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct window_pane *wp;
|
||||||
|
struct session *s;
|
||||||
|
const char *str;
|
||||||
|
int i, key;
|
||||||
|
|
||||||
|
if (cmd_find_pane(ctx, args_get(args, 't'), &s, &wp) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
for (i = 0; i < args->argc; i++) {
|
||||||
|
str = args->argv[i];
|
||||||
|
|
||||||
|
if ((key = key_string_lookup_string(str)) != KEYC_NONE) {
|
||||||
|
window_pane_key(wp, s, key);
|
||||||
|
} else {
|
||||||
|
for (; *str != '\0'; str++)
|
||||||
|
window_pane_key(wp, s, *str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
54
external/bsd/tmux/dist/cmd-send-prefix.c
vendored
Normal file
54
external/bsd/tmux/dist/cmd-send-prefix.c
vendored
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
/* $Id: cmd-send-prefix.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 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 "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Send prefix key as a key.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_send_prefix_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_send_prefix_entry = {
|
||||||
|
"send-prefix", NULL,
|
||||||
|
"t:", 0, 0,
|
||||||
|
CMD_TARGET_PANE_USAGE,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_send_prefix_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_send_prefix_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct session *s;
|
||||||
|
struct window_pane *wp;
|
||||||
|
struct keylist *keylist;
|
||||||
|
|
||||||
|
if (cmd_find_pane(ctx, args_get(args, 't'), &s, &wp) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
keylist = options_get_data(&s->options, "prefix");
|
||||||
|
window_pane_key(wp, s, ARRAY_FIRST(keylist));
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
185
external/bsd/tmux/dist/cmd-server-info.c
vendored
Normal file
185
external/bsd/tmux/dist/cmd-server-info.c
vendored
Normal file
|
@ -0,0 +1,185 @@
|
||||||
|
/* $Id: cmd-server-info.c,v 1.3 2011/08/17 18:48:35 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008 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/utsname.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Show various information about server.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_server_info_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_server_info_entry = {
|
||||||
|
"server-info", "info",
|
||||||
|
"", 0, 0,
|
||||||
|
"",
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_server_info_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ARGSUSED */
|
||||||
|
int
|
||||||
|
cmd_server_info_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct tty_term *term;
|
||||||
|
struct client *c;
|
||||||
|
struct session *s;
|
||||||
|
struct winlink *wl;
|
||||||
|
struct window *w;
|
||||||
|
struct window_pane *wp;
|
||||||
|
struct tty_code *code;
|
||||||
|
const struct tty_term_code_entry *ent;
|
||||||
|
struct utsname un;
|
||||||
|
struct job *job;
|
||||||
|
struct grid *gd;
|
||||||
|
struct grid_line *gl;
|
||||||
|
u_int i, j, k;
|
||||||
|
char *tim;
|
||||||
|
time_t t;
|
||||||
|
u_int lines, ulines;
|
||||||
|
size_t size, usize;
|
||||||
|
|
||||||
|
tim = ctime(&start_time);
|
||||||
|
*strchr(tim, '\n') = '\0';
|
||||||
|
ctx->print(ctx,
|
||||||
|
"tmux " VERSION ", pid %ld, started %s", (long) getpid(), tim);
|
||||||
|
ctx->print(
|
||||||
|
ctx, "socket path %s, debug level %d", socket_path, debug_level);
|
||||||
|
if (uname(&un) >= 0) {
|
||||||
|
ctx->print(ctx, "system is %s %s %s %s",
|
||||||
|
un.sysname, un.release, un.version, un.machine);
|
||||||
|
}
|
||||||
|
if (cfg_file != NULL)
|
||||||
|
ctx->print(ctx, "configuration file is %s", cfg_file);
|
||||||
|
else
|
||||||
|
ctx->print(ctx, "configuration file not specified");
|
||||||
|
ctx->print(ctx, "protocol version is %d", PROTOCOL_VERSION);
|
||||||
|
ctx->print(ctx, "%s", "");
|
||||||
|
|
||||||
|
ctx->print(ctx, "Clients:");
|
||||||
|
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||||
|
c = ARRAY_ITEM(&clients, i);
|
||||||
|
if (c == NULL || c->session == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
ctx->print(ctx,"%2d: %s (%d, %d): %s [%ux%u %s bs=%hho] "
|
||||||
|
"[flags=0x%x/0x%x, references=%u]", i, c->tty.path,
|
||||||
|
c->ibuf.fd, c->tty.fd, c->session->name,
|
||||||
|
c->tty.sx, c->tty.sy, c->tty.termname,
|
||||||
|
c->tty.tio.c_cc[VERASE], c->flags,
|
||||||
|
c->tty.flags, c->references);
|
||||||
|
}
|
||||||
|
ctx->print(ctx, "%s", "");
|
||||||
|
|
||||||
|
ctx->print(ctx, "Sessions: [%zu/%zu]",
|
||||||
|
sizeof (struct grid_cell), sizeof (struct grid_utf8));
|
||||||
|
RB_FOREACH(s, sessions, &sessions) {
|
||||||
|
t = s->creation_time.tv_sec;
|
||||||
|
tim = ctime(&t);
|
||||||
|
*strchr(tim, '\n') = '\0';
|
||||||
|
|
||||||
|
ctx->print(ctx, "%2u: %s: %u windows (created %s) [%ux%u] "
|
||||||
|
"[flags=0x%x]", s->idx, s->name,
|
||||||
|
winlink_count(&s->windows), tim, s->sx, s->sy, s->flags);
|
||||||
|
RB_FOREACH(wl, winlinks, &s->windows) {
|
||||||
|
w = wl->window;
|
||||||
|
ctx->print(ctx, "%4u: %s [%ux%u] [flags=0x%x, "
|
||||||
|
"references=%u, last layout=%d]", wl->idx, w->name,
|
||||||
|
w->sx, w->sy, w->flags, w->references,
|
||||||
|
w->lastlayout);
|
||||||
|
j = 0;
|
||||||
|
TAILQ_FOREACH(wp, &w->panes, entry) {
|
||||||
|
lines = ulines = size = usize = 0;
|
||||||
|
gd = wp->base.grid;
|
||||||
|
for (k = 0; k < gd->hsize + gd->sy; k++) {
|
||||||
|
gl = &gd->linedata[k];
|
||||||
|
if (gl->celldata != NULL) {
|
||||||
|
lines++;
|
||||||
|
size += gl->cellsize *
|
||||||
|
sizeof *gl->celldata;
|
||||||
|
}
|
||||||
|
if (gl->utf8data != NULL) {
|
||||||
|
ulines++;
|
||||||
|
usize += gl->utf8size *
|
||||||
|
sizeof *gl->utf8data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ctx->print(ctx, "%6u: %s %lu %d %u/%u, %zu "
|
||||||
|
"bytes; UTF-8 %u/%u, %zu bytes", j,
|
||||||
|
wp->tty, (u_long) wp->pid, wp->fd, lines,
|
||||||
|
gd->hsize + gd->sy, size, ulines,
|
||||||
|
gd->hsize + gd->sy, usize);
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ctx->print(ctx, "%s", "");
|
||||||
|
|
||||||
|
ctx->print(ctx, "Terminals:");
|
||||||
|
LIST_FOREACH(term, &tty_terms, entry) {
|
||||||
|
ctx->print(ctx, "%s [references=%u, flags=0x%x]:",
|
||||||
|
term->name, term->references, term->flags);
|
||||||
|
for (i = 0; i < NTTYCODE; i++) {
|
||||||
|
ent = &tty_term_codes[i];
|
||||||
|
code = &term->codes[ent->code];
|
||||||
|
switch (code->type) {
|
||||||
|
case TTYCODE_NONE:
|
||||||
|
ctx->print(ctx, "%2u: %s: [missing]",
|
||||||
|
ent->code, ent->name);
|
||||||
|
break;
|
||||||
|
case TTYCODE_STRING: {
|
||||||
|
size_t slen = strlen(code->value.string);
|
||||||
|
char out[slen * 4 + 1];
|
||||||
|
strvisx(out, code->value.string, slen,
|
||||||
|
VIS_OCTAL|VIS_TAB|VIS_NL);
|
||||||
|
ctx->print(ctx, "%2u: %s: (string) %s",
|
||||||
|
ent->code, ent->name, out);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case TTYCODE_NUMBER:
|
||||||
|
ctx->print(ctx, "%2u: %s: (number) %d",
|
||||||
|
ent->code, ent->name, code->value.number);
|
||||||
|
break;
|
||||||
|
case TTYCODE_FLAG:
|
||||||
|
ctx->print(ctx, "%2u: %s: (flag) %s",
|
||||||
|
ent->code, ent->name,
|
||||||
|
code->value.flag ? "true" : "false");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ctx->print(ctx, "%s", "");
|
||||||
|
|
||||||
|
ctx->print(ctx, "Jobs:");
|
||||||
|
LIST_FOREACH(job, &all_jobs, lentry) {
|
||||||
|
ctx->print(ctx, "%s [fd=%d, pid=%d, status=%d]",
|
||||||
|
job->cmd, job->fd, job->pid, job->status);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
75
external/bsd/tmux/dist/cmd-set-buffer.c
vendored
Normal file
75
external/bsd/tmux/dist/cmd-set-buffer.c
vendored
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
/* $Id: cmd-set-buffer.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 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 <string.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Add or set a session paste buffer.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_set_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_set_buffer_entry = {
|
||||||
|
"set-buffer", "setb",
|
||||||
|
"b:", 1, 1,
|
||||||
|
CMD_BUFFER_USAGE " data",
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_set_buffer_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_set_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
u_int limit;
|
||||||
|
char *pdata, *cause;
|
||||||
|
size_t psize;
|
||||||
|
int buffer;
|
||||||
|
|
||||||
|
limit = options_get_number(&global_options, "buffer-limit");
|
||||||
|
|
||||||
|
pdata = xstrdup(args->argv[0]);
|
||||||
|
psize = strlen(pdata);
|
||||||
|
|
||||||
|
if (!args_has(args, 'b')) {
|
||||||
|
paste_add(&global_buffers, pdata, psize, limit);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
|
||||||
|
if (cause != NULL) {
|
||||||
|
ctx->error(ctx, "buffer %s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
xfree(pdata);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (paste_replace(&global_buffers, buffer, pdata, psize) != 0) {
|
||||||
|
ctx->error(ctx, "no buffer %d", buffer);
|
||||||
|
xfree(pdata);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
94
external/bsd/tmux/dist/cmd-set-environment.c
vendored
Normal file
94
external/bsd/tmux/dist/cmd-set-environment.c
vendored
Normal file
|
@ -0,0 +1,94 @@
|
||||||
|
/* $Id: cmd-set-environment.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set an environment variable.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_set_environment_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_set_environment_entry = {
|
||||||
|
"set-environment", "setenv",
|
||||||
|
"grt:u", 1, 2,
|
||||||
|
"[-gru] " CMD_TARGET_SESSION_USAGE " name [value]",
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_set_environment_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_set_environment_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct session *s;
|
||||||
|
struct environ *env;
|
||||||
|
const char *name, *value;
|
||||||
|
|
||||||
|
name = args->argv[0];
|
||||||
|
if (*name == '\0') {
|
||||||
|
ctx->error(ctx, "empty variable name");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
if (strchr(name, '=') != NULL) {
|
||||||
|
ctx->error(ctx, "variable name contains =");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args->argc < 1)
|
||||||
|
value = NULL;
|
||||||
|
else
|
||||||
|
value = args->argv[1];
|
||||||
|
|
||||||
|
if (args_has(self->args, 'g'))
|
||||||
|
env = &global_environ;
|
||||||
|
else {
|
||||||
|
if ((s = cmd_find_session(ctx, args_get(args, 't'), 0)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
env = &s->environ;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args_has(self->args, 'u')) {
|
||||||
|
if (value != NULL) {
|
||||||
|
ctx->error(ctx, "can't specify a value with -u");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
environ_unset(env, name);
|
||||||
|
} else if (args_has(self->args, 'r')) {
|
||||||
|
if (value != NULL) {
|
||||||
|
ctx->error(ctx, "can't specify a value with -r");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
environ_set(env, name, NULL);
|
||||||
|
} else {
|
||||||
|
if (value == NULL) {
|
||||||
|
ctx->error(ctx, "no value specified");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
environ_set(env, name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
411
external/bsd/tmux/dist/cmd-set-option.c
vendored
Normal file
411
external/bsd/tmux/dist/cmd-set-option.c
vendored
Normal file
|
@ -0,0 +1,411 @@
|
||||||
|
/* $Id: cmd-set-option.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 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 <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set an option.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_set_option_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
int cmd_set_option_find(const char *, const struct options_table_entry **,
|
||||||
|
const struct options_table_entry **);
|
||||||
|
|
||||||
|
int cmd_set_option_unset(struct cmd *, struct cmd_ctx *,
|
||||||
|
const struct options_table_entry *, struct options *,
|
||||||
|
const char *);
|
||||||
|
int cmd_set_option_set(struct cmd *, struct cmd_ctx *,
|
||||||
|
const struct options_table_entry *, struct options *,
|
||||||
|
const char *);
|
||||||
|
|
||||||
|
struct options_entry *cmd_set_option_string(struct cmd *, struct cmd_ctx *,
|
||||||
|
const struct options_table_entry *, struct options *,
|
||||||
|
const char *);
|
||||||
|
struct options_entry *cmd_set_option_number(struct cmd *, struct cmd_ctx *,
|
||||||
|
const struct options_table_entry *, struct options *,
|
||||||
|
const char *);
|
||||||
|
struct options_entry *cmd_set_option_keys(struct cmd *, struct cmd_ctx *,
|
||||||
|
const struct options_table_entry *, struct options *,
|
||||||
|
const char *);
|
||||||
|
struct options_entry *cmd_set_option_colour(struct cmd *, struct cmd_ctx *,
|
||||||
|
const struct options_table_entry *, struct options *,
|
||||||
|
const char *);
|
||||||
|
struct options_entry *cmd_set_option_attributes(struct cmd *, struct cmd_ctx *,
|
||||||
|
const struct options_table_entry *, struct options *,
|
||||||
|
const char *);
|
||||||
|
struct options_entry *cmd_set_option_flag(struct cmd *, struct cmd_ctx *,
|
||||||
|
const struct options_table_entry *, struct options *,
|
||||||
|
const char *);
|
||||||
|
struct options_entry *cmd_set_option_choice(struct cmd *, struct cmd_ctx *,
|
||||||
|
const struct options_table_entry *, struct options *,
|
||||||
|
const char *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_set_option_entry = {
|
||||||
|
"set-option", "set",
|
||||||
|
"agst:uw", 1, 2,
|
||||||
|
"[-agsuw] [-t target-session|target-window] option [value]",
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_set_option_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_set_window_option_entry = {
|
||||||
|
"set-window-option", "setw",
|
||||||
|
"agt:u", 1, 2,
|
||||||
|
"[-agu] " CMD_TARGET_WINDOW_USAGE " option [value]",
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_set_option_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Look for an option in all three tables. */
|
||||||
|
int
|
||||||
|
cmd_set_option_find(
|
||||||
|
const char *optstr, const struct options_table_entry **table,
|
||||||
|
const struct options_table_entry **oe)
|
||||||
|
{
|
||||||
|
static const struct options_table_entry *tables[] = {
|
||||||
|
server_options_table,
|
||||||
|
window_options_table,
|
||||||
|
session_options_table
|
||||||
|
};
|
||||||
|
const struct options_table_entry *oe_loop;
|
||||||
|
u_int i;
|
||||||
|
|
||||||
|
for (i = 0; i < nitems(tables); i++) {
|
||||||
|
for (oe_loop = tables[i]; oe_loop->name != NULL; oe_loop++) {
|
||||||
|
if (strncmp(oe_loop->name, optstr, strlen(optstr)) != 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* If already found, ambiguous. */
|
||||||
|
if (*oe != NULL)
|
||||||
|
return (-1);
|
||||||
|
*oe = oe_loop;
|
||||||
|
*table = tables[i];
|
||||||
|
|
||||||
|
/* Bail now if an exact match. */
|
||||||
|
if (strcmp((*oe)->name, optstr) == 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
const struct options_table_entry *table, *oe;
|
||||||
|
struct session *s;
|
||||||
|
struct winlink *wl;
|
||||||
|
struct client *c;
|
||||||
|
struct options *oo;
|
||||||
|
const char *optstr, *valstr;
|
||||||
|
u_int i;
|
||||||
|
|
||||||
|
/* Get the option name and value. */
|
||||||
|
optstr = args->argv[0];
|
||||||
|
if (*optstr == '\0') {
|
||||||
|
ctx->error(ctx, "invalid option");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
if (args->argc < 2)
|
||||||
|
valstr = NULL;
|
||||||
|
else
|
||||||
|
valstr = args->argv[1];
|
||||||
|
|
||||||
|
/* Find the option entry, try each table. */
|
||||||
|
table = oe = NULL;
|
||||||
|
if (cmd_set_option_find(optstr, &table, &oe) != 0) {
|
||||||
|
ctx->error(ctx, "ambiguous option: %s", optstr);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
if (oe == NULL) {
|
||||||
|
ctx->error(ctx, "unknown option: %s", optstr);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Work out the tree from the table. */
|
||||||
|
if (table == server_options_table)
|
||||||
|
oo = &global_options;
|
||||||
|
else if (table == window_options_table) {
|
||||||
|
if (args_has(self->args, 'g'))
|
||||||
|
oo = &global_w_options;
|
||||||
|
else {
|
||||||
|
wl = cmd_find_window(ctx, args_get(args, 't'), NULL);
|
||||||
|
if (wl == NULL)
|
||||||
|
return (-1);
|
||||||
|
oo = &wl->window->options;
|
||||||
|
}
|
||||||
|
} else if (table == session_options_table) {
|
||||||
|
if (args_has(self->args, 'g'))
|
||||||
|
oo = &global_s_options;
|
||||||
|
else {
|
||||||
|
s = cmd_find_session(ctx, args_get(args, 't'), 0);
|
||||||
|
if (s == NULL)
|
||||||
|
return (-1);
|
||||||
|
oo = &s->options;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ctx->error(ctx, "unknown table");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Unset or set the option. */
|
||||||
|
if (args_has(args, 'u')) {
|
||||||
|
if (cmd_set_option_unset(self, ctx, oe, oo, valstr) != 0)
|
||||||
|
return (-1);
|
||||||
|
} else {
|
||||||
|
if (cmd_set_option_set(self, ctx, oe, oo, valstr) != 0)
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Update sizes and redraw. May not need it but meh. */
|
||||||
|
recalculate_sizes();
|
||||||
|
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||||
|
c = ARRAY_ITEM(&clients, i);
|
||||||
|
if (c != NULL && c->session != NULL)
|
||||||
|
server_redraw_client(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Unset an option. */
|
||||||
|
int
|
||||||
|
cmd_set_option_unset(struct cmd *self, struct cmd_ctx *ctx,
|
||||||
|
const struct options_table_entry *oe, struct options *oo, const char *value)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
|
||||||
|
if (args_has(args, 'g')) {
|
||||||
|
ctx->error(ctx, "can't unset global option: %s", oe->name);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
if (value != NULL) {
|
||||||
|
ctx->error(ctx, "value passed to unset option: %s", oe->name);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
options_remove(oo, oe->name);
|
||||||
|
ctx->info(ctx, "unset option: %s", oe->name);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set an option. */
|
||||||
|
int
|
||||||
|
cmd_set_option_set(struct cmd *self, struct cmd_ctx *ctx,
|
||||||
|
const struct options_table_entry *oe, struct options *oo, const char *value)
|
||||||
|
{
|
||||||
|
struct options_entry *o;
|
||||||
|
const char *s;
|
||||||
|
|
||||||
|
if (oe->type != OPTIONS_TABLE_FLAG && value == NULL) {
|
||||||
|
ctx->error(ctx, "empty value");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
o = NULL;
|
||||||
|
switch (oe->type) {
|
||||||
|
case OPTIONS_TABLE_STRING:
|
||||||
|
o = cmd_set_option_string(self, ctx, oe, oo, value);
|
||||||
|
break;
|
||||||
|
case OPTIONS_TABLE_NUMBER:
|
||||||
|
o = cmd_set_option_number(self, ctx, oe, oo, value);
|
||||||
|
break;
|
||||||
|
case OPTIONS_TABLE_KEYS:
|
||||||
|
o = cmd_set_option_keys(self, ctx, oe, oo, value);
|
||||||
|
break;
|
||||||
|
case OPTIONS_TABLE_COLOUR:
|
||||||
|
o = cmd_set_option_colour(self, ctx, oe, oo, value);
|
||||||
|
break;
|
||||||
|
case OPTIONS_TABLE_ATTRIBUTES:
|
||||||
|
o = cmd_set_option_attributes(self, ctx, oe, oo, value);
|
||||||
|
break;
|
||||||
|
case OPTIONS_TABLE_FLAG:
|
||||||
|
o = cmd_set_option_flag(self, ctx, oe, oo, value);
|
||||||
|
break;
|
||||||
|
case OPTIONS_TABLE_CHOICE:
|
||||||
|
o = cmd_set_option_choice(self, ctx, oe, oo, value);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (o == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
s = options_table_print_entry(oe, o);
|
||||||
|
ctx->info(ctx, "set option: %s -> %s", oe->name, s);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set a string option. */
|
||||||
|
struct options_entry *
|
||||||
|
cmd_set_option_string(struct cmd *self, unused struct cmd_ctx *ctx,
|
||||||
|
const struct options_table_entry *oe, struct options *oo, const char *value)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct options_entry *o;
|
||||||
|
char *oldval, *newval;
|
||||||
|
|
||||||
|
if (args_has(args, 'a')) {
|
||||||
|
oldval = options_get_string(oo, oe->name);
|
||||||
|
xasprintf(&newval, "%s%s", oldval, value);
|
||||||
|
} else
|
||||||
|
newval = xstrdup(value);
|
||||||
|
|
||||||
|
o = options_set_string(oo, oe->name, "%s", newval);
|
||||||
|
|
||||||
|
xfree(newval);
|
||||||
|
return (o);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set a number option. */
|
||||||
|
struct options_entry *
|
||||||
|
cmd_set_option_number(unused struct cmd *self, struct cmd_ctx *ctx,
|
||||||
|
const struct options_table_entry *oe, struct options *oo, const char *value)
|
||||||
|
{
|
||||||
|
long long ll;
|
||||||
|
const char *errstr;
|
||||||
|
|
||||||
|
ll = strtonum(value, oe->minimum, oe->maximum, &errstr);
|
||||||
|
if (errstr != NULL) {
|
||||||
|
ctx->error(ctx, "value is %s: %s", errstr, value);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (options_set_number(oo, oe->name, ll));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set a keys option. */
|
||||||
|
struct options_entry *
|
||||||
|
cmd_set_option_keys(unused struct cmd *self, struct cmd_ctx *ctx,
|
||||||
|
const struct options_table_entry *oe, struct options *oo, const char *value)
|
||||||
|
{
|
||||||
|
struct keylist *keylist;
|
||||||
|
char *copy, *ptr, *s;
|
||||||
|
int key;
|
||||||
|
|
||||||
|
keylist = xmalloc(sizeof *keylist);
|
||||||
|
ARRAY_INIT(keylist);
|
||||||
|
|
||||||
|
ptr = copy = xstrdup(value);
|
||||||
|
while ((s = strsep(&ptr, ",")) != NULL) {
|
||||||
|
if ((key = key_string_lookup_string(s)) == KEYC_NONE) {
|
||||||
|
ctx->error(ctx, "unknown key: %s", s);
|
||||||
|
xfree(copy);
|
||||||
|
xfree(keylist);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
ARRAY_ADD(keylist, key);
|
||||||
|
}
|
||||||
|
xfree(copy);
|
||||||
|
|
||||||
|
return (options_set_data(oo, oe->name, keylist, xfree));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set a colour option. */
|
||||||
|
struct options_entry *
|
||||||
|
cmd_set_option_colour(unused struct cmd *self, struct cmd_ctx *ctx,
|
||||||
|
const struct options_table_entry *oe, struct options *oo, const char *value)
|
||||||
|
{
|
||||||
|
int colour;
|
||||||
|
|
||||||
|
if ((colour = colour_fromstring(value)) == -1) {
|
||||||
|
ctx->error(ctx, "bad colour: %s", value);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (options_set_number(oo, oe->name, colour));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set an attributes option. */
|
||||||
|
struct options_entry *
|
||||||
|
cmd_set_option_attributes(unused struct cmd *self, struct cmd_ctx *ctx,
|
||||||
|
const struct options_table_entry *oe, struct options *oo, const char *value)
|
||||||
|
{
|
||||||
|
int attr;
|
||||||
|
|
||||||
|
if ((attr = attributes_fromstring(value)) == -1) {
|
||||||
|
ctx->error(ctx, "bad attributes: %s", value);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (options_set_number(oo, oe->name, attr));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set a flag option. */
|
||||||
|
struct options_entry *
|
||||||
|
cmd_set_option_flag(unused struct cmd *self, struct cmd_ctx *ctx,
|
||||||
|
const struct options_table_entry *oe, struct options *oo, const char *value)
|
||||||
|
{
|
||||||
|
int flag;
|
||||||
|
|
||||||
|
if (value == NULL || *value == '\0')
|
||||||
|
flag = !options_get_number(oo, oe->name);
|
||||||
|
else {
|
||||||
|
if ((value[0] == '1' && value[1] == '\0') ||
|
||||||
|
strcasecmp(value, "on") == 0 ||
|
||||||
|
strcasecmp(value, "yes") == 0)
|
||||||
|
flag = 1;
|
||||||
|
else if ((value[0] == '0' && value[1] == '\0') ||
|
||||||
|
strcasecmp(value, "off") == 0 ||
|
||||||
|
strcasecmp(value, "no") == 0)
|
||||||
|
flag = 0;
|
||||||
|
else {
|
||||||
|
ctx->error(ctx, "bad value: %s", value);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (options_set_number(oo, oe->name, flag));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set a choice option. */
|
||||||
|
struct options_entry *
|
||||||
|
cmd_set_option_choice(unused struct cmd *self, struct cmd_ctx *ctx,
|
||||||
|
const struct options_table_entry *oe, struct options *oo, const char *value)
|
||||||
|
{
|
||||||
|
const char **choicep;
|
||||||
|
int n, choice = -1;
|
||||||
|
|
||||||
|
n = 0;
|
||||||
|
for (choicep = oe->choices; *choicep != NULL; choicep++) {
|
||||||
|
n++;
|
||||||
|
if (strncmp(*choicep, value, strlen(value)) != 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (choice != -1) {
|
||||||
|
ctx->error(ctx, "ambiguous value: %s", value);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
choice = n - 1;
|
||||||
|
}
|
||||||
|
if (choice == -1) {
|
||||||
|
ctx->error(ctx, "unknown value: %s", value);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (options_set_number(oo, oe->name, choice));
|
||||||
|
}
|
109
external/bsd/tmux/dist/cmd-show-buffer.c
vendored
Normal file
109
external/bsd/tmux/dist/cmd-show-buffer.c
vendored
Normal file
|
@ -0,0 +1,109 @@
|
||||||
|
/* $Id: cmd-show-buffer.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 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 "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Show a session paste buffer.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_show_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_show_buffer_entry = {
|
||||||
|
"show-buffer", "showb",
|
||||||
|
"b:", 0, 0,
|
||||||
|
CMD_BUFFER_USAGE,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_show_buffer_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_show_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct session *s;
|
||||||
|
struct paste_buffer *pb;
|
||||||
|
int buffer;
|
||||||
|
char *in, *buf, *ptr, *cause;
|
||||||
|
size_t size, len;
|
||||||
|
u_int width;
|
||||||
|
|
||||||
|
if ((s = cmd_find_session(ctx, NULL, 0)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
if (!args_has(args, 'b')) {
|
||||||
|
if ((pb = paste_get_top(&global_buffers)) == NULL) {
|
||||||
|
ctx->error(ctx, "no buffers");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
|
||||||
|
if (cause != NULL) {
|
||||||
|
ctx->error(ctx, "buffer %s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
pb = paste_get_index(&global_buffers, buffer);
|
||||||
|
if (pb == NULL) {
|
||||||
|
ctx->error(ctx, "no buffer %d", buffer);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
size = pb->size;
|
||||||
|
if (size > SIZE_MAX / 4 - 1)
|
||||||
|
size = SIZE_MAX / 4 - 1;
|
||||||
|
in = xmalloc(size * 4 + 1);
|
||||||
|
strvisx(in, pb->data, size, VIS_OCTAL|VIS_TAB);
|
||||||
|
|
||||||
|
width = s->sx;
|
||||||
|
if (ctx->cmdclient != NULL)
|
||||||
|
width = ctx->cmdclient->tty.sx;
|
||||||
|
|
||||||
|
buf = xmalloc(width + 1);
|
||||||
|
len = 0;
|
||||||
|
|
||||||
|
ptr = in;
|
||||||
|
do {
|
||||||
|
buf[len++] = *ptr++;
|
||||||
|
|
||||||
|
if (len == width || buf[len - 1] == '\n') {
|
||||||
|
if (buf[len - 1] == '\n')
|
||||||
|
len--;
|
||||||
|
buf[len] = '\0';
|
||||||
|
|
||||||
|
ctx->print(ctx, "%s", buf);
|
||||||
|
len = 0;
|
||||||
|
}
|
||||||
|
} while (*ptr != '\0');
|
||||||
|
|
||||||
|
if (len != 0) {
|
||||||
|
buf[len] = '\0';
|
||||||
|
ctx->print(ctx, "%s", buf);
|
||||||
|
}
|
||||||
|
xfree(buf);
|
||||||
|
|
||||||
|
xfree(in);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
66
external/bsd/tmux/dist/cmd-show-environment.c
vendored
Normal file
66
external/bsd/tmux/dist/cmd-show-environment.c
vendored
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
/* $Id: cmd-show-environment.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Show environment.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_show_environment_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_show_environment_entry = {
|
||||||
|
"show-environment", "showenv",
|
||||||
|
"gt:", 0, 0,
|
||||||
|
"[-g] " CMD_TARGET_SESSION_USAGE,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_show_environment_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_show_environment_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct session *s;
|
||||||
|
struct environ *env;
|
||||||
|
struct environ_entry *envent;
|
||||||
|
|
||||||
|
if (args_has(self->args, 'g'))
|
||||||
|
env = &global_environ;
|
||||||
|
else {
|
||||||
|
if ((s = cmd_find_session(ctx, args_get(args, 't'), 0)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
env = &s->environ;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_FOREACH(envent, environ, env) {
|
||||||
|
if (envent->value != NULL)
|
||||||
|
ctx->print(ctx, "%s=%s", envent->name, envent->value);
|
||||||
|
else
|
||||||
|
ctx->print(ctx, "-%s", envent->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
64
external/bsd/tmux/dist/cmd-show-messages.c
vendored
Normal file
64
external/bsd/tmux/dist/cmd-show-messages.c
vendored
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
/* $Id: cmd-show-messages.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Show client message log.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_show_messages_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_show_messages_entry = {
|
||||||
|
"show-messages", "showmsgs",
|
||||||
|
"t:", 0, 0,
|
||||||
|
CMD_TARGET_CLIENT_USAGE,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_show_messages_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_show_messages_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct client *c;
|
||||||
|
struct message_entry *msg;
|
||||||
|
char *tim;
|
||||||
|
u_int i;
|
||||||
|
|
||||||
|
if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
for (i = 0; i < ARRAY_LENGTH(&c->message_log); i++) {
|
||||||
|
msg = &ARRAY_ITEM(&c->message_log, i);
|
||||||
|
|
||||||
|
tim = ctime(&msg->msg_time);
|
||||||
|
*strchr(tim, '\n') = '\0';
|
||||||
|
|
||||||
|
ctx->print(ctx, "%s %s", tim, msg->msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
97
external/bsd/tmux/dist/cmd-show-options.c
vendored
Normal file
97
external/bsd/tmux/dist/cmd-show-options.c
vendored
Normal file
|
@ -0,0 +1,97 @@
|
||||||
|
/* $Id: cmd-show-options.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 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 <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Show options.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_show_options_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_show_options_entry = {
|
||||||
|
"show-options", "show",
|
||||||
|
"gst:w", 0, 0,
|
||||||
|
"[-gsw] [-t target-session|target-window]",
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_show_options_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_show_window_options_entry = {
|
||||||
|
"show-window-options", "showw",
|
||||||
|
"gt:", 0, 0,
|
||||||
|
"[-g] " CMD_TARGET_WINDOW_USAGE,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_show_options_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
const struct options_table_entry *table, *oe;
|
||||||
|
struct session *s;
|
||||||
|
struct winlink *wl;
|
||||||
|
struct options *oo;
|
||||||
|
struct options_entry *o;
|
||||||
|
const char *optval;
|
||||||
|
|
||||||
|
if (args_has(self->args, 's')) {
|
||||||
|
oo = &global_options;
|
||||||
|
table = server_options_table;
|
||||||
|
} else if (args_has(self->args, 'w') ||
|
||||||
|
self->entry == &cmd_show_window_options_entry) {
|
||||||
|
table = window_options_table;
|
||||||
|
if (args_has(self->args, 'g'))
|
||||||
|
oo = &global_w_options;
|
||||||
|
else {
|
||||||
|
wl = cmd_find_window(ctx, args_get(args, 't'), NULL);
|
||||||
|
if (wl == NULL)
|
||||||
|
return (-1);
|
||||||
|
oo = &wl->window->options;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
table = session_options_table;
|
||||||
|
if (args_has(self->args, 'g'))
|
||||||
|
oo = &global_s_options;
|
||||||
|
else {
|
||||||
|
s = cmd_find_session(ctx, args_get(args, 't'), 0);
|
||||||
|
if (s == NULL)
|
||||||
|
return (-1);
|
||||||
|
oo = &s->options;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (oe = table; oe->name != NULL; oe++) {
|
||||||
|
if ((o = options_find1(oo, oe->name)) == NULL)
|
||||||
|
continue;
|
||||||
|
optval = options_table_print_entry(oe, o);
|
||||||
|
ctx->print(ctx, "%s %s", oe->name, optval);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
74
external/bsd/tmux/dist/cmd-source-file.c
vendored
Normal file
74
external/bsd/tmux/dist/cmd-source-file.c
vendored
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
/* $Id: cmd-source-file.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008 Tiago Cunha <me@tiagocunha.org>
|
||||||
|
*
|
||||||
|
* 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 "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Sources a configuration file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_source_file_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_source_file_entry = {
|
||||||
|
"source-file", "source",
|
||||||
|
"", 1, 1,
|
||||||
|
"path",
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_source_file_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_source_file_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct causelist causes;
|
||||||
|
char *cause;
|
||||||
|
struct window_pane *wp;
|
||||||
|
int retval;
|
||||||
|
u_int i;
|
||||||
|
|
||||||
|
ARRAY_INIT(&causes);
|
||||||
|
|
||||||
|
retval = load_cfg(args->argv[0], ctx, &causes);
|
||||||
|
if (ARRAY_EMPTY(&causes))
|
||||||
|
return (retval);
|
||||||
|
|
||||||
|
if (retval == 1 && !RB_EMPTY(&sessions) && ctx->cmdclient != NULL) {
|
||||||
|
wp = RB_MIN(sessions, &sessions)->curw->window->active;
|
||||||
|
window_pane_set_mode(wp, &window_copy_mode);
|
||||||
|
window_copy_init_for_output(wp);
|
||||||
|
for (i = 0; i < ARRAY_LENGTH(&causes); i++) {
|
||||||
|
cause = ARRAY_ITEM(&causes, i);
|
||||||
|
window_copy_add(wp, "%s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (i = 0; i < ARRAY_LENGTH(&causes); i++) {
|
||||||
|
cause = ARRAY_ITEM(&causes, i);
|
||||||
|
ctx->print(ctx, "%s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ARRAY_FREE(&causes);
|
||||||
|
|
||||||
|
return (retval);
|
||||||
|
}
|
152
external/bsd/tmux/dist/cmd-split-window.c
vendored
Normal file
152
external/bsd/tmux/dist/cmd-split-window.c
vendored
Normal file
|
@ -0,0 +1,152 @@
|
||||||
|
/* $Id: cmd-split-window.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Split a window (add a new pane).
|
||||||
|
*/
|
||||||
|
|
||||||
|
void cmd_split_window_key_binding(struct cmd *, int);
|
||||||
|
int cmd_split_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_split_window_entry = {
|
||||||
|
"split-window", "splitw",
|
||||||
|
"dl:hp:Pt:v", 0, 1,
|
||||||
|
"[-dhvP] [-p percentage|-l size] [-t target-pane] [command]",
|
||||||
|
0,
|
||||||
|
cmd_split_window_key_binding,
|
||||||
|
NULL,
|
||||||
|
cmd_split_window_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_split_window_key_binding(struct cmd *self, int key)
|
||||||
|
{
|
||||||
|
self->args = args_create(0);
|
||||||
|
if (key == '%')
|
||||||
|
args_set(self->args, 'h', NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct session *s;
|
||||||
|
struct winlink *wl;
|
||||||
|
struct window *w;
|
||||||
|
struct window_pane *wp, *new_wp = NULL;
|
||||||
|
struct environ env;
|
||||||
|
char *cmd, *cwd, *cause;
|
||||||
|
const char *shell;
|
||||||
|
u_int hlimit, paneidx;
|
||||||
|
int size, percentage;
|
||||||
|
enum layout_type type;
|
||||||
|
struct layout_cell *lc;
|
||||||
|
|
||||||
|
if ((wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
w = wl->window;
|
||||||
|
|
||||||
|
environ_init(&env);
|
||||||
|
environ_copy(&global_environ, &env);
|
||||||
|
environ_copy(&s->environ, &env);
|
||||||
|
server_fill_environ(s, &env);
|
||||||
|
|
||||||
|
if (args->argc == 0)
|
||||||
|
cmd = options_get_string(&s->options, "default-command");
|
||||||
|
else
|
||||||
|
cmd = args->argv[0];
|
||||||
|
cwd = options_get_string(&s->options, "default-path");
|
||||||
|
if (*cwd == '\0') {
|
||||||
|
if (ctx->cmdclient != NULL && ctx->cmdclient->cwd != NULL)
|
||||||
|
cwd = ctx->cmdclient->cwd;
|
||||||
|
else
|
||||||
|
cwd = s->cwd;
|
||||||
|
}
|
||||||
|
|
||||||
|
type = LAYOUT_TOPBOTTOM;
|
||||||
|
if (args_has(args, 'h'))
|
||||||
|
type = LAYOUT_LEFTRIGHT;
|
||||||
|
|
||||||
|
size = -1;
|
||||||
|
if (args_has(args, 'l')) {
|
||||||
|
size = args_strtonum(args, 'l', 0, INT_MAX, &cause);
|
||||||
|
if (cause != NULL) {
|
||||||
|
ctx->error(ctx, "size %s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
} else if (args_has(args, 'p')) {
|
||||||
|
percentage = args_strtonum(args, 'p', 0, INT_MAX, &cause);
|
||||||
|
if (cause != NULL) {
|
||||||
|
ctx->error(ctx, "percentage %s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
if (type == LAYOUT_TOPBOTTOM)
|
||||||
|
size = (wp->sy * percentage) / 100;
|
||||||
|
else
|
||||||
|
size = (wp->sx * percentage) / 100;
|
||||||
|
}
|
||||||
|
hlimit = options_get_number(&s->options, "history-limit");
|
||||||
|
|
||||||
|
shell = options_get_string(&s->options, "default-shell");
|
||||||
|
if (*shell == '\0' || areshell(shell))
|
||||||
|
shell = _PATH_BSHELL;
|
||||||
|
|
||||||
|
if ((lc = layout_split_pane(wp, type, size)) == NULL) {
|
||||||
|
cause = xstrdup("pane too small");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
new_wp = window_add_pane(w, hlimit);
|
||||||
|
if (window_pane_spawn(
|
||||||
|
new_wp, cmd, shell, cwd, &env, s->tio, &cause) != 0)
|
||||||
|
goto error;
|
||||||
|
layout_assign_pane(lc, new_wp);
|
||||||
|
|
||||||
|
server_redraw_window(w);
|
||||||
|
|
||||||
|
if (!args_has(args, 'd')) {
|
||||||
|
window_set_active_pane(w, new_wp);
|
||||||
|
session_select(s, wl->idx);
|
||||||
|
server_redraw_session(s);
|
||||||
|
} else
|
||||||
|
server_status_session(s);
|
||||||
|
|
||||||
|
environ_free(&env);
|
||||||
|
|
||||||
|
if (args_has(args, 'P')) {
|
||||||
|
paneidx = window_pane_index(wl->window, new_wp);
|
||||||
|
ctx->print(ctx, "%s:%u.%u", s->name, wl->idx, paneidx);
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
error:
|
||||||
|
environ_free(&env);
|
||||||
|
if (new_wp != NULL)
|
||||||
|
window_remove_pane(w, new_wp);
|
||||||
|
ctx->error(ctx, "create pane failed: %s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
return (-1);
|
||||||
|
}
|
44
external/bsd/tmux/dist/cmd-start-server.c
vendored
Normal file
44
external/bsd/tmux/dist/cmd-start-server.c
vendored
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
/* $Id: cmd-start-server.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 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 "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Start the server and do nothing else.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_start_server_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_start_server_entry = {
|
||||||
|
"start-server", "start",
|
||||||
|
"", 0, 0,
|
||||||
|
"",
|
||||||
|
CMD_STARTSERVER,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_start_server_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ARGSUSED */
|
||||||
|
int
|
||||||
|
cmd_start_server_exec(unused struct cmd *self, unused struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
return (0);
|
||||||
|
}
|
349
external/bsd/tmux/dist/cmd-string.c
vendored
Normal file
349
external/bsd/tmux/dist/cmd-string.c
vendored
Normal file
|
@ -0,0 +1,349 @@
|
||||||
|
/* $Id: cmd-string.c,v 1.4 2011/10/07 10:38:02 joerg Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008 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 <errno.h>
|
||||||
|
#include <pwd.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Parse a command from a string.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_string_getc(const char *, size_t *);
|
||||||
|
void cmd_string_ungetc(size_t *);
|
||||||
|
char *cmd_string_string(const char *, size_t *, char, int);
|
||||||
|
char *cmd_string_variable(const char *, size_t *);
|
||||||
|
char *cmd_string_expand_tilde(const char *, size_t *);
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_string_getc(const char *s, size_t *p)
|
||||||
|
{
|
||||||
|
const char *ucs = s;
|
||||||
|
|
||||||
|
if (ucs[*p] == '\0')
|
||||||
|
return (EOF);
|
||||||
|
return (u_char)(ucs[(*p)++]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_string_ungetc(size_t *p)
|
||||||
|
{
|
||||||
|
(*p)--;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Parse command string. Returns -1 on error. If returning -1, cause is error
|
||||||
|
* string, or NULL for empty command.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
cmd_string_parse(const char *s, struct cmd_list **cmdlist, char **cause)
|
||||||
|
{
|
||||||
|
size_t p;
|
||||||
|
int ch, i, argc, rval;
|
||||||
|
char **argv, *buf, *t;
|
||||||
|
const char *whitespace, *equals;
|
||||||
|
size_t len, len2;
|
||||||
|
|
||||||
|
argv = NULL;
|
||||||
|
argc = 0;
|
||||||
|
|
||||||
|
buf = NULL;
|
||||||
|
len = 0;
|
||||||
|
|
||||||
|
*cause = NULL;
|
||||||
|
|
||||||
|
*cmdlist = NULL;
|
||||||
|
rval = -1;
|
||||||
|
|
||||||
|
p = 0;
|
||||||
|
for (;;) {
|
||||||
|
ch = cmd_string_getc(s, &p);
|
||||||
|
switch (ch) {
|
||||||
|
case '\'':
|
||||||
|
if ((t = cmd_string_string(s, &p, '\'', 0)) == NULL)
|
||||||
|
goto error;
|
||||||
|
len2 = strlen(t);
|
||||||
|
buf = xrealloc(buf, 1, len + len2 + 1);
|
||||||
|
memcpy(buf + len, t, len2 + 1);
|
||||||
|
len += len2;
|
||||||
|
xfree(t);
|
||||||
|
break;
|
||||||
|
case '"':
|
||||||
|
if ((t = cmd_string_string(s, &p, '"', 1)) == NULL)
|
||||||
|
goto error;
|
||||||
|
len2 = strlen(t);
|
||||||
|
buf = xrealloc(buf, 1, len + len2 + 1);
|
||||||
|
memcpy(buf + len, t, len2 + 1);
|
||||||
|
len += len2;
|
||||||
|
xfree(t);
|
||||||
|
break;
|
||||||
|
case '$':
|
||||||
|
if ((t = cmd_string_variable(s, &p)) == NULL)
|
||||||
|
goto error;
|
||||||
|
len2 = strlen(t);
|
||||||
|
buf = xrealloc(buf, 1, len + len2 + 1);
|
||||||
|
strlcpy(buf + len, t, len2 + 1);
|
||||||
|
len += len2;
|
||||||
|
xfree(t);
|
||||||
|
break;
|
||||||
|
case '#':
|
||||||
|
/* Comment: discard rest of line. */
|
||||||
|
while ((ch = cmd_string_getc(s, &p)) != EOF)
|
||||||
|
;
|
||||||
|
/* FALLTHROUGH */
|
||||||
|
case EOF:
|
||||||
|
case ' ':
|
||||||
|
case '\t':
|
||||||
|
if (buf != NULL) {
|
||||||
|
buf = xrealloc(buf, 1, len + 1);
|
||||||
|
buf[len] = '\0';
|
||||||
|
|
||||||
|
argv = xrealloc(argv, argc + 1, sizeof *argv);
|
||||||
|
argv[argc++] = buf;
|
||||||
|
|
||||||
|
buf = NULL;
|
||||||
|
len = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ch != EOF)
|
||||||
|
break;
|
||||||
|
|
||||||
|
while (argc != 0) {
|
||||||
|
equals = strchr(argv[0], '=');
|
||||||
|
whitespace = argv[0] + strcspn(argv[0], " \t");
|
||||||
|
if (equals == NULL || equals > whitespace)
|
||||||
|
break;
|
||||||
|
environ_put(&global_environ, argv[0]);
|
||||||
|
argc--;
|
||||||
|
memmove(argv, argv + 1, argc * (sizeof *argv));
|
||||||
|
}
|
||||||
|
if (argc == 0)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
*cmdlist = cmd_list_parse(argc, argv, cause);
|
||||||
|
if (*cmdlist == NULL)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
rval = 0;
|
||||||
|
goto out;
|
||||||
|
case '~':
|
||||||
|
if (buf == NULL) {
|
||||||
|
if ((t = cmd_string_expand_tilde(s, &p)) == NULL)
|
||||||
|
goto error;
|
||||||
|
len2 = strlen(t);
|
||||||
|
buf = xrealloc(buf, 1, len + len2 + 1);
|
||||||
|
memcpy(buf + len, t, len2 + 1);
|
||||||
|
len += len2;
|
||||||
|
xfree(t);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* FALLTHROUGH */
|
||||||
|
default:
|
||||||
|
if (len >= SIZE_MAX - 2)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
buf = xrealloc(buf, 1, len + 1);
|
||||||
|
buf[len++] = ch;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
error:
|
||||||
|
xasprintf(cause, "invalid or unknown command: %s", s);
|
||||||
|
|
||||||
|
out:
|
||||||
|
if (buf != NULL)
|
||||||
|
xfree(buf);
|
||||||
|
|
||||||
|
if (argv != NULL) {
|
||||||
|
for (i = 0; i < argc; i++)
|
||||||
|
xfree(argv[i]);
|
||||||
|
xfree(argv);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (rval);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
cmd_string_string(const char *s, size_t *p, char endch, int esc)
|
||||||
|
{
|
||||||
|
int ch;
|
||||||
|
char *buf, *t;
|
||||||
|
size_t len, len2;
|
||||||
|
|
||||||
|
buf = NULL;
|
||||||
|
len = 0;
|
||||||
|
|
||||||
|
while ((ch = cmd_string_getc(s, p)) != endch) {
|
||||||
|
switch (ch) {
|
||||||
|
case EOF:
|
||||||
|
goto error;
|
||||||
|
case '\\':
|
||||||
|
if (!esc)
|
||||||
|
break;
|
||||||
|
switch (ch = cmd_string_getc(s, p)) {
|
||||||
|
case EOF:
|
||||||
|
goto error;
|
||||||
|
case 'e':
|
||||||
|
ch = '\033';
|
||||||
|
break;
|
||||||
|
case 'r':
|
||||||
|
ch = '\r';
|
||||||
|
break;
|
||||||
|
case 'n':
|
||||||
|
ch = '\n';
|
||||||
|
break;
|
||||||
|
case 't':
|
||||||
|
ch = '\t';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case '$':
|
||||||
|
if (!esc)
|
||||||
|
break;
|
||||||
|
if ((t = cmd_string_variable(s, p)) == NULL)
|
||||||
|
goto error;
|
||||||
|
len2 = strlen(t);
|
||||||
|
buf = xrealloc(buf, 1, len + len2 + 1);
|
||||||
|
memcpy(buf + len, t, len2 + 1);
|
||||||
|
len += len2;
|
||||||
|
xfree(t);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (len >= SIZE_MAX - 2)
|
||||||
|
goto error;
|
||||||
|
buf = xrealloc(buf, 1, len + 1);
|
||||||
|
buf[len++] = ch;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf = xrealloc(buf, 1, len + 1);
|
||||||
|
buf[len] = '\0';
|
||||||
|
return (buf);
|
||||||
|
|
||||||
|
error:
|
||||||
|
if (buf != NULL)
|
||||||
|
xfree(buf);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
cmd_string_variable(const char *s, size_t *p)
|
||||||
|
{
|
||||||
|
int ch, fch;
|
||||||
|
char *buf, *t;
|
||||||
|
size_t len;
|
||||||
|
struct environ_entry *envent;
|
||||||
|
|
||||||
|
#define cmd_string_first(ch) ((ch) == '_' || \
|
||||||
|
((ch) >= 'a' && (ch) <= 'z') || ((ch) >= 'A' && (ch) <= 'Z'))
|
||||||
|
#define cmd_string_other(ch) ((ch) == '_' || \
|
||||||
|
((ch) >= 'a' && (ch) <= 'z') || ((ch) >= 'A' && (ch) <= 'Z') || \
|
||||||
|
((ch) >= '0' && (ch) <= '9'))
|
||||||
|
|
||||||
|
buf = NULL;
|
||||||
|
len = 0;
|
||||||
|
|
||||||
|
fch = EOF;
|
||||||
|
switch (ch = cmd_string_getc(s, p)) {
|
||||||
|
case EOF:
|
||||||
|
goto error;
|
||||||
|
case '{':
|
||||||
|
fch = '{';
|
||||||
|
|
||||||
|
ch = cmd_string_getc(s, p);
|
||||||
|
if (!cmd_string_first(ch))
|
||||||
|
goto error;
|
||||||
|
/* FALLTHROUGH */
|
||||||
|
default:
|
||||||
|
if (!cmd_string_first(ch)) {
|
||||||
|
xasprintf(&t, "$%c", ch);
|
||||||
|
return (t);
|
||||||
|
}
|
||||||
|
|
||||||
|
buf = xrealloc(buf, 1, len + 1);
|
||||||
|
buf[len++] = ch;
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
ch = cmd_string_getc(s, p);
|
||||||
|
if (ch == EOF || !cmd_string_other(ch))
|
||||||
|
break;
|
||||||
|
else {
|
||||||
|
if (len >= SIZE_MAX - 3)
|
||||||
|
goto error;
|
||||||
|
buf = xrealloc(buf, 1, len + 1);
|
||||||
|
buf[len++] = ch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fch == '{' && ch != '}')
|
||||||
|
goto error;
|
||||||
|
if (ch != EOF && fch != '{')
|
||||||
|
cmd_string_ungetc(p); /* ch */
|
||||||
|
|
||||||
|
buf = xrealloc(buf, 1, len + 1);
|
||||||
|
buf[len] = '\0';
|
||||||
|
|
||||||
|
envent = environ_find(&global_environ, buf);
|
||||||
|
xfree(buf);
|
||||||
|
if (envent == NULL)
|
||||||
|
return (xstrdup(""));
|
||||||
|
return (xstrdup(envent->value));
|
||||||
|
|
||||||
|
error:
|
||||||
|
if (buf != NULL)
|
||||||
|
xfree(buf);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
cmd_string_expand_tilde(const char *s, size_t *p)
|
||||||
|
{
|
||||||
|
struct passwd *pw;
|
||||||
|
struct environ_entry *envent;
|
||||||
|
char *home, *path, *username;
|
||||||
|
|
||||||
|
home = NULL;
|
||||||
|
if (cmd_string_getc(s, p) == '/') {
|
||||||
|
envent = environ_find(&global_environ, "HOME");
|
||||||
|
if (envent != NULL && *envent->value != '\0')
|
||||||
|
home = envent->value;
|
||||||
|
else if ((pw = getpwuid(getuid())) != NULL)
|
||||||
|
home = pw->pw_dir;
|
||||||
|
} else {
|
||||||
|
cmd_string_ungetc(p);
|
||||||
|
if ((username = cmd_string_string(s, p, '/', 0)) == NULL)
|
||||||
|
return (NULL);
|
||||||
|
if ((pw = getpwnam(username)) != NULL)
|
||||||
|
home = pw->pw_dir;
|
||||||
|
xfree(username);
|
||||||
|
}
|
||||||
|
if (home == NULL)
|
||||||
|
return (NULL);
|
||||||
|
|
||||||
|
xasprintf(&path, "%s/", home);
|
||||||
|
return (path);
|
||||||
|
}
|
56
external/bsd/tmux/dist/cmd-suspend-client.c
vendored
Normal file
56
external/bsd/tmux/dist/cmd-suspend-client.c
vendored
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
/* $Id: cmd-suspend-client.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Suspend client with SIGTSTP.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_suspend_client_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_suspend_client_entry = {
|
||||||
|
"suspend-client", "suspendc",
|
||||||
|
"t:", 0, 0,
|
||||||
|
CMD_TARGET_CLIENT_USAGE,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_suspend_client_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_suspend_client_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct client *c;
|
||||||
|
|
||||||
|
if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
tty_stop_tty(&c->tty);
|
||||||
|
c->flags |= CLIENT_SUSPENDED;
|
||||||
|
server_write_client(c, MSG_SUSPEND, NULL, 0);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
142
external/bsd/tmux/dist/cmd-swap-pane.c
vendored
Normal file
142
external/bsd/tmux/dist/cmd-swap-pane.c
vendored
Normal file
|
@ -0,0 +1,142 @@
|
||||||
|
/* $Id: cmd-swap-pane.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 <stdlib.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Swap two panes.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void cmd_swap_pane_key_binding(struct cmd *, int);
|
||||||
|
int cmd_swap_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_swap_pane_entry = {
|
||||||
|
"swap-pane", "swapp",
|
||||||
|
"dDs:t:U", 0, 0,
|
||||||
|
"[-dDU] " CMD_SRCDST_PANE_USAGE,
|
||||||
|
0,
|
||||||
|
cmd_swap_pane_key_binding,
|
||||||
|
NULL,
|
||||||
|
cmd_swap_pane_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_swap_pane_key_binding(struct cmd *self, int key)
|
||||||
|
{
|
||||||
|
self->args = args_create(0);
|
||||||
|
if (key == '{')
|
||||||
|
args_set(self->args, 'U', NULL);
|
||||||
|
else if (key == '}')
|
||||||
|
args_set(self->args, 'D', NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_swap_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct winlink *src_wl, *dst_wl;
|
||||||
|
struct window *src_w, *dst_w;
|
||||||
|
struct window_pane *tmp_wp, *src_wp, *dst_wp;
|
||||||
|
struct layout_cell *src_lc, *dst_lc;
|
||||||
|
u_int sx, sy, xoff, yoff;
|
||||||
|
|
||||||
|
dst_wl = cmd_find_pane(ctx, args_get(args, 't'), NULL, &dst_wp);
|
||||||
|
if (dst_wl == NULL)
|
||||||
|
return (-1);
|
||||||
|
dst_w = dst_wl->window;
|
||||||
|
|
||||||
|
if (!args_has(args, 's')) {
|
||||||
|
src_w = dst_w;
|
||||||
|
if (args_has(self->args, 'D')) {
|
||||||
|
src_wp = TAILQ_NEXT(dst_wp, entry);
|
||||||
|
if (src_wp == NULL)
|
||||||
|
src_wp = TAILQ_FIRST(&dst_w->panes);
|
||||||
|
} else if (args_has(self->args, 'U')) {
|
||||||
|
src_wp = TAILQ_PREV(dst_wp, window_panes, entry);
|
||||||
|
if (src_wp == NULL)
|
||||||
|
src_wp = TAILQ_LAST(&dst_w->panes, window_panes);
|
||||||
|
} else
|
||||||
|
return (0);
|
||||||
|
} else {
|
||||||
|
src_wl = cmd_find_pane(ctx, args_get(args, 's'), NULL, &src_wp);
|
||||||
|
if (src_wl == NULL)
|
||||||
|
return (-1);
|
||||||
|
src_w = src_wl->window;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (src_wp == dst_wp)
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
tmp_wp = TAILQ_PREV(dst_wp, window_panes, entry);
|
||||||
|
TAILQ_REMOVE(&dst_w->panes, dst_wp, entry);
|
||||||
|
TAILQ_REPLACE(&src_w->panes, src_wp, dst_wp, entry);
|
||||||
|
if (tmp_wp == src_wp)
|
||||||
|
tmp_wp = dst_wp;
|
||||||
|
if (tmp_wp == NULL)
|
||||||
|
TAILQ_INSERT_HEAD(&dst_w->panes, src_wp, entry);
|
||||||
|
else
|
||||||
|
TAILQ_INSERT_AFTER(&dst_w->panes, tmp_wp, src_wp, entry);
|
||||||
|
|
||||||
|
src_lc = src_wp->layout_cell;
|
||||||
|
dst_lc = dst_wp->layout_cell;
|
||||||
|
src_lc->wp = dst_wp;
|
||||||
|
dst_wp->layout_cell = src_lc;
|
||||||
|
dst_lc->wp = src_wp;
|
||||||
|
src_wp->layout_cell = dst_lc;
|
||||||
|
|
||||||
|
src_wp->window = dst_w;
|
||||||
|
dst_wp->window = src_w;
|
||||||
|
|
||||||
|
sx = src_wp->sx; sy = src_wp->sy;
|
||||||
|
xoff = src_wp->xoff; yoff = src_wp->yoff;
|
||||||
|
src_wp->xoff = dst_wp->xoff; src_wp->yoff = dst_wp->yoff;
|
||||||
|
window_pane_resize(src_wp, dst_wp->sx, dst_wp->sy);
|
||||||
|
dst_wp->xoff = xoff; dst_wp->yoff = yoff;
|
||||||
|
window_pane_resize(dst_wp, sx, sy);
|
||||||
|
|
||||||
|
if (!args_has(self->args, 'd')) {
|
||||||
|
if (src_w != dst_w) {
|
||||||
|
window_set_active_pane(src_w, dst_wp);
|
||||||
|
window_set_active_pane(dst_w, src_wp);
|
||||||
|
} else {
|
||||||
|
tmp_wp = dst_wp;
|
||||||
|
if (!window_pane_visible(tmp_wp))
|
||||||
|
tmp_wp = src_wp;
|
||||||
|
window_set_active_pane(src_w, tmp_wp);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (src_w->active == src_wp)
|
||||||
|
window_set_active_pane(src_w, dst_wp);
|
||||||
|
if (dst_w->active == dst_wp)
|
||||||
|
window_set_active_pane(dst_w, src_wp);
|
||||||
|
}
|
||||||
|
if (src_w != dst_w) {
|
||||||
|
if (src_w->last == src_wp)
|
||||||
|
src_w->last = NULL;
|
||||||
|
if (dst_w->last == dst_wp)
|
||||||
|
dst_w->last = NULL;
|
||||||
|
}
|
||||||
|
server_redraw_window(src_w);
|
||||||
|
server_redraw_window(dst_w);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
87
external/bsd/tmux/dist/cmd-swap-window.c
vendored
Normal file
87
external/bsd/tmux/dist/cmd-swap-window.c
vendored
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
/* $Id: cmd-swap-window.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 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 <stdlib.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Swap one window with another.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_swap_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_swap_window_entry = {
|
||||||
|
"swap-window", "swapw",
|
||||||
|
"ds:t:", 0, 0,
|
||||||
|
"[-d] " CMD_SRCDST_WINDOW_USAGE,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_swap_window_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_swap_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
const char *target_src, *target_dst;
|
||||||
|
struct session *src, *dst;
|
||||||
|
struct session_group *sg_src, *sg_dst;
|
||||||
|
struct winlink *wl_src, *wl_dst;
|
||||||
|
struct window *w;
|
||||||
|
|
||||||
|
target_src = args_get(args, 's');
|
||||||
|
if ((wl_src = cmd_find_window(ctx, target_src, &src)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
target_dst = args_get(args, 't');
|
||||||
|
if ((wl_dst = cmd_find_window(ctx, target_dst, &dst)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
sg_src = session_group_find(src);
|
||||||
|
sg_dst = session_group_find(dst);
|
||||||
|
if (src != dst &&
|
||||||
|
sg_src != NULL && sg_dst != NULL && sg_src == sg_dst) {
|
||||||
|
ctx->error(ctx, "can't move window, sessions are grouped");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wl_dst->window == wl_src->window)
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
w = wl_dst->window;
|
||||||
|
wl_dst->window = wl_src->window;
|
||||||
|
wl_src->window = w;
|
||||||
|
|
||||||
|
if (!args_has(self->args, 'd')) {
|
||||||
|
session_select(dst, wl_dst->idx);
|
||||||
|
if (src != dst)
|
||||||
|
session_select(src, wl_src->idx);
|
||||||
|
}
|
||||||
|
session_group_synchronize_from(src);
|
||||||
|
server_redraw_session_group(src);
|
||||||
|
if (src != dst) {
|
||||||
|
session_group_synchronize_from(dst);
|
||||||
|
server_redraw_session_group(dst);
|
||||||
|
}
|
||||||
|
recalculate_sizes();
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
103
external/bsd/tmux/dist/cmd-switch-client.c
vendored
Normal file
103
external/bsd/tmux/dist/cmd-switch-client.c
vendored
Normal file
|
@ -0,0 +1,103 @@
|
||||||
|
/* $Id: cmd-switch-client.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 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 <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Switch client to a different session.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void cmd_switch_client_key_binding(struct cmd *, int);
|
||||||
|
int cmd_switch_client_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_switch_client_entry = {
|
||||||
|
"switch-client", "switchc",
|
||||||
|
"lc:npt:", 0, 0,
|
||||||
|
"[-lnp] [-c target-client] [-t target-session]",
|
||||||
|
0,
|
||||||
|
cmd_switch_client_key_binding,
|
||||||
|
NULL,
|
||||||
|
cmd_switch_client_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_switch_client_key_binding(struct cmd *self, int key)
|
||||||
|
{
|
||||||
|
self->args = args_create(0);
|
||||||
|
switch (key) {
|
||||||
|
case '(':
|
||||||
|
args_set(self->args, 'p', NULL);
|
||||||
|
break;
|
||||||
|
case ')':
|
||||||
|
args_set(self->args, 'n', NULL);
|
||||||
|
break;
|
||||||
|
case 'L':
|
||||||
|
args_set(self->args, 'l', NULL);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_switch_client_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct client *c;
|
||||||
|
struct session *s;
|
||||||
|
|
||||||
|
if ((c = cmd_find_client(ctx, args_get(args, 'c'))) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
s = NULL;
|
||||||
|
if (args_has(args, 'n')) {
|
||||||
|
if ((s = session_next_session(c->session)) == NULL) {
|
||||||
|
ctx->error(ctx, "can't find next session");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
} else if (args_has(args, 'p')) {
|
||||||
|
if ((s = session_previous_session(c->session)) == NULL) {
|
||||||
|
ctx->error(ctx, "can't find previous session");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
} else if (args_has(args, 'l')) {
|
||||||
|
if (c->last_session != NULL && session_alive(c->last_session))
|
||||||
|
s = c->last_session;
|
||||||
|
if (s == NULL) {
|
||||||
|
ctx->error(ctx, "can't find last session");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
s = cmd_find_session(ctx, args_get(args, 't'), 0);
|
||||||
|
if (s == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
if (c->session != NULL)
|
||||||
|
c->last_session = c->session;
|
||||||
|
c->session = s;
|
||||||
|
session_update_activity(s);
|
||||||
|
|
||||||
|
recalculate_sizes();
|
||||||
|
server_check_unattached();
|
||||||
|
server_redraw_client(c);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
105
external/bsd/tmux/dist/cmd-unbind-key.c
vendored
Normal file
105
external/bsd/tmux/dist/cmd-unbind-key.c
vendored
Normal file
|
@ -0,0 +1,105 @@
|
||||||
|
/* $Id: cmd-unbind-key.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 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 "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Unbind key from command.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_unbind_key_check(struct args *);
|
||||||
|
int cmd_unbind_key_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
int cmd_unbind_key_table(struct cmd *, struct cmd_ctx *, int);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_unbind_key_entry = {
|
||||||
|
"unbind-key", "unbind",
|
||||||
|
"acnt:", 0, 1,
|
||||||
|
"[-acn] [-t key-table] key",
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
cmd_unbind_key_check,
|
||||||
|
cmd_unbind_key_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_unbind_key_check(struct args *args)
|
||||||
|
{
|
||||||
|
if (args_has(args, 'a') && (args->argc != 0 || args_has(args, 't')))
|
||||||
|
return (-1);
|
||||||
|
if (!args_has(args, 'a') && args->argc != 1)
|
||||||
|
return (-1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_unbind_key_exec(struct cmd *self, unused struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct key_binding *bd;
|
||||||
|
int key;
|
||||||
|
|
||||||
|
if (args_has(args, 'a')) {
|
||||||
|
while (!SPLAY_EMPTY(&key_bindings)) {
|
||||||
|
bd = SPLAY_ROOT(&key_bindings);
|
||||||
|
SPLAY_REMOVE(key_bindings, &key_bindings, bd);
|
||||||
|
cmd_list_free(bd->cmdlist);
|
||||||
|
xfree(bd);
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
key = key_string_lookup_string(args->argv[0]);
|
||||||
|
if (key == KEYC_NONE) {
|
||||||
|
ctx->error(ctx, "unknown key: %s", args->argv[0]);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args_has(args, 't'))
|
||||||
|
return (cmd_unbind_key_table(self, ctx, key));
|
||||||
|
|
||||||
|
if (!args_has(args, 'n'))
|
||||||
|
key |= KEYC_PREFIX;
|
||||||
|
key_bindings_remove(key);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_unbind_key_table(struct cmd *self, struct cmd_ctx *ctx, int key)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
const char *tablename;
|
||||||
|
const struct mode_key_table *mtab;
|
||||||
|
struct mode_key_binding *mbind, mtmp;
|
||||||
|
|
||||||
|
tablename = args_get(args, 't');
|
||||||
|
if ((mtab = mode_key_findtable(tablename)) == NULL) {
|
||||||
|
ctx->error(ctx, "unknown key table: %s", tablename);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
mtmp.key = key;
|
||||||
|
mtmp.mode = !!args_has(args, 'c');
|
||||||
|
if ((mbind = SPLAY_FIND(mode_key_tree, mtab->tree, &mtmp)) != NULL) {
|
||||||
|
SPLAY_REMOVE(mode_key_tree, mtab->tree, mbind);
|
||||||
|
xfree(mbind);
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
70
external/bsd/tmux/dist/cmd-unlink-window.c
vendored
Normal file
70
external/bsd/tmux/dist/cmd-unlink-window.c
vendored
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
/* $Id: cmd-unlink-window.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 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 "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Unlink a window, unless it would be destroyed by doing so (only one link).
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_unlink_window_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_unlink_window_entry = {
|
||||||
|
"unlink-window", "unlinkw",
|
||||||
|
"kt:", 0, 0,
|
||||||
|
"[-k] " CMD_TARGET_WINDOW_USAGE,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
cmd_unlink_window_exec
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_unlink_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct args *args = self->args;
|
||||||
|
struct winlink *wl;
|
||||||
|
struct window *w;
|
||||||
|
struct session *s, *s2;
|
||||||
|
struct session_group *sg;
|
||||||
|
u_int references;
|
||||||
|
|
||||||
|
if ((wl = cmd_find_window(ctx, args_get(args, 't'), &s)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
w = wl->window;
|
||||||
|
|
||||||
|
sg = session_group_find(s);
|
||||||
|
if (sg != NULL) {
|
||||||
|
references = 0;
|
||||||
|
TAILQ_FOREACH(s2, &sg->sessions, gentry)
|
||||||
|
references++;
|
||||||
|
} else
|
||||||
|
references = 1;
|
||||||
|
|
||||||
|
if (!args_has(self->args, 'k') && w->references == references) {
|
||||||
|
ctx->error(ctx, "window is only linked to one session");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
server_unlink_window(s, wl);
|
||||||
|
recalculate_sizes();
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
1214
external/bsd/tmux/dist/cmd.c
vendored
Normal file
1214
external/bsd/tmux/dist/cmd.c
vendored
Normal file
File diff suppressed because it is too large
Load diff
276
external/bsd/tmux/dist/colour.c
vendored
Normal file
276
external/bsd/tmux/dist/colour.c
vendored
Normal file
|
@ -0,0 +1,276 @@
|
||||||
|
/* $Id: colour.c,v 1.3 2011/08/22 09:19:51 he Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008 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 <ctype.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Colour to string conversion functions. Bit 8 of the colour means it is one
|
||||||
|
* of the 256 colour palette.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* An RGB colour. */
|
||||||
|
struct colour_rgb {
|
||||||
|
u_char r;
|
||||||
|
u_char g;
|
||||||
|
u_char b;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* 256 colour RGB table, generated on first use. */
|
||||||
|
struct colour_rgb *colour_rgb_256;
|
||||||
|
|
||||||
|
void colour_rgb_generate256(void);
|
||||||
|
u_int colour_rgb_distance(struct colour_rgb *, struct colour_rgb *);
|
||||||
|
int colour_rgb_find(struct colour_rgb *);
|
||||||
|
|
||||||
|
/* Generate 256 colour RGB table. */
|
||||||
|
void
|
||||||
|
colour_rgb_generate256(void)
|
||||||
|
{
|
||||||
|
struct colour_rgb *rgb;
|
||||||
|
u_int i, r, g, b;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Allocate the table. The first 16 colours are often changed by users
|
||||||
|
* and terminals so don't include them.
|
||||||
|
*/
|
||||||
|
colour_rgb_256 = xcalloc(240, sizeof *colour_rgb_256);
|
||||||
|
|
||||||
|
/* Add the colours first. */
|
||||||
|
r = g = b = 0;
|
||||||
|
for (i = 240; i > 24; i--) {
|
||||||
|
rgb = &colour_rgb_256[240 - i];
|
||||||
|
|
||||||
|
if (r != 0)
|
||||||
|
rgb->r = (r * 40) + 55;
|
||||||
|
if (g != 0)
|
||||||
|
rgb->g = (g * 40) + 55;
|
||||||
|
if (b != 0)
|
||||||
|
rgb->b = (b * 40) + 55;
|
||||||
|
|
||||||
|
b++;
|
||||||
|
if (b > 5) {
|
||||||
|
b = 0;
|
||||||
|
g++;
|
||||||
|
}
|
||||||
|
if (g > 5) {
|
||||||
|
g = 0;
|
||||||
|
r++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Then add the greys. */
|
||||||
|
for (i = 24; i > 0; i--) {
|
||||||
|
rgb = &colour_rgb_256[240 - i];
|
||||||
|
|
||||||
|
rgb->r = 8 + (24 - i) * 10;
|
||||||
|
rgb->g = 8 + (24 - i) * 10;
|
||||||
|
rgb->b = 8 + (24 - i) * 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get a measure of colour RGB distance. */
|
||||||
|
u_int
|
||||||
|
colour_rgb_distance(struct colour_rgb *rgb1, struct colour_rgb *rgb2)
|
||||||
|
{
|
||||||
|
int r, g, b;
|
||||||
|
|
||||||
|
r = rgb1->r - rgb2->r;
|
||||||
|
g = rgb1->g - rgb2->g;
|
||||||
|
b = rgb1->b - rgb2->b;
|
||||||
|
return (r * r + g * g + b * b);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Work out the nearest colour from the 256 colour set. */
|
||||||
|
int
|
||||||
|
colour_rgb_find(struct colour_rgb *rgb)
|
||||||
|
{
|
||||||
|
u_int distance, lowest;
|
||||||
|
u_int colour, i;
|
||||||
|
|
||||||
|
if (colour_rgb_256 == NULL)
|
||||||
|
colour_rgb_generate256();
|
||||||
|
|
||||||
|
colour = 16;
|
||||||
|
lowest = UINT_MAX;
|
||||||
|
for (i = 0; i < 240; i++) {
|
||||||
|
distance = colour_rgb_distance(&colour_rgb_256[i], rgb);
|
||||||
|
if (distance < lowest) {
|
||||||
|
lowest = distance;
|
||||||
|
colour = 16 + i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (colour);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set grid cell foreground colour. */
|
||||||
|
void
|
||||||
|
colour_set_fg(struct grid_cell *gc, int c)
|
||||||
|
{
|
||||||
|
if (c & 0x100)
|
||||||
|
gc->flags |= GRID_FLAG_FG256;
|
||||||
|
gc->fg = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set grid cell background colour. */
|
||||||
|
void
|
||||||
|
colour_set_bg(struct grid_cell *gc, int c)
|
||||||
|
{
|
||||||
|
if (c & 0x100)
|
||||||
|
gc->flags |= GRID_FLAG_BG256;
|
||||||
|
gc->bg = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Convert colour to a string. */
|
||||||
|
const char *
|
||||||
|
colour_tostring(int c)
|
||||||
|
{
|
||||||
|
static char s[32];
|
||||||
|
|
||||||
|
if (c & 0x100) {
|
||||||
|
xsnprintf(s, sizeof s, "colour%u", c & ~0x100);
|
||||||
|
return (s);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (c) {
|
||||||
|
case 0:
|
||||||
|
return ("black");
|
||||||
|
case 1:
|
||||||
|
return ("red");
|
||||||
|
case 2:
|
||||||
|
return ("green");
|
||||||
|
case 3:
|
||||||
|
return ("yellow");
|
||||||
|
case 4:
|
||||||
|
return ("blue");
|
||||||
|
case 5:
|
||||||
|
return ("magenta");
|
||||||
|
case 6:
|
||||||
|
return ("cyan");
|
||||||
|
case 7:
|
||||||
|
return ("white");
|
||||||
|
case 8:
|
||||||
|
return ("default");
|
||||||
|
}
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Convert colour from string. */
|
||||||
|
int
|
||||||
|
colour_fromstring(const char *s)
|
||||||
|
{
|
||||||
|
const char *errstr;
|
||||||
|
const char *cp;
|
||||||
|
struct colour_rgb rgb;
|
||||||
|
int n;
|
||||||
|
|
||||||
|
if (*s == '#' && strlen(s) == 7) {
|
||||||
|
for (cp = s + 1; isxdigit((u_char) *cp); cp++)
|
||||||
|
;
|
||||||
|
if (*cp != '\0')
|
||||||
|
return (-1);
|
||||||
|
n = sscanf(s + 1, "%2hhx%2hhx%2hhx", &rgb.r, &rgb.g, &rgb.b);
|
||||||
|
if (n != 3)
|
||||||
|
return (-1);
|
||||||
|
return (colour_rgb_find(&rgb) | 0x100);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strncasecmp(s, "colour", (sizeof "colour") - 1) == 0) {
|
||||||
|
n = strtonum(s + (sizeof "colour") - 1, 0, 255, &errstr);
|
||||||
|
if (errstr != NULL)
|
||||||
|
return (-1);
|
||||||
|
return (n | 0x100);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strcasecmp(s, "black") == 0 || (s[0] == '0' && s[1] == '\0'))
|
||||||
|
return (0);
|
||||||
|
if (strcasecmp(s, "red") == 0 || (s[0] == '1' && s[1] == '\0'))
|
||||||
|
return (1);
|
||||||
|
if (strcasecmp(s, "green") == 0 || (s[0] == '2' && s[1] == '\0'))
|
||||||
|
return (2);
|
||||||
|
if (strcasecmp(s, "yellow") == 0 || (s[0] == '3' && s[1] == '\0'))
|
||||||
|
return (3);
|
||||||
|
if (strcasecmp(s, "blue") == 0 || (s[0] == '4' && s[1] == '\0'))
|
||||||
|
return (4);
|
||||||
|
if (strcasecmp(s, "magenta") == 0 || (s[0] == '5' && s[1] == '\0'))
|
||||||
|
return (5);
|
||||||
|
if (strcasecmp(s, "cyan") == 0 || (s[0] == '6' && s[1] == '\0'))
|
||||||
|
return (6);
|
||||||
|
if (strcasecmp(s, "white") == 0 || (s[0] == '7' && s[1] == '\0'))
|
||||||
|
return (7);
|
||||||
|
if (strcasecmp(s, "default") == 0 || (s[0] == '8' && s[1] == '\0'))
|
||||||
|
return (8);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Convert 256 colour palette to 16. */
|
||||||
|
u_char
|
||||||
|
colour_256to16(u_char c)
|
||||||
|
{
|
||||||
|
static const u_char table[256] = {
|
||||||
|
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
||||||
|
0, 4, 4, 4, 12, 12, 2, 6, 4, 4, 12, 12, 2, 2, 6, 4,
|
||||||
|
12, 12, 2, 2, 2, 6, 12, 12, 10, 10, 10, 10, 14, 12, 10, 10,
|
||||||
|
10, 10, 10, 14, 1, 5, 4, 4, 12, 12, 3, 8, 4, 4, 12, 12,
|
||||||
|
2, 2, 6, 4, 12, 12, 2, 2, 2, 6, 12, 12, 10, 10, 10, 10,
|
||||||
|
14, 12, 10, 10, 10, 10, 10, 14, 1, 1, 5, 4, 12, 12, 1, 1,
|
||||||
|
5, 4, 12, 12, 3, 3, 8, 4, 12, 12, 2, 2, 2, 6, 12, 12,
|
||||||
|
10, 10, 10, 10, 14, 12, 10, 10, 10, 10, 10, 14, 1, 1, 1, 5,
|
||||||
|
12, 12, 1, 1, 1, 5, 12, 12, 1, 1, 1, 5, 12, 12, 3, 3,
|
||||||
|
3, 7, 12, 12, 10, 10, 10, 10, 14, 12, 10, 10, 10, 10, 10, 14,
|
||||||
|
9, 9, 9, 9, 13, 12, 9, 9, 9, 9, 13, 12, 9, 9, 9, 9,
|
||||||
|
13, 12, 9, 9, 9, 9, 13, 12, 11, 11, 11, 11, 7, 12, 10, 10,
|
||||||
|
10, 10, 10, 14, 9, 9, 9, 9, 9, 13, 9, 9, 9, 9, 9, 13,
|
||||||
|
9, 9, 9, 9, 9, 13, 9, 9, 9, 9, 9, 13, 9, 9, 9, 9,
|
||||||
|
9, 13, 11, 11, 11, 11, 11, 15, 0, 0, 0, 0, 0, 0, 8, 8,
|
||||||
|
8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 15, 15, 15, 15, 15, 15
|
||||||
|
};
|
||||||
|
|
||||||
|
return (table[c]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Convert 256 colour palette to 88. */
|
||||||
|
u_char
|
||||||
|
colour_256to88(u_char c)
|
||||||
|
{
|
||||||
|
static const u_char table[256] = {
|
||||||
|
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
||||||
|
16, 17, 17, 18, 18, 19, 20, 21, 21, 22, 22, 23, 20, 21, 21, 22,
|
||||||
|
22, 23, 24, 25, 25, 26, 26, 27, 24, 25, 25, 26, 26, 27, 28, 29,
|
||||||
|
29, 30, 30, 31, 32, 33, 33, 34, 34, 35, 36, 37, 37, 38, 38, 39,
|
||||||
|
36, 37, 37, 38, 38, 39, 40, 41, 41, 42, 42, 43, 40, 41, 41, 42,
|
||||||
|
42, 43, 44, 45, 45, 46, 46, 47, 32, 33, 33, 34, 34, 35, 36, 37,
|
||||||
|
37, 38, 38, 39, 36, 37, 37, 38, 38, 39, 40, 41, 41, 42, 42, 43,
|
||||||
|
40, 41, 41, 42, 42, 43, 44, 45, 45, 46, 46, 47, 48, 49, 49, 50,
|
||||||
|
50, 51, 52, 53, 53, 54, 54, 55, 52, 53, 53, 54, 54, 55, 56, 57,
|
||||||
|
57, 58, 58, 59, 56, 57, 57, 58, 58, 59, 60, 61, 61, 62, 62, 63,
|
||||||
|
48, 49, 49, 50, 50, 51, 52, 53, 53, 54, 54, 55, 52, 53, 53, 54,
|
||||||
|
54, 55, 56, 57, 57, 58, 58, 59, 56, 57, 57, 58, 58, 59, 60, 61,
|
||||||
|
61, 62, 62, 63, 64, 65, 65, 66, 66, 67, 68, 69, 69, 70, 70, 71,
|
||||||
|
68, 69, 69, 70, 70, 71, 72, 73, 73, 74, 74, 75, 72, 73, 73, 74,
|
||||||
|
74, 75, 76, 77, 77, 78, 78, 79, 0, 0, 80, 80, 80, 81, 81, 81,
|
||||||
|
82, 82, 82, 83, 83, 83, 84, 84, 84, 85, 85, 85, 86, 86, 86, 87
|
||||||
|
};
|
||||||
|
|
||||||
|
return (table[c]);
|
||||||
|
}
|
240
external/bsd/tmux/dist/compat.h
vendored
Normal file
240
external/bsd/tmux/dist/compat.h
vendored
Normal file
|
@ -0,0 +1,240 @@
|
||||||
|
/* $Id: compat.h,v 1.1.1.2 2011/08/17 18:40:05 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef COMPAT_H
|
||||||
|
#define COMPAT_H
|
||||||
|
|
||||||
|
#ifndef __GNUC__
|
||||||
|
#define __attribute__(a)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __dead
|
||||||
|
#define __dead __attribute__ ((__noreturn__))
|
||||||
|
#endif
|
||||||
|
#ifndef __packed
|
||||||
|
#define __packed __attribute__ ((__packed__))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_BSD_TYPES
|
||||||
|
typedef uint8_t u_int8_t;
|
||||||
|
typedef uint16_t u_int16_t;
|
||||||
|
typedef uint32_t u_int32_t;
|
||||||
|
typedef uint64_t u_int64_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_PATHS_H
|
||||||
|
#define _PATH_BSHELL "/bin/sh"
|
||||||
|
#define _PATH_TMP "/tmp/"
|
||||||
|
#define _PATH_DEVNULL "/dev/null"
|
||||||
|
#define _PATH_TTY "/dev/tty"
|
||||||
|
#define _PATH_DEV "/dev/"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_QUEUE_H
|
||||||
|
#include <sys/queue.h>
|
||||||
|
#else
|
||||||
|
#include "compat/queue.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_TREE_H
|
||||||
|
#include <sys/tree.h>
|
||||||
|
#else
|
||||||
|
#include "compat/tree.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_BITSTRING_H
|
||||||
|
#include <bitstring.h>
|
||||||
|
#else
|
||||||
|
#include "compat/bitstring.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_PATHS_H
|
||||||
|
#include <paths.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_FORKPTY
|
||||||
|
#ifdef HAVE_LIBUTIL_H
|
||||||
|
#include <libutil.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_PTY_H
|
||||||
|
#include <pty.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_UTIL_H
|
||||||
|
#include <util.h>
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_VIS
|
||||||
|
#include <vis.h>
|
||||||
|
#else
|
||||||
|
#include "compat/vis.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_IMSG
|
||||||
|
#include <imsg.h>
|
||||||
|
#else
|
||||||
|
#include "compat/imsg.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_STDINT_H
|
||||||
|
#include <stdint.h>
|
||||||
|
#else
|
||||||
|
#include <inttypes.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef BROKEN_CMSG_FIRSTHDR
|
||||||
|
#undef CMSG_FIRSTHDR
|
||||||
|
#define CMSG_FIRSTHDR(mhdr) \
|
||||||
|
((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \
|
||||||
|
(struct cmsghdr *)(mhdr)->msg_control : \
|
||||||
|
(struct cmsghdr *)NULL)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef CMSG_ALIGN
|
||||||
|
#ifdef _CMSG_DATA_ALIGN
|
||||||
|
#define CMSG_ALIGN _CMSG_DATA_ALIGN
|
||||||
|
#else
|
||||||
|
#define CMSG_ALIGN(len) (((len) + sizeof(long) - 1) & ~(sizeof(long) - 1))
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef CMSG_SPACE
|
||||||
|
#define CMSG_SPACE(len) (CMSG_ALIGN(sizeof(struct cmsghdr)) + CMSG_ALIGN(len))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef CMSG_LEN
|
||||||
|
#define CMSG_LEN(len) (CMSG_ALIGN(sizeof(struct cmsghdr)) + (len))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef INFTIM
|
||||||
|
#define INFTIM -1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef WAIT_ANY
|
||||||
|
#define WAIT_ANY -1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef SUN_LEN
|
||||||
|
#define SUN_LEN(sun) (sizeof (sun)->sun_path)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef timercmp
|
||||||
|
#define timercmp(tvp, uvp, cmp) \
|
||||||
|
(((tvp)->tv_sec == (uvp)->tv_sec) ? \
|
||||||
|
((tvp)->tv_usec cmp (uvp)->tv_usec) : \
|
||||||
|
((tvp)->tv_sec cmp (uvp)->tv_sec))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef timeradd
|
||||||
|
#define timeradd(tvp, uvp, vvp) \
|
||||||
|
do { \
|
||||||
|
(vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
|
||||||
|
(vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
|
||||||
|
if ((vvp)->tv_usec >= 1000000) { \
|
||||||
|
(vvp)->tv_sec++; \
|
||||||
|
(vvp)->tv_usec -= 1000000; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef TTY_NAME_MAX
|
||||||
|
#define TTY_NAME_MAX 32
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_BZERO
|
||||||
|
#undef bzero
|
||||||
|
#define bzero(buf, len) memset(buf, 0, len);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_CLOSEFROM
|
||||||
|
/* closefrom.c */
|
||||||
|
void closefrom(int);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_STRCASESTR
|
||||||
|
/* strcasestr.c */
|
||||||
|
char *strcasestr(const char *, const char *);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_STRSEP
|
||||||
|
/* strsep.c */
|
||||||
|
char *strsep(char **, const char *);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_STRTONUM
|
||||||
|
/* strtonum.c */
|
||||||
|
long long strtonum(const char *, long long, long long, const char **);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_STRLCPY
|
||||||
|
/* strlcpy.c */
|
||||||
|
size_t strlcpy(char *, const char *, size_t);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_STRLCAT
|
||||||
|
/* strlcat.c */
|
||||||
|
size_t strlcat(char *, const char *, size_t);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_DAEMON
|
||||||
|
/* daemon.c */
|
||||||
|
int daemon(int, int);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_FORKPTY
|
||||||
|
/* forkpty.c */
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
pid_t forkpty(int *, char *, struct termios *, struct winsize *);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_ASPRINTF
|
||||||
|
/* asprintf.c */
|
||||||
|
int asprintf(char **, const char *, ...);
|
||||||
|
int vasprintf(char **, const char *, va_list);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_FGETLN
|
||||||
|
/* fgetln.c */
|
||||||
|
char *fgetln(FILE *, size_t *);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_SETENV
|
||||||
|
/* setenv.c */
|
||||||
|
int setenv(const char *, const char *, int);
|
||||||
|
int unsetenv(const char *);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_GETOPT
|
||||||
|
#include <getopt.h>
|
||||||
|
#else
|
||||||
|
/* getopt.c */
|
||||||
|
extern int BSDopterr;
|
||||||
|
extern int BSDoptind;
|
||||||
|
extern int BSDoptopt;
|
||||||
|
extern int BSDoptreset;
|
||||||
|
extern char *BSDoptarg;
|
||||||
|
int BSDgetopt(int, char *const *, const char *);
|
||||||
|
#define getopt(ac, av, o) BSDgetopt(ac, av, o)
|
||||||
|
#define opterr BSDopterr
|
||||||
|
#define optind BSDoptind
|
||||||
|
#define optopt BSDoptopt
|
||||||
|
#define optreset BSDoptreset
|
||||||
|
#define optarg BSDoptarg
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* COMPAT_H */
|
303
external/bsd/tmux/dist/compat/imsg-buffer.c
vendored
Normal file
303
external/bsd/tmux/dist/compat/imsg-buffer.c
vendored
Normal file
|
@ -0,0 +1,303 @@
|
||||||
|
/* $Id: imsg-buffer.c,v 1.5 2012/01/20 14:08:04 joerg Exp $ */
|
||||||
|
/* $OpenBSD: imsg-buffer.c,v 1.3 2010/05/26 13:56:07 nicm Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
|
||||||
|
*
|
||||||
|
* 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 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/param.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <sys/uio.h>
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
int ibuf_realloc(struct ibuf *, size_t);
|
||||||
|
void ibuf_enqueue(struct msgbuf *, struct ibuf *);
|
||||||
|
void ibuf_dequeue(struct msgbuf *, struct ibuf *);
|
||||||
|
|
||||||
|
struct ibuf *
|
||||||
|
ibuf_open(size_t len)
|
||||||
|
{
|
||||||
|
struct ibuf *buf;
|
||||||
|
|
||||||
|
if ((buf = calloc(1, sizeof(struct ibuf))) == NULL)
|
||||||
|
return (NULL);
|
||||||
|
if ((buf->buf = malloc(len)) == NULL) {
|
||||||
|
free(buf);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
buf->size = buf->max = len;
|
||||||
|
buf->fd = -1;
|
||||||
|
|
||||||
|
return (buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ibuf *
|
||||||
|
ibuf_dynamic(size_t len, size_t max)
|
||||||
|
{
|
||||||
|
struct ibuf *buf;
|
||||||
|
|
||||||
|
if (max < len)
|
||||||
|
return (NULL);
|
||||||
|
|
||||||
|
if ((buf = ibuf_open(len)) == NULL)
|
||||||
|
return (NULL);
|
||||||
|
|
||||||
|
if (max > 0)
|
||||||
|
buf->max = max;
|
||||||
|
|
||||||
|
return (buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ibuf_realloc(struct ibuf *buf, size_t len)
|
||||||
|
{
|
||||||
|
u_char *b;
|
||||||
|
|
||||||
|
/* on static buffers max is eq size and so the following fails */
|
||||||
|
if (buf->wpos + len > buf->max) {
|
||||||
|
errno = ENOMEM;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
b = realloc(buf->buf, buf->wpos + len);
|
||||||
|
if (b == NULL)
|
||||||
|
return (-1);
|
||||||
|
buf->buf = b;
|
||||||
|
buf->size = buf->wpos + len;
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ibuf_add(struct ibuf *buf, const void *data, size_t len)
|
||||||
|
{
|
||||||
|
if (buf->wpos + len > buf->size)
|
||||||
|
if (ibuf_realloc(buf, len) == -1)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
memcpy(buf->buf + buf->wpos, data, len);
|
||||||
|
buf->wpos += len;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void *
|
||||||
|
ibuf_reserve(struct ibuf *buf, size_t len)
|
||||||
|
{
|
||||||
|
void *b;
|
||||||
|
|
||||||
|
if (buf->wpos + len > buf->size)
|
||||||
|
if (ibuf_realloc(buf, len) == -1)
|
||||||
|
return (NULL);
|
||||||
|
|
||||||
|
b = buf->buf + buf->wpos;
|
||||||
|
buf->wpos += len;
|
||||||
|
return (b);
|
||||||
|
}
|
||||||
|
|
||||||
|
void *
|
||||||
|
ibuf_seek(struct ibuf *buf, size_t pos, size_t len)
|
||||||
|
{
|
||||||
|
/* only allowed to seek in already written parts */
|
||||||
|
if (pos + len > buf->wpos)
|
||||||
|
return (NULL);
|
||||||
|
|
||||||
|
return (buf->buf + pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
ibuf_size(struct ibuf *buf)
|
||||||
|
{
|
||||||
|
return (buf->wpos);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
ibuf_left(struct ibuf *buf)
|
||||||
|
{
|
||||||
|
return (buf->max - buf->wpos);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ibuf_close(struct msgbuf *msgbuf, struct ibuf *buf)
|
||||||
|
{
|
||||||
|
ibuf_enqueue(msgbuf, buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ibuf_write(struct msgbuf *msgbuf)
|
||||||
|
{
|
||||||
|
struct iovec iov[IOV_MAX];
|
||||||
|
struct ibuf *buf;
|
||||||
|
unsigned int i = 0;
|
||||||
|
ssize_t n;
|
||||||
|
|
||||||
|
bzero(&iov, sizeof(iov));
|
||||||
|
TAILQ_FOREACH(buf, &msgbuf->bufs, entry) {
|
||||||
|
if (i >= IOV_MAX)
|
||||||
|
break;
|
||||||
|
iov[i].iov_base = buf->buf + buf->rpos;
|
||||||
|
iov[i].iov_len = buf->wpos - buf->rpos;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((n = writev(msgbuf->fd, iov, i)) == -1) {
|
||||||
|
if (errno == EAGAIN || errno == ENOBUFS ||
|
||||||
|
errno == EINTR) /* try later */
|
||||||
|
return (0);
|
||||||
|
else
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (n == 0) { /* connection closed */
|
||||||
|
errno = 0;
|
||||||
|
return (-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
msgbuf_drain(msgbuf, n);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ibuf_free(struct ibuf *buf)
|
||||||
|
{
|
||||||
|
free(buf->buf);
|
||||||
|
free(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
msgbuf_init(struct msgbuf *msgbuf)
|
||||||
|
{
|
||||||
|
msgbuf->queued = 0;
|
||||||
|
msgbuf->fd = -1;
|
||||||
|
TAILQ_INIT(&msgbuf->bufs);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
msgbuf_drain(struct msgbuf *msgbuf, size_t n)
|
||||||
|
{
|
||||||
|
struct ibuf *buf, *next;
|
||||||
|
|
||||||
|
for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0;
|
||||||
|
buf = next) {
|
||||||
|
next = TAILQ_NEXT(buf, entry);
|
||||||
|
if (buf->rpos + n >= buf->wpos) {
|
||||||
|
n -= buf->wpos - buf->rpos;
|
||||||
|
ibuf_dequeue(msgbuf, buf);
|
||||||
|
} else {
|
||||||
|
buf->rpos += n;
|
||||||
|
n = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
msgbuf_clear(struct msgbuf *msgbuf)
|
||||||
|
{
|
||||||
|
struct ibuf *buf;
|
||||||
|
|
||||||
|
while ((buf = TAILQ_FIRST(&msgbuf->bufs)) != NULL)
|
||||||
|
ibuf_dequeue(msgbuf, buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
msgbuf_write(struct msgbuf *msgbuf)
|
||||||
|
{
|
||||||
|
struct iovec iov[IOV_MAX];
|
||||||
|
struct ibuf *buf;
|
||||||
|
unsigned int i = 0;
|
||||||
|
ssize_t n;
|
||||||
|
struct msghdr msg;
|
||||||
|
struct cmsghdr *cmsg;
|
||||||
|
union {
|
||||||
|
struct cmsghdr hdr;
|
||||||
|
char buf[CMSG_SPACE(sizeof(int))];
|
||||||
|
} cmsgbuf;
|
||||||
|
|
||||||
|
bzero(&iov, sizeof(iov));
|
||||||
|
bzero(&msg, sizeof(msg));
|
||||||
|
TAILQ_FOREACH(buf, &msgbuf->bufs, entry) {
|
||||||
|
if (i >= IOV_MAX)
|
||||||
|
break;
|
||||||
|
iov[i].iov_base = buf->buf + buf->rpos;
|
||||||
|
iov[i].iov_len = buf->wpos - buf->rpos;
|
||||||
|
i++;
|
||||||
|
if (buf->fd != -1)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
msg.msg_iov = iov;
|
||||||
|
msg.msg_iovlen = i;
|
||||||
|
|
||||||
|
if (buf != NULL && buf->fd != -1) {
|
||||||
|
msg.msg_control = (caddr_t)&cmsgbuf.buf;
|
||||||
|
msg.msg_controllen = CMSG_SPACE(sizeof(int));
|
||||||
|
cmsg = CMSG_FIRSTHDR(&msg);
|
||||||
|
cmsg->cmsg_len = CMSG_LEN(sizeof(int));
|
||||||
|
cmsg->cmsg_level = SOL_SOCKET;
|
||||||
|
cmsg->cmsg_type = SCM_RIGHTS;
|
||||||
|
*(int *)CMSG_DATA(cmsg) = buf->fd;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((n = sendmsg(msgbuf->fd, &msg, 0)) == -1) {
|
||||||
|
if (errno == EAGAIN || errno == ENOBUFS ||
|
||||||
|
errno == EINTR) /* try later */
|
||||||
|
return (0);
|
||||||
|
else
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (n == 0) { /* connection closed */
|
||||||
|
errno = 0;
|
||||||
|
return (-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* assumption: fd got sent if sendmsg sent anything
|
||||||
|
* this works because fds are passed one at a time
|
||||||
|
*/
|
||||||
|
if (buf != NULL && buf->fd != -1) {
|
||||||
|
close(buf->fd);
|
||||||
|
buf->fd = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
msgbuf_drain(msgbuf, n);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ibuf_enqueue(struct msgbuf *msgbuf, struct ibuf *buf)
|
||||||
|
{
|
||||||
|
TAILQ_INSERT_TAIL(&msgbuf->bufs, buf, entry);
|
||||||
|
msgbuf->queued++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ibuf_dequeue(struct msgbuf *msgbuf, struct ibuf *buf)
|
||||||
|
{
|
||||||
|
TAILQ_REMOVE(&msgbuf->bufs, buf, entry);
|
||||||
|
|
||||||
|
if (buf->fd != -1)
|
||||||
|
close(buf->fd);
|
||||||
|
|
||||||
|
msgbuf->queued--;
|
||||||
|
ibuf_free(buf);
|
||||||
|
}
|
271
external/bsd/tmux/dist/compat/imsg.c
vendored
Normal file
271
external/bsd/tmux/dist/compat/imsg.c
vendored
Normal file
|
@ -0,0 +1,271 @@
|
||||||
|
/* $Id: imsg.c,v 1.5 2012/01/20 14:08:04 joerg Exp $ */
|
||||||
|
/* $OpenBSD: imsg.c,v 1.3 2010/05/26 13:56:07 nicm Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
|
||||||
|
*
|
||||||
|
* 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 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/param.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <sys/uio.h>
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
int imsg_get_fd(struct imsgbuf *);
|
||||||
|
|
||||||
|
void
|
||||||
|
imsg_init(struct imsgbuf *ibuf, int fd)
|
||||||
|
{
|
||||||
|
msgbuf_init(&ibuf->w);
|
||||||
|
bzero(&ibuf->r, sizeof(ibuf->r));
|
||||||
|
ibuf->fd = fd;
|
||||||
|
ibuf->w.fd = fd;
|
||||||
|
ibuf->pid = getpid();
|
||||||
|
TAILQ_INIT(&ibuf->fds);
|
||||||
|
}
|
||||||
|
|
||||||
|
ssize_t
|
||||||
|
imsg_read(struct imsgbuf *ibuf)
|
||||||
|
{
|
||||||
|
struct msghdr msg;
|
||||||
|
struct cmsghdr *cmsg;
|
||||||
|
union {
|
||||||
|
struct cmsghdr hdr;
|
||||||
|
char buf[CMSG_SPACE(sizeof(int) * 16)];
|
||||||
|
} cmsgbuf;
|
||||||
|
struct iovec iov;
|
||||||
|
ssize_t n;
|
||||||
|
int fd;
|
||||||
|
struct imsg_fd *ifd;
|
||||||
|
|
||||||
|
bzero(&msg, sizeof(msg));
|
||||||
|
|
||||||
|
iov.iov_base = ibuf->r.buf + ibuf->r.wpos;
|
||||||
|
iov.iov_len = sizeof(ibuf->r.buf) - ibuf->r.wpos;
|
||||||
|
msg.msg_iov = &iov;
|
||||||
|
msg.msg_iovlen = 1;
|
||||||
|
msg.msg_control = &cmsgbuf.buf;
|
||||||
|
msg.msg_controllen = CMSG_SPACE(sizeof(int) * 16);
|
||||||
|
|
||||||
|
if ((n = recvmsg(ibuf->fd, &msg, 0)) == -1) {
|
||||||
|
if (errno != EINTR && errno != EAGAIN) {
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
return (-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
ibuf->r.wpos += n;
|
||||||
|
|
||||||
|
for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL;
|
||||||
|
cmsg = CMSG_NXTHDR(&msg, cmsg)) {
|
||||||
|
if (cmsg->cmsg_level == SOL_SOCKET &&
|
||||||
|
cmsg->cmsg_type == SCM_RIGHTS) {
|
||||||
|
fd = (*(int *)CMSG_DATA(cmsg));
|
||||||
|
if ((ifd = calloc(1, sizeof(struct imsg_fd))) == NULL) {
|
||||||
|
close(fd);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
ifd->fd = fd;
|
||||||
|
TAILQ_INSERT_TAIL(&ibuf->fds, ifd, entry);
|
||||||
|
}
|
||||||
|
/* we do not handle other ctl data level */
|
||||||
|
}
|
||||||
|
|
||||||
|
return (n);
|
||||||
|
}
|
||||||
|
|
||||||
|
ssize_t
|
||||||
|
imsg_get(struct imsgbuf *ibuf, struct imsg *imsg)
|
||||||
|
{
|
||||||
|
size_t av, left, datalen;
|
||||||
|
|
||||||
|
av = ibuf->r.wpos;
|
||||||
|
|
||||||
|
if (IMSG_HEADER_SIZE > av)
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
memcpy(&imsg->hdr, ibuf->r.buf, sizeof(imsg->hdr));
|
||||||
|
if (imsg->hdr.len < IMSG_HEADER_SIZE ||
|
||||||
|
imsg->hdr.len > MAX_IMSGSIZE) {
|
||||||
|
errno = ERANGE;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
if (imsg->hdr.len > av)
|
||||||
|
return (0);
|
||||||
|
datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
|
||||||
|
ibuf->r.rptr = ibuf->r.buf + IMSG_HEADER_SIZE;
|
||||||
|
if ((imsg->data = malloc(datalen)) == NULL && datalen != 0)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
if (imsg->hdr.flags & IMSGF_HASFD)
|
||||||
|
imsg->fd = imsg_get_fd(ibuf);
|
||||||
|
else
|
||||||
|
imsg->fd = -1;
|
||||||
|
|
||||||
|
memcpy(imsg->data, ibuf->r.rptr, datalen);
|
||||||
|
|
||||||
|
if (imsg->hdr.len < av) {
|
||||||
|
left = av - imsg->hdr.len;
|
||||||
|
memmove(&ibuf->r.buf, ibuf->r.buf + imsg->hdr.len, left);
|
||||||
|
ibuf->r.wpos = left;
|
||||||
|
} else
|
||||||
|
ibuf->r.wpos = 0;
|
||||||
|
|
||||||
|
return (datalen + IMSG_HEADER_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
imsg_compose(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid,
|
||||||
|
pid_t pid, int fd, void *data, u_int16_t datalen)
|
||||||
|
{
|
||||||
|
struct ibuf *wbuf;
|
||||||
|
|
||||||
|
if ((wbuf = imsg_create(ibuf, type, peerid, pid, datalen)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
if (imsg_add(wbuf, data, datalen) == -1)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
wbuf->fd = fd;
|
||||||
|
|
||||||
|
imsg_close(ibuf, wbuf);
|
||||||
|
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
imsg_composev(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid,
|
||||||
|
pid_t pid, int fd, const struct iovec *iov, int iovcnt)
|
||||||
|
{
|
||||||
|
struct ibuf *wbuf;
|
||||||
|
int i, datalen = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < iovcnt; i++)
|
||||||
|
datalen += iov[i].iov_len;
|
||||||
|
|
||||||
|
if ((wbuf = imsg_create(ibuf, type, peerid, pid, datalen)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
for (i = 0; i < iovcnt; i++)
|
||||||
|
if (imsg_add(wbuf, iov[i].iov_base, iov[i].iov_len) == -1)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
wbuf->fd = fd;
|
||||||
|
|
||||||
|
imsg_close(ibuf, wbuf);
|
||||||
|
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ARGSUSED */
|
||||||
|
struct ibuf *
|
||||||
|
imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid,
|
||||||
|
pid_t pid, u_int16_t datalen)
|
||||||
|
{
|
||||||
|
struct ibuf *wbuf;
|
||||||
|
struct imsg_hdr hdr;
|
||||||
|
|
||||||
|
datalen += IMSG_HEADER_SIZE;
|
||||||
|
if (datalen > MAX_IMSGSIZE) {
|
||||||
|
errno = ERANGE;
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
hdr.type = type;
|
||||||
|
hdr.flags = 0;
|
||||||
|
hdr.peerid = peerid;
|
||||||
|
if ((hdr.pid = pid) == 0)
|
||||||
|
hdr.pid = ibuf->pid;
|
||||||
|
if ((wbuf = ibuf_dynamic(datalen, MAX_IMSGSIZE)) == NULL) {
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
if (imsg_add(wbuf, &hdr, sizeof(hdr)) == -1)
|
||||||
|
return (NULL);
|
||||||
|
|
||||||
|
return (wbuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
imsg_add(struct ibuf *msg, void *data, u_int16_t datalen)
|
||||||
|
{
|
||||||
|
if (datalen)
|
||||||
|
if (ibuf_add(msg, data, datalen) == -1) {
|
||||||
|
ibuf_free(msg);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
return (datalen);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
imsg_close(struct imsgbuf *ibuf, struct ibuf *msg)
|
||||||
|
{
|
||||||
|
struct imsg_hdr *hdr;
|
||||||
|
|
||||||
|
hdr = (struct imsg_hdr *)msg->buf;
|
||||||
|
|
||||||
|
hdr->flags &= ~IMSGF_HASFD;
|
||||||
|
if (msg->fd != -1)
|
||||||
|
hdr->flags |= IMSGF_HASFD;
|
||||||
|
|
||||||
|
hdr->len = (u_int16_t)msg->wpos;
|
||||||
|
|
||||||
|
ibuf_close(&ibuf->w, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
imsg_free(struct imsg *imsg)
|
||||||
|
{
|
||||||
|
free(imsg->data);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
imsg_get_fd(struct imsgbuf *ibuf)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
struct imsg_fd *ifd;
|
||||||
|
|
||||||
|
if ((ifd = TAILQ_FIRST(&ibuf->fds)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
fd = ifd->fd;
|
||||||
|
TAILQ_REMOVE(&ibuf->fds, ifd, entry);
|
||||||
|
free(ifd);
|
||||||
|
|
||||||
|
return (fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
imsg_flush(struct imsgbuf *ibuf)
|
||||||
|
{
|
||||||
|
while (ibuf->w.queued)
|
||||||
|
if (msgbuf_write(&ibuf->w) < 0)
|
||||||
|
return (-1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
imsg_clear(struct imsgbuf *ibuf)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
msgbuf_clear(&ibuf->w);
|
||||||
|
while ((fd = imsg_get_fd(ibuf)) != -1)
|
||||||
|
close(fd);
|
||||||
|
}
|
110
external/bsd/tmux/dist/compat/imsg.h
vendored
Normal file
110
external/bsd/tmux/dist/compat/imsg.h
vendored
Normal file
|
@ -0,0 +1,110 @@
|
||||||
|
/* $Id: imsg.h,v 1.1.1.2 2011/08/17 18:40:06 jmmv Exp $ */
|
||||||
|
/* $OpenBSD: imsg.h,v 1.4 2010/05/26 13:56:07 nicm Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org>
|
||||||
|
* Copyright (c) 2006, 2007, 2008 Reyk Floeter <reyk@openbsd.org>
|
||||||
|
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
|
||||||
|
*
|
||||||
|
* 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 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 "tmux.h"
|
||||||
|
|
||||||
|
#define IBUF_READ_SIZE 65535
|
||||||
|
#define IMSG_HEADER_SIZE sizeof(struct imsg_hdr)
|
||||||
|
#define MAX_IMSGSIZE 16384
|
||||||
|
|
||||||
|
struct ibuf {
|
||||||
|
TAILQ_ENTRY(ibuf) entry;
|
||||||
|
u_char *buf;
|
||||||
|
size_t size;
|
||||||
|
size_t max;
|
||||||
|
size_t wpos;
|
||||||
|
size_t rpos;
|
||||||
|
int fd;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct msgbuf {
|
||||||
|
TAILQ_HEAD(, ibuf) bufs;
|
||||||
|
u_int32_t queued;
|
||||||
|
int fd;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ibuf_read {
|
||||||
|
u_char buf[IBUF_READ_SIZE];
|
||||||
|
u_char *rptr;
|
||||||
|
size_t wpos;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct imsg_fd {
|
||||||
|
TAILQ_ENTRY(imsg_fd) entry;
|
||||||
|
int fd;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct imsgbuf {
|
||||||
|
TAILQ_HEAD(, imsg_fd) fds;
|
||||||
|
struct ibuf_read r;
|
||||||
|
struct msgbuf w;
|
||||||
|
int fd;
|
||||||
|
pid_t pid;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define IMSGF_HASFD 1
|
||||||
|
|
||||||
|
struct imsg_hdr {
|
||||||
|
u_int32_t type;
|
||||||
|
u_int16_t len;
|
||||||
|
u_int16_t flags;
|
||||||
|
u_int32_t peerid;
|
||||||
|
u_int32_t pid;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct imsg {
|
||||||
|
struct imsg_hdr hdr;
|
||||||
|
int fd;
|
||||||
|
void *data;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* buffer.c */
|
||||||
|
struct ibuf *ibuf_open(size_t);
|
||||||
|
struct ibuf *ibuf_dynamic(size_t, size_t);
|
||||||
|
int ibuf_add(struct ibuf *, const void *, size_t);
|
||||||
|
void *ibuf_reserve(struct ibuf *, size_t);
|
||||||
|
void *ibuf_seek(struct ibuf *, size_t, size_t);
|
||||||
|
size_t ibuf_size(struct ibuf *);
|
||||||
|
size_t ibuf_left(struct ibuf *);
|
||||||
|
void ibuf_close(struct msgbuf *, struct ibuf *);
|
||||||
|
int ibuf_write(struct msgbuf *);
|
||||||
|
void ibuf_free(struct ibuf *);
|
||||||
|
void msgbuf_init(struct msgbuf *);
|
||||||
|
void msgbuf_clear(struct msgbuf *);
|
||||||
|
int msgbuf_write(struct msgbuf *);
|
||||||
|
void msgbuf_drain(struct msgbuf *, size_t);
|
||||||
|
|
||||||
|
/* imsg.c */
|
||||||
|
void imsg_init(struct imsgbuf *, int);
|
||||||
|
ssize_t imsg_read(struct imsgbuf *);
|
||||||
|
ssize_t imsg_get(struct imsgbuf *, struct imsg *);
|
||||||
|
int imsg_compose(struct imsgbuf *, u_int32_t, u_int32_t, pid_t,
|
||||||
|
int, void *, u_int16_t);
|
||||||
|
int imsg_composev(struct imsgbuf *, u_int32_t, u_int32_t, pid_t,
|
||||||
|
int, const struct iovec *, int);
|
||||||
|
struct ibuf *imsg_create(struct imsgbuf *, u_int32_t, u_int32_t, pid_t,
|
||||||
|
u_int16_t);
|
||||||
|
int imsg_add(struct ibuf *, void *, u_int16_t);
|
||||||
|
void imsg_close(struct imsgbuf *, struct ibuf *);
|
||||||
|
void imsg_free(struct imsg *);
|
||||||
|
int imsg_flush(struct imsgbuf *);
|
||||||
|
void imsg_clear(struct imsgbuf *);
|
68
external/bsd/tmux/dist/compat/strtonum.c
vendored
Normal file
68
external/bsd/tmux/dist/compat/strtonum.c
vendored
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
/* $Id: strtonum.c,v 1.1.1.2 2011/08/17 18:40:06 jmmv Exp $ */
|
||||||
|
/* $OpenBSD: strtonum.c,v 1.6 2004/08/03 19:38:01 millert Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2004 Ted Unangst and Todd Miller
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* 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 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 <errno.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
#define INVALID 1
|
||||||
|
#define TOOSMALL 2
|
||||||
|
#define TOOLARGE 3
|
||||||
|
|
||||||
|
long long
|
||||||
|
strtonum(const char *numstr, long long minval, long long maxval,
|
||||||
|
const char **errstrp)
|
||||||
|
{
|
||||||
|
long long ll = 0;
|
||||||
|
char *ep;
|
||||||
|
int error = 0;
|
||||||
|
struct errval {
|
||||||
|
const char *errstr;
|
||||||
|
int err;
|
||||||
|
} ev[4] = {
|
||||||
|
{ NULL, 0 },
|
||||||
|
{ "invalid", EINVAL },
|
||||||
|
{ "too small", ERANGE },
|
||||||
|
{ "too large", ERANGE },
|
||||||
|
};
|
||||||
|
|
||||||
|
ev[0].err = errno;
|
||||||
|
errno = 0;
|
||||||
|
if (minval > maxval)
|
||||||
|
error = INVALID;
|
||||||
|
else {
|
||||||
|
ll = strtoll(numstr, &ep, 10);
|
||||||
|
if (numstr == ep || *ep != '\0')
|
||||||
|
error = INVALID;
|
||||||
|
else if ((ll == LLONG_MIN && errno == ERANGE) || ll < minval)
|
||||||
|
error = TOOSMALL;
|
||||||
|
else if ((ll == LLONG_MAX && errno == ERANGE) || ll > maxval)
|
||||||
|
error = TOOLARGE;
|
||||||
|
}
|
||||||
|
if (errstrp != NULL)
|
||||||
|
*errstrp = ev[error].errstr;
|
||||||
|
errno = ev[error].err;
|
||||||
|
if (error)
|
||||||
|
ll = 0;
|
||||||
|
|
||||||
|
return (ll);
|
||||||
|
}
|
181
external/bsd/tmux/dist/environ.c
vendored
Normal file
181
external/bsd/tmux/dist/environ.c
vendored
Normal file
|
@ -0,0 +1,181 @@
|
||||||
|
/* $Id: environ.c,v 1.3 2011/08/17 18:48:36 jmmv Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Environment - manipulate a set of environment variables.
|
||||||
|
*/
|
||||||
|
|
||||||
|
RB_GENERATE(environ, environ_entry, entry, environ_cmp);
|
||||||
|
|
||||||
|
int
|
||||||
|
environ_cmp(struct environ_entry *envent1, struct environ_entry *envent2)
|
||||||
|
{
|
||||||
|
return (strcmp(envent1->name, envent2->name));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Initialise the environment. */
|
||||||
|
void
|
||||||
|
environ_init(struct environ *env)
|
||||||
|
{
|
||||||
|
RB_INIT(env);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Free an environment. */
|
||||||
|
void
|
||||||
|
environ_free(struct environ *env)
|
||||||
|
{
|
||||||
|
struct environ_entry *envent;
|
||||||
|
|
||||||
|
while (!RB_EMPTY(env)) {
|
||||||
|
envent = RB_ROOT(env);
|
||||||
|
RB_REMOVE(environ, env, envent);
|
||||||
|
xfree(envent->name);
|
||||||
|
if (envent->value != NULL)
|
||||||
|
xfree(envent->value);
|
||||||
|
xfree(envent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Copy one environment into another. */
|
||||||
|
void
|
||||||
|
environ_copy(struct environ *srcenv, struct environ *dstenv)
|
||||||
|
{
|
||||||
|
struct environ_entry *envent;
|
||||||
|
|
||||||
|
RB_FOREACH(envent, environ, srcenv)
|
||||||
|
environ_set(dstenv, envent->name, envent->value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Find an environment variable. */
|
||||||
|
struct environ_entry *
|
||||||
|
environ_find(struct environ *env, const char *name)
|
||||||
|
{
|
||||||
|
struct environ_entry envent;
|
||||||
|
|
||||||
|
envent.name = __UNCONST(name);
|
||||||
|
return (RB_FIND(environ, env, &envent));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set an environment variable. */
|
||||||
|
void
|
||||||
|
environ_set(struct environ *env, const char *name, const char *value)
|
||||||
|
{
|
||||||
|
struct environ_entry *envent;
|
||||||
|
|
||||||
|
if ((envent = environ_find(env, name)) != NULL) {
|
||||||
|
if (envent->value != NULL)
|
||||||
|
xfree(envent->value);
|
||||||
|
if (value != NULL)
|
||||||
|
envent->value = xstrdup(value);
|
||||||
|
else
|
||||||
|
envent->value = NULL;
|
||||||
|
} else {
|
||||||
|
envent = xmalloc(sizeof *envent);
|
||||||
|
envent->name = xstrdup(name);
|
||||||
|
if (value != NULL)
|
||||||
|
envent->value = xstrdup(value);
|
||||||
|
else
|
||||||
|
envent->value = NULL;
|
||||||
|
RB_INSERT(environ, env, envent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set an environment variable from a NAME=VALUE string. */
|
||||||
|
void
|
||||||
|
environ_put(struct environ *env, const char *var)
|
||||||
|
{
|
||||||
|
char *name, *value;
|
||||||
|
|
||||||
|
value = strchr(var, '=');
|
||||||
|
if (value == NULL)
|
||||||
|
return;
|
||||||
|
value++;
|
||||||
|
|
||||||
|
name = xstrdup(var);
|
||||||
|
name[strcspn(name, "=")] = '\0';
|
||||||
|
|
||||||
|
environ_set(env, name, value);
|
||||||
|
xfree(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Unset an environment variable. */
|
||||||
|
void
|
||||||
|
environ_unset(struct environ *env, const char *name)
|
||||||
|
{
|
||||||
|
struct environ_entry *envent;
|
||||||
|
|
||||||
|
if ((envent = environ_find(env, name)) == NULL)
|
||||||
|
return;
|
||||||
|
RB_REMOVE(environ, env, envent);
|
||||||
|
xfree(envent->name);
|
||||||
|
if (envent->value != NULL)
|
||||||
|
xfree(envent->value);
|
||||||
|
xfree(envent);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copy a space-separated list of variables from a destination into a source
|
||||||
|
* environment.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
environ_update(const char *vars, struct environ *srcenv, struct environ *dstenv)
|
||||||
|
{
|
||||||
|
struct environ_entry *envent;
|
||||||
|
char *copyvars, *var, *next;
|
||||||
|
|
||||||
|
copyvars = next = xstrdup(vars);
|
||||||
|
while ((var = strsep(&next, " ")) != NULL) {
|
||||||
|
if ((envent = environ_find(srcenv, var)) == NULL)
|
||||||
|
environ_set(dstenv, var, NULL);
|
||||||
|
else
|
||||||
|
environ_set(dstenv, envent->name, envent->value);
|
||||||
|
}
|
||||||
|
xfree(copyvars);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Push environment into the real environment - use after fork(). */
|
||||||
|
void
|
||||||
|
environ_push(struct environ *env)
|
||||||
|
{
|
||||||
|
ARRAY_DECL(, char *) varlist;
|
||||||
|
struct environ_entry *envent;
|
||||||
|
char **varp, *var;
|
||||||
|
u_int i;
|
||||||
|
|
||||||
|
ARRAY_INIT(&varlist);
|
||||||
|
for (varp = environ; *varp != NULL; varp++) {
|
||||||
|
var = xstrdup(*varp);
|
||||||
|
var[strcspn(var, "=")] = '\0';
|
||||||
|
ARRAY_ADD(&varlist, var);
|
||||||
|
}
|
||||||
|
for (i = 0; i < ARRAY_LENGTH(&varlist); i++)
|
||||||
|
unsetenv(ARRAY_ITEM(&varlist, i));
|
||||||
|
ARRAY_FREE(&varlist);
|
||||||
|
|
||||||
|
RB_FOREACH(envent, environ, env) {
|
||||||
|
if (envent->value != NULL)
|
||||||
|
setenv(envent->name, envent->value, 1);
|
||||||
|
}
|
||||||
|
}
|
105
external/bsd/tmux/dist/examples/bash_completion_tmux.sh
vendored
Normal file
105
external/bsd/tmux/dist/examples/bash_completion_tmux.sh
vendored
Normal file
|
@ -0,0 +1,105 @@
|
||||||
|
# START tmux completion
|
||||||
|
# This file is in the public domain
|
||||||
|
# See: http://www.debian-administration.org/articles/317 for how to write more.
|
||||||
|
# Usage: Put "source bash_completion_tmux.sh" into your .bashrc
|
||||||
|
_tmux()
|
||||||
|
{
|
||||||
|
local cur prev opts
|
||||||
|
COMPREPLY=()
|
||||||
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||||
|
|
||||||
|
opts=" \
|
||||||
|
attach-session \
|
||||||
|
bind-key \
|
||||||
|
break-pane \
|
||||||
|
capture-pane \
|
||||||
|
choose-client \
|
||||||
|
choose-session \
|
||||||
|
choose-window \
|
||||||
|
clear-history \
|
||||||
|
clock-mode \
|
||||||
|
command-prompt \
|
||||||
|
confirm-before \
|
||||||
|
copy-buffer \
|
||||||
|
copy-mode \
|
||||||
|
delete-buffer \
|
||||||
|
detach-client \
|
||||||
|
display-message \
|
||||||
|
display-panes \
|
||||||
|
down-pane \
|
||||||
|
find-window \
|
||||||
|
has-session \
|
||||||
|
if-shell \
|
||||||
|
join-pane \
|
||||||
|
kill-pane \
|
||||||
|
kill-server \
|
||||||
|
kill-session \
|
||||||
|
kill-window \
|
||||||
|
last-window \
|
||||||
|
link-window \
|
||||||
|
list-buffers \
|
||||||
|
list-clients \
|
||||||
|
list-commands \
|
||||||
|
list-keys \
|
||||||
|
list-panes \
|
||||||
|
list-sessions \
|
||||||
|
list-windows \
|
||||||
|
load-buffer \
|
||||||
|
lock-client \
|
||||||
|
lock-server \
|
||||||
|
lock-session \
|
||||||
|
move-window \
|
||||||
|
new-session \
|
||||||
|
new-window \
|
||||||
|
next-layout \
|
||||||
|
next-window \
|
||||||
|
paste-buffer \
|
||||||
|
pipe-pane \
|
||||||
|
previous-layout \
|
||||||
|
previous-window \
|
||||||
|
refresh-client \
|
||||||
|
rename-session \
|
||||||
|
rename-window \
|
||||||
|
resize-pane \
|
||||||
|
respawn-window \
|
||||||
|
rotate-window \
|
||||||
|
run-shell \
|
||||||
|
save-buffer \
|
||||||
|
select-layout \
|
||||||
|
select-pane \
|
||||||
|
select-prompt \
|
||||||
|
select-window \
|
||||||
|
send-keys \
|
||||||
|
send-prefix \
|
||||||
|
server-info \
|
||||||
|
set-buffer \
|
||||||
|
set-environment \
|
||||||
|
set-option \
|
||||||
|
set-window-option \
|
||||||
|
show-buffer \
|
||||||
|
show-environment \
|
||||||
|
show-messages \
|
||||||
|
show-options \
|
||||||
|
show-window-options \
|
||||||
|
source-file \
|
||||||
|
split-window \
|
||||||
|
start-server \
|
||||||
|
suspend-client \
|
||||||
|
swap-pane \
|
||||||
|
swap-window \
|
||||||
|
switch-client \
|
||||||
|
unbind-key \
|
||||||
|
unlink-window \
|
||||||
|
up-pane"
|
||||||
|
|
||||||
|
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
|
||||||
|
return 0
|
||||||
|
|
||||||
|
}
|
||||||
|
complete -F _tmux tmux
|
||||||
|
|
||||||
|
# END tmux completion
|
||||||
|
|
||||||
|
|
||||||
|
|
42
external/bsd/tmux/dist/examples/h-boetes.conf
vendored
Normal file
42
external/bsd/tmux/dist/examples/h-boetes.conf
vendored
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
# $Id: h-boetes.conf,v 1.1.1.2 2011/08/17 18:40:06 jmmv Exp $
|
||||||
|
#
|
||||||
|
# From Han Boetes.
|
||||||
|
|
||||||
|
set -g default-command zsh
|
||||||
|
set -g status-right "#(uptime|awk '{print $11}') #(date)"
|
||||||
|
|
||||||
|
# Statusbar properties.
|
||||||
|
set -g display-time 3000
|
||||||
|
set -g status-bg black
|
||||||
|
set -g status-fg cyan
|
||||||
|
set-window-option -g window-status-current-attr bright,reverse
|
||||||
|
set-window-option -g window-status-current-bg cyan
|
||||||
|
set-window-option -g window-status-current-fg black
|
||||||
|
|
||||||
|
# Use c-t instead of c-b as the prefix
|
||||||
|
unbind C-b
|
||||||
|
set -g prefix C-t
|
||||||
|
bind C-t send-prefix
|
||||||
|
bind t send-prefix
|
||||||
|
|
||||||
|
# Bind function keys.
|
||||||
|
bind -n F1 select-window -t 1
|
||||||
|
bind -n F2 select-window -t 2
|
||||||
|
bind -n F3 select-window -t 3
|
||||||
|
bind -n F4 select-window -t 4
|
||||||
|
bind -n F5 select-window -t 5
|
||||||
|
bind -n F6 select-window -t 6
|
||||||
|
bind -n F7 select-window -t 7
|
||||||
|
bind -n F8 select-window -t 8
|
||||||
|
|
||||||
|
# All new windows started at startup.
|
||||||
|
new emacs
|
||||||
|
neww irssi
|
||||||
|
neww mutt
|
||||||
|
neww
|
||||||
|
neww
|
||||||
|
neww
|
||||||
|
neww
|
||||||
|
neww
|
||||||
|
|
||||||
|
select-window -t 1
|
110
external/bsd/tmux/dist/examples/n-marriott.conf
vendored
Normal file
110
external/bsd/tmux/dist/examples/n-marriott.conf
vendored
Normal file
|
@ -0,0 +1,110 @@
|
||||||
|
# $Id: n-marriott.conf,v 1.1.1.2 2011/08/17 18:40:06 jmmv Exp $
|
||||||
|
#
|
||||||
|
# By Nicholas Marriott. Public domain.
|
||||||
|
|
||||||
|
# Default global options.
|
||||||
|
set -g status-bg green
|
||||||
|
set -g status-right "%H:%M" # %d-%b-%y
|
||||||
|
set -g bell-action none
|
||||||
|
set -g lock-after-time 1800
|
||||||
|
|
||||||
|
# Default global window options.
|
||||||
|
setw -g remain-on-exit on
|
||||||
|
setw -g window-status-current-attr "underscore"
|
||||||
|
#setw -g xterm-keys on
|
||||||
|
|
||||||
|
# Prefix key.
|
||||||
|
set -g prefix C-a
|
||||||
|
unbind C-b
|
||||||
|
bind C-a send-prefix
|
||||||
|
|
||||||
|
# Keys to switch session.
|
||||||
|
bind Q switchc -t0
|
||||||
|
bind W switchc -t1
|
||||||
|
bind E switchc -t2
|
||||||
|
|
||||||
|
# Other key bindings.
|
||||||
|
bind F1 selectw -t:10
|
||||||
|
bind F2 selectw -t:11
|
||||||
|
bind F3 selectw -t:12
|
||||||
|
bind F4 selectw -t:13
|
||||||
|
bind F5 selectw -t:14
|
||||||
|
bind F6 selectw -t:15
|
||||||
|
bind F7 selectw -t:16
|
||||||
|
bind F8 selectw -t:17
|
||||||
|
bind F9 selectw -t:18
|
||||||
|
bind F10 selectw -t:19
|
||||||
|
bind F11 selectw -t:20
|
||||||
|
bind F12 selectw -t:21
|
||||||
|
|
||||||
|
bind m setw monitor-activity
|
||||||
|
|
||||||
|
bind y setw force-width 81
|
||||||
|
bind u setw force-width 0
|
||||||
|
|
||||||
|
bind -n F1 run-shell 'mpc toggle >/dev/null 2>&1'
|
||||||
|
bind -n F2 run-shell 'mpc'
|
||||||
|
bind -n F3 run-shell 'mpc prev >/dev/null 2>&1'
|
||||||
|
bind -n F4 run-shell 'mpc next >/dev/null 2>&1'
|
||||||
|
bind -n F5 run-shell 'mpc volume -5 >/dev/null 2>&1'
|
||||||
|
bind -n F6 run-shell 'mpc volume +5 >/dev/null 2>&1'
|
||||||
|
|
||||||
|
# Hide and show window name from status line
|
||||||
|
bind '-' setw window-status-format '#I'\; setw window-status-current-format '#I'
|
||||||
|
bind '+' setw window-status-format '#I:#W#F'\; setw window-status-current-format '#I:#W#F'
|
||||||
|
|
||||||
|
# First session.
|
||||||
|
new -d -s0 -nirssi 'exec ssh -t natalya exec sh ~/bin/tmux-start'
|
||||||
|
setw -t0:0 monitor-activity on
|
||||||
|
setw -t0:0 aggressive-resize on
|
||||||
|
set -t0 status-bg green
|
||||||
|
neww -d -ntodo 'exec emacs ~/TODO'
|
||||||
|
setw -t0:1 aggressive-resize on
|
||||||
|
neww -d -ntodo2 'exec emacs ~/TODO2'
|
||||||
|
setw -t0:2 aggressive-resize on
|
||||||
|
neww -d -nncmpc 'exec ncmpc -f ~/.ncmpc.conf'
|
||||||
|
setw -t0:3 aggressive-resize on
|
||||||
|
neww -d -nmutt 'exec mutt'
|
||||||
|
setw -t0:4 aggressive-resize on
|
||||||
|
neww -d
|
||||||
|
neww -d
|
||||||
|
neww -d
|
||||||
|
neww -d
|
||||||
|
neww -d
|
||||||
|
neww -d
|
||||||
|
neww -d
|
||||||
|
neww -d
|
||||||
|
neww -d
|
||||||
|
neww -d
|
||||||
|
neww -d
|
||||||
|
neww -d
|
||||||
|
|
||||||
|
# Second session.
|
||||||
|
new -d -s1
|
||||||
|
set -t1 status-bg cyan
|
||||||
|
linkw -dk -t0 -s0:0
|
||||||
|
linkw -dk -t1 -s0:1
|
||||||
|
linkw -dk -t2 -s0:2
|
||||||
|
linkw -dk -t3 -s0:3
|
||||||
|
linkw -dk -t4 -s0:4
|
||||||
|
neww -d
|
||||||
|
neww -d
|
||||||
|
neww -d
|
||||||
|
neww -d
|
||||||
|
neww -d
|
||||||
|
neww -d
|
||||||
|
|
||||||
|
# Third session.
|
||||||
|
new -d -s2
|
||||||
|
set -t2 status-bg yellow
|
||||||
|
linkw -dk -t0 -s0:0
|
||||||
|
linkw -dk -t1 -s0:1
|
||||||
|
linkw -dk -t2 -s0:2
|
||||||
|
linkw -dk -t3 -s0:3
|
||||||
|
linkw -dk -t4 -s0:4
|
||||||
|
neww -d
|
||||||
|
neww -d
|
||||||
|
neww -d
|
||||||
|
neww -d
|
||||||
|
neww -d
|
||||||
|
neww -d
|
102
external/bsd/tmux/dist/examples/screen-keys.conf
vendored
Normal file
102
external/bsd/tmux/dist/examples/screen-keys.conf
vendored
Normal file
|
@ -0,0 +1,102 @@
|
||||||
|
# $Id: screen-keys.conf,v 1.1.1.2 2011/08/17 18:40:06 jmmv Exp $
|
||||||
|
#
|
||||||
|
# By Nicholas Marriott. Public domain.
|
||||||
|
#
|
||||||
|
# This configuration file binds many of the common GNU screen key bindings to
|
||||||
|
# appropriate tmux key bindings. Note that for some key bindings there is no
|
||||||
|
# tmux analogue and also that this set omits binding some commands available in
|
||||||
|
# tmux but not in screen.
|
||||||
|
#
|
||||||
|
# Note this is only a selection of key bindings and they are in addition to the
|
||||||
|
# normal tmux key bindings. This is intended as an example not as to be used
|
||||||
|
# as-is.
|
||||||
|
|
||||||
|
# Set the prefix to ^A.
|
||||||
|
unbind C-b
|
||||||
|
set -g prefix ^A
|
||||||
|
bind a send-prefix
|
||||||
|
|
||||||
|
# Bind appropriate commands similar to screen.
|
||||||
|
# lockscreen ^X x
|
||||||
|
unbind ^X
|
||||||
|
bind ^X lock-server
|
||||||
|
unbind x
|
||||||
|
bind x lock-server
|
||||||
|
|
||||||
|
# screen ^C c
|
||||||
|
unbind ^C
|
||||||
|
bind ^C new-window
|
||||||
|
bind c
|
||||||
|
bind c new-window
|
||||||
|
|
||||||
|
# detach ^D d
|
||||||
|
unbind ^D
|
||||||
|
bind ^D detach
|
||||||
|
|
||||||
|
# displays *
|
||||||
|
unbind *
|
||||||
|
bind * list-clients
|
||||||
|
|
||||||
|
# next ^@ ^N sp n
|
||||||
|
unbind ^@
|
||||||
|
bind ^@ next-window
|
||||||
|
unbind ^N
|
||||||
|
bind ^N next-window
|
||||||
|
unbind " "
|
||||||
|
bind " " next-window
|
||||||
|
unbind n
|
||||||
|
bind n next-window
|
||||||
|
|
||||||
|
# title A
|
||||||
|
unbind A
|
||||||
|
bind A command-prompt "rename-window %%"
|
||||||
|
|
||||||
|
# other ^A
|
||||||
|
unbind ^A
|
||||||
|
bind ^A last-window
|
||||||
|
|
||||||
|
# prev ^H ^P p ^?
|
||||||
|
unbind ^H
|
||||||
|
bind ^H previous-window
|
||||||
|
unbind ^P
|
||||||
|
bind ^P previous-window
|
||||||
|
unbind p
|
||||||
|
bind p previous-window
|
||||||
|
unbind BSpace
|
||||||
|
bind BSpace previous-window
|
||||||
|
|
||||||
|
# windows ^W w
|
||||||
|
unbind ^W
|
||||||
|
bind ^W list-windows
|
||||||
|
unbind w
|
||||||
|
bind w list-windows
|
||||||
|
|
||||||
|
# quit \
|
||||||
|
unbind \
|
||||||
|
bind \ confirm-before "kill-server"
|
||||||
|
|
||||||
|
# kill K k
|
||||||
|
unbind K
|
||||||
|
bind K confirm-before "kill-window"
|
||||||
|
unbind k
|
||||||
|
bind k confirm-before "kill-window"
|
||||||
|
|
||||||
|
# redisplay ^L l
|
||||||
|
unbind ^L
|
||||||
|
bind ^L refresh-client
|
||||||
|
unbind l
|
||||||
|
bind l refresh-client
|
||||||
|
|
||||||
|
# split -v |
|
||||||
|
unbind |
|
||||||
|
bind | split-window
|
||||||
|
|
||||||
|
# :kB: focus up
|
||||||
|
unbind Tab
|
||||||
|
bind Tab select-pane -t:.+
|
||||||
|
unbind BTab
|
||||||
|
bind BTab select-pane -t:.-
|
||||||
|
|
||||||
|
# " windowlist -b
|
||||||
|
unbind '"'
|
||||||
|
bind '"' choose-window
|
104
external/bsd/tmux/dist/examples/t-williams.conf
vendored
Normal file
104
external/bsd/tmux/dist/examples/t-williams.conf
vendored
Normal file
|
@ -0,0 +1,104 @@
|
||||||
|
# $Id: t-williams.conf,v 1.1.1.2 2011/08/17 18:40:06 jmmv Exp $
|
||||||
|
#
|
||||||
|
# ~/.tmux.conf - tmux terminal multiplexer config
|
||||||
|
# Thayer Williams (http://cinderwick.ca)
|
||||||
|
# "Feel free to do whatever you like with it."
|
||||||
|
|
||||||
|
# I typically start tmux from ~/.xinitrc with the following:
|
||||||
|
#
|
||||||
|
# urxvt -e bash -c "tmux attach -d -t mysession" &
|
||||||
|
#
|
||||||
|
# and recall it any time thereafter with xbindkeys (Mod4+s):
|
||||||
|
#
|
||||||
|
# "urxvt -e bash -c 'tmux attach -d -t mysession'"
|
||||||
|
# m:0x50 + c:39
|
||||||
|
|
||||||
|
|
||||||
|
# set prefix key to ctrl+a until I have time to adapt
|
||||||
|
unbind C-b
|
||||||
|
set -g prefix C-a
|
||||||
|
|
||||||
|
# send the prefix to client inside window (ala nested sessions)
|
||||||
|
bind-key a send-prefix
|
||||||
|
|
||||||
|
# toggle last window like screen
|
||||||
|
bind-key C-a last-window
|
||||||
|
|
||||||
|
# confirm before killing a window or the server
|
||||||
|
bind-key k confirm kill-window
|
||||||
|
bind-key K confirm kill-server
|
||||||
|
|
||||||
|
# toggle statusbar
|
||||||
|
bind-key b set-option status
|
||||||
|
|
||||||
|
# ctrl+left/right cycles thru windows
|
||||||
|
bind-key -n C-right next
|
||||||
|
bind-key -n C-left prev
|
||||||
|
|
||||||
|
# open a man page in new window
|
||||||
|
bind / command-prompt "split-window 'exec man %%'"
|
||||||
|
|
||||||
|
# quick view of processes
|
||||||
|
bind '~' split-window "exec htop"
|
||||||
|
|
||||||
|
# scrollback buffer n lines
|
||||||
|
set -g history-limit 5000
|
||||||
|
|
||||||
|
# listen for activity on all windows
|
||||||
|
set -g bell-action any
|
||||||
|
|
||||||
|
# on-screen time for display-panes in ms
|
||||||
|
set -g display-panes-time 2000
|
||||||
|
|
||||||
|
# start window indexing at one instead of zero
|
||||||
|
set -g base-index 1
|
||||||
|
|
||||||
|
# enable wm window titles
|
||||||
|
set -g set-titles on
|
||||||
|
|
||||||
|
# wm window title string (uses statusbar variables)
|
||||||
|
set -g set-titles-string "tmux.#I.#W"
|
||||||
|
|
||||||
|
# session initialization
|
||||||
|
new -s mysession mutt
|
||||||
|
neww -t 2
|
||||||
|
neww -d -t 3
|
||||||
|
neww -d -t 5 mocp
|
||||||
|
neww -d -t 6 rtorrent
|
||||||
|
selectw -t 1
|
||||||
|
|
||||||
|
# statusbar --------------------------------------------------------------
|
||||||
|
|
||||||
|
set -g display-time 2000
|
||||||
|
|
||||||
|
# default statusbar colors
|
||||||
|
set -g status-fg white
|
||||||
|
set -g status-bg default
|
||||||
|
set -g status-attr default
|
||||||
|
|
||||||
|
# default window title colors
|
||||||
|
set-window-option -g window-status-fg cyan
|
||||||
|
set-window-option -g window-status-bg default
|
||||||
|
set-window-option -g window-status-attr dim
|
||||||
|
|
||||||
|
# active window title colors
|
||||||
|
set-window-option -g window-status-current-fg white
|
||||||
|
set-window-option -g window-status-current-bg default
|
||||||
|
set-window-option -g window-status-current-attr bright
|
||||||
|
|
||||||
|
# command/message line colors
|
||||||
|
set -g message-fg white
|
||||||
|
set -g message-bg black
|
||||||
|
set -g message-attr bright
|
||||||
|
|
||||||
|
# center align the window list
|
||||||
|
set -g status-justify centre
|
||||||
|
|
||||||
|
# show some useful stats but only when tmux is started
|
||||||
|
# outside of Xorg, otherwise dwm statusbar shows these already
|
||||||
|
set -g status-right ""
|
||||||
|
set -g status-left ""
|
||||||
|
if '[ -z "$DISPLAY" ]' 'set -g status-left "[#[fg=green] #H #[default]]"'
|
||||||
|
if '[ -z "$DISPLAY" ]' 'set -g status-right "[ #[fg=magenta]#(cat /proc/loadavg | cut -d \" \" -f 1,2,3)#[default] ][ #[fg=cyan,bright]%a %Y-%m-%d %H:%M #[default]]"'
|
||||||
|
if '[ -z "$DISPLAY" ]' 'set -g status-right-length 50'
|
||||||
|
|
104
external/bsd/tmux/dist/examples/tmux.vim
vendored
Normal file
104
external/bsd/tmux/dist/examples/tmux.vim
vendored
Normal file
|
@ -0,0 +1,104 @@
|
||||||
|
" Vim syntax file
|
||||||
|
" Language: tmux(1) configuration file
|
||||||
|
" Maintainer: Tiago Cunha <me@tiagocunha.org>
|
||||||
|
" Last Change: $Date: 2011/08/17 18:40:06 $
|
||||||
|
" License: This file is placed in the public domain.
|
||||||
|
|
||||||
|
if version < 600
|
||||||
|
syntax clear
|
||||||
|
elseif exists("b:current_syntax")
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
|
||||||
|
setlocal iskeyword+=-
|
||||||
|
syntax case match
|
||||||
|
|
||||||
|
syn keyword tmuxAction any current none
|
||||||
|
syn keyword tmuxBoolean off on
|
||||||
|
|
||||||
|
syn keyword tmuxCmds detach[-client] ls list-sessions neww new-window
|
||||||
|
syn keyword tmuxCmds bind[-key] unbind[-key] prev[ious-window] last[-window]
|
||||||
|
syn keyword tmuxCmds lsk list-keys set[-option] renamew rename-window selectw
|
||||||
|
syn keyword tmuxCmds select-window lsw list-windows attach[-session]
|
||||||
|
syn keyword tmuxCmds send-prefix refresh[-client] killw kill-window lsc
|
||||||
|
syn keyword tmuxCmds list-clients linkw link-window unlinkw unlink-window
|
||||||
|
syn keyword tmuxCmds next[-window] send[-keys] swapw swap-window
|
||||||
|
syn keyword tmuxCmds rename[-session] kill-session switchc switch-client
|
||||||
|
syn keyword tmuxCmds has[-session] copy-mode pasteb paste-buffer
|
||||||
|
syn keyword tmuxCmds new[-session] start[-server] kill-server setw
|
||||||
|
syn keyword tmuxCmds set-window-option show[-options] showw show-window-options
|
||||||
|
syn keyword tmuxCmds command-prompt setb set-buffer showb show-buffer lsb
|
||||||
|
syn keyword tmuxCmds list-buffers deleteb delete-buffer lscm list-commands
|
||||||
|
syn keyword tmuxCmds movew move-window respawnw respawn-window
|
||||||
|
syn keyword tmuxCmds source[-file] info server-info clock-mode lock[-server]
|
||||||
|
syn keyword tmuxCmds saveb save-buffer killp
|
||||||
|
syn keyword tmuxCmds kill-pane resizep resize-pane selectp select-pane swapp
|
||||||
|
syn keyword tmuxCmds swap-pane splitw split-window choose-session
|
||||||
|
syn keyword tmuxCmds choose-window loadb load-buffer copyb copy-buffer suspendc
|
||||||
|
syn keyword tmuxCmds suspend-client findw find-window breakp break-pane nextl
|
||||||
|
syn keyword tmuxCmds next-layout rotatew rotate-window confirm[-before]
|
||||||
|
syn keyword tmuxCmds clearhist clear-history selectl select-layout if[-shell]
|
||||||
|
syn keyword tmuxCmds display[-message] setenv set-environment showenv
|
||||||
|
syn keyword tmuxCmds show-environment choose-client displayp display-panes
|
||||||
|
syn keyword tmuxCmds run[-shell] lockc lock-client locks lock-session lsp
|
||||||
|
syn keyword tmuxCmds list-panes pipep pipe-pane showmsgs show-messages capturep
|
||||||
|
syn keyword tmuxCmds capture-pane joinp join-pane choose-buffer
|
||||||
|
|
||||||
|
syn keyword tmuxOptsSet prefix status status-fg status-bg bell-action
|
||||||
|
syn keyword tmuxOptsSet default-command history-limit status-left status-right
|
||||||
|
syn keyword tmuxOptsSet status-interval set-titles display-time buffer-limit
|
||||||
|
syn keyword tmuxOptsSet status-left-length status-right-length message-fg
|
||||||
|
syn keyword tmuxOptsSet message-bg lock-after-time default-path repeat-time
|
||||||
|
syn keyword tmuxOptsSet message-attr status-attr status-keys set-remain-on-exit
|
||||||
|
syn keyword tmuxOptsSet status-utf8 default-terminal visual-activity
|
||||||
|
syn keyword tmuxOptsSet visual-bell visual-content status-justify
|
||||||
|
syn keyword tmuxOptsSet terminal-overrides status-left-attr status-left-bg
|
||||||
|
syn keyword tmuxOptsSet status-left-fg status-right-attr status-right-bg
|
||||||
|
syn keyword tmuxOptsSet status-right-fg update-environment base-index
|
||||||
|
syn keyword tmuxOptsSet display-panes-colour display-panes-time default-shell
|
||||||
|
syn keyword tmuxOptsSet set-titles-string lock-command lock-server
|
||||||
|
syn keyword tmuxOptsSet mouse-select-pane message-limit quiet escape-time
|
||||||
|
syn keyword tmuxOptsSet pane-active-border-bg pane-active-border-fg
|
||||||
|
syn keyword tmuxOptsSet pane-border-bg pane-border-fg
|
||||||
|
syn keyword tmuxOptsSet display-panes-active-colour alternate-screen
|
||||||
|
syn keyword tmuxOptsSet detach-on-destroy
|
||||||
|
|
||||||
|
syn keyword tmuxOptsSetw monitor-activity aggressive-resize force-width
|
||||||
|
syn keyword tmuxOptsSetw force-height remain-on-exit uft8 mode-fg mode-bg
|
||||||
|
syn keyword tmuxOptsSetw mode-keys clock-mode-colour clock-mode-style
|
||||||
|
syn keyword tmuxOptsSetw xterm-keys mode-attr window-status-attr
|
||||||
|
syn keyword tmuxOptsSetw window-status-bg window-status-fg automatic-rename
|
||||||
|
syn keyword tmuxOptsSetw main-pane-width main-pane-height monitor-content
|
||||||
|
syn keyword tmuxOptsSetw window-status-current-attr window-status-current-bg
|
||||||
|
syn keyword tmuxOptsSetw window-status-current-fg mode-mouse synchronize-panes
|
||||||
|
syn keyword tmuxOptsSetw window-status-format window-status-current-format
|
||||||
|
syn keyword tmuxOptsSetw word-separators window-status-alert-alert
|
||||||
|
syn keyword tmuxOptsSetw window-status-alert-bg window-status-alert-fg
|
||||||
|
|
||||||
|
syn keyword tmuxTodo FIXME NOTE TODO XXX contained
|
||||||
|
|
||||||
|
syn match tmuxKey /\(C-\|M-\|\^\)\p/ display
|
||||||
|
syn match tmuxNumber /\d\+/ display
|
||||||
|
syn match tmuxOptions /\s-\a\+/ display
|
||||||
|
syn match tmuxVariable /\w\+=/ display
|
||||||
|
syn match tmuxVariableExpansion /\${\=\w\+}\=/ display
|
||||||
|
|
||||||
|
syn region tmuxComment start=/#/ end=/$/ contains=tmuxTodo display oneline
|
||||||
|
syn region tmuxString start=/"/ end=/"/ display oneline
|
||||||
|
syn region tmuxString start=/'/ end=/'/ display oneline
|
||||||
|
|
||||||
|
hi def link tmuxAction Boolean
|
||||||
|
hi def link tmuxBoolean Boolean
|
||||||
|
hi def link tmuxCmds Keyword
|
||||||
|
hi def link tmuxComment Comment
|
||||||
|
hi def link tmuxKey Special
|
||||||
|
hi def link tmuxNumber Number
|
||||||
|
hi def link tmuxOptions Identifier
|
||||||
|
hi def link tmuxOptsSet Function
|
||||||
|
hi def link tmuxOptsSetw Function
|
||||||
|
hi def link tmuxString String
|
||||||
|
hi def link tmuxTodo Todo
|
||||||
|
hi def link tmuxVariable Constant
|
||||||
|
hi def link tmuxVariableExpansion Constant
|
||||||
|
|
||||||
|
let b:current_syntax = "tmux"
|
81
external/bsd/tmux/dist/examples/tmux_backup.sh
vendored
Normal file
81
external/bsd/tmux/dist/examples/tmux_backup.sh
vendored
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# By Victor Orlikowski. Public domain.
|
||||||
|
#
|
||||||
|
# This script maintains snapshots of each pane's
|
||||||
|
# history buffer, for each tmux session you are running.
|
||||||
|
#
|
||||||
|
# It is intended to be run by cron, on whatever interval works
|
||||||
|
# for you.
|
||||||
|
|
||||||
|
# Maximum number of snapshots to keep.
|
||||||
|
max_backups=12
|
||||||
|
# Names of sessions you may wish to exclude from snapshotting,
|
||||||
|
# space separated.
|
||||||
|
ignore_sessions=""
|
||||||
|
# The directory into which you want your snapshots placed.
|
||||||
|
# The default is probably "good enough."
|
||||||
|
backup_dir=~/.tmux_backup/snapshot
|
||||||
|
|
||||||
|
########################################################################
|
||||||
|
|
||||||
|
# Rotate previous backups.
|
||||||
|
i=${max_backups}
|
||||||
|
while [[ ${i} != 0 ]] ; do
|
||||||
|
if [ -d ${backup_dir}.${i} ] ; then
|
||||||
|
if [[ ${i} = ${max_backups} ]] ; then
|
||||||
|
rm -r ${backup_dir}.${i}
|
||||||
|
else
|
||||||
|
mv ${backup_dir}.${i} ${backup_dir}.$((${i}+1))
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
i=$((${i}-1))
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -d ${backup_dir} ] ; then
|
||||||
|
mv ${backup_dir} ${backup_dir}.1
|
||||||
|
fi
|
||||||
|
|
||||||
|
## Dump hardcopy from all windows in all available tmux sessions.
|
||||||
|
unset TMUX
|
||||||
|
for session in $(tmux list-sessions | cut -d' ' -f1 | sed -e 's/:$//') ; do
|
||||||
|
for ignore_session in ${ignore_sessions} ; do
|
||||||
|
if [ ${session} = ${ignore_session} ] ; then
|
||||||
|
continue 2
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Session name can contain the colon character (":").
|
||||||
|
# This can screw up addressing of windows within tmux, since
|
||||||
|
# target windows are specified as target-session:target-window.
|
||||||
|
#
|
||||||
|
# We use uuidgen to create a "safe" temporary session name,
|
||||||
|
# which we then use to create a "detached" session that "links"
|
||||||
|
# to the "real" session that we want to back up.
|
||||||
|
tmpsession=$(uuidgen)
|
||||||
|
tmux new-session -d -s "$tmpsession" -t "$session"
|
||||||
|
HISTSIZE=$(tmux show-options -g -t "$tmpsession" | grep "history-limit" | awk '{print $2}')
|
||||||
|
for win in $(tmux list-windows -t "$tmpsession" | grep -v "^\s" | cut -d' ' -f1 | sed -e 's/:$//'); do
|
||||||
|
session_dir=$(echo "$session" | sed -e 's/ /_/g' | sed -e 's%/%|%g')
|
||||||
|
win_spec="$tmpsession":"$win"
|
||||||
|
|
||||||
|
if [ ! -d ${backup_dir}/${session_dir}/${win} ] ; then
|
||||||
|
mkdir -p ${backup_dir}/${session_dir}/${win}
|
||||||
|
fi
|
||||||
|
|
||||||
|
for pane in $(tmux list-panes -t "$win_spec" | cut -d' ' -f1 | sed -e 's/:$//'); do
|
||||||
|
pane_path=${backup_dir}/${session_dir}/${win}/${pane}
|
||||||
|
pane_spec="$win_spec"."$pane"
|
||||||
|
|
||||||
|
tmux capture-pane -t "$pane_spec" -S -${HISTSIZE}
|
||||||
|
tmux save-buffer ${pane_path}
|
||||||
|
|
||||||
|
if [ ! -s ${pane_path} ] ; then
|
||||||
|
sleep 1
|
||||||
|
rm ${pane_path}
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
done
|
||||||
|
tmux kill-session -t "$tmpsession"
|
||||||
|
|
||||||
|
done
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue