void cmd_select_layout_key_binding(struct cmd *self, int key) { switch (key) { case '1' | KEYC_ESCAPE: self->args = args_create(1, "even-horizontal"); break; case '2' | KEYC_ESCAPE: self->args = args_create(1, "even-vertical"); break; case '3' | KEYC_ESCAPE: self->args = args_create(1, "main-horizontal"); break; case '4' | KEYC_ESCAPE: self->args = args_create(1, "main-vertical"); break; case '5' | KEYC_ESCAPE: self->args = args_create(1, "tiled"); break; case 'u': self->args = args_create(0); args_set(self->args, 'u', NULL); break; case 'U': self->args = args_create(0); args_set(self->args, 'U', NULL); break; default: self->args = args_create(0); break; } }
void cmd_swap_pane_key_binding(struct cmd *self, int key) { self->args = args_create(0); if (key == '{') args_set(self->args, 'U', NULL); else if (key == '}') args_set(self->args, 'D', NULL); }
void cmd_select_window_key_binding(struct cmd *self, int key) { char tmp[16]; self->args = args_create(0); if (key >= '0' && key <= '9') { xsnprintf(tmp, sizeof tmp, ":%d", key - '0'); args_set(self->args, 't', tmp); } if (key == ('n' | KEYC_ESCAPE) || key == ('p' | KEYC_ESCAPE)) args_set(self->args, 'a', NULL); }
void cmd_select_pane_key_binding(struct cmd *self, int key) { self->args = args_create(0); if (key == KEYC_UP) args_set(self->args, 'U', NULL); if (key == KEYC_DOWN) args_set(self->args, 'D', NULL); if (key == KEYC_LEFT) args_set(self->args, 'L', NULL); if (key == KEYC_RIGHT) args_set(self->args, 'R', NULL); if (key == 'o') args_set(self->args, 't', ":.+"); }
void cmd_copy_mode_key_binding(struct cmd *self, int key) { self->args = args_create(0); if (key == KEYC_PPAGE) args_set(self->args, 'u', NULL); }
void cmd_split_window_key_binding(struct cmd *self, int key) { self->args = args_create(0); if (key == '%') args_set(self->args, 'h', NULL); }
void cmd_switch_client_key_binding(struct cmd *self, int key) { self->args = args_create(0); switch (key) { case '(': args_set(self->args, 'p', NULL); break; case ')': args_set(self->args, 'n', NULL); break; case 'L': args_set(self->args, 'l', NULL); break; } }
void cmd_confirm_before_key_binding(struct cmd *self, int key) { switch (key) { case '&': self->args = args_create(1, "kill-window"); args_set(self->args, 'p', "kill-window #W? (y/n)"); break; case 'x': self->args = args_create(1, "kill-pane"); args_set(self->args, 'p', "kill-pane #P? (y/n)"); break; default: self->args = args_create(0); break; } }
void cmd_resize_pane_key_binding(struct cmd *self, int key) { switch (key) { case KEYC_UP | KEYC_CTRL: self->args = args_create(0); args_set(self->args, 'U', NULL); break; case KEYC_DOWN | KEYC_CTRL: self->args = args_create(0); args_set(self->args, 'D', NULL); break; case KEYC_LEFT | KEYC_CTRL: self->args = args_create(0); args_set(self->args, 'L', NULL); break; case KEYC_RIGHT | KEYC_CTRL: self->args = args_create(0); args_set(self->args, 'R', NULL); break; case KEYC_UP | KEYC_ESCAPE: self->args = args_create(1, "5"); args_set(self->args, 'U', NULL); break; case KEYC_DOWN | KEYC_ESCAPE: self->args = args_create(1, "5"); args_set(self->args, 'D', NULL); break; case KEYC_LEFT | KEYC_ESCAPE: self->args = args_create(1, "5"); args_set(self->args, 'L', NULL); break; case KEYC_RIGHT | KEYC_ESCAPE: self->args = args_create(1, "5"); args_set(self->args, 'R', NULL); break; case 'z': self->args = args_create(0); args_set(self->args, 'Z', NULL); break; default: self->args = args_create(0); break; } }
void cmd_join_pane_key_binding(struct cmd *self, int key) { switch (key) { case '%': self->args = args_create(0); args_set(self->args, 'h', NULL); break; default: self->args = args_create(0); break; } }
static enum cmd_retval cmd_find_window_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args, *new_args; struct window_pane *wp = item->target.wp; const char *s = args->argv[0]; char *filter, *argv = { NULL }; int C, N, T; C = args_has(args, 'C'); N = args_has(args, 'N'); T = args_has(args, 'T'); if (!C && !N && !T) C = N = T = 1; if (C && N && T) { xasprintf(&filter, "#{||:" "#{C:%s},#{||:#{m:*%s*,#{window_name}}," "#{m:*%s*,#{pane_title}}}}", s, s, s); } else if (C && N) { xasprintf(&filter, "#{||:#{C:%s},#{m:*%s*,#{window_name}}}", s, s); } else if (C && T) { xasprintf(&filter, "#{||:#{C:%s},#{m:*%s*,#{pane_title}}}", s, s); } else if (N && T) { xasprintf(&filter, "#{||:#{m:*%s*,#{window_name}},#{m:*%s*,#{pane_title}}}", s, s); } else if (C) xasprintf(&filter, "#{C:%s}", s); else if (N) xasprintf(&filter, "#{m:*%s*,#{window_name}}", s); else xasprintf(&filter, "#{m:*%s*,#{pane_title}}", s); new_args = args_parse("", 1, &argv); args_set(new_args, 'f', filter); window_pane_set_mode(wp, &window_tree_mode, &item->target, new_args); args_free(new_args); free(filter); return (CMD_RETURN_NORMAL); }
void handle_args(BFInterpreter& interpreter, int argc, char* argv[]) { std::string code; //Set the args flag to no args entered Args args_set(static_cast<Args>(0)); //If no argument are used the Interpreter is put in console mode if (argc == 1) interpreter.set_console(); //Iteration over the argument for (int i(1); i != argc; ++i) { if (*argv[i] == '-') { try { switch (*(argv[i] + 1)) { case 'h': std::cout << HELP; args_set = args_set | Args::H; break; case 'f': if (args_set & Args::C) throw std::invalid_argument("'-f' and '-c' are unusable together\n"); if (args_set & Args::B) throw std::invalid_argument("'-f' and '-b' are unsunabe together\n"); if (argc == ++i) throw std::invalid_argument("missing filename after '-f'\n"); args_set = args_set | Args::F; interpreter.set_file(); load_file(code, argv[i]); interpreter.set_code(code); break; case 'c': if (args_set & Args::F) throw std::invalid_argument("'-f' and '-c' are unusable together\n"); if (args_set & Args::B) throw std::invalid_argument("'-c' and '-b' are unusable together\n"); args_set = args_set | Args::C; interpreter.set_console(); break; case 'b': if (args_set & Args::F) throw std::invalid_argument("'-b' and '-f' are not usable together\n"); if (args_set & Args::B) throw std::invalid_argument("'-c' and '-b' are unusable together\n"); if (argc == ++i) throw std::invalid_argument("missing filename after '-b'\n"); args_set = args_set | Args::B; interpreter.set_file(); interpreter.set_code(argv[i]); break; } //If the '-h' arg has been used we don't need to check for other args if (args_set & Args::H) break; } catch (std::invalid_argument e) { throw e; } } else { throw std::invalid_argument("Argument unknown\n"); } } }
bool hash_command_output(struct mdfour *hash, const char *command, const char *compiler) { #ifdef _WIN32 SECURITY_ATTRIBUTES sa = { sizeof(SECURITY_ATTRIBUTES), NULL, TRUE }; HANDLE pipe_out[2]; PROCESS_INFORMATION pi; STARTUPINFO si; DWORD exitcode; bool cmd = false; char *sh = NULL; char *win32args; char *path; BOOL ret; bool ok; int fd; #else pid_t pid; int pipefd[2]; #endif #ifdef _WIN32 /* trim leading space */ while (isspace(*command)) { command++; } /* add "echo" command */ if (str_startswith(command, "echo")) { command = format("cmd.exe /c \"%s\"", command); cmd = true; } else if (str_startswith(command, "%compiler%") && str_eq(compiler, "echo")) { command = format("cmd.exe /c \"%s%s\"", compiler, command + 10); cmd = true; } else { command = x_strdup(command); } #endif struct args *args = args_init_from_string(command); int i; for (i = 0; i < args->argc; i++) { if (str_eq(args->argv[i], "%compiler%")) { args_set(args, i, compiler); } } cc_log_argv("Executing compiler check command ", args->argv); #ifdef _WIN32 memset(&pi, 0x00, sizeof(pi)); memset(&si, 0x00, sizeof(si)); path = find_executable(args->argv[0], NULL); if (!path) { path = args->argv[0]; } sh = win32getshell(path); if (sh) { path = sh; } si.cb = sizeof(STARTUPINFO); CreatePipe(&pipe_out[0], &pipe_out[1], &sa, 0); SetHandleInformation(pipe_out[0], HANDLE_FLAG_INHERIT, 0); si.hStdOutput = pipe_out[1]; si.hStdError = pipe_out[1]; si.hStdInput = GetStdHandle(STD_INPUT_HANDLE); si.dwFlags = STARTF_USESTDHANDLES; if (!cmd) { win32args = win32argvtos(sh, args->argv); } else { win32args = (char *) command; /* quoted */ } ret = CreateProcess(path, win32args, NULL, NULL, 1, 0, NULL, NULL, &si, &pi); CloseHandle(pipe_out[1]); args_free(args); free(win32args); if (cmd) { free((char *) command); /* original argument was replaced above */ } if (ret == 0) { stats_update(STATS_COMPCHECK); return false; } fd = _open_osfhandle((intptr_t) pipe_out[0], O_BINARY); ok = hash_fd(hash, fd); if (!ok) { cc_log("Error hashing compiler check command output: %s", strerror(errno)); stats_update(STATS_COMPCHECK); } WaitForSingleObject(pi.hProcess, INFINITE); GetExitCodeProcess(pi.hProcess, &exitcode); CloseHandle(pipe_out[0]); CloseHandle(pi.hProcess); CloseHandle(pi.hThread); if (exitcode != 0) { cc_log("Compiler check command returned %d", (int) exitcode); stats_update(STATS_COMPCHECK); return false; } return ok; #else if (pipe(pipefd) == -1) { fatal("pipe failed"); } pid = fork(); if (pid == -1) { fatal("fork failed"); } if (pid == 0) { /* Child. */ close(pipefd[0]); close(0); dup2(pipefd[1], 1); dup2(pipefd[1], 2); _exit(execvp(args->argv[0], args->argv)); return false; /* Never reached. */ } else { /* Parent. */ int status; bool ok; args_free(args); close(pipefd[1]); ok = hash_fd(hash, pipefd[0]); if (!ok) { cc_log("Error hashing compiler check command output: %s", strerror(errno)); stats_update(STATS_COMPCHECK); } close(pipefd[0]); if (waitpid(pid, &status, 0) != pid) { cc_log("waitpid failed"); return false; } if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { cc_log("Compiler check command returned %d", WEXITSTATUS(status)); stats_update(STATS_COMPCHECK); return false; } return ok; } #endif }