xref: /openbsd-src/usr.bin/tmux/tmux.h (revision 6f05df2d9be0954bec42d51d943d77bd250fb664)
1 /* $OpenBSD: tmux.h,v 1.482 2014/11/30 08:03:29 nicm Exp $ */
2 
3 /*
4  * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15  * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #ifndef TMUX_H
20 #define TMUX_H
21 
22 #define PROTOCOL_VERSION 8
23 
24 #include <sys/time.h>
25 #include <sys/queue.h>
26 #include <sys/tree.h>
27 #include <sys/uio.h>
28 
29 #include <bitstring.h>
30 #include <event.h>
31 #include <imsg.h>
32 #include <limits.h>
33 #include <stdarg.h>
34 #include <stdint.h>
35 #include <stdio.h>
36 #include <termios.h>
37 
38 #include "array.h"
39 
40 extern char    *__progname;
41 extern char   **environ;
42 
43 /* Default global configuration file. */
44 #define TMUX_CONF "/etc/tmux.conf"
45 
46 /* Default prompt history length. */
47 #define PROMPT_HISTORY 100
48 
49 /*
50  * Minimum layout cell size, NOT including separator line. The scroll region
51  * cannot be one line in height so this must be at least two.
52  */
53 #define PANE_MINIMUM 2
54 
55 /* Automatic name refresh interval, in milliseconds. */
56 #define NAME_INTERVAL 500
57 
58 /*
59  * UTF-8 data size. This must be big enough to hold combined characters as well
60  * as single.
61  */
62 #define UTF8_SIZE 9
63 
64 /* Fatal errors. */
65 #define fatal(msg) log_fatal("%s: %s", __func__, msg);
66 #define fatalx(msg) log_fatalx("%s: %s", __func__, msg);
67 
68 /* Definition to shut gcc up about unused arguments. */
69 #define unused __attribute__ ((unused))
70 
71 /* Attribute to make gcc check printf-like arguments. */
72 #define printflike(a, b) __attribute__ ((format (printf, a, b)))
73 
74 /* Number of items in array. */
75 #ifndef nitems
76 #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
77 #endif
78 
79 /* Bell option values. */
80 #define BELL_NONE 0
81 #define BELL_ANY 1
82 #define BELL_CURRENT 2
83 
84 /* Special key codes. */
85 #define KEYC_NONE 0xfff
86 #define KEYC_BASE 0x1000
87 
88 /* Key modifier bits. */
89 #define KEYC_ESCAPE 0x2000
90 #define KEYC_CTRL 0x4000
91 #define KEYC_SHIFT 0x8000
92 #define KEYC_PREFIX 0x10000
93 
94 /* Mask to obtain key w/o modifiers. */
95 #define KEYC_MASK_MOD (KEYC_ESCAPE|KEYC_CTRL|KEYC_SHIFT|KEYC_PREFIX)
96 #define KEYC_MASK_KEY (~KEYC_MASK_MOD)
97 
98 /* Other key codes. */
99 enum key_code {
100 	/* Mouse key. */
101 	KEYC_MOUSE = KEYC_BASE,
102 
103 	/* Backspace key. */
104 	KEYC_BSPACE,
105 
106 	/* Function keys. */
107 	KEYC_F1,
108 	KEYC_F2,
109 	KEYC_F3,
110 	KEYC_F4,
111 	KEYC_F5,
112 	KEYC_F6,
113 	KEYC_F7,
114 	KEYC_F8,
115 	KEYC_F9,
116 	KEYC_F10,
117 	KEYC_F11,
118 	KEYC_F12,
119 	KEYC_IC,
120 	KEYC_DC,
121 	KEYC_HOME,
122 	KEYC_END,
123 	KEYC_NPAGE,
124 	KEYC_PPAGE,
125 	KEYC_BTAB,
126 
127 	/* Arrow keys. */
128 	KEYC_UP,
129 	KEYC_DOWN,
130 	KEYC_LEFT,
131 	KEYC_RIGHT,
132 
133 	/* Numeric keypad. */
134 	KEYC_KP_SLASH,
135 	KEYC_KP_STAR,
136 	KEYC_KP_MINUS,
137 	KEYC_KP_SEVEN,
138 	KEYC_KP_EIGHT,
139 	KEYC_KP_NINE,
140 	KEYC_KP_PLUS,
141 	KEYC_KP_FOUR,
142 	KEYC_KP_FIVE,
143 	KEYC_KP_SIX,
144 	KEYC_KP_ONE,
145 	KEYC_KP_TWO,
146 	KEYC_KP_THREE,
147 	KEYC_KP_ENTER,
148 	KEYC_KP_ZERO,
149 	KEYC_KP_PERIOD,
150 
151 	KEYC_FOCUS_IN,
152 	KEYC_FOCUS_OUT,
153 };
154 
155 /* Termcap codes. */
156 enum tty_code_code {
157 	TTYC_AX = 0,
158 	TTYC_ACSC,	/* acs_chars, ac */
159 	TTYC_BEL,	/* bell, bl */
160 	TTYC_BLINK,	/* enter_blink_mode, mb */
161 	TTYC_BOLD,	/* enter_bold_mode, md */
162 	TTYC_CIVIS,	/* cursor_invisible, vi */
163 	TTYC_CLEAR,	/* clear_screen, cl */
164 	TTYC_CNORM,	/* cursor_normal, ve */
165 	TTYC_COLORS,	/* max_colors, Co */
166 	TTYC_CR,	/* restore cursor colour, Cr */
167 	TTYC_CS,	/* set cursor colour, Cs */
168 	TTYC_CSR,	/* change_scroll_region, cs */
169 	TTYC_CUB,	/* parm_left_cursor, LE */
170 	TTYC_CUB1,	/* cursor_left, le */
171 	TTYC_CUD,	/* parm_down_cursor, DO */
172 	TTYC_CUD1,	/* cursor_down, do */
173 	TTYC_CUF,	/* parm_right_cursor, RI */
174 	TTYC_CUF1,	/* cursor_right, nd */
175 	TTYC_CUP,	/* cursor_address, cm */
176 	TTYC_CUU,	/* parm_up_cursor, UP */
177 	TTYC_CUU1,	/* cursor_up, up */
178 	TTYC_DCH,	/* parm_dch, DC */
179 	TTYC_DCH1,	/* delete_character, dc */
180 	TTYC_DIM,	/* enter_dim_mode, mh */
181 	TTYC_DL,	/* parm_delete_line, DL */
182 	TTYC_DL1,	/* delete_line, dl */
183 	TTYC_E3,
184 	TTYC_ECH,	/* erase_chars, ec */
185 	TTYC_EL,	/* clr_eol, ce */
186 	TTYC_EL1,	/* clr_bol, cb */
187 	TTYC_ENACS,	/* ena_acs, eA */
188 	TTYC_FSL,	/* from_status_line, fsl */
189 	TTYC_HOME,	/* cursor_home, ho */
190 	TTYC_HPA,	/* column_address, ch */
191 	TTYC_ICH,	/* parm_ich, IC */
192 	TTYC_ICH1,	/* insert_character, ic */
193 	TTYC_IL,	/* parm_insert_line, IL */
194 	TTYC_IL1,	/* insert_line, il */
195 	TTYC_INVIS,	/* enter_secure_mode, mk */
196 	TTYC_IS1,	/* init_1string, i1 */
197 	TTYC_IS2,	/* init_2string, i2 */
198 	TTYC_IS3,	/* init_3string, i3 */
199 	TTYC_KCBT,	/* key_btab, kB */
200 	TTYC_KCUB1,	/* key_left, kl */
201 	TTYC_KCUD1,	/* key_down, kd */
202 	TTYC_KCUF1,	/* key_right, kr */
203 	TTYC_KCUU1,	/* key_up, ku */
204 	TTYC_KDC2,
205 	TTYC_KDC3,
206 	TTYC_KDC4,
207 	TTYC_KDC5,
208 	TTYC_KDC6,
209 	TTYC_KDC7,
210 	TTYC_KDCH1,	/* key_dc, kD */
211 	TTYC_KDN2,
212 	TTYC_KDN3,
213 	TTYC_KDN4,
214 	TTYC_KDN5,
215 	TTYC_KDN6,
216 	TTYC_KDN7,
217 	TTYC_KEND,	/* key_end, ke */
218 	TTYC_KEND2,
219 	TTYC_KEND3,
220 	TTYC_KEND4,
221 	TTYC_KEND5,
222 	TTYC_KEND6,
223 	TTYC_KEND7,
224 	TTYC_KF1,
225 	TTYC_KF10,
226 	TTYC_KF11,
227 	TTYC_KF12,
228 	TTYC_KF13,
229 	TTYC_KF14,
230 	TTYC_KF15,
231 	TTYC_KF16,
232 	TTYC_KF17,
233 	TTYC_KF18,
234 	TTYC_KF19,
235 	TTYC_KF2,
236 	TTYC_KF20,
237 	TTYC_KF21,
238 	TTYC_KF22,
239 	TTYC_KF23,
240 	TTYC_KF24,
241 	TTYC_KF25,
242 	TTYC_KF26,
243 	TTYC_KF27,
244 	TTYC_KF28,
245 	TTYC_KF29,
246 	TTYC_KF3,
247 	TTYC_KF30,
248 	TTYC_KF31,
249 	TTYC_KF32,
250 	TTYC_KF33,
251 	TTYC_KF34,
252 	TTYC_KF35,
253 	TTYC_KF36,
254 	TTYC_KF37,
255 	TTYC_KF38,
256 	TTYC_KF39,
257 	TTYC_KF4,
258 	TTYC_KF40,
259 	TTYC_KF41,
260 	TTYC_KF42,
261 	TTYC_KF43,
262 	TTYC_KF44,
263 	TTYC_KF45,
264 	TTYC_KF46,
265 	TTYC_KF47,
266 	TTYC_KF48,
267 	TTYC_KF49,
268 	TTYC_KF5,
269 	TTYC_KF50,
270 	TTYC_KF51,
271 	TTYC_KF52,
272 	TTYC_KF53,
273 	TTYC_KF54,
274 	TTYC_KF55,
275 	TTYC_KF56,
276 	TTYC_KF57,
277 	TTYC_KF58,
278 	TTYC_KF59,
279 	TTYC_KF6,
280 	TTYC_KF60,
281 	TTYC_KF61,
282 	TTYC_KF62,
283 	TTYC_KF63,
284 	TTYC_KF7,
285 	TTYC_KF8,
286 	TTYC_KF9,
287 	TTYC_KHOM2,
288 	TTYC_KHOM3,
289 	TTYC_KHOM4,
290 	TTYC_KHOM5,
291 	TTYC_KHOM6,
292 	TTYC_KHOM7,
293 	TTYC_KHOME,	/* key_home, kh */
294 	TTYC_KIC2,
295 	TTYC_KIC3,
296 	TTYC_KIC4,
297 	TTYC_KIC5,
298 	TTYC_KIC6,
299 	TTYC_KIC7,
300 	TTYC_KICH1,	/* key_ic, kI */
301 	TTYC_KLFT2,
302 	TTYC_KLFT3,
303 	TTYC_KLFT4,
304 	TTYC_KLFT5,
305 	TTYC_KLFT6,
306 	TTYC_KLFT7,
307 	TTYC_KMOUS,	/* key_mouse, Km */
308 	TTYC_KNP,	/* key_npage, kN */
309 	TTYC_KNXT2,
310 	TTYC_KNXT3,
311 	TTYC_KNXT4,
312 	TTYC_KNXT5,
313 	TTYC_KNXT6,
314 	TTYC_KNXT7,
315 	TTYC_KPP,	/* key_ppage, kP */
316 	TTYC_KPRV2,
317 	TTYC_KPRV3,
318 	TTYC_KPRV4,
319 	TTYC_KPRV5,
320 	TTYC_KPRV6,
321 	TTYC_KPRV7,
322 	TTYC_KRIT2,
323 	TTYC_KRIT3,
324 	TTYC_KRIT4,
325 	TTYC_KRIT5,
326 	TTYC_KRIT6,
327 	TTYC_KRIT7,
328 	TTYC_KUP2,
329 	TTYC_KUP3,
330 	TTYC_KUP4,
331 	TTYC_KUP5,
332 	TTYC_KUP6,
333 	TTYC_KUP7,
334 	TTYC_MS,	/* modify xterm(1) selection */
335 	TTYC_OP,	/* orig_pair, op */
336 	TTYC_REV,	/* enter_reverse_mode, mr */
337 	TTYC_RI,	/* scroll_reverse, sr */
338 	TTYC_RMACS,	/* exit_alt_charset_mode */
339 	TTYC_RMCUP,	/* exit_ca_mode, te */
340 	TTYC_RMKX,	/* keypad_local, ke */
341 	TTYC_SE,	/* reset cursor style, Se */
342 	TTYC_SETAB,	/* set_a_background, AB */
343 	TTYC_SETAF,	/* set_a_foreground, AF */
344 	TTYC_SGR0,	/* exit_attribute_mode, me */
345 	TTYC_SITM,	/* enter_italics_mode, it */
346 	TTYC_SMACS,	/* enter_alt_charset_mode, as */
347 	TTYC_SMCUP,	/* enter_ca_mode, ti */
348 	TTYC_SMKX,	/* keypad_xmit, ks */
349 	TTYC_SMSO,	/* enter_standout_mode, so */
350 	TTYC_SMUL,	/* enter_underline_mode, us */
351 	TTYC_SS,	/* set cursor style, Ss */
352 	TTYC_TSL,	/* to_status_line, tsl */
353 	TTYC_VPA,	/* row_address, cv */
354 	TTYC_XENL,	/* eat_newline_glitch, xn */
355 	TTYC_XT,	/* xterm(1)-compatible title, XT */
356 };
357 #define NTTYCODE (TTYC_XT + 1)
358 
359 /* Termcap types. */
360 enum tty_code_type {
361 	TTYCODE_NONE = 0,
362 	TTYCODE_STRING,
363 	TTYCODE_NUMBER,
364 	TTYCODE_FLAG,
365 };
366 
367 /* Termcap code. */
368 struct tty_code {
369 	enum tty_code_type	type;
370 	union {
371 		char	       *string;
372 		int		number;
373 		int		flag;
374 	} value;
375 };
376 
377 /* Entry in terminal code table. */
378 struct tty_term_code_entry {
379 	enum tty_code_code	code;
380 	enum tty_code_type	type;
381 	const char	       *name;
382 };
383 
384 /* Message codes. */
385 enum msgtype {
386 	MSG_VERSION = 12,
387 
388 	MSG_IDENTIFY_FLAGS = 100,
389 	MSG_IDENTIFY_TERM,
390 	MSG_IDENTIFY_TTYNAME,
391 	MSG_IDENTIFY_CWD,
392 	MSG_IDENTIFY_STDIN,
393 	MSG_IDENTIFY_ENVIRON,
394 	MSG_IDENTIFY_DONE,
395 
396 	MSG_COMMAND = 200,
397 	MSG_DETACH,
398 	MSG_DETACHKILL,
399 	MSG_EXIT,
400 	MSG_EXITED,
401 	MSG_EXITING,
402 	MSG_LOCK,
403 	MSG_READY,
404 	MSG_RESIZE,
405 	MSG_SHELL,
406 	MSG_SHUTDOWN,
407 	MSG_STDERR,
408 	MSG_STDIN,
409 	MSG_STDOUT,
410 	MSG_SUSPEND,
411 	MSG_UNLOCK,
412 	MSG_WAKEUP,
413 };
414 
415 /*
416  * Message data.
417  *
418  * Don't forget to bump PROTOCOL_VERSION if any of these change!
419  */
420 struct msg_command_data {
421 	int	argc;
422 }; /* followed by packed argv */
423 
424 struct msg_stdin_data {
425 	ssize_t	size;
426 	char	data[BUFSIZ];
427 };
428 
429 struct msg_stdout_data {
430 	ssize_t	size;
431 	char	data[BUFSIZ];
432 };
433 
434 struct msg_stderr_data {
435 	ssize_t	size;
436 	char	data[BUFSIZ];
437 };
438 
439 /* Mode key commands. */
440 enum mode_key_cmd {
441 	MODEKEY_NONE,
442 	MODEKEY_OTHER,
443 
444 	/* Editing keys. */
445 	MODEKEYEDIT_BACKSPACE,
446 	MODEKEYEDIT_CANCEL,
447 	MODEKEYEDIT_COMPLETE,
448 	MODEKEYEDIT_CURSORLEFT,
449 	MODEKEYEDIT_CURSORRIGHT,
450 	MODEKEYEDIT_DELETE,
451 	MODEKEYEDIT_DELETELINE,
452 	MODEKEYEDIT_DELETETOENDOFLINE,
453 	MODEKEYEDIT_DELETEWORD,
454 	MODEKEYEDIT_ENDOFLINE,
455 	MODEKEYEDIT_ENTER,
456 	MODEKEYEDIT_HISTORYDOWN,
457 	MODEKEYEDIT_HISTORYUP,
458 	MODEKEYEDIT_NEXTSPACE,
459 	MODEKEYEDIT_NEXTSPACEEND,
460 	MODEKEYEDIT_NEXTWORD,
461 	MODEKEYEDIT_NEXTWORDEND,
462 	MODEKEYEDIT_PASTE,
463 	MODEKEYEDIT_PREVIOUSSPACE,
464 	MODEKEYEDIT_PREVIOUSWORD,
465 	MODEKEYEDIT_STARTOFLINE,
466 	MODEKEYEDIT_SWITCHMODE,
467 	MODEKEYEDIT_SWITCHMODEAPPEND,
468 	MODEKEYEDIT_SWITCHMODEAPPENDLINE,
469 	MODEKEYEDIT_SWITCHMODEBEGINLINE,
470 	MODEKEYEDIT_SWITCHMODECHANGELINE,
471 	MODEKEYEDIT_SWITCHMODESUBSTITUTE,
472 	MODEKEYEDIT_SWITCHMODESUBSTITUTELINE,
473 	MODEKEYEDIT_TRANSPOSECHARS,
474 
475 	/* Menu (choice) keys. */
476 	MODEKEYCHOICE_BACKSPACE,
477 	MODEKEYCHOICE_BOTTOMLINE,
478 	MODEKEYCHOICE_CANCEL,
479 	MODEKEYCHOICE_CHOOSE,
480 	MODEKEYCHOICE_DOWN,
481 	MODEKEYCHOICE_ENDOFLIST,
482 	MODEKEYCHOICE_PAGEDOWN,
483 	MODEKEYCHOICE_PAGEUP,
484 	MODEKEYCHOICE_SCROLLDOWN,
485 	MODEKEYCHOICE_SCROLLUP,
486 	MODEKEYCHOICE_STARTNUMBERPREFIX,
487 	MODEKEYCHOICE_STARTOFLIST,
488 	MODEKEYCHOICE_TOPLINE,
489 	MODEKEYCHOICE_TREE_COLLAPSE,
490 	MODEKEYCHOICE_TREE_COLLAPSE_ALL,
491 	MODEKEYCHOICE_TREE_EXPAND,
492 	MODEKEYCHOICE_TREE_EXPAND_ALL,
493 	MODEKEYCHOICE_TREE_TOGGLE,
494 	MODEKEYCHOICE_UP,
495 
496 	/* Copy keys. */
497 	MODEKEYCOPY_APPENDSELECTION,
498 	MODEKEYCOPY_BACKTOINDENTATION,
499 	MODEKEYCOPY_BOTTOMLINE,
500 	MODEKEYCOPY_CANCEL,
501 	MODEKEYCOPY_CLEARSELECTION,
502 	MODEKEYCOPY_COPYPIPE,
503 	MODEKEYCOPY_COPYLINE,
504 	MODEKEYCOPY_COPYENDOFLINE,
505 	MODEKEYCOPY_COPYSELECTION,
506 	MODEKEYCOPY_DOWN,
507 	MODEKEYCOPY_ENDOFLINE,
508 	MODEKEYCOPY_GOTOLINE,
509 	MODEKEYCOPY_HALFPAGEDOWN,
510 	MODEKEYCOPY_HALFPAGEUP,
511 	MODEKEYCOPY_HISTORYBOTTOM,
512 	MODEKEYCOPY_HISTORYTOP,
513 	MODEKEYCOPY_JUMP,
514 	MODEKEYCOPY_JUMPAGAIN,
515 	MODEKEYCOPY_JUMPREVERSE,
516 	MODEKEYCOPY_JUMPBACK,
517 	MODEKEYCOPY_JUMPTO,
518 	MODEKEYCOPY_JUMPTOBACK,
519 	MODEKEYCOPY_LEFT,
520 	MODEKEYCOPY_MIDDLELINE,
521 	MODEKEYCOPY_NEXTPAGE,
522 	MODEKEYCOPY_NEXTSPACE,
523 	MODEKEYCOPY_NEXTSPACEEND,
524 	MODEKEYCOPY_NEXTWORD,
525 	MODEKEYCOPY_NEXTWORDEND,
526 	MODEKEYCOPY_OTHEREND,
527 	MODEKEYCOPY_PREVIOUSPAGE,
528 	MODEKEYCOPY_PREVIOUSSPACE,
529 	MODEKEYCOPY_PREVIOUSWORD,
530 	MODEKEYCOPY_RECTANGLETOGGLE,
531 	MODEKEYCOPY_RIGHT,
532 	MODEKEYCOPY_SCROLLDOWN,
533 	MODEKEYCOPY_SCROLLUP,
534 	MODEKEYCOPY_SEARCHAGAIN,
535 	MODEKEYCOPY_SEARCHDOWN,
536 	MODEKEYCOPY_SEARCHREVERSE,
537 	MODEKEYCOPY_SEARCHUP,
538 	MODEKEYCOPY_SELECTLINE,
539 	MODEKEYCOPY_STARTNAMEDBUFFER,
540 	MODEKEYCOPY_STARTNUMBERPREFIX,
541 	MODEKEYCOPY_STARTOFLINE,
542 	MODEKEYCOPY_STARTSELECTION,
543 	MODEKEYCOPY_TOPLINE,
544 	MODEKEYCOPY_UP,
545 };
546 
547 /* Entry in the default mode key tables. */
548 struct mode_key_entry {
549 	int			key;
550 
551 	/*
552 	 * Editing mode for vi: 0 is edit mode, keys not in the table are
553 	 * returned as MODEKEY_OTHER; 1 is command mode, keys not in the table
554 	 * are returned as MODEKEY_NONE. This is also matched on, allowing some
555 	 * keys to be bound in edit mode.
556 	 */
557 	int			mode;
558 	enum mode_key_cmd	cmd;
559 };
560 
561 /* Data required while mode keys are in use. */
562 struct mode_key_data {
563 	struct mode_key_tree   *tree;
564 	int			mode;
565 };
566 #define MODEKEY_EMACS 0
567 #define MODEKEY_VI 1
568 
569 /* Binding between a key and a command. */
570 struct mode_key_binding {
571 	int				 key;
572 
573 	int				 mode;
574 	enum mode_key_cmd		 cmd;
575 	const char			*arg;
576 
577 	RB_ENTRY(mode_key_binding)	 entry;
578 };
579 RB_HEAD(mode_key_tree, mode_key_binding);
580 
581 /* Command to string mapping. */
582 struct mode_key_cmdstr {
583 	enum mode_key_cmd	 cmd;
584 	const char		*name;
585 };
586 
587 /* Named mode key table description. */
588 struct mode_key_table {
589 	const char			*name;
590 	const struct mode_key_cmdstr	*cmdstr;
591 	struct mode_key_tree		*tree;
592 	const struct mode_key_entry	*table;	/* default entries */
593 };
594 
595 /* Modes. */
596 #define MODE_CURSOR 0x1
597 #define MODE_INSERT 0x2
598 #define MODE_KCURSOR 0x4
599 #define MODE_KKEYPAD 0x8	/* set = application, clear = number */
600 #define MODE_WRAP 0x10		/* whether lines wrap */
601 #define MODE_MOUSE_STANDARD 0x20
602 #define MODE_MOUSE_BUTTON 0x40
603 /* 0x80 unused */
604 #define MODE_MOUSE_UTF8 0x100
605 #define MODE_MOUSE_SGR 0x200
606 #define MODE_BRACKETPASTE 0x400
607 #define MODE_FOCUSON 0x800
608 
609 #define ALL_MOUSE_MODES (MODE_MOUSE_STANDARD|MODE_MOUSE_BUTTON)
610 
611 /* A single UTF-8 character. */
612 struct utf8_data {
613 	u_char	data[UTF8_SIZE];
614 
615 	size_t	have;
616 	size_t	size;
617 
618 	u_int	width;
619 };
620 
621 /* Grid attributes. */
622 #define GRID_ATTR_BRIGHT 0x1
623 #define GRID_ATTR_DIM 0x2
624 #define GRID_ATTR_UNDERSCORE 0x4
625 #define GRID_ATTR_BLINK 0x8
626 #define GRID_ATTR_REVERSE 0x10
627 #define GRID_ATTR_HIDDEN 0x20
628 #define GRID_ATTR_ITALICS 0x40
629 #define GRID_ATTR_CHARSET 0x80	/* alternative character set */
630 
631 /* Grid flags. */
632 #define GRID_FLAG_FG256 0x1
633 #define GRID_FLAG_BG256 0x2
634 #define GRID_FLAG_PADDING 0x4
635 
636 /* Grid line flags. */
637 #define GRID_LINE_WRAPPED 0x1
638 
639 /* Grid cell data. */
640 struct grid_cell {
641 	u_char	attr;
642 	u_char	flags;
643 	u_char	fg;
644 	u_char	bg;
645 
646 	u_char	xstate; /* top 4 bits width, bottom 4 bits size */
647 	u_char	xdata[UTF8_SIZE];
648 } __packed;
649 
650 /* Grid line. */
651 struct grid_line {
652 	u_int	cellsize;
653 	struct grid_cell *celldata;
654 
655 	int	flags;
656 } __packed;
657 
658 /* Entire grid of cells. */
659 struct grid {
660 	int	flags;
661 #define GRID_HISTORY 0x1	/* scroll lines into history */
662 
663 	u_int	sx;
664 	u_int	sy;
665 
666 	u_int	hsize;
667 	u_int	hlimit;
668 
669 	struct grid_line *linedata;
670 };
671 
672 /* Option data structures. */
673 struct options_entry {
674 	char		*name;
675 
676 	enum {
677 		OPTIONS_STRING,
678 		OPTIONS_NUMBER,
679 		OPTIONS_STYLE
680 	} type;
681 
682 	char			*str;
683 	long long	 	 num;
684 	struct grid_cell	 style;
685 
686 	RB_ENTRY(options_entry) entry;
687 };
688 
689 struct options {
690 	RB_HEAD(options_tree, options_entry) tree;
691 	struct options	*parent;
692 };
693 
694 /* Scheduled job. */
695 struct job {
696 	char		*cmd;
697 	pid_t		 pid;
698 	int		 status;
699 
700 	int		 fd;
701 	struct bufferevent *event;
702 
703 	void		(*callbackfn)(struct job *);
704 	void		(*freefn)(void *);
705 	void		*data;
706 
707 	LIST_ENTRY(job)	 lentry;
708 };
709 LIST_HEAD(joblist, job);
710 
711 /* Screen selection. */
712 struct screen_sel {
713 	int		 flag;
714 	int		 rectflag;
715 	enum {
716 		LINE_SEL_NONE,
717 		LINE_SEL_LEFT_RIGHT,
718 		LINE_SEL_RIGHT_LEFT,
719 	} lineflag;
720 
721 	int		 modekeys;
722 
723 	u_int		 sx;
724 	u_int		 sy;
725 
726 	u_int		 ex;
727 	u_int		 ey;
728 
729 	struct grid_cell cell;
730 };
731 
732 /* Virtual screen. */
733 struct screen {
734 	char		*title;
735 
736 	struct grid	*grid;		/* grid data */
737 
738 	u_int		 cx;		/* cursor x */
739 	u_int		 cy;		/* cursor y */
740 
741 	u_int		 cstyle;	/* cursor style */
742 	char		*ccolour;	/* cursor colour string */
743 
744 	u_int		 rupper;	/* scroll region top */
745 	u_int		 rlower;	/* scroll region bottom */
746 
747 	int		 mode;
748 
749 	bitstr_t	*tabs;
750 
751 	struct screen_sel sel;
752 };
753 
754 /* Screen write context. */
755 struct screen_write_ctx {
756 	struct window_pane *wp;
757 	struct screen	*s;
758 };
759 
760 /* Screen size. */
761 #define screen_size_x(s) ((s)->grid->sx)
762 #define screen_size_y(s) ((s)->grid->sy)
763 #define screen_hsize(s) ((s)->grid->hsize)
764 #define screen_hlimit(s) ((s)->grid->hlimit)
765 
766 /* Input parser cell. */
767 struct input_cell {
768 	struct grid_cell	cell;
769 	int			set;
770 	int			g0set;	/* 1 if ACS */
771 	int			g1set;	/* 1 if ACS */
772 };
773 
774 /* Input parser context. */
775 struct input_ctx {
776 	struct window_pane     *wp;
777 	struct screen_write_ctx ctx;
778 
779 	struct input_cell	cell;
780 
781 	struct input_cell	old_cell;
782 	u_int 			old_cx;
783 	u_int			old_cy;
784 
785 	u_char			interm_buf[4];
786 	size_t			interm_len;
787 
788 	u_char			param_buf[64];
789 	size_t			param_len;
790 
791 #define INPUT_BUF_START 32
792 #define INPUT_BUF_LIMIT 1048576
793 	u_char		       *input_buf;
794 	size_t			input_len;
795 	size_t			input_space;
796 
797 	int			param_list[24];	/* -1 not present */
798 	u_int			param_list_len;
799 
800 	struct utf8_data	utf8data;
801 
802 	int			ch;
803 	int			flags;
804 #define INPUT_DISCARD 0x1
805 
806 	const struct input_state *state;
807 
808 	/*
809 	 * All input received since we were last in the ground state. Sent to
810 	 * control clients on connection.
811 	 */
812 	struct evbuffer	 	*since_ground;
813 };
814 
815 /*
816  * Window mode. Windows can be in several modes and this is used to call the
817  * right function to handle input and output.
818  */
819 struct session;
820 struct window;
821 struct mouse_event;
822 struct window_mode {
823 	struct screen *(*init)(struct window_pane *);
824 	void	(*free)(struct window_pane *);
825 	void	(*resize)(struct window_pane *, u_int, u_int);
826 	void	(*key)(struct window_pane *, struct session *, int);
827 	void	(*mouse)(struct window_pane *,
828 		    struct session *, struct mouse_event *);
829 	void	(*timer)(struct window_pane *);
830 };
831 
832 /* Structures for choose mode. */
833 struct window_choose_data {
834 	struct client		*start_client;
835 	struct session		*start_session;
836 
837 	u_int			 idx;
838 	int			 type;
839 #define TREE_OTHER 0x0
840 #define TREE_WINDOW 0x1
841 #define TREE_SESSION 0x2
842 
843 	struct session		*tree_session; /* session of items in tree */
844 
845 	struct winlink		*wl;
846 	int			 pane_id;
847 
848 	char		        *ft_template;
849 	struct format_tree	*ft;
850 
851 	char			*command;
852 };
853 
854 struct window_choose_mode_item {
855 	struct window_choose_data	*wcd;
856 	char				*name;
857 	int				 pos;
858 	int				 state;
859 #define TREE_EXPANDED 0x1
860 };
861 
862 /* Child window structure. */
863 struct window_pane {
864 	u_int		 id;
865 	u_int		 active_point;
866 
867 	struct window	*window;
868 
869 	struct layout_cell *layout_cell;
870 	struct layout_cell *saved_layout_cell;
871 
872 	u_int		 sx;
873 	u_int		 sy;
874 
875 	u_int		 xoff;
876 	u_int		 yoff;
877 
878 	int		 flags;
879 #define PANE_REDRAW 0x1
880 #define PANE_DROP 0x2
881 #define PANE_FOCUSED 0x4
882 #define PANE_RESIZE 0x8
883 #define PANE_FOCUSPUSH 0x10
884 #define PANE_INPUTOFF 0x20
885 
886 	int		 argc;
887 	char	       **argv;
888 	char		*shell;
889 	int		 cwd;
890 
891 	pid_t		 pid;
892 	char		 tty[TTY_NAME_MAX];
893 
894 	u_int		 changes;
895 	struct event	 changes_timer;
896 	u_int		 changes_redraw;
897 
898 	int		 fd;
899 	struct bufferevent *event;
900 
901 	struct input_ctx ictx;
902 
903 	int		 pipe_fd;
904 	struct bufferevent *pipe_event;
905 	size_t		 pipe_off;
906 
907 	struct screen	*screen;
908 	struct screen	 base;
909 
910 	/* Saved in alternative screen mode. */
911 	u_int		 saved_cx;
912 	u_int		 saved_cy;
913 	struct grid	*saved_grid;
914 	struct grid_cell saved_cell;
915 
916 	const struct window_mode *mode;
917 	void		*modedata;
918 
919 	TAILQ_ENTRY(window_pane) entry;
920 	RB_ENTRY(window_pane) tree_entry;
921 };
922 TAILQ_HEAD(window_panes, window_pane);
923 RB_HEAD(window_pane_tree, window_pane);
924 ARRAY_DECL(window_pane_list, struct window_pane *);
925 
926 /* Window structure. */
927 struct window {
928 	u_int		 id;
929 	char		*name;
930 	struct event	 name_timer;
931 	struct timeval   silence_timer;
932 
933 	struct window_pane *active;
934 	struct window_pane *last;
935 	struct window_panes panes;
936 
937 	int		 lastlayout;
938 	struct layout_cell *layout_root;
939 	struct layout_cell *saved_layout_root;
940 
941 	u_int		 sx;
942 	u_int		 sy;
943 
944 	int		 flags;
945 #define WINDOW_BELL 0x1
946 #define WINDOW_ACTIVITY 0x2
947 #define WINDOW_REDRAW 0x4
948 #define WINDOW_SILENCE 0x8
949 #define WINDOW_ZOOMED 0x1000
950 #define WINDOW_FORCEWIDTH 0x2000
951 #define WINDOW_FORCEHEIGHT 0x4000
952 #define WINDOW_ALERTFLAGS (WINDOW_BELL|WINDOW_ACTIVITY|WINDOW_SILENCE)
953 
954 	struct options	 options;
955 
956 	u_int		 references;
957 };
958 ARRAY_DECL(windows, struct window *);
959 
960 /* Entry on local window list. */
961 struct winlink {
962 	int		 idx;
963 	struct window	*window;
964 
965 	size_t		 status_width;
966 	struct grid_cell status_cell;
967 	char		*status_text;
968 
969 	int              flags;
970 #define WINLINK_BELL 0x1
971 #define WINLINK_ACTIVITY 0x2
972 #define WINLINK_SILENCE 0x4
973 #define WINLINK_ALERTFLAGS (WINLINK_BELL|WINLINK_ACTIVITY|WINLINK_SILENCE)
974 
975 	RB_ENTRY(winlink) entry;
976 	TAILQ_ENTRY(winlink) sentry;
977 };
978 RB_HEAD(winlinks, winlink);
979 TAILQ_HEAD(winlink_stack, winlink);
980 
981 /* Layout direction. */
982 enum layout_type {
983 	LAYOUT_LEFTRIGHT,
984 	LAYOUT_TOPBOTTOM,
985 	LAYOUT_WINDOWPANE
986 };
987 
988 /* Layout cells queue. */
989 TAILQ_HEAD(layout_cells, layout_cell);
990 
991 /* Layout cell. */
992 struct layout_cell {
993 	enum layout_type type;
994 
995 	struct layout_cell *parent;
996 
997 	u_int		 sx;
998 	u_int		 sy;
999 
1000 	u_int		 xoff;
1001 	u_int		 yoff;
1002 
1003 	struct window_pane *wp;
1004 	struct layout_cells cells;
1005 
1006 	TAILQ_ENTRY(layout_cell) entry;
1007 };
1008 
1009 /* Paste buffer. */
1010 struct paste_buffer {
1011 	char		*data;
1012 	size_t		 size;
1013 
1014 	char		*name;
1015 	int		 automatic;
1016 	u_int		 order;
1017 
1018 	RB_ENTRY(paste_buffer) name_entry;
1019 	RB_ENTRY(paste_buffer) time_entry;
1020 };
1021 
1022 /* Environment variable. */
1023 struct environ_entry {
1024 	char		*name;
1025 	char		*value;
1026 
1027 	RB_ENTRY(environ_entry) entry;
1028 };
1029 RB_HEAD(environ, environ_entry);
1030 
1031 /* Client session. */
1032 struct session_group {
1033 	TAILQ_HEAD(, session) sessions;
1034 
1035 	TAILQ_ENTRY(session_group) entry;
1036 };
1037 TAILQ_HEAD(session_groups, session_group);
1038 
1039 struct session {
1040 	u_int		 id;
1041 
1042 	char		*name;
1043 	int		 cwd;
1044 
1045 	struct timeval	 creation_time;
1046 	struct timeval	 activity_time;
1047 	struct timeval	 last_activity_time;
1048 
1049 	u_int		 sx;
1050 	u_int		 sy;
1051 
1052 	struct winlink	*curw;
1053 	struct winlink_stack lastw;
1054 	struct winlinks	 windows;
1055 
1056 	struct options	 options;
1057 
1058 #define SESSION_UNATTACHED 0x1	/* not attached to any clients */
1059 	int		 flags;
1060 
1061 	u_int            attached;
1062 
1063 	struct termios	*tio;
1064 
1065 	struct environ	 environ;
1066 
1067 	int		 references;
1068 
1069 	TAILQ_ENTRY(session) gentry;
1070 	RB_ENTRY(session)    entry;
1071 };
1072 RB_HEAD(sessions, session);
1073 ARRAY_DECL(sessionslist, struct session *);
1074 
1075 /* TTY information. */
1076 struct tty_key {
1077 	char		 ch;
1078 	int		 key;
1079 
1080 	struct tty_key	*left;
1081 	struct tty_key	*right;
1082 
1083 	struct tty_key	*next;
1084 };
1085 
1086 struct tty_term {
1087 	char		*name;
1088 	u_int		 references;
1089 
1090 	char		 acs[UCHAR_MAX + 1][2];
1091 
1092 	struct tty_code	 codes[NTTYCODE];
1093 
1094 #define TERM_256COLOURS 0x1
1095 #define TERM_EARLYWRAP 0x2
1096 	int		 flags;
1097 
1098 	LIST_ENTRY(tty_term) entry;
1099 };
1100 LIST_HEAD(tty_terms, tty_term);
1101 
1102 /* Mouse button masks. */
1103 #define MOUSE_MASK_BUTTONS 3
1104 #define MOUSE_MASK_SHIFT 4
1105 #define MOUSE_MASK_META 8
1106 #define MOUSE_MASK_CTRL 16
1107 #define MOUSE_MASK_DRAG 32
1108 #define MOUSE_MASK_WHEEL 64
1109 
1110 /* Mouse wheel states. */
1111 #define MOUSE_WHEEL_UP 0
1112 #define MOUSE_WHEEL_DOWN 1
1113 
1114 /* Mouse wheel multipler. */
1115 #define MOUSE_WHEEL_SCALE 3
1116 
1117 /* Mouse event bits. */
1118 #define MOUSE_EVENT_DOWN 0x1
1119 #define MOUSE_EVENT_DRAG 0x2
1120 #define MOUSE_EVENT_UP 0x4
1121 #define MOUSE_EVENT_CLICK 0x8
1122 #define MOUSE_EVENT_WHEEL 0x10
1123 
1124 /* Mouse flag bits. */
1125 #define MOUSE_RESIZE_PANE 0x1
1126 
1127 /*
1128  * Mouse input. When sent by xterm:
1129  *
1130  * - buttons are in the bottom two bits: 0 = b1; 1 = b2; 2 = b3; 3 = released
1131  * - bits 3, 4 and 5 are for keys
1132  * - bit 6 is set for dragging
1133  * - bit 7 for buttons 4 and 5
1134  *
1135  * With the SGR 1006 extension the released button becomes known. Store these
1136  * in separate fields and store the value converted to the old format in xb.
1137  */
1138 struct mouse_event {
1139 	u_int	xb;
1140 
1141 	u_int	x;
1142 	u_int	lx;
1143 	u_int	sx;
1144 
1145 	u_int	y;
1146 	u_int	ly;
1147 	u_int	sy;
1148 
1149 	u_int   sgr;		/* whether the input arrived in SGR format */
1150 	u_int   sgr_xb;		/* only for SGR: the unmangled button */
1151 	u_int   sgr_rel;	/* only for SGR: if it is a release event */
1152 
1153 	u_int	button;
1154 	u_int	clicks;
1155 	u_int	scroll;
1156 
1157 	int	wheel;
1158 	int     event;
1159 	int     flags;
1160 };
1161 
1162 struct tty {
1163 	struct client	*client;
1164 
1165 	char		*path;
1166 	u_int		 class;
1167 
1168 	u_int		 sx;
1169 	u_int		 sy;
1170 
1171 	u_int		 cx;
1172 	u_int		 cy;
1173 	u_int		 cstyle;
1174 	char		*ccolour;
1175 
1176 	int		 mode;
1177 
1178 	u_int		 rlower;
1179 	u_int		 rupper;
1180 
1181 	char		*termname;
1182 	struct tty_term	*term;
1183 
1184 	int		 fd;
1185 	struct bufferevent *event;
1186 
1187 	int		 log_fd;
1188 
1189 	struct termios	 tio;
1190 
1191 	struct grid_cell cell;
1192 
1193 #define TTY_NOCURSOR 0x1
1194 #define TTY_FREEZE 0x2
1195 #define TTY_TIMER 0x4
1196 #define TTY_UTF8 0x8
1197 #define TTY_STARTED 0x10
1198 #define TTY_OPENED 0x20
1199 #define TTY_FOCUS 0x40
1200 	int		 flags;
1201 
1202 	int		 term_flags;
1203 
1204 	struct mouse_event mouse;
1205 
1206 	struct event	 key_timer;
1207 	struct tty_key	*key_tree;
1208 };
1209 
1210 /* TTY command context and function pointer. */
1211 struct tty_ctx {
1212 	struct window_pane *wp;
1213 
1214 	const struct grid_cell *cell;
1215 
1216 	u_int		 num;
1217 	void		*ptr;
1218 
1219 	/*
1220 	 * Cursor and region position before the screen was updated - this is
1221 	 * where the command should be applied; the values in the screen have
1222 	 * already been updated.
1223 	 */
1224 	u_int		 ocx;
1225 	u_int		 ocy;
1226 
1227 	u_int		 orupper;
1228 	u_int		 orlower;
1229 
1230 	u_int		 xoff;
1231 	u_int		 yoff;
1232 
1233 	/* Saved last cell on line. */
1234 	struct grid_cell last_cell;
1235 	u_int		 last_width;
1236 };
1237 
1238 /* Saved message entry. */
1239 struct message_entry {
1240 	char   *msg;
1241 	time_t	msg_time;
1242 };
1243 
1244 /* Status output data from a job. */
1245 struct status_out {
1246 	char   *cmd;
1247 	char   *out;
1248 
1249 	RB_ENTRY(status_out) entry;
1250 };
1251 RB_HEAD(status_out_tree, status_out);
1252 
1253 /* Client connection. */
1254 struct client {
1255 	struct imsgbuf	 ibuf;
1256 
1257 	int		 fd;
1258 	struct event	 event;
1259 	int		 retval;
1260 
1261 	struct timeval	 creation_time;
1262 	struct timeval	 activity_time;
1263 
1264 	struct environ	 environ;
1265 
1266 	char		*title;
1267 	int		 cwd;
1268 
1269 	char		*term;
1270 	char		*ttyname;
1271 	struct tty	 tty;
1272 
1273 	void		(*stdin_callback)(struct client *, int, void *);
1274 	void		*stdin_callback_data;
1275 	struct evbuffer	*stdin_data;
1276 	int              stdin_closed;
1277 	struct evbuffer	*stdout_data;
1278 	struct evbuffer	*stderr_data;
1279 
1280 	struct event	 repeat_timer;
1281 
1282 	struct status_out_tree status_old;
1283 	struct status_out_tree status_new;
1284 	struct timeval	 status_timer;
1285 	struct screen	 status;
1286 
1287 #define CLIENT_TERMINAL 0x1
1288 #define CLIENT_PREFIX 0x2
1289 #define CLIENT_EXIT 0x4
1290 #define CLIENT_REDRAW 0x8
1291 #define CLIENT_STATUS 0x10
1292 #define CLIENT_REPEAT 0x20
1293 #define CLIENT_SUSPENDED 0x40
1294 #define CLIENT_BAD 0x80
1295 #define CLIENT_IDENTIFY 0x100
1296 #define CLIENT_DEAD 0x200
1297 #define CLIENT_BORDERS 0x400
1298 #define CLIENT_READONLY 0x800
1299 #define CLIENT_REDRAWWINDOW 0x1000
1300 #define CLIENT_CONTROL 0x2000
1301 #define CLIENT_CONTROLCONTROL 0x4000
1302 #define CLIENT_FOCUSED 0x8000
1303 #define CLIENT_UTF8 0x10000
1304 #define CLIENT_256COLOURS 0x20000
1305 #define CLIENT_IDENTIFIED 0x40000
1306 	int		 flags;
1307 
1308 	struct event	 identify_timer;
1309 
1310 	char		*message_string;
1311 	struct event	 message_timer;
1312 	ARRAY_DECL(, struct message_entry) message_log;
1313 
1314 	char		*prompt_string;
1315 	char		*prompt_buffer;
1316 	size_t		 prompt_index;
1317 	int		 (*prompt_callbackfn)(void *, const char *);
1318 	void		 (*prompt_freefn)(void *);
1319 	void		*prompt_data;
1320 	u_int            prompt_hindex;
1321 
1322 #define PROMPT_SINGLE 0x1
1323 	int		 prompt_flags;
1324 
1325 	struct mode_key_data prompt_mdata;
1326 
1327 	struct session	*session;
1328 	struct session	*last_session;
1329 
1330 	int		 wlmouse;
1331 
1332 	struct cmd_q	*cmdq;
1333 	int		 references;
1334 };
1335 ARRAY_DECL(clients, struct client *);
1336 
1337 /* Parsed arguments structures. */
1338 struct args_entry {
1339 	u_char			 flag;
1340 	char			*value;
1341 	RB_ENTRY(args_entry)	 entry;
1342 };
1343 RB_HEAD(args_tree, args_entry);
1344 
1345 struct args {
1346 	struct args_tree	  tree;
1347 	int		 	  argc;
1348 	char	       		**argv;
1349 };
1350 
1351 /* Command and list of commands. */
1352 struct cmd {
1353 	const struct cmd_entry	*entry;
1354 	struct args		*args;
1355 
1356 	char			*file;
1357 	u_int			 line;
1358 
1359 #define CMD_CONTROL 0x1
1360 	int			 flags;
1361 
1362 	TAILQ_ENTRY(cmd)	 qentry;
1363 };
1364 struct cmd_list {
1365 	int		 	 references;
1366 	TAILQ_HEAD(, cmd) 	 list;
1367 };
1368 
1369 /* Command return values. */
1370 enum cmd_retval {
1371 	CMD_RETURN_ERROR = -1,
1372 	CMD_RETURN_NORMAL = 0,
1373 	CMD_RETURN_WAIT,
1374 	CMD_RETURN_STOP
1375 };
1376 
1377 /* Command queue entry. */
1378 struct cmd_q_item {
1379 	struct cmd_list		*cmdlist;
1380 	TAILQ_ENTRY(cmd_q_item)	 qentry;
1381 };
1382 TAILQ_HEAD(cmd_q_items, cmd_q_item);
1383 
1384 /* Command queue. */
1385 struct cmd_q {
1386 	int			 references;
1387 	int			 dead;
1388 
1389 	struct client		*client;
1390 	int			 client_exit;
1391 
1392 	struct cmd_q_items	 queue;
1393 	struct cmd_q_item	*item;
1394 	struct cmd		*cmd;
1395 
1396 	time_t			 time;
1397 	u_int			 number;
1398 
1399 	void			 (*emptyfn)(struct cmd_q *);
1400 	void			*data;
1401 
1402 	TAILQ_ENTRY(cmd_q)       waitentry;
1403 };
1404 
1405 /* Command definition. */
1406 struct cmd_entry {
1407 	const char	*name;
1408 	const char	*alias;
1409 
1410 	const char	*args_template;
1411 	int		 args_lower;
1412 	int		 args_upper;
1413 
1414 	const char	*usage;
1415 
1416 #define CMD_STARTSERVER 0x1
1417 #define CMD_CANTNEST 0x2
1418 #define CMD_READONLY 0x4
1419 	int		 flags;
1420 
1421 	enum cmd_retval	 (*exec)(struct cmd *, struct cmd_q *);
1422 };
1423 
1424 /* Key binding. */
1425 struct key_binding {
1426 	int		 key;
1427 	struct cmd_list	*cmdlist;
1428 	int		 can_repeat;
1429 
1430 	RB_ENTRY(key_binding) entry;
1431 };
1432 RB_HEAD(key_bindings, key_binding);
1433 
1434 /*
1435  * Option table entries. The option table is the user-visible part of the
1436  * option, as opposed to the internal options (struct option) which are just
1437  * number or string.
1438  */
1439 enum options_table_type {
1440 	OPTIONS_TABLE_STRING,
1441 	OPTIONS_TABLE_NUMBER,
1442 	OPTIONS_TABLE_KEY,
1443 	OPTIONS_TABLE_COLOUR,
1444 	OPTIONS_TABLE_ATTRIBUTES,
1445 	OPTIONS_TABLE_FLAG,
1446 	OPTIONS_TABLE_CHOICE,
1447 	OPTIONS_TABLE_STYLE
1448 };
1449 
1450 struct options_table_entry {
1451 	const char	       *name;
1452 	enum options_table_type	type;
1453 
1454 	u_int		 	minimum;
1455 	u_int		 	maximum;
1456 	const char	      **choices;
1457 
1458 	const char	       *default_str;
1459 	long long		default_num;
1460 
1461 	const char	       *style;
1462 };
1463 
1464 /* Tree of format entries. */
1465 struct format_entry {
1466 	char		       *key;
1467 	char		       *value;
1468 
1469 	RB_ENTRY(format_entry)	entry;
1470 };
1471 RB_HEAD(format_tree, format_entry);
1472 
1473 /* Common command usages. */
1474 #define CMD_TARGET_PANE_USAGE "[-t target-pane]"
1475 #define CMD_TARGET_WINDOW_USAGE "[-t target-window]"
1476 #define CMD_TARGET_SESSION_USAGE "[-t target-session]"
1477 #define CMD_TARGET_CLIENT_USAGE "[-t target-client]"
1478 #define CMD_SRCDST_PANE_USAGE "[-s src-pane] [-t dst-pane]"
1479 #define CMD_SRCDST_WINDOW_USAGE "[-s src-window] [-t dst-window]"
1480 #define CMD_SRCDST_SESSION_USAGE "[-s src-session] [-t dst-session]"
1481 #define CMD_SRCDST_CLIENT_USAGE "[-s src-client] [-t dst-client]"
1482 #define CMD_BUFFER_USAGE "[-b buffer-name]"
1483 
1484 /* tmux.c */
1485 extern struct options global_options;
1486 extern struct options global_s_options;
1487 extern struct options global_w_options;
1488 extern struct environ global_environ;
1489 extern struct event_base *ev_base;
1490 extern char	*cfg_file;
1491 extern char	*shell_cmd;
1492 extern int	 debug_level;
1493 extern time_t	 start_time;
1494 extern char	 socket_path[PATH_MAX];
1495 extern int	 login_shell;
1496 extern char	*environ_path;
1497 void		 logfile(const char *);
1498 const char	*getshell(void);
1499 int		 checkshell(const char *);
1500 int		 areshell(const char *);
1501 void		 setblocking(int, int);
1502 __dead void	 shell_exec(const char *, const char *);
1503 
1504 /* cfg.c */
1505 extern struct cmd_q *cfg_cmd_q;
1506 extern int cfg_finished;
1507 extern int cfg_references;
1508 extern struct client *cfg_client;
1509 int		 load_cfg(const char *, struct cmd_q *, char **);
1510 void		 cfg_default_done(struct cmd_q *);
1511 void		 cfg_add_cause(const char *, ...);
1512 void		 cfg_print_causes(struct cmd_q *);
1513 void		 cfg_show_causes(struct session *);
1514 
1515 /* format.c */
1516 int		 format_cmp(struct format_entry *, struct format_entry *);
1517 RB_PROTOTYPE(format_tree, format_entry, entry, format_cmp);
1518 struct format_tree *format_create(void);
1519 void		 format_free(struct format_tree *);
1520 void printflike(3, 4) format_add(struct format_tree *, const char *,
1521 		     const char *, ...);
1522 const char	*format_find(struct format_tree *, const char *);
1523 char		*format_expand(struct format_tree *, const char *);
1524 void		 format_session(struct format_tree *, struct session *);
1525 void		 format_client(struct format_tree *, struct client *);
1526 void		 format_window(struct format_tree *, struct window *);
1527 void		 format_winlink(struct format_tree *, struct session *,
1528 		     struct winlink *);
1529 void		 format_window_pane(struct format_tree *,
1530 		     struct window_pane *);
1531 void		 format_paste_buffer(struct format_tree *,
1532 		     struct paste_buffer *, int);
1533 
1534 /* mode-key.c */
1535 extern const struct mode_key_table mode_key_tables[];
1536 extern struct mode_key_tree mode_key_tree_vi_edit;
1537 extern struct mode_key_tree mode_key_tree_vi_choice;
1538 extern struct mode_key_tree mode_key_tree_vi_copy;
1539 extern struct mode_key_tree mode_key_tree_emacs_edit;
1540 extern struct mode_key_tree mode_key_tree_emacs_choice;
1541 extern struct mode_key_tree mode_key_tree_emacs_copy;
1542 int	mode_key_cmp(struct mode_key_binding *, struct mode_key_binding *);
1543 RB_PROTOTYPE(mode_key_tree, mode_key_binding, entry, mode_key_cmp);
1544 const char *mode_key_tostring(const struct mode_key_cmdstr *,
1545 	    enum mode_key_cmd);
1546 enum mode_key_cmd mode_key_fromstring(const struct mode_key_cmdstr *,
1547 	    const char *);
1548 const struct mode_key_table *mode_key_findtable(const char *);
1549 void	mode_key_init_trees(void);
1550 void	mode_key_init(struct mode_key_data *, struct mode_key_tree *);
1551 enum mode_key_cmd mode_key_lookup(struct mode_key_data *, int, const char **);
1552 
1553 /* notify.c */
1554 void	notify_enable(void);
1555 void	notify_disable(void);
1556 void	notify_input(struct window_pane *, struct evbuffer *);
1557 void	notify_window_layout_changed(struct window *);
1558 void	notify_window_unlinked(struct session *, struct window *);
1559 void	notify_window_linked(struct session *, struct window *);
1560 void	notify_window_renamed(struct window *);
1561 void	notify_attached_session_changed(struct client *);
1562 void	notify_session_renamed(struct session *);
1563 void	notify_session_created(struct session *);
1564 void	notify_session_closed(struct session *);
1565 
1566 /* options.c */
1567 int	options_cmp(struct options_entry *, struct options_entry *);
1568 RB_PROTOTYPE(options_tree, options_entry, entry, options_cmp);
1569 void	options_init(struct options *, struct options *);
1570 void	options_free(struct options *);
1571 struct options_entry *options_find1(struct options *, const char *);
1572 struct options_entry *options_find(struct options *, const char *);
1573 void	options_remove(struct options *, const char *);
1574 struct options_entry *printflike(3, 4) options_set_string(struct options *,
1575 	    const char *, const char *, ...);
1576 char   *options_get_string(struct options *, const char *);
1577 struct options_entry *options_set_number(struct options *, const char *,
1578 	    long long);
1579 long long options_get_number(struct options *, const char *);
1580 struct options_entry *options_set_style(struct options *, const char *,
1581 	    const char *, int);
1582 struct grid_cell *options_get_style(struct options *, const char *);
1583 
1584 /* options-table.c */
1585 extern const struct options_table_entry server_options_table[];
1586 extern const struct options_table_entry session_options_table[];
1587 extern const struct options_table_entry window_options_table[];
1588 void	options_table_populate_tree(const struct options_table_entry *,
1589 	    struct options *);
1590 const char *options_table_print_entry(const struct options_table_entry *,
1591 	    struct options_entry *, int);
1592 int	options_table_find(const char *, const struct options_table_entry **,
1593 	    const struct options_table_entry **);
1594 
1595 /* job.c */
1596 extern struct joblist all_jobs;
1597 struct job *job_run(const char *, struct session *,
1598 	    void (*)(struct job *), void (*)(void *), void *);
1599 void	job_free(struct job *);
1600 void	job_died(struct job *, int);
1601 
1602 /* environ.c */
1603 int	environ_cmp(struct environ_entry *, struct environ_entry *);
1604 RB_PROTOTYPE(environ, environ_entry, entry, environ_cmp);
1605 void	environ_init(struct environ *);
1606 void	environ_free(struct environ *);
1607 void	environ_copy(struct environ *, struct environ *);
1608 struct environ_entry *environ_find(struct environ *, const char *);
1609 void	environ_set(struct environ *, const char *, const char *);
1610 void	environ_put(struct environ *, const char *);
1611 void	environ_unset(struct environ *, const char *);
1612 void	environ_update(const char *, struct environ *, struct environ *);
1613 void	environ_push(struct environ *);
1614 
1615 /* tty.c */
1616 void	tty_init_termios(int, struct termios *, struct bufferevent *);
1617 void	tty_raw(struct tty *, const char *);
1618 void	tty_attributes(struct tty *, const struct grid_cell *);
1619 void	tty_reset(struct tty *);
1620 void	tty_region_pane(struct tty *, const struct tty_ctx *, u_int, u_int);
1621 void	tty_region(struct tty *, u_int, u_int);
1622 void	tty_cursor_pane(struct tty *, const struct tty_ctx *, u_int, u_int);
1623 void	tty_cursor(struct tty *, u_int, u_int);
1624 void	tty_putcode(struct tty *, enum tty_code_code);
1625 void	tty_putcode1(struct tty *, enum tty_code_code, int);
1626 void	tty_putcode2(struct tty *, enum tty_code_code, int, int);
1627 void	tty_putcode_ptr1(struct tty *, enum tty_code_code, const void *);
1628 void	tty_putcode_ptr2(struct tty *, enum tty_code_code, const void *,
1629 	    const void *);
1630 void	tty_puts(struct tty *, const char *);
1631 void	tty_putc(struct tty *, u_char);
1632 void	tty_putn(struct tty *, const void *, size_t, u_int);
1633 void	tty_init(struct tty *, struct client *, int, char *);
1634 int	tty_resize(struct tty *);
1635 int	tty_set_size(struct tty *, u_int, u_int);
1636 void	tty_set_class(struct tty *, u_int);
1637 void	tty_start_tty(struct tty *);
1638 void	tty_stop_tty(struct tty *);
1639 void	tty_set_title(struct tty *, const char *);
1640 void	tty_update_mode(struct tty *, int, struct screen *);
1641 void	tty_force_cursor_colour(struct tty *, const char *);
1642 void	tty_draw_line(struct tty *, struct screen *, u_int, u_int, u_int);
1643 int	tty_open(struct tty *, char **);
1644 void	tty_close(struct tty *);
1645 void	tty_free(struct tty *);
1646 void	tty_write(
1647 	    void (*)(struct tty *, const struct tty_ctx *), struct tty_ctx *);
1648 void	tty_cmd_alignmenttest(struct tty *, const struct tty_ctx *);
1649 void	tty_cmd_cell(struct tty *, const struct tty_ctx *);
1650 void	tty_cmd_clearendofline(struct tty *, const struct tty_ctx *);
1651 void	tty_cmd_clearendofscreen(struct tty *, const struct tty_ctx *);
1652 void	tty_cmd_clearline(struct tty *, const struct tty_ctx *);
1653 void	tty_cmd_clearscreen(struct tty *, const struct tty_ctx *);
1654 void	tty_cmd_clearstartofline(struct tty *, const struct tty_ctx *);
1655 void	tty_cmd_clearstartofscreen(struct tty *, const struct tty_ctx *);
1656 void	tty_cmd_deletecharacter(struct tty *, const struct tty_ctx *);
1657 void	tty_cmd_clearcharacter(struct tty *, const struct tty_ctx *);
1658 void	tty_cmd_deleteline(struct tty *, const struct tty_ctx *);
1659 void	tty_cmd_erasecharacter(struct tty *, const struct tty_ctx *);
1660 void	tty_cmd_insertcharacter(struct tty *, const struct tty_ctx *);
1661 void	tty_cmd_insertline(struct tty *, const struct tty_ctx *);
1662 void	tty_cmd_linefeed(struct tty *, const struct tty_ctx *);
1663 void	tty_cmd_utf8character(struct tty *, const struct tty_ctx *);
1664 void	tty_cmd_reverseindex(struct tty *, const struct tty_ctx *);
1665 void	tty_cmd_setselection(struct tty *, const struct tty_ctx *);
1666 void	tty_cmd_rawstring(struct tty *, const struct tty_ctx *);
1667 void	tty_bell(struct tty *);
1668 
1669 /* tty-term.c */
1670 extern struct tty_terms tty_terms;
1671 extern const struct tty_term_code_entry tty_term_codes[NTTYCODE];
1672 struct tty_term *tty_term_find(char *, int, char **);
1673 void		 tty_term_free(struct tty_term *);
1674 int		 tty_term_has(struct tty_term *, enum tty_code_code);
1675 const char	*tty_term_string(struct tty_term *, enum tty_code_code);
1676 const char	*tty_term_string1(struct tty_term *, enum tty_code_code, int);
1677 const char	*tty_term_string2(
1678 		     struct tty_term *, enum tty_code_code, int, int);
1679 const char	*tty_term_ptr1(
1680 		     struct tty_term *, enum tty_code_code, const void *);
1681 const char	*tty_term_ptr2(struct tty_term *, enum tty_code_code,
1682 		     const void *, const void *);
1683 int		 tty_term_number(struct tty_term *, enum tty_code_code);
1684 int		 tty_term_flag(struct tty_term *, enum tty_code_code);
1685 
1686 /* tty-acs.c */
1687 const char	*tty_acs_get(struct tty *, u_char);
1688 
1689 /* tty-keys.c */
1690 void	tty_keys_build(struct tty *);
1691 void	tty_keys_free(struct tty *);
1692 int	tty_keys_next(struct tty *);
1693 
1694 /* paste.c */
1695 struct paste_buffer *paste_walk(struct paste_buffer *);
1696 struct paste_buffer *paste_get_top(void);
1697 struct paste_buffer *paste_get_name(const char *);
1698 int		 paste_free_top(void);
1699 int		 paste_free_name(const char *);
1700 void		 paste_add(char *, size_t);
1701 int		 paste_rename(const char *, const char *, char **);
1702 int		 paste_set(char *, size_t, const char *, char **);
1703 char		*paste_make_sample(struct paste_buffer *, int);
1704 void		 paste_send_pane(struct paste_buffer *, struct window_pane *,
1705 		     const char *, int);
1706 
1707 /* arguments.c */
1708 int		 args_cmp(struct args_entry *, struct args_entry *);
1709 RB_PROTOTYPE(args_tree, args_entry, entry, args_cmp);
1710 struct args	*args_create(int, ...);
1711 struct args	*args_parse(const char *, int, char **);
1712 void		 args_free(struct args *);
1713 size_t		 args_print(struct args *, char *, size_t);
1714 int		 args_has(struct args *, u_char);
1715 void		 args_set(struct args *, u_char, const char *);
1716 const char	*args_get(struct args *, u_char);
1717 long long	 args_strtonum(
1718 		    struct args *, u_char, long long, long long, char **);
1719 
1720 /* cmd.c */
1721 int		 cmd_pack_argv(int, char **, char *, size_t);
1722 int		 cmd_unpack_argv(char *, size_t, int, char ***);
1723 char	       **cmd_copy_argv(int, char **);
1724 void		 cmd_free_argv(int, char **);
1725 char		*cmd_stringify_argv(int, char **);
1726 struct cmd	*cmd_parse(int, char **, const char *, u_int, char **);
1727 size_t		 cmd_print(struct cmd *, char *, size_t);
1728 struct session	*cmd_current_session(struct cmd_q *, int);
1729 struct client	*cmd_current_client(struct cmd_q *);
1730 struct client	*cmd_find_client(struct cmd_q *, const char *, int);
1731 struct session	*cmd_find_session(struct cmd_q *, const char *, int);
1732 struct winlink	*cmd_find_window(struct cmd_q *, const char *,
1733 		     struct session **);
1734 int		 cmd_find_index(struct cmd_q *, const char *,
1735 		     struct session **);
1736 struct winlink	*cmd_find_pane(struct cmd_q *, const char *, struct session **,
1737 		     struct window_pane **);
1738 char		*cmd_template_replace(const char *, const char *, int);
1739 struct window	*cmd_lookup_windowid(const char *);
1740 struct window_pane *cmd_lookup_paneid(const char *);
1741 extern const struct cmd_entry *cmd_table[];
1742 extern const struct cmd_entry cmd_attach_session_entry;
1743 extern const struct cmd_entry cmd_bind_key_entry;
1744 extern const struct cmd_entry cmd_break_pane_entry;
1745 extern const struct cmd_entry cmd_capture_pane_entry;
1746 extern const struct cmd_entry cmd_choose_buffer_entry;
1747 extern const struct cmd_entry cmd_choose_client_entry;
1748 extern const struct cmd_entry cmd_choose_session_entry;
1749 extern const struct cmd_entry cmd_choose_tree_entry;
1750 extern const struct cmd_entry cmd_choose_window_entry;
1751 extern const struct cmd_entry cmd_clear_history_entry;
1752 extern const struct cmd_entry cmd_clock_mode_entry;
1753 extern const struct cmd_entry cmd_command_prompt_entry;
1754 extern const struct cmd_entry cmd_confirm_before_entry;
1755 extern const struct cmd_entry cmd_copy_mode_entry;
1756 extern const struct cmd_entry cmd_delete_buffer_entry;
1757 extern const struct cmd_entry cmd_detach_client_entry;
1758 extern const struct cmd_entry cmd_display_message_entry;
1759 extern const struct cmd_entry cmd_display_panes_entry;
1760 extern const struct cmd_entry cmd_down_pane_entry;
1761 extern const struct cmd_entry cmd_find_window_entry;
1762 extern const struct cmd_entry cmd_has_session_entry;
1763 extern const struct cmd_entry cmd_if_shell_entry;
1764 extern const struct cmd_entry cmd_join_pane_entry;
1765 extern const struct cmd_entry cmd_kill_pane_entry;
1766 extern const struct cmd_entry cmd_kill_server_entry;
1767 extern const struct cmd_entry cmd_kill_session_entry;
1768 extern const struct cmd_entry cmd_kill_window_entry;
1769 extern const struct cmd_entry cmd_last_pane_entry;
1770 extern const struct cmd_entry cmd_last_window_entry;
1771 extern const struct cmd_entry cmd_link_window_entry;
1772 extern const struct cmd_entry cmd_list_buffers_entry;
1773 extern const struct cmd_entry cmd_list_clients_entry;
1774 extern const struct cmd_entry cmd_list_commands_entry;
1775 extern const struct cmd_entry cmd_list_keys_entry;
1776 extern const struct cmd_entry cmd_list_panes_entry;
1777 extern const struct cmd_entry cmd_list_sessions_entry;
1778 extern const struct cmd_entry cmd_list_windows_entry;
1779 extern const struct cmd_entry cmd_load_buffer_entry;
1780 extern const struct cmd_entry cmd_lock_client_entry;
1781 extern const struct cmd_entry cmd_lock_server_entry;
1782 extern const struct cmd_entry cmd_lock_session_entry;
1783 extern const struct cmd_entry cmd_move_pane_entry;
1784 extern const struct cmd_entry cmd_move_window_entry;
1785 extern const struct cmd_entry cmd_new_session_entry;
1786 extern const struct cmd_entry cmd_new_window_entry;
1787 extern const struct cmd_entry cmd_next_layout_entry;
1788 extern const struct cmd_entry cmd_next_window_entry;
1789 extern const struct cmd_entry cmd_paste_buffer_entry;
1790 extern const struct cmd_entry cmd_pipe_pane_entry;
1791 extern const struct cmd_entry cmd_previous_layout_entry;
1792 extern const struct cmd_entry cmd_previous_window_entry;
1793 extern const struct cmd_entry cmd_refresh_client_entry;
1794 extern const struct cmd_entry cmd_rename_session_entry;
1795 extern const struct cmd_entry cmd_rename_window_entry;
1796 extern const struct cmd_entry cmd_resize_pane_entry;
1797 extern const struct cmd_entry cmd_respawn_pane_entry;
1798 extern const struct cmd_entry cmd_respawn_window_entry;
1799 extern const struct cmd_entry cmd_rotate_window_entry;
1800 extern const struct cmd_entry cmd_run_shell_entry;
1801 extern const struct cmd_entry cmd_save_buffer_entry;
1802 extern const struct cmd_entry cmd_select_layout_entry;
1803 extern const struct cmd_entry cmd_select_pane_entry;
1804 extern const struct cmd_entry cmd_select_window_entry;
1805 extern const struct cmd_entry cmd_send_keys_entry;
1806 extern const struct cmd_entry cmd_send_prefix_entry;
1807 extern const struct cmd_entry cmd_server_info_entry;
1808 extern const struct cmd_entry cmd_set_buffer_entry;
1809 extern const struct cmd_entry cmd_set_environment_entry;
1810 extern const struct cmd_entry cmd_set_option_entry;
1811 extern const struct cmd_entry cmd_set_window_option_entry;
1812 extern const struct cmd_entry cmd_show_buffer_entry;
1813 extern const struct cmd_entry cmd_show_environment_entry;
1814 extern const struct cmd_entry cmd_show_messages_entry;
1815 extern const struct cmd_entry cmd_show_options_entry;
1816 extern const struct cmd_entry cmd_show_window_options_entry;
1817 extern const struct cmd_entry cmd_source_file_entry;
1818 extern const struct cmd_entry cmd_split_window_entry;
1819 extern const struct cmd_entry cmd_start_server_entry;
1820 extern const struct cmd_entry cmd_suspend_client_entry;
1821 extern const struct cmd_entry cmd_swap_pane_entry;
1822 extern const struct cmd_entry cmd_swap_window_entry;
1823 extern const struct cmd_entry cmd_switch_client_entry;
1824 extern const struct cmd_entry cmd_unbind_key_entry;
1825 extern const struct cmd_entry cmd_unlink_window_entry;
1826 extern const struct cmd_entry cmd_up_pane_entry;
1827 extern const struct cmd_entry cmd_wait_for_entry;
1828 
1829 /* cmd-attach-session.c */
1830 enum cmd_retval	 cmd_attach_session(struct cmd_q *, const char *, int, int,
1831 		     const char *);
1832 
1833 /* cmd-list.c */
1834 struct cmd_list	*cmd_list_parse(int, char **, const char *, u_int, char **);
1835 void		 cmd_list_free(struct cmd_list *);
1836 size_t		 cmd_list_print(struct cmd_list *, char *, size_t);
1837 
1838 /* cmd-queue.c */
1839 struct cmd_q	*cmdq_new(struct client *);
1840 int		 cmdq_free(struct cmd_q *);
1841 void printflike(2, 3) cmdq_print(struct cmd_q *, const char *, ...);
1842 void printflike(2, 3) cmdq_error(struct cmd_q *, const char *, ...);
1843 int		 cmdq_guard(struct cmd_q *, const char *, int);
1844 void		 cmdq_run(struct cmd_q *, struct cmd_list *);
1845 void		 cmdq_append(struct cmd_q *, struct cmd_list *);
1846 int		 cmdq_continue(struct cmd_q *);
1847 void		 cmdq_flush(struct cmd_q *);
1848 
1849 /* cmd-string.c */
1850 int	cmd_string_parse(const char *, struct cmd_list **, const char *,
1851 	    u_int, char **);
1852 
1853 /* cmd-wait-for.c */
1854 void	cmd_wait_for_flush(void);
1855 
1856 /* client.c */
1857 int	client_main(int, char **, int);
1858 
1859 /* key-bindings.c */
1860 extern struct key_bindings key_bindings;
1861 int	 key_bindings_cmp(struct key_binding *, struct key_binding *);
1862 RB_PROTOTYPE(key_bindings, key_binding, entry, key_bindings_cmp);
1863 struct key_binding *key_bindings_lookup(int);
1864 void	 key_bindings_add(int, int, struct cmd_list *);
1865 void	 key_bindings_remove(int);
1866 void	 key_bindings_init(void);
1867 void	 key_bindings_dispatch(struct key_binding *, struct client *);
1868 
1869 /* key-string.c */
1870 int	 key_string_lookup_string(const char *);
1871 const char *key_string_lookup_key(int);
1872 
1873 /* server.c */
1874 extern struct clients clients;
1875 extern struct clients dead_clients;
1876 int	 server_start(int, char *);
1877 void	 server_update_socket(void);
1878 void	 server_add_accept(int);
1879 
1880 /* server-client.c */
1881 void	 server_client_handle_key(struct client *, int);
1882 void	 server_client_create(int);
1883 int      server_client_open(struct client *, char **);
1884 void	 server_client_lost(struct client *);
1885 void	 server_client_callback(int, short, void *);
1886 void	 server_client_status_timer(void);
1887 void	 server_client_loop(void);
1888 
1889 /* server-window.c */
1890 void	 server_window_loop(void);
1891 
1892 /* server-fn.c */
1893 void	 server_fill_environ(struct session *, struct environ *);
1894 void	 server_write_ready(struct client *);
1895 int	 server_write_client(struct client *, enum msgtype, const void *,
1896 	     size_t);
1897 void	 server_write_session(struct session *, enum msgtype, const void *,
1898 	     size_t);
1899 void	 server_redraw_client(struct client *);
1900 void	 server_status_client(struct client *);
1901 void	 server_redraw_session(struct session *);
1902 void	 server_redraw_session_group(struct session *);
1903 void	 server_status_session(struct session *);
1904 void	 server_status_session_group(struct session *);
1905 void	 server_redraw_window(struct window *);
1906 void	 server_redraw_window_borders(struct window *);
1907 void	 server_status_window(struct window *);
1908 void	 server_lock(void);
1909 void	 server_lock_session(struct session *);
1910 void	 server_lock_client(struct client *);
1911 int	 server_unlock(const char *);
1912 void	 server_kill_window(struct window *);
1913 int	 server_link_window(struct session *,
1914 	     struct winlink *, struct session *, int, int, int, char **);
1915 void	 server_unlink_window(struct session *, struct winlink *);
1916 void	 server_destroy_pane(struct window_pane *);
1917 void	 server_destroy_session_group(struct session *);
1918 void	 server_destroy_session(struct session *);
1919 void	 server_check_unattached(void);
1920 void	 server_set_identify(struct client *);
1921 void	 server_clear_identify(struct client *);
1922 void	 server_update_event(struct client *);
1923 void	 server_push_stdout(struct client *);
1924 void	 server_push_stderr(struct client *);
1925 int	 server_set_stdin_callback(struct client *, void (*)(struct client *,
1926 	     int, void *), void *, char **);
1927 void	 server_unzoom_window(struct window *);
1928 
1929 /* status.c */
1930 int	 status_out_cmp(struct status_out *, struct status_out *);
1931 RB_PROTOTYPE(status_out_tree, status_out, entry, status_out_cmp);
1932 int	 status_at_line(struct client *);
1933 void	 status_free_jobs(struct status_out_tree *);
1934 void	 status_update_jobs(struct client *);
1935 void	 status_set_window_at(struct client *, u_int);
1936 int	 status_redraw(struct client *);
1937 char	*status_replace(struct client *, struct session *, struct winlink *,
1938 	     struct window_pane *, const char *, time_t, int);
1939 void printflike(2, 3) status_message_set(struct client *, const char *, ...);
1940 void	 status_message_clear(struct client *);
1941 int	 status_message_redraw(struct client *);
1942 void	 status_prompt_set(struct client *, const char *, const char *,
1943 	     int (*)(void *, const char *), void (*)(void *), void *, int);
1944 void	 status_prompt_clear(struct client *);
1945 int	 status_prompt_redraw(struct client *);
1946 void	 status_prompt_key(struct client *, int);
1947 void	 status_prompt_update(struct client *, const char *, const char *);
1948 
1949 /* resize.c */
1950 void	 recalculate_sizes(void);
1951 
1952 /* input.c */
1953 void	 input_init(struct window_pane *);
1954 void	 input_free(struct window_pane *);
1955 void	 input_parse(struct window_pane *);
1956 
1957 /* input-key.c */
1958 void	 input_key(struct window_pane *, int);
1959 void	 input_mouse(struct window_pane *, struct session *,
1960 	     struct mouse_event *);
1961 
1962 /* xterm-keys.c */
1963 char	*xterm_keys_lookup(int);
1964 int	 xterm_keys_find(const char *, size_t, size_t *, int *);
1965 
1966 /* colour.c */
1967 void	 colour_set_fg(struct grid_cell *, int);
1968 void	 colour_set_bg(struct grid_cell *, int);
1969 const char *colour_tostring(int);
1970 int	 colour_fromstring(const char *);
1971 u_char	 colour_256to16(u_char);
1972 
1973 /* attributes.c */
1974 const char *attributes_tostring(u_char);
1975 int	 attributes_fromstring(const char *);
1976 
1977 /* grid.c */
1978 extern const struct grid_cell grid_default_cell;
1979 extern const struct grid_cell grid_marker_cell;
1980 struct grid *grid_create(u_int, u_int, u_int);
1981 void	 grid_destroy(struct grid *);
1982 int	 grid_compare(struct grid *, struct grid *);
1983 void	 grid_collect_history(struct grid *);
1984 void	 grid_scroll_history(struct grid *);
1985 void	 grid_scroll_history_region(struct grid *, u_int, u_int);
1986 void	 grid_expand_line(struct grid *, u_int, u_int);
1987 const struct grid_cell *grid_peek_cell(struct grid *, u_int, u_int);
1988 const struct grid_line *grid_peek_line(struct grid *, u_int);
1989 struct grid_cell *grid_get_cell(struct grid *, u_int, u_int);
1990 void	 grid_set_cell(struct grid *, u_int, u_int, const struct grid_cell *);
1991 void	 grid_clear(struct grid *, u_int, u_int, u_int, u_int);
1992 void	 grid_clear_lines(struct grid *, u_int, u_int);
1993 void	 grid_move_lines(struct grid *, u_int, u_int, u_int);
1994 void	 grid_move_cells(struct grid *, u_int, u_int, u_int, u_int);
1995 char	*grid_string_cells(struct grid *, u_int, u_int, u_int,
1996 	     struct grid_cell **, int, int, int);
1997 void	 grid_duplicate_lines(
1998 	     struct grid *, u_int, struct grid *, u_int, u_int);
1999 u_int	 grid_reflow(struct grid *, struct grid *, u_int);
2000 
2001 /* grid-cell.c */
2002 u_int	 grid_cell_width(const struct grid_cell *);
2003 void	 grid_cell_get(const struct grid_cell *, struct utf8_data *);
2004 void	 grid_cell_set(struct grid_cell *, const struct utf8_data *);
2005 void	 grid_cell_one(struct grid_cell *, u_char);
2006 
2007 /* grid-view.c */
2008 const struct grid_cell *grid_view_peek_cell(struct grid *, u_int, u_int);
2009 struct grid_cell *grid_view_get_cell(struct grid *, u_int, u_int);
2010 void	 grid_view_set_cell(
2011 	     struct grid *, u_int, u_int, const struct grid_cell *);
2012 void	 grid_view_clear_history(struct grid *);
2013 void	 grid_view_clear(struct grid *, u_int, u_int, u_int, u_int);
2014 void	 grid_view_scroll_region_up(struct grid *, u_int, u_int);
2015 void	 grid_view_scroll_region_down(struct grid *, u_int, u_int);
2016 void	 grid_view_insert_lines(struct grid *, u_int, u_int);
2017 void	 grid_view_insert_lines_region(struct grid *, u_int, u_int, u_int);
2018 void	 grid_view_delete_lines(struct grid *, u_int, u_int);
2019 void	 grid_view_delete_lines_region(struct grid *, u_int, u_int, u_int);
2020 void	 grid_view_insert_cells(struct grid *, u_int, u_int, u_int);
2021 void	 grid_view_delete_cells(struct grid *, u_int, u_int, u_int);
2022 char	*grid_view_string_cells(struct grid *, u_int, u_int, u_int);
2023 
2024 /* screen-write.c */
2025 void	 screen_write_start(
2026 	     struct screen_write_ctx *, struct window_pane *, struct screen *);
2027 void	 screen_write_stop(struct screen_write_ctx *);
2028 void	 screen_write_reset(struct screen_write_ctx *);
2029 size_t printflike(2, 3) screen_write_cstrlen(int, const char *, ...);
2030 void printflike(5, 6) screen_write_cnputs(struct screen_write_ctx *,
2031 	     ssize_t, struct grid_cell *, int, const char *, ...);
2032 size_t printflike(2, 3) screen_write_strlen(int, const char *, ...);
2033 void printflike(3, 4) screen_write_puts(struct screen_write_ctx *,
2034 	     struct grid_cell *, const char *, ...);
2035 void printflike(5, 6) screen_write_nputs(struct screen_write_ctx *,
2036 	     ssize_t, struct grid_cell *, int, const char *, ...);
2037 void	 screen_write_vnputs(struct screen_write_ctx *,
2038 	     ssize_t, struct grid_cell *, int, const char *, va_list);
2039 void	 screen_write_putc(
2040 	     struct screen_write_ctx *, struct grid_cell *, u_char);
2041 void	 screen_write_copy(struct screen_write_ctx *,
2042 	     struct screen *, u_int, u_int, u_int, u_int);
2043 void	 screen_write_backspace(struct screen_write_ctx *);
2044 void	 screen_write_mode_set(struct screen_write_ctx *, int);
2045 void	 screen_write_mode_clear(struct screen_write_ctx *, int);
2046 void	 screen_write_cursorup(struct screen_write_ctx *, u_int);
2047 void	 screen_write_cursordown(struct screen_write_ctx *, u_int);
2048 void	 screen_write_cursorright(struct screen_write_ctx *, u_int);
2049 void	 screen_write_cursorleft(struct screen_write_ctx *, u_int);
2050 void	 screen_write_alignmenttest(struct screen_write_ctx *);
2051 void	 screen_write_insertcharacter(struct screen_write_ctx *, u_int);
2052 void	 screen_write_deletecharacter(struct screen_write_ctx *, u_int);
2053 void	 screen_write_clearcharacter(struct screen_write_ctx *, u_int);
2054 void	 screen_write_insertline(struct screen_write_ctx *, u_int);
2055 void	 screen_write_deleteline(struct screen_write_ctx *, u_int);
2056 void	 screen_write_clearline(struct screen_write_ctx *);
2057 void	 screen_write_clearendofline(struct screen_write_ctx *);
2058 void	 screen_write_clearstartofline(struct screen_write_ctx *);
2059 void	 screen_write_cursormove(struct screen_write_ctx *, u_int, u_int);
2060 void	 screen_write_reverseindex(struct screen_write_ctx *);
2061 void	 screen_write_scrollregion(struct screen_write_ctx *, u_int, u_int);
2062 void	 screen_write_linefeed(struct screen_write_ctx *, int);
2063 void	 screen_write_linefeedscreen(struct screen_write_ctx *, int);
2064 void	 screen_write_carriagereturn(struct screen_write_ctx *);
2065 void	 screen_write_clearendofscreen(struct screen_write_ctx *);
2066 void	 screen_write_clearstartofscreen(struct screen_write_ctx *);
2067 void	 screen_write_clearscreen(struct screen_write_ctx *);
2068 void	 screen_write_clearhistory(struct screen_write_ctx *);
2069 void	 screen_write_cell(struct screen_write_ctx *, const struct grid_cell *);
2070 void	 screen_write_setselection(struct screen_write_ctx *, u_char *, u_int);
2071 void	 screen_write_rawstring(struct screen_write_ctx *, u_char *, u_int);
2072 
2073 /* screen-redraw.c */
2074 void	 screen_redraw_screen(struct client *, int, int, int);
2075 void	 screen_redraw_pane(struct client *, struct window_pane *);
2076 
2077 /* screen.c */
2078 void	 screen_init(struct screen *, u_int, u_int, u_int);
2079 void	 screen_reinit(struct screen *);
2080 void	 screen_free(struct screen *);
2081 void	 screen_reset_tabs(struct screen *);
2082 void	 screen_set_cursor_style(struct screen *, u_int);
2083 void	 screen_set_cursor_colour(struct screen *, const char *);
2084 void	 screen_set_title(struct screen *, const char *);
2085 void	 screen_resize(struct screen *, u_int, u_int, int);
2086 void	 screen_set_selection(struct screen *,
2087 	     u_int, u_int, u_int, u_int, u_int, struct grid_cell *);
2088 void	 screen_clear_selection(struct screen *);
2089 int	 screen_check_selection(struct screen *, u_int, u_int);
2090 void	 screen_reflow(struct screen *, u_int);
2091 
2092 /* window.c */
2093 extern struct windows windows;
2094 extern struct window_pane_tree all_window_panes;
2095 int		 winlink_cmp(struct winlink *, struct winlink *);
2096 RB_PROTOTYPE(winlinks, winlink, entry, winlink_cmp);
2097 int		 window_pane_cmp(struct window_pane *, struct window_pane *);
2098 RB_PROTOTYPE(window_pane_tree, window_pane, tree_entry, window_pane_cmp);
2099 struct winlink	*winlink_find_by_index(struct winlinks *, int);
2100 struct winlink	*winlink_find_by_window(struct winlinks *, struct window *);
2101 struct winlink	*winlink_find_by_window_id(struct winlinks *, u_int);
2102 int		 winlink_next_index(struct winlinks *, int);
2103 u_int		 winlink_count(struct winlinks *);
2104 struct winlink	*winlink_add(struct winlinks *, int);
2105 void		 winlink_set_window(struct winlink *, struct window *);
2106 void		 winlink_remove(struct winlinks *, struct winlink *);
2107 struct winlink	*winlink_next(struct winlink *);
2108 struct winlink	*winlink_previous(struct winlink *);
2109 struct winlink	*winlink_next_by_number(struct winlink *, struct session *,
2110 		     int);
2111 struct winlink	*winlink_previous_by_number(struct winlink *, struct session *,
2112 		     int);
2113 void		 winlink_stack_push(struct winlink_stack *, struct winlink *);
2114 void		 winlink_stack_remove(struct winlink_stack *, struct winlink *);
2115 int		 window_index(struct window *, u_int *);
2116 struct window	*window_find_by_id(u_int);
2117 struct window	*window_create1(u_int, u_int);
2118 struct window	*window_create(const char *, int, char **, const char *,
2119 		     const char *, int, struct environ *, struct termios *,
2120 		     u_int, u_int, u_int, char **);
2121 void		 window_destroy(struct window *);
2122 struct window_pane *window_get_active_at(struct window *, u_int, u_int);
2123 void		 window_set_active_at(struct window *, u_int, u_int);
2124 struct window_pane *window_find_string(struct window *, const char *);
2125 int		 window_set_active_pane(struct window *, struct window_pane *);
2126 struct window_pane *window_add_pane(struct window *, u_int);
2127 void		 window_resize(struct window *, u_int, u_int);
2128 int		 window_zoom(struct window_pane *);
2129 int		 window_unzoom(struct window *);
2130 void		 window_lost_pane(struct window *, struct window_pane *);
2131 void		 window_remove_pane(struct window *, struct window_pane *);
2132 struct window_pane *window_pane_at_index(struct window *, u_int);
2133 struct window_pane *window_pane_next_by_number(struct window *,
2134 		        struct window_pane *, u_int);
2135 struct window_pane *window_pane_previous_by_number(struct window *,
2136 		        struct window_pane *, u_int);
2137 int		 window_pane_index(struct window_pane *, u_int *);
2138 u_int		 window_count_panes(struct window *);
2139 void		 window_destroy_panes(struct window *);
2140 struct window_pane *window_pane_find_by_id(u_int);
2141 struct window_pane *window_pane_create(struct window *, u_int, u_int, u_int);
2142 void		 window_pane_destroy(struct window_pane *);
2143 void		 window_pane_timer_start(struct window_pane *);
2144 int		 window_pane_spawn(struct window_pane *, int, char **,
2145 		     const char *, const char *, int, struct environ *,
2146 		     struct termios *, char **);
2147 void		 window_pane_resize(struct window_pane *, u_int, u_int);
2148 void		 window_pane_alternate_on(struct window_pane *,
2149 		     struct grid_cell *, int);
2150 void		 window_pane_alternate_off(struct window_pane *,
2151 		     struct grid_cell *, int);
2152 int		 window_pane_set_mode(
2153 		     struct window_pane *, const struct window_mode *);
2154 void		 window_pane_reset_mode(struct window_pane *);
2155 void		 window_pane_key(struct window_pane *, struct session *, int);
2156 void		 window_pane_mouse(struct window_pane *,
2157 		     struct session *, struct mouse_event *);
2158 int		 window_pane_visible(struct window_pane *);
2159 char		*window_pane_search(
2160 		     struct window_pane *, const char *, u_int *);
2161 char		*window_printable_flags(struct session *, struct winlink *);
2162 struct window_pane *window_pane_find_up(struct window_pane *);
2163 struct window_pane *window_pane_find_down(struct window_pane *);
2164 struct window_pane *window_pane_find_left(struct window_pane *);
2165 struct window_pane *window_pane_find_right(struct window_pane *);
2166 void		 window_set_name(struct window *, const char *);
2167 void		 window_remove_ref(struct window *);
2168 void		 winlink_clear_flags(struct winlink *);
2169 
2170 /* layout.c */
2171 u_int		 layout_count_cells(struct layout_cell *);
2172 struct layout_cell *layout_create_cell(struct layout_cell *);
2173 void		 layout_free_cell(struct layout_cell *);
2174 void		 layout_print_cell(struct layout_cell *, const char *, u_int);
2175 void		 layout_destroy_cell(struct layout_cell *, struct layout_cell **);
2176 void		 layout_set_size(
2177 		     struct layout_cell *, u_int, u_int, u_int, u_int);
2178 void		 layout_make_leaf(
2179 		     struct layout_cell *, struct window_pane *);
2180 void		 layout_make_node(struct layout_cell *, enum layout_type);
2181 void		 layout_fix_offsets(struct layout_cell *);
2182 void		 layout_fix_panes(struct window *, u_int, u_int);
2183 u_int		 layout_resize_check(struct layout_cell *, enum layout_type);
2184 void		 layout_resize_adjust(
2185 		     struct layout_cell *, enum layout_type, int);
2186 void		 layout_init(struct window *, struct window_pane *);
2187 void		 layout_free(struct window *);
2188 void		 layout_resize(struct window *, u_int, u_int);
2189 void		 layout_resize_pane(struct window_pane *, enum layout_type,
2190 		     int);
2191 void		 layout_resize_pane_to(struct window_pane *, enum layout_type,
2192 		     u_int);
2193 void		 layout_resize_pane_mouse(struct client *);
2194 void		 layout_assign_pane(struct layout_cell *, struct window_pane *);
2195 struct layout_cell *layout_split_pane(
2196 		     struct window_pane *, enum layout_type, int, int);
2197 void		 layout_close_pane(struct window_pane *);
2198 
2199 /* layout-custom.c */
2200 char		*layout_dump(struct window *);
2201 int		 layout_parse(struct window *, const char *);
2202 
2203 /* layout-set.c */
2204 const char	*layout_set_name(u_int);
2205 int		 layout_set_lookup(const char *);
2206 u_int		 layout_set_select(struct window *, u_int);
2207 u_int		 layout_set_next(struct window *);
2208 u_int		 layout_set_previous(struct window *);
2209 void		 layout_set_active_changed(struct window *);
2210 
2211 /* window-clock.c */
2212 extern const struct window_mode window_clock_mode;
2213 extern const char window_clock_table[14][5][5];
2214 
2215 /* window-copy.c */
2216 extern const struct window_mode window_copy_mode;
2217 void		 window_copy_init_from_pane(struct window_pane *);
2218 void		 window_copy_init_for_output(struct window_pane *);
2219 void printflike(2, 3) window_copy_add(struct window_pane *, const char *, ...);
2220 void		 window_copy_vadd(struct window_pane *, const char *, va_list);
2221 void		 window_copy_pageup(struct window_pane *);
2222 
2223 /* window-choose.c */
2224 extern const struct window_mode window_choose_mode;
2225 void		 window_choose_add(struct window_pane *,
2226 			 struct window_choose_data *);
2227 void		 window_choose_ready(struct window_pane *,
2228 		     u_int, void (*)(struct window_choose_data *));
2229 struct window_choose_data	*window_choose_data_create (int,
2230 		     struct client *, struct session *);
2231 void	window_choose_data_free(struct window_choose_data *);
2232 void	window_choose_data_run(struct window_choose_data *);
2233 struct window_choose_data	*window_choose_add_window(struct window_pane *,
2234 			struct client *, struct session *, struct winlink *,
2235 			const char *, const char *, u_int);
2236 struct window_choose_data	*window_choose_add_session(struct window_pane *,
2237 			struct client *, struct session *, const char *,
2238 			const char *, u_int);
2239 void	window_choose_expand_all(struct window_pane *);
2240 void	window_choose_collapse_all(struct window_pane *);
2241 void	window_choose_set_current(struct window_pane *, u_int);
2242 
2243 /* names.c */
2244 void	 queue_window_name(struct window *);
2245 char	*default_window_name(struct window *);
2246 char	*format_window_name(struct window *);
2247 char	*parse_window_name(const char *);
2248 
2249 /* signal.c */
2250 void	set_signals(void(*)(int, short, void *));
2251 void	clear_signals(int);
2252 
2253 /* control.c */
2254 void	control_callback(struct client *, int, void *);
2255 void printflike(2, 3) control_write(struct client *, const char *, ...);
2256 void	control_write_buffer(struct client *, struct evbuffer *);
2257 
2258 /* control-notify.c */
2259 void	control_notify_input(struct client *, struct window_pane *,
2260 	    struct evbuffer *);
2261 void	control_notify_window_layout_changed(struct window *);
2262 void	control_notify_window_unlinked(struct session *, struct window *);
2263 void	control_notify_window_linked(struct session *, struct window *);
2264 void	control_notify_window_renamed(struct window *);
2265 void	control_notify_attached_session_changed(struct client *);
2266 void	control_notify_session_renamed(struct session *);
2267 void	control_notify_session_created(struct session *);
2268 void	control_notify_session_close(struct session *);
2269 
2270 /* session.c */
2271 extern struct sessions sessions;
2272 extern struct sessions dead_sessions;
2273 extern struct session_groups session_groups;
2274 int	session_cmp(struct session *, struct session *);
2275 RB_PROTOTYPE(sessions, session, entry, session_cmp);
2276 int		 session_alive(struct session *);
2277 struct session	*session_find(const char *);
2278 struct session	*session_find_by_id(u_int);
2279 struct session	*session_create(const char *, int, char **, const char *,
2280 		     int, struct environ *, struct termios *, int, u_int,
2281 		     u_int, char **);
2282 void		 session_destroy(struct session *);
2283 int		 session_check_name(const char *);
2284 void		 session_update_activity(struct session *);
2285 struct session	*session_next_session(struct session *);
2286 struct session	*session_previous_session(struct session *);
2287 struct winlink	*session_new(struct session *, const char *, int, char **,
2288 		     const char *, int, int, char **);
2289 struct winlink	*session_attach(struct session *, struct window *, int,
2290 		     char **);
2291 int		 session_detach(struct session *, struct winlink *);
2292 struct winlink	*session_has(struct session *, struct window *);
2293 int		 session_next(struct session *, int);
2294 int		 session_previous(struct session *, int);
2295 int		 session_select(struct session *, int);
2296 int		 session_last(struct session *);
2297 int		 session_set_current(struct session *, struct winlink *);
2298 struct session_group *session_group_find(struct session *);
2299 u_int		 session_group_index(struct session_group *);
2300 void		 session_group_add(struct session *, struct session *);
2301 void		 session_group_remove(struct session *);
2302 u_int		 session_group_count(struct session_group *);
2303 void		 session_group_synchronize_to(struct session *);
2304 void		 session_group_synchronize_from(struct session *);
2305 void		 session_group_synchronize1(struct session *, struct session *);
2306 void		 session_renumber_windows(struct session *);
2307 
2308 /* utf8.c */
2309 void		 utf8_build(void);
2310 void		 utf8_set(struct utf8_data *, u_char);
2311 int		 utf8_open(struct utf8_data *, u_char);
2312 int		 utf8_append(struct utf8_data *, u_char);
2313 u_int		 utf8_combine(const struct utf8_data *);
2314 u_int		 utf8_split2(u_int, u_char *);
2315 int		 utf8_strvis(char *, const char *, size_t, int);
2316 struct utf8_data *utf8_fromcstr(const char *);
2317 char		*utf8_tocstr(struct utf8_data *);
2318 u_int		 utf8_cstrwidth(const char *);
2319 char		*utf8_trimcstr(const char *, u_int);
2320 
2321 /* procname.c */
2322 char   *get_proc_name(int, char *);
2323 
2324 /* log.c */
2325 void		 log_open(const char *);
2326 void		 log_close(void);
2327 void printflike(1, 2) log_debug(const char *, ...);
2328 __dead void printflike(1, 2) log_fatal(const char *, ...);
2329 __dead void printflike(1, 2) log_fatalx(const char *, ...);
2330 
2331 /* xmalloc.c */
2332 char		*xstrdup(const char *);
2333 void		*xcalloc(size_t, size_t);
2334 void		*xmalloc(size_t);
2335 void		*xrealloc(void *, size_t);
2336 void		*xreallocarray(void *, size_t, size_t);
2337 int printflike(2, 3) xasprintf(char **, const char *, ...);
2338 int		 xvasprintf(char **, const char *, va_list);
2339 int printflike(3, 4) xsnprintf(char *, size_t, const char *, ...);
2340 int		 xvsnprintf(char *, size_t, const char *, va_list);
2341 
2342 /* style.c */
2343 int		 style_parse(const struct grid_cell *,
2344 		     struct grid_cell *, const char *);
2345 const char	*style_tostring(struct grid_cell *);
2346 void		 style_update_new(struct options *, const char *, const char *);
2347 void		 style_update_old(struct options *, const char *,
2348 		     struct grid_cell *);
2349 void		 style_apply(struct grid_cell *, struct options *,
2350 		     const char *);
2351 void		 style_apply_update(struct grid_cell *, struct options *,
2352 		     const char *);
2353 
2354 #endif /* TMUX_H */
2355