tmux  3.2a
About: tmux is a terminal multiplexer that lets you switch easily between several programs in one terminal.
  Fossies Dox: tmux-3.2a.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

cmd-queue.c
Go to the documentation of this file.
1 /* $OpenBSD$ */
2 
3 /*
4  * Copyright (c) 2013 Nicholas Marriott <nicholas.marriott@gmail.com>
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 #include <sys/types.h>
20 
21 #include <ctype.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <time.h>
25 
26 #include "tmux.h"
27 
28 /* Command queue flags. */
29 #define CMDQ_FIRED 0x1
30 #define CMDQ_WAITING 0x2
31 
32 /* Command queue item type. */
33 enum cmdq_type {
36 };
37 
38 /* Command queue item. */
39 struct cmdq_item {
40  char *name;
41  struct cmdq_list *queue;
42  struct cmdq_item *next;
43 
44  struct client *client;
46 
47  enum cmdq_type type;
48  u_int group;
49 
50  u_int number;
51  time_t time;
52 
53  int flags;
54 
55  struct cmdq_state *state;
56  struct cmd_find_state source;
57  struct cmd_find_state target;
58 
59  struct cmd_list *cmdlist;
60  struct cmd *cmd;
61 
63  void *data;
64 
65  TAILQ_ENTRY(cmdq_item) entry;
66 };
67 TAILQ_HEAD(cmdq_item_list, cmdq_item);
68 
69 /*
70  * Command queue state. This is the context for commands on the command queue.
71  * It holds information about how the commands were fired (the key and flags),
72  * any additional formats for the commands, and the current default target.
73  * Multiple commands can share the same state and a command may update the
74  * default target.
75  */
76 struct cmdq_state {
78  int flags;
79 
81 
82  struct key_event event;
83  struct cmd_find_state current;
84 };
85 
86 /* Command queue. */
87 struct cmdq_list {
88  struct cmdq_item *item;
89  struct cmdq_item_list list;
90 };
91 
92 /* Get command queue name. */
93 static const char *
94 cmdq_name(struct client *c)
95 {
96  static char s[256];
97 
98  if (c == NULL)
99  return ("<global>");
100  if (c->name != NULL)
101  xsnprintf(s, sizeof s, "<%s>", c->name);
102  else
103  xsnprintf(s, sizeof s, "<%p>", c);
104  return (s);
105 }
106 
107 /* Get command queue from client. */
108 static struct cmdq_list *
109 cmdq_get(struct client *c)
110 {
111  static struct cmdq_list *global_queue;
112 
113  if (c == NULL) {
114  if (global_queue == NULL)
115  global_queue = cmdq_new();
116  return (global_queue);
117  }
118  return (c->queue);
119 }
120 
121 /* Create a queue. */
122 struct cmdq_list *
123 cmdq_new(void)
124 {
125  struct cmdq_list *queue;
126 
127  queue = xcalloc (1, sizeof *queue);
128  TAILQ_INIT (&queue->list);
129  return (queue);
130 }
131 
132 /* Free a queue. */
133 void
134 cmdq_free(struct cmdq_list *queue)
135 {
136  if (!TAILQ_EMPTY(&queue->list))
137  fatalx("queue not empty");
138  free(queue);
139 }
140 
141 /* Get item name. */
142 const char *
144 {
145  return (item->name);
146 }
147 
148 /* Get item client. */
149 struct client *
151 {
152  return (item->client);
153 }
154 
155 /* Get item target client. */
156 struct client *
158 {
159  return (item->target_client);
160 }
161 
162 /* Get item state. */
163 struct cmdq_state *
165 {
166  return (item->state);
167 }
168 
169 /* Get item target. */
170 struct cmd_find_state *
172 {
173  return (&item->target);
174 }
175 
176 /* Get item source. */
177 struct cmd_find_state *
179 {
180  return (&item->source);
181 }
182 
183 /* Get state event. */
184 struct key_event *
186 {
187  return (&item->state->event);
188 }
189 
190 /* Get state current target. */
191 struct cmd_find_state *
193 {
194  return (&item->state->current);
195 }
196 
197 /* Get state flags. */
198 int
200 {
201  return (item->state->flags);
202 }
203 
204 /* Create a new state. */
205 struct cmdq_state *
207  int flags)
208 {
209  struct cmdq_state *state;
210 
211  state = xcalloc(1, sizeof *state);
212  state->references = 1;
213  state->flags = flags;
214 
215  if (event != NULL)
216  memcpy(&state->event, event, sizeof state->event);
217  else
218  state->event.key = KEYC_NONE;
219  if (current != NULL && cmd_find_valid_state(current))
221  else
222  cmd_find_clear_state(&state->current, 0);
223 
224  return (state);
225 }
226 
227 /* Add a reference to a state. */
228 struct cmdq_state *
230 {
231  state->references++;
232  return (state);
233 }
234 
235 /* Make a copy of a state. */
236 struct cmdq_state *
238 {
239  return (cmdq_new_state(&state->current, &state->event, state->flags));
240 }
241 
242 /* Free a state. */
243 void
245 {
246  if (--state->references != 0)
247  return;
248 
249  if (state->formats != NULL)
250  format_free(state->formats);
251  free(state);
252 }
253 
254 /* Add a format to command queue. */
255 void
256 cmdq_add_format(struct cmdq_state *state, const char *key, const char *fmt, ...)
257 {
258  va_list ap;
259  char *value;
260 
261  va_start(ap, fmt);
262  xvasprintf(&value, fmt, ap);
263  va_end(ap);
264 
265  if (state->formats == NULL)
266  state->formats = format_create(NULL, NULL, FORMAT_NONE, 0);
267  format_add(state->formats, key, "%s", value);
268 
269  free(value);
270 }
271 
272 /* Merge formats from item. */
273 void
274 cmdq_merge_formats(struct cmdq_item *item, struct format_tree *ft)
275 {
276  const struct cmd_entry *entry;
277 
278  if (item->cmd != NULL) {
279  entry = cmd_get_entry(item->cmd);
280  format_add(ft, "command", "%s", entry->name);
281  }
282  if (item->state->formats != NULL)
283  format_merge(ft, item->state->formats);
284 }
285 
286 /* Append an item. */
287 struct cmdq_item *
288 cmdq_append(struct client *c, struct cmdq_item *item)
289 {
290  struct cmdq_list *queue = cmdq_get(c);
291  struct cmdq_item *next;
292 
293  do {
294  next = item->next;
295  item->next = NULL;
296 
297  if (c != NULL)
298  c->references++;
299  item->client = c;
300 
301  item->queue = queue;
302  TAILQ_INSERT_TAIL(&queue->list, item, entry);
303  log_debug("%s %s: %s", __func__, cmdq_name(c), item->name);
304 
305  item = next;
306  } while (item != NULL);
307  return (TAILQ_LAST(&queue->list, cmdq_item_list));
308 }
309 
310 /* Insert an item. */
311 struct cmdq_item *
312 cmdq_insert_after(struct cmdq_item *after, struct cmdq_item *item)
313 {
314  struct client *c = after->client;
315  struct cmdq_list *queue = after->queue;
316  struct cmdq_item *next;
317 
318  do {
319  next = item->next;
320  item->next = after->next;
321  after->next = item;
322 
323  if (c != NULL)
324  c->references++;
325  item->client = c;
326 
327  item->queue = queue;
328  TAILQ_INSERT_AFTER(&queue->list, after, item, entry);
329  log_debug("%s %s: %s after %s", __func__, cmdq_name(c),
330  item->name, after->name);
331 
332  after = item;
333  item = next;
334  } while (item != NULL);
335  return (after);
336 }
337 
338 /* Insert a hook. */
339 void
340 cmdq_insert_hook(struct session *s, struct cmdq_item *item,
341  struct cmd_find_state *current, const char *fmt, ...)
342 {
343  struct cmdq_state *state = item->state;
344  struct cmd *cmd = item->cmd;
345  struct args *args = cmd_get_args(cmd);
346  struct args_entry *entryp;
347  struct args_value *valuep;
348  struct options *oo;
349  va_list ap;
350  char *name, tmp[32], flag, *arguments;
351  int i;
352  const char *value;
353  struct cmdq_item *new_item;
354  struct cmdq_state *new_state;
355  struct options_entry *o;
356  struct options_array_item *a;
357  struct cmd_list *cmdlist;
358 
359  if (item->state->flags & CMDQ_STATE_NOHOOKS)
360  return;
361  if (s == NULL)
362  oo = global_s_options;
363  else
364  oo = s->options;
365 
366  va_start(ap, fmt);
367  xvasprintf(&name, fmt, ap);
368  va_end(ap);
369 
370  o = options_get(oo, name);
371  if (o == NULL) {
372  free(name);
373  return;
374  }
375  log_debug("running hook %s (parent %p)", name, item);
376 
377  /*
378  * The hooks get a new state because they should not update the current
379  * target or formats for any subsequent commands.
380  */
381  new_state = cmdq_new_state(current, &state->event, CMDQ_STATE_NOHOOKS);
382  cmdq_add_format(new_state, "hook", "%s", name);
383 
384  arguments = args_print(args);
385  cmdq_add_format(new_state, "hook_arguments", "%s", arguments);
386  free(arguments);
387 
388  for (i = 0; i < args->argc; i++) {
389  xsnprintf(tmp, sizeof tmp, "hook_argument_%d", i);
390  cmdq_add_format(new_state, tmp, "%s", args->argv[i]);
391  }
392  flag = args_first(args, &entryp);
393  while (flag != 0) {
394  value = args_get(args, flag);
395  if (value == NULL) {
396  xsnprintf(tmp, sizeof tmp, "hook_flag_%c", flag);
397  cmdq_add_format(new_state, tmp, "1");
398  } else {
399  xsnprintf(tmp, sizeof tmp, "hook_flag_%c", flag);
400  cmdq_add_format(new_state, tmp, "%s", value);
401  }
402 
403  i = 0;
404  value = args_first_value(args, flag, &valuep);
405  while (value != NULL) {
406  xsnprintf(tmp, sizeof tmp, "hook_flag_%c_%d", flag, i);
407  cmdq_add_format(new_state, tmp, "%s", value);
408  i++;
409  value = args_next_value(&valuep);
410  }
411 
412  flag = args_next(&entryp);
413  }
414 
415  a = options_array_first(o);
416  while (a != NULL) {
417  cmdlist = options_array_item_value(a)->cmdlist;
418  if (cmdlist != NULL) {
419  new_item = cmdq_get_command(cmdlist, new_state);
420  if (item != NULL)
421  item = cmdq_insert_after(item, new_item);
422  else
423  item = cmdq_append(NULL, new_item);
424  }
425  a = options_array_next(a);
426  }
427 
428  cmdq_free_state(new_state);
429  free(name);
430 }
431 
432 /* Continue processing command queue. */
433 void
435 {
436  item->flags &= ~~CMDQ_WAITING;
437 }
438 
439 /* Remove an item. */
440 static void
441 cmdq_remove(struct cmdq_item *item)
442 {
443  if (item->client != NULL)
445  if (item->cmdlist != NULL)
446  cmd_list_free(item->cmdlist);
447  cmdq_free_state(item->state);
448 
449  TAILQ_REMOVE(&item->queue->list, item, entry);
450 
451  free(item->name);
452  free(item);
453 }
454 
455 /* Remove all subsequent items that match this item's group. */
456 static void
458 {
459  struct cmdq_item *this, *next;
460 
461  if (item->group == 0)
462  return;
463  this = TAILQ_NEXT(item, entry);
464  while (this != NULL) {
465  next = TAILQ_NEXT(this, entry);
466  if (this->group == item->group)
467  cmdq_remove(this);
468  this = next;
469  }
470 }
471 
472 /* Get a command for the command queue. */
473 struct cmdq_item *
475 {
476  struct cmdq_item *item, *first = NULL, *last = NULL;
477  struct cmd *cmd;
478  const struct cmd_entry *entry;
479  int created = 0;
480 
481  if (state == NULL) {
482  state = cmdq_new_state(NULL, NULL, 0);
483  created = 1;
484  }
485 
486  cmd = cmd_list_first(cmdlist);
487  while (cmd != NULL) {
488  entry = cmd_get_entry(cmd);
489 
490  item = xcalloc(1, sizeof *item);
491  xasprintf(&item->name, "[%s/%p]", entry->name, item);
492  item->type = CMDQ_COMMAND;
493 
494  item->group = cmd_get_group(cmd);
495  item->state = cmdq_link_state(state);
496 
497  item->cmdlist = cmdlist;
498  item->cmd = cmd;
499 
500  cmdlist->references++;
501  log_debug("%s: %s group %u", __func__, item->name, item->group);
502 
503  if (first == NULL)
504  first = item;
505  if (last != NULL)
506  last->next = item;
507  last = item;
508 
509  cmd = cmd_list_next(cmd);
510  }
511 
512  if (created)
513  cmdq_free_state(state);
514  return (first);
515 }
516 
517 /* Fill in flag for a command. */
518 static enum cmd_retval
519 cmdq_find_flag(struct cmdq_item *item, struct cmd_find_state *fs,
520  const struct cmd_entry_flag *flag)
521 {
522  const char *value;
523 
524  if (flag->flag == 0) {
525  cmd_find_from_client(fs, item->target_client, 0);
526  return (CMD_RETURN_NORMAL);
527  }
528 
529  value = args_get(cmd_get_args(item->cmd), flag->flag);
530  if (cmd_find_target(fs, item, value, flag->type, flag->flags) != 0) {
531  cmd_find_clear_state(fs, 0);
532  return (CMD_RETURN_ERROR);
533  }
534  return (CMD_RETURN_NORMAL);
535 }
536 
537 /* Add message with command. */
538 static void
540 {
541  struct client *c = item->client;
542  struct cmdq_state *state = item->state;
543  const char *name, *key;
544  char *tmp;
545 
546  tmp = cmd_print(item->cmd);
547  if (c != NULL) {
548  name = c->name;
549  if (c->session != NULL && state->event.key != KEYC_NONE) {
550  key = key_string_lookup_key(state->event.key, 0);
551  server_add_message("%s key %s: %s", name, key, tmp);
552  } else
553  server_add_message("%s command: %s", name, tmp);
554  } else
555  server_add_message("command: %s", tmp);
556  free(tmp);
557 }
558 
559 /* Fire command on command queue. */
560 static enum cmd_retval
561 cmdq_fire_command(struct cmdq_item *item)
562 {
563  const char *name = cmdq_name(item->client);
564  struct cmdq_state *state = item->state;
565  struct cmd *cmd = item->cmd;
566  struct args *args = cmd_get_args(cmd);
567  const struct cmd_entry *entry = cmd_get_entry(cmd);
568  struct client *tc, *saved = item->client;
569  enum cmd_retval retval;
570  struct cmd_find_state *fsp, fs;
571  int flags, quiet = 0;
572  char *tmp;
573 
574  if (cfg_finished)
575  cmdq_add_message(item);
576  if (log_get_level() > 1) {
577  tmp = cmd_print(cmd);
578  log_debug("%s %s: (%u) %s", __func__, name, item->group, tmp);
579  free(tmp);
580  }
581 
582  flags = !!(state->flags & CMDQ_STATE_CONTROL);
583  cmdq_guard(item, "begin", flags);
584 
585  if (item->client == NULL)
586  item->client = cmd_find_client(item, NULL, 1);
587 
588  if (entry->flags & CMD_CLIENT_CANFAIL)
589  quiet = 1;
590  if (entry->flags & CMD_CLIENT_CFLAG) {
591  tc = cmd_find_client(item, args_get(args, 'c'), quiet);
592  if (tc == NULL && !quiet) {
593  retval = CMD_RETURN_ERROR;
594  goto out;
595  }
596  } else if (entry->flags & CMD_CLIENT_TFLAG) {
597  tc = cmd_find_client(item, args_get(args, 't'), quiet);
598  if (tc == NULL && !quiet) {
599  retval = CMD_RETURN_ERROR;
600  goto out;
601  }
602  } else
603  tc = cmd_find_client(item, NULL, 1);
604  item->target_client = tc;
605 
606  retval = cmdq_find_flag(item, &item->source, &entry->source);
607  if (retval == CMD_RETURN_ERROR)
608  goto out;
609  retval = cmdq_find_flag(item, &item->target, &entry->target);
610  if (retval == CMD_RETURN_ERROR)
611  goto out;
612 
613  retval = entry->exec(cmd, item);
614  if (retval == CMD_RETURN_ERROR)
615  goto out;
616 
617  if (entry->flags & CMD_AFTERHOOK) {
618  if (cmd_find_valid_state(&item->target))
619  fsp = &item->target;
620  else if (cmd_find_valid_state(&item->state->current))
621  fsp = &item->state->current;
622  else if (cmd_find_from_client(&fs, item->client, 0) == 0)
623  fsp = &fs;
624  else
625  goto out;
626  cmdq_insert_hook(fsp->s, item, fsp, "after-%s", entry->name);
627  }
628 
629 out:
630  item->client = saved;
631  if (retval == CMD_RETURN_ERROR)
632  cmdq_guard(item, "error", flags);
633  else
634  cmdq_guard(item, "end", flags);
635  return (retval);
636 }
637 
638 /* Get a callback for the command queue. */
639 struct cmdq_item *
640 cmdq_get_callback1(const char *name, cmdq_cb cb, void *data)
641 {
642  struct cmdq_item *item;
643 
644  item = xcalloc(1, sizeof *item);
645  xasprintf(&item->name, "[%s/%p]", name, item);
646  item->type = CMDQ_CALLBACK;
647 
648  item->group = 0;
649  item->state = cmdq_new_state(NULL, NULL, 0);
650 
651  item->cb = cb;
652  item->data = data;
653 
654  return (item);
655 }
656 
657 /* Generic error callback. */
658 static enum cmd_retval
659 cmdq_error_callback(struct cmdq_item *item, void *data)
660 {
661  char *error = data;
662 
663  cmdq_error(item, "%s", error);
664  free(error);
665 
666  return (CMD_RETURN_NORMAL);
667 }
668 
669 /* Get an error callback for the command queue. */
670 struct cmdq_item *
671 cmdq_get_error(const char *error)
672 {
674 }
675 
676 /* Fire callback on callback queue. */
677 static enum cmd_retval
678 cmdq_fire_callback(struct cmdq_item *item)
679 {
680  return (item->cb(item, item->data));
681 }
682 
683 /* Process next item on command queue. */
684 u_int
685 cmdq_next(struct client *c)
686 {
687  struct cmdq_list *queue = cmdq_get(c);
688  const char *name = cmdq_name(c);
689  struct cmdq_item *item;
690  enum cmd_retval retval;
691  u_int items = 0;
692  static u_int number;
693 
694  if (TAILQ_EMPTY(&queue->list)) {
695  log_debug("%s %s: empty", __func__, name);
696  return (0);
697  }
698  if (TAILQ_FIRST(&queue->list)->flags & CMDQ_WAITING) {
699  log_debug("%s %s: waiting", __func__, name);
700  return (0);
701  }
702 
703  log_debug("%s %s: enter", __func__, name);
704  for (;;) {
705  item = queue->item = TAILQ_FIRST(&queue->list);
706  if (item == NULL)
707  break;
708  log_debug("%s %s: %s (%d), flags %x", __func__, name,
709  item->name, item->type, item->flags);
710 
711  /*
712  * Any item with the waiting flag set waits until an external
713  * event clears the flag (for example, a job - look at
714  * run-shell).
715  */
716  if (item->flags & CMDQ_WAITING)
717  goto waiting;
718 
719  /*
720  * Items are only fired once, once the fired flag is set, a
721  * waiting flag can only be cleared by an external event.
722  */
723  if (~item->flags & CMDQ_FIRED) {
724  item->time = time(NULL);
725  item->number = ++number;
726 
727  switch (item->type) {
728  case CMDQ_COMMAND:
729  retval = cmdq_fire_command(item);
730 
731  /*
732  * If a command returns an error, remove any
733  * subsequent commands in the same group.
734  */
735  if (retval == CMD_RETURN_ERROR)
736  cmdq_remove_group(item);
737  break;
738  case CMDQ_CALLBACK:
739  retval = cmdq_fire_callback(item);
740  break;
741  default:
742  retval = CMD_RETURN_ERROR;
743  break;
744  }
745  item->flags |= CMDQ_FIRED;
746 
747  if (retval == CMD_RETURN_WAIT) {
748  item->flags |= CMDQ_WAITING;
749  goto waiting;
750  }
751  items++;
752  }
753  cmdq_remove(item);
754  }
755  queue->item = NULL;
756 
757  log_debug("%s %s: exit (empty)", __func__, name);
758  return (items);
759 
760 waiting:
761  log_debug("%s %s: exit (wait)", __func__, name);
762  return (items);
763 }
764 
765 /* Get running item if any. */
766 struct cmdq_item *
768 {
769  struct cmdq_list *queue = cmdq_get(c);
770 
771  if (queue->item == NULL)
772  return (NULL);
773  if (queue->item->flags & CMDQ_WAITING)
774  return (NULL);
775  return (queue->item);
776 }
777 
778 /* Print a guard line. */
779 void
780 cmdq_guard(struct cmdq_item *item, const char *guard, int flags)
781 {
782  struct client *c = item->client;
783  long t = item->time;
784  u_int number = item->number;
785 
786  if (c != NULL && (c->flags & CLIENT_CONTROL))
787  control_write(c, "%%%s %ld %u %d", guard, t, number, flags);
788 }
789 
790 /* Show message from command. */
791 void
792 cmdq_print(struct cmdq_item *item, const char *fmt, ...)
793 {
794  struct client *c = item->client;
795  struct window_pane *wp;
796  struct window_mode_entry *wme;
797  va_list ap;
798  char *tmp, *msg;
799 
800  va_start(ap, fmt);
801  xvasprintf(&msg, fmt, ap);
802  va_end(ap);
803 
804  log_debug("%s: %s", __func__, msg);
805 
806  if (c == NULL)
807  /* nothing */;
808  else if (c->session == NULL || (c->flags & CLIENT_CONTROL)) {
809  if (~c->flags & CLIENT_UTF8) {
810  tmp = msg;
811  msg = utf8_sanitize(tmp);
812  free(tmp);
813  }
814  if (c->flags & CLIENT_CONTROL)
815  control_write(c, "%s", msg);
816  else
817  file_print(c, "%s\n", msg);
818  } else {
820  wme = TAILQ_FIRST(&wp->modes);
821  if (wme == NULL || wme->mode != &window_view_mode) {
823  NULL);
824  }
825  window_copy_add(wp, "%s", msg);
826  }
827 
828  free(msg);
829 }
830 
831 /* Show error from command. */
832 void
833 cmdq_error(struct cmdq_item *item, const char *fmt, ...)
834 {
835  struct client *c = item->client;
836  struct cmd *cmd = item->cmd;
837  va_list ap;
838  char *msg, *tmp;
839  const char *file;
840  u_int line;
841 
842  va_start(ap, fmt);
843  xvasprintf(&msg, fmt, ap);
844  va_end(ap);
845 
846  log_debug("%s: %s", __func__, msg);
847 
848  if (c == NULL) {
850  cfg_add_cause("%s:%u: %s", file, line, msg);
851  } else if (c->session == NULL || (c->flags & CLIENT_CONTROL)) {
852  server_add_message("%s message: %s", c->name, msg);
853  if (~c->flags & CLIENT_UTF8) {
854  tmp = msg;
855  msg = utf8_sanitize(tmp);
856  free(tmp);
857  }
858  if (c->flags & CLIENT_CONTROL)
859  control_write(c, "%s", msg);
860  else
861  file_error(c, "%s\n", msg);
862  c->retval = 1;
863  } else {
864  *msg = toupper((u_char) *msg);
865  status_message_set(c, -1, 1, 0, "%s", msg);
866  }
867 
868  free(msg);
869 }
const char * args_get(struct args *args, u_char flag)
Definition: arguments.c:295
char * args_print(struct args *args)
Definition: arguments.c:174
u_char args_first(struct args *args, struct args_entry **entry)
Definition: arguments.c:308
const char * args_next_value(struct args_value **value)
Definition: arguments.c:343
const char * args_first_value(struct args *args, u_char flag, struct args_value **value)
Definition: arguments.c:328
u_char args_next(struct args_entry **entry)
Definition: arguments.c:318
void cfg_add_cause(const char *fmt,...)
Definition: cfg.c:213
int cfg_finished
Definition: cfg.c:30
int cmd_find_target(struct cmd_find_state *fs, struct cmdq_item *item, const char *target, enum cmd_find_type type, int flags)
Definition: cmd-find.c:923
void cmd_find_copy_state(struct cmd_find_state *dst, struct cmd_find_state *src)
Definition: cmd-find.c:689
int cmd_find_valid_state(struct cmd_find_state *fs)
Definition: cmd-find.c:664
void cmd_find_clear_state(struct cmd_find_state *fs, int flags)
Definition: cmd-find.c:644
struct client * cmd_find_client(struct cmdq_item *item, const char *target, int quiet)
Definition: cmd-find.c:1274
int cmd_find_from_client(struct cmd_find_state *fs, struct client *c, int flags)
Definition: cmd-find.c:859
void cmdq_print(struct cmdq_item *item, const char *fmt,...)
Definition: cmd-queue.c:792
struct client * cmdq_get_target_client(struct cmdq_item *item)
Definition: cmd-queue.c:157
const char * cmdq_get_name(struct cmdq_item *item)
Definition: cmd-queue.c:143
static enum cmd_retval cmdq_fire_command(struct cmdq_item *item)
Definition: cmd-queue.c:561
void cmdq_merge_formats(struct cmdq_item *item, struct format_tree *ft)
Definition: cmd-queue.c:274
void cmdq_free(struct cmdq_list *queue)
Definition: cmd-queue.c:134
struct cmdq_state * cmdq_get_state(struct cmdq_item *item)
Definition: cmd-queue.c:164
struct client * cmdq_get_client(struct cmdq_item *item)
Definition: cmd-queue.c:150
struct cmdq_item * cmdq_get_error(const char *error)
Definition: cmd-queue.c:671
int cmdq_get_flags(struct cmdq_item *item)
Definition: cmd-queue.c:199
static enum cmd_retval cmdq_fire_callback(struct cmdq_item *item)
Definition: cmd-queue.c:678
void cmdq_free_state(struct cmdq_state *state)
Definition: cmd-queue.c:244
static struct cmdq_list * cmdq_get(struct client *c)
Definition: cmd-queue.c:109
#define CMDQ_FIRED
Definition: cmd-queue.c:29
struct cmdq_item * cmdq_get_callback1(const char *name, cmdq_cb cb, void *data)
Definition: cmd-queue.c:640
#define CMDQ_WAITING
Definition: cmd-queue.c:30
struct cmd_find_state * cmdq_get_source(struct cmdq_item *item)
Definition: cmd-queue.c:178
struct cmd_find_state * cmdq_get_target(struct cmdq_item *item)
Definition: cmd-queue.c:171
static enum cmd_retval cmdq_error_callback(struct cmdq_item *item, void *data)
Definition: cmd-queue.c:659
static void cmdq_remove(struct cmdq_item *item)
Definition: cmd-queue.c:441
void cmdq_guard(struct cmdq_item *item, const char *guard, int flags)
Definition: cmd-queue.c:780
struct key_event * cmdq_get_event(struct cmdq_item *item)
Definition: cmd-queue.c:185
struct cmdq_list * cmdq_new(void)
Definition: cmd-queue.c:123
static const char * cmdq_name(struct client *c)
Definition: cmd-queue.c:94
struct cmdq_item * cmdq_get_command(struct cmd_list *cmdlist, struct cmdq_state *state)
Definition: cmd-queue.c:474
struct cmdq_item * cmdq_append(struct client *c, struct cmdq_item *item)
Definition: cmd-queue.c:288
TAILQ_HEAD(cmdq_item_list, cmdq_item)
void cmdq_add_format(struct cmdq_state *state, const char *key, const char *fmt,...)
Definition: cmd-queue.c:256
static void cmdq_remove_group(struct cmdq_item *item)
Definition: cmd-queue.c:457
struct cmdq_state * cmdq_new_state(struct cmd_find_state *current, struct key_event *event, int flags)
Definition: cmd-queue.c:206
u_int cmdq_next(struct client *c)
Definition: cmd-queue.c:685
struct cmdq_item * cmdq_insert_after(struct cmdq_item *after, struct cmdq_item *item)
Definition: cmd-queue.c:312
struct cmdq_state * cmdq_copy_state(struct cmdq_state *state)
Definition: cmd-queue.c:237
struct cmdq_state * cmdq_link_state(struct cmdq_state *state)
Definition: cmd-queue.c:229
void cmdq_insert_hook(struct session *s, struct cmdq_item *item, struct cmd_find_state *current, const char *fmt,...)
Definition: cmd-queue.c:340
static enum cmd_retval cmdq_find_flag(struct cmdq_item *item, struct cmd_find_state *fs, const struct cmd_entry_flag *flag)
Definition: cmd-queue.c:519
struct cmdq_item * cmdq_running(struct client *c)
Definition: cmd-queue.c:767
static void cmdq_add_message(struct cmdq_item *item)
Definition: cmd-queue.c:539
cmdq_type
Definition: cmd-queue.c:33
@ CMDQ_COMMAND
Definition: cmd-queue.c:34
@ CMDQ_CALLBACK
Definition: cmd-queue.c:35
void cmdq_continue(struct cmdq_item *item)
Definition: cmd-queue.c:434
void cmdq_error(struct cmdq_item *item, const char *fmt,...)
Definition: cmd-queue.c:833
struct cmd_find_state * cmdq_get_current(struct cmdq_item *item)
Definition: cmd-queue.c:192
u_int cmd_get_group(struct cmd *cmd)
Definition: cmd.c:400
struct cmd * cmd_list_first(struct cmd_list *cmdlist)
Definition: cmd.c:663
struct args * cmd_get_args(struct cmd *cmd)
Definition: cmd.c:393
char * cmd_print(struct cmd *cmd)
Definition: cmd.c:560
void cmd_get_source(struct cmd *cmd, const char **file, u_int *line)
Definition: cmd.c:407
void cmd_list_free(struct cmd_list *cmdlist)
Definition: cmd.c:606
struct cmd * cmd_list_next(struct cmd *cmd)
Definition: cmd.c:670
const struct cmd_entry * cmd_get_entry(struct cmd *cmd)
Definition: cmd.c:386
void control_write(struct client *c, const char *fmt,...)
Definition: control.c:406
void file_error(struct client *c, const char *fmt,...)
Definition: file.c:250
void file_print(struct client *c, const char *fmt,...)
Definition: file.c:185
void format_merge(struct format_tree *ft, struct format_tree *from)
Definition: format.c:3012
void format_add(struct format_tree *ft, const char *key, const char *fmt,...)
Definition: format.c:3126
struct format_tree * format_create(struct client *c, struct cmdq_item *item, int tag, int flags)
Definition: format.c:3042
void format_free(struct format_tree *ft)
Definition: format.c:3066
key_code key
Definition: key-string.c:32
const char * key_string_lookup_key(key_code key, int with_flags)
Definition: key-string.c:265
const char * name
Definition: layout-set.c:38
void fatalx(const char *msg,...)
Definition: log.c:159
int log_get_level(void)
Definition: log.c:51
void log_debug(const char *msg,...)
Definition: log.c:130
union options_value * options_array_item_value(struct options_array_item *a)
Definition: options.c:549
struct options_array_item * options_array_first(struct options_entry *o)
Definition: options.c:529
struct options_array_item * options_array_next(struct options_array_item *a)
Definition: options.c:537
struct options_entry * options_get(struct options *oo, const char *name)
Definition: options.c:229
void server_client_unref(struct client *c)
struct window_pane * server_client_get_pane(struct client *c)
void server_add_message(const char *fmt,...)
Definition: server.c:513
void status_message_set(struct client *c, int delay, int ignore_styles, int ignore_keys, const char *fmt,...)
Definition: status.c:428
Definition: arguments.c:37
Definition: tmux.h:1435
int argc
Definition: tmux.h:1437
char ** argv
Definition: tmux.h:1438
Definition: tmux.h:1608
int retval
Definition: tmux.h:1622
struct cmdq_list * queue
Definition: tmux.h:1611
int references
Definition: tmux.h:1746
const char * name
Definition: tmux.h:1609
struct session * session
Definition: tmux.h:1743
uint64_t flags
Definition: tmux.h:1703
Definition: tmux.h:1518
int flags
Definition: tmux.h:1521
char flag
Definition: tmux.h:1519
enum cmd_find_type type
Definition: tmux.h:1520
Definition: tmux.h:1525
struct cmd_entry_flag source
Definition: tmux.h:1536
const char * name
Definition: tmux.h:1526
struct cmd_entry_flag target
Definition: tmux.h:1537
int flags
Definition: tmux.h:1545
enum cmd_retval(* exec)(struct cmd *, struct cmdq_item *)
Definition: tmux.h:1547
struct session * s
Definition: tmux.h:1451
int references
Definition: tmux.h:1469
Definition: cmd.c:212
char * file
Definition: cmd.c:217
u_int line
Definition: cmd.c:218
const struct cmd_entry * entry
Definition: cmd.c:213
struct client * target_client
Definition: cmd-queue.c:45
struct cmd * cmd
Definition: cmd-queue.c:60
cmdq_cb cb
Definition: cmd-queue.c:62
char * name
Definition: cmd-queue.c:40
enum cmdq_type type
Definition: cmd-queue.c:47
struct cmd_list * cmdlist
Definition: cmd-queue.c:59
void * data
Definition: cmd-queue.c:63
struct cmdq_list * queue
Definition: cmd-queue.c:41
int flags
Definition: cmd-queue.c:53
u_int group
Definition: cmd-queue.c:48
u_int number
Definition: cmd-queue.c:50
time_t time
Definition: cmd-queue.c:51
struct cmd_find_state source
Definition: cmd-queue.c:56
struct cmdq_item * next
Definition: cmd-queue.c:42
struct cmd_find_state target
Definition: cmd-queue.c:57
struct cmdq_state * state
Definition: cmd-queue.c:55
struct client * client
Definition: cmd-queue.c:44
struct cmdq_item * item
Definition: cmd-queue.c:88
struct cmdq_item_list list
Definition: cmd-queue.c:89
struct key_event event
Definition: cmd-queue.c:82
int references
Definition: cmd-queue.c:77
struct format_tree * formats
Definition: cmd-queue.c:80
int flags
Definition: cmd-queue.c:78
struct cmd_find_state current
Definition: cmd-queue.c:83
key_code key
Definition: tmux.h:1267
Definition: options.c:50
Definition: tmux.h:1179
struct options * options
Definition: tmux.h:1199
Definition: tmux.h:927
const struct window_mode * mode
Definition: tmux.h:931
struct window_pane * wp
Definition: tmux.h:928
struct options * global_s_options
Definition: tmux.c:37
#define CMDQ_STATE_NOHOOKS
Definition: tmux.h:1512
#define cmdq_get_callback(cb, data)
Definition: tmux.h:2364
#define CLIENT_UTF8
Definition: tmux.h:1670
void window_copy_add(struct window_pane *, const char *,...)
Definition: window-copy.c:503
cmd_retval
Definition: tmux.h:1475
@ CMD_RETURN_NORMAL
Definition: tmux.h:1477
@ CMD_RETURN_ERROR
Definition: tmux.h:1476
@ CMD_RETURN_WAIT
Definition: tmux.h:1478
#define CMDQ_STATE_CONTROL
Definition: tmux.h:1511
#define CMD_CLIENT_CFLAG
Definition: tmux.h:1542
#define CMD_AFTERHOOK
Definition: tmux.h:1541
#define KEYC_NONE
Definition: tmux.h:113
char * utf8_sanitize(const char *)
Definition: utf8.c:408
int window_pane_set_mode(struct window_pane *, struct window_pane *, const struct window_mode *, struct cmd_find_state *, struct args *)
Definition: window.c:1068
enum cmd_retval(* cmdq_cb)(struct cmdq_item *, void *)
Definition: tmux.h:1515
#define CMD_CLIENT_TFLAG
Definition: tmux.h:1543
#define FORMAT_NONE
Definition: tmux.h:1973
#define CLIENT_CONTROL
Definition: tmux.h:1667
#define CMD_CLIENT_CANFAIL
Definition: tmux.h:1544
const struct window_mode window_view_mode
Definition: window-copy.c:157
struct cmd_list * cmdlist
Definition: tmux.h:1806
int xsnprintf(char *str, size_t len, const char *fmt,...)
Definition: xmalloc.c:135
int xasprintf(char **ret, const char *fmt,...)
Definition: xmalloc.c:109
void * xcalloc(size_t nmemb, size_t size)
Definition: xmalloc.c:41
char * xstrdup(const char *str)
Definition: xmalloc.c:89
int xvasprintf(char **ret, const char *fmt, va_list ap)
Definition: xmalloc.c:122