int cmd_move_window_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; struct session *src, *dst; struct winlink *wl; char *cause; int idx, kflag, dflag; if ((wl = cmd_find_window(ctx, args_get(args, 's'), &src)) == NULL) return (-1); if ((idx = cmd_find_index(ctx, args_get(args, 't'), &dst)) == -2) return (-1); kflag = args_has(self->args, 'k'); dflag = args_has(self->args, 'd'); if (server_link_window(src, wl, dst, idx, kflag, !dflag, &cause) != 0) { ctx->error(ctx, "can't move window: %s", cause); xfree(cause); return (-1); } server_unlink_window(src, wl); recalculate_sizes(); return (0); }
/*********************************************************************** * * Function: cmd_process * * Purpose: Parses and processes the passed command string * * Processing: * Break up the parse string into whitespace seperated components * and convert the components according to the parse list. Route * to the command function based on the parsed command. * * Parameters: * parse_str : String to parse * * Outputs: None * * Returns: TRUE if the command was processed, otherwise FALSE * * Notes: None * **********************************************************************/ BOOL_32 cmd_process(UNS_8 *parse_str) { CMD_ROUTE_T *pCmd; BOOL_32 cmdok = TRUE; GROUP_LIST_T *pGroup = &group_list_head; // Parse the string into whitespace seperated elements and find // matching command parse_string(parse_str); cmdok = cmd_find_index(get_parsed_entry(0), &pGroup, &pCmd); if (cmdok == FALSE) { term_dat_out_crlf(errorcmd_msg); } else if (pCmd == NULL) { // Group command only term_dat_out_crlf(errorgrp_msg); } else if (cmd_parse_fields(pCmd) == FALSE) { term_dat_out(errorparse_msg); cmd_show_cmd_syntax(pCmd); cmdok = FALSE; } else { // Process command cmdok = pCmd->func(); } return cmdok; }
int cmd_move_window_exec(struct cmd *self, struct cmd_ctx *ctx) { struct cmd_srcdst_data *data = self->data; struct session *src, *dst; struct winlink *wl; char *cause; int idx, kflag, dflag; if ((wl = cmd_find_window(ctx, data->src, &src)) == NULL) return (-1); if ((idx = cmd_find_index(ctx, data->dst, &dst)) == -2) return (-1); kflag = cmd_check_flag(data->chflags, 'k'); dflag = cmd_check_flag(data->chflags, 'd'); if (server_link_window(src, wl, dst, idx, kflag, !dflag, &cause) != 0) { ctx->error(ctx, "can't move window: %s", cause); xfree(cause); return (-1); } server_unlink_window(src, wl); recalculate_sizes(); return (0); }
enum cmd_retval cmd_link_window_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; struct session *src, *dst; struct winlink *wl; char *cause; int idx, kflag, dflag; if ((wl = cmd_find_window(cmdq, args_get(args, 's'), &src)) == NULL) return (CMD_RETURN_ERROR); if ((idx = cmd_find_index(cmdq, args_get(args, 't'), &dst)) == -2) return (CMD_RETURN_ERROR); kflag = args_has(self->args, 'k'); dflag = args_has(self->args, 'd'); if (server_link_window(src, wl, dst, idx, kflag, !dflag, &cause) != 0) { cmdq_error(cmdq, "can't link window: %s", cause); free(cause); return (CMD_RETURN_ERROR); } recalculate_sizes(); return (CMD_RETURN_NORMAL); }
/*********************************************************************** * * Function: cmd_help * * Purpose: Processes the help command * * Processing: * See function. * * Parameters: None * * Outputs: None * * Returns: Nothing * * Notes: None * **********************************************************************/ BOOL_32 cmd_help(void) { GROUP_LIST_T *pGroup = &group_list_head; UNS_8 *str = get_parsed_entry(1); CMD_ROUTE_T *pCmd; // If this is just the help command with no arguments, then display // the standard help message if (parse_get_entry_count() == 1) { cmd_show_group_help(pGroup, FALSE); } else { // Verify second argument if (str_cmp(str, "menu") == 0) { // Show everything while (pGroup != NULL) { cmd_show_group_help(pGroup, FALSE); pGroup = pGroup->next_group; } } else if (str_cmp(str, "all") == 0) { // Show everything while (pGroup != NULL) { cmd_show_group_help(pGroup, TRUE); pGroup = pGroup->next_group; } } else { // Second argument is either a command or group name, so // attempt to find the matching name if (cmd_find_index(str, &pGroup, &pCmd) == FALSE) { // No matching group or command term_dat_out_crlf(helperr_msg); } else { if (pCmd != NULL) { cmd_show_cmd_help(pCmd); } else { cmd_show_group_help(pGroup, TRUE); } } } } return TRUE; }
enum cmd_retval cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; struct session *s; struct winlink *wl; struct client *c; const char *cmd, *template; char *cause, *cp; int idx, last, detached, cwd, fd = -1; struct format_tree *ft; if (args_has(args, 'a')) { wl = cmd_find_window(cmdq, args_get(args, 't'), &s); if (wl == NULL) return (CMD_RETURN_ERROR); idx = wl->idx + 1; /* Find the next free index. */ for (last = idx; last < INT_MAX; last++) { if (winlink_find_by_index(&s->windows, last) == NULL) break; } if (last == INT_MAX) { cmdq_error(cmdq, "no free window indexes"); return (CMD_RETURN_ERROR); } /* Move everything from last - 1 to idx up a bit. */ for (; last > idx; last--) { wl = winlink_find_by_index(&s->windows, last - 1); server_link_window(s, wl, s, last, 0, 0, NULL); server_unlink_window(s, wl); } } else { if ((idx = cmd_find_index(cmdq, args_get(args, 't'), &s)) == -2) return (CMD_RETURN_ERROR); } detached = args_has(args, 'd'); wl = NULL; if (idx != -1) wl = winlink_find_by_index(&s->windows, idx); if (wl != NULL && args_has(args, 'k')) { /* * Can't use session_detach as it will destroy session if this * makes it empty. */ notify_window_unlinked(s, wl->window); wl->flags &= ~WINLINK_ALERTFLAGS; winlink_stack_remove(&s->lastw, wl); winlink_remove(&s->windows, wl); /* Force select/redraw if current. */ if (wl == s->curw) { detached = 0; s->curw = NULL; } } if (args->argc == 0) cmd = options_get_string(&s->options, "default-command"); else cmd = args->argv[0]; if (args_has(args, 'c')) { ft = format_create(); if ((c = cmd_find_client(cmdq, NULL, 1)) != NULL) format_client(ft, c); format_session(ft, s); format_winlink(ft, s, s->curw); format_window_pane(ft, s->curw->window->active); cp = format_expand(ft, args_get(args, 'c')); format_free(ft); fd = open(cp, O_RDONLY|O_DIRECTORY); free(cp); if (fd == -1) { cmdq_error(cmdq, "bad working directory: %s", strerror(errno)); return (CMD_RETURN_ERROR); } cwd = fd; } else if (cmdq->client != NULL && cmdq->client->session == NULL) cwd = cmdq->client->cwd; else cwd = s->cwd; if (idx == -1) idx = -1 - options_get_number(&s->options, "base-index"); wl = session_new(s, args_get(args, 'n'), cmd, cwd, idx, &cause); if (wl == NULL) { cmdq_error(cmdq, "create window failed: %s", cause); free(cause); goto error; } if (!detached) { session_select(s, wl->idx); server_redraw_session_group(s); } else server_status_session_group(s); if (args_has(args, 'P')) { if ((template = args_get(args, 'F')) == NULL)
enum cmd_retval cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; struct session *s; struct winlink *wl; struct client *c; const char *cmd, *cwd; const char *template; char *cause; int idx, last, detached; struct format_tree *ft; char *cp; if (args_has(args, 'a')) { wl = cmd_find_window(ctx, args_get(args, 't'), &s); if (wl == NULL) return (CMD_RETURN_ERROR); idx = wl->idx + 1; /* Find the next free index. */ for (last = idx; last < INT_MAX; last++) { if (winlink_find_by_index(&s->windows, last) == NULL) break; } if (last == INT_MAX) { ctx->error(ctx, "no free window indexes"); return (CMD_RETURN_ERROR); } /* Move everything from last - 1 to idx up a bit. */ for (; last > idx; last--) { wl = winlink_find_by_index(&s->windows, last - 1); server_link_window(s, wl, s, last, 0, 0, NULL); server_unlink_window(s, wl); } } else { if ((idx = cmd_find_index(ctx, args_get(args, 't'), &s)) == -2) return (CMD_RETURN_ERROR); } detached = args_has(args, 'd'); wl = NULL; if (idx != -1) wl = winlink_find_by_index(&s->windows, idx); if (wl != NULL && args_has(args, 'k')) { /* * Can't use session_detach as it will destroy session if this * makes it empty. */ notify_window_unlinked(s, wl->window); wl->flags &= ~WINLINK_ALERTFLAGS; winlink_stack_remove(&s->lastw, wl); winlink_remove(&s->windows, wl); /* Force select/redraw if current. */ if (wl == s->curw) { detached = 0; s->curw = NULL; } } if (args->argc == 0) cmd = options_get_string(&s->options, "default-command"); else cmd = args->argv[0]; cwd = cmd_get_default_path(ctx, args_get(args, 'c')); if (idx == -1) idx = -1 - options_get_number(&s->options, "base-index"); wl = session_new(s, args_get(args, 'n'), cmd, cwd, idx, &cause); if (wl == NULL) { ctx->error(ctx, "create window failed: %s", cause); free(cause); return (CMD_RETURN_ERROR); } if (!detached) { session_select(s, wl->idx); server_redraw_session_group(s); } else server_status_session_group(s); if (args_has(args, 'P')) { if ((template = args_get(args, 'F')) == NULL)
int cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx) { struct cmd_new_window_data *data = self->data; struct session *s; struct winlink *wl; char *cmd, *cwd, *cause; int idx, last; if (data == NULL) return (0); if (data->flag_insert_after) { if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL) return (-1); idx = wl->idx + 1; /* Find the next free index. */ for (last = idx; last < INT_MAX; last++) { if (winlink_find_by_index(&s->windows, last) == NULL) break; } if (last == INT_MAX) { ctx->error(ctx, "no free window indexes"); return (-1); } /* Move everything from last - 1 to idx up a bit. */ for (; last > idx; last--) { wl = winlink_find_by_index(&s->windows, last - 1); server_link_window(s, wl, s, last, 0, 0, NULL); server_unlink_window(s, wl); } } else { if ((idx = cmd_find_index(ctx, data->target, &s)) == -2) return (-1); } wl = NULL; if (idx != -1) wl = winlink_find_by_index(&s->windows, idx); if (wl != NULL && data->flag_kill) { /* * Can't use session_detach as it will destroy session if this * makes it empty. */ wl->flags &= ~WINLINK_ALERTFLAGS; winlink_stack_remove(&s->lastw, wl); winlink_remove(&s->windows, wl); /* Force select/redraw if current. */ if (wl == s->curw) { data->flag_detached = 0; s->curw = NULL; } } cmd = data->cmd; if (cmd == NULL) cmd = options_get_string(&s->options, "default-command"); cwd = options_get_string(&s->options, "default-path"); if (*cwd == '\0') { if (ctx->cmdclient != NULL && ctx->cmdclient->cwd != NULL) cwd = ctx->cmdclient->cwd; else cwd = s->cwd; } if (idx == -1) idx = -1 - options_get_number(&s->options, "base-index"); wl = session_new(s, data->name, cmd, cwd, idx, &cause); if (wl == NULL) { ctx->error(ctx, "create window failed: %s", cause); xfree(cause); return (-1); } if (!data->flag_detached) { session_select(s, wl->idx); server_redraw_session_group(s); } else server_status_session_group(s); if (data->flag_print) ctx->print(ctx, "%s:%u", s->name, wl->idx); return (0); }