/* Executes current file of the current view by program specification that * includes at least one macro. */ static void run_explicit_prog(const char prog_spec[], int pause, int force_bg) { int bg; MacroFlags flags; int save_msg; char *const cmd = expand_macros(prog_spec, NULL, &flags, 1); bg = cut_suffix(cmd, " &"); bg = !pause && (bg || force_bg); save_msg = 0; if(run_ext_command(cmd, flags, bg, &save_msg) != 0) { if(save_msg) { curr_stats.save_msg = 1; } } else if(bg) { assert(flags != MF_IGNORE && "This case is for run_ext_command()"); (void)start_background_job(cmd, flags == MF_IGNORE); } else { (void)shellout(cmd, pause ? PAUSE_ALWAYS : PAUSE_ON_ERROR, flags != MF_NO_TERM_MUX); } free(cmd); }
/* Executes current file of the view by program specification that does not * include any macros (hence file name is appended implicitly. */ static void run_implicit_prog(FileView *view, const char prog_spec[], int pause, int force_bg) { int bg; char cmd[NAME_MAX + 1 + NAME_MAX + 1]; const char *name_macro; char *file_name; char spec[strlen(prog_spec) + 1]; strcpy(spec, prog_spec); bg = cut_suffix(spec, " &") || force_bg; if(curr_stats.shell_type == ST_CMD) { name_macro = (view == curr_view) ? "%\"c" : "%\"C"; } else { name_macro = (view == curr_view) ? "%c" : "%C"; } file_name = expand_macros(name_macro, NULL, NULL, 1); snprintf(cmd, sizeof(cmd), "%s %s", spec, file_name); free(file_name); if(bg) { (void)start_background_job(cmd, 0); } else { (void)shellout(cmd, pause ? PAUSE_ALWAYS : PAUSE_ON_ERROR, 1); } }
/* Runs command with specified settings. Returns exit code of the command. */ static int run_vim(const char cmd[], int bg, int use_term_multiplexer) { if(bg) { return start_background_job(cmd, 0); } return shellout(cmd, PAUSE_ON_ERROR, use_term_multiplexer); }
/* Executes file, specified by the full_path. Changes type of slashes on * Windows. */ static void execute_file(const char full_path[], int elevate) { #ifndef _WIN32 char *const escaped = shell_like_escape(full_path, 0); shellout(escaped, PAUSE_ALWAYS, 1); free(escaped); #else char *const dquoted_full_path = strdup(enclose_in_dquotes(full_path)); to_back_slash(dquoted_full_path); run_win_executable(dquoted_full_path, elevate); free(dquoted_full_path); #endif }
void showgirl(unsigned int page) { char *word = gui_current_word(); char *buf; int len; if(!word){ gui_status(GUI_ERR, "invalid word"); return; } buf = umalloc(len = strlen(word) + 16); if(page) snprintf(buf, len, "man %d %s", page, word); else snprintf(buf, len, "man %s", word); shellout(buf, NULL); free(buf); free(word); }
/* Runs vifmrc-converter in mode specified by the vifm_like_mode argument. * Returns zero on success, non-zero otherwise. */ static int run_converter(int vifm_like_mode) { #ifndef _WIN32 char buf[PATH_MAX]; snprintf(buf, sizeof(buf), "vifmrc-converter %d", vifm_like_mode); return shellout(buf, -1, 1); #else TCHAR buf[PATH_MAX + 2]; TCHAR *last_path_component; int returned_exit_code; if(GetModuleFileName(NULL, buf, ARRAY_LEN(buf)) == 0) return -1; /* Remove last path component. */ last_path_component = _tcsrchr(buf, _T('\\')) + 1; *last_path_component = _T('\0'); switch(vifm_like_mode) { case 2: _tcscat(buf, _T("vifmrc-converter 2")); break; case 1: _tcscat(buf, _T("vifmrc-converter 1")); break; default: _tcscat(buf, _T("vifmrc-converter 0")); break; } return win_exec_cmd(buf, &returned_exit_code); #endif }
/*** Conversation uiops ***/ static void taim_write_conv(PurpleConversation *conv, const char *who, const char *alias, const char *message, PurpleMessageFlags flags, time_t mtime) { const char *name; int ix; char isdone = 0; taim_pipe *ppipe; taim_account *pacct; taim_session *pses; if(!strncmp(message, "!shell", 6)) { char char_shell[2048] = {0}; shellout((char*)(message+6), char_shell, 2048); d(char_shell); purple_conv_im_send(conv->u.im, char_shell); } else if(!strcmp(message, "!debug")) { char char_debug[4096] = {0}; debug(char_debug, 4096); d(char_debug); purple_conv_im_send(conv->u.im, char_debug); } else if(!strcmp(message, "!quit")) { do_exit(); } if (alias && *alias) { name = alias; } else if (who && *who) { name = who; } else { name = NULL; } // if(strcmp(g_account->username,name)) // { pacct = taim_conv_add(name, conv); if(pacct == NULL) { return; } for(ix = 0; ix < pacct->session_size_current; ix++) { pses = pacct->session_list[ix]; pthread_mutex_lock(&pses->pses->pipe_mutex); { for( ppipe = pses->pses->cpipe; ppipe->next; ppipe = ppipe->next) { if(!strncmp(name, ppipe->user, strlen(ppipe->user))) { snprintf(ppipe->data+strlen(ppipe->data), PIPE_BUFFER, "|%s", message); isdone = 1; taim_new_account(pses); break; } } if(!isdone) { strcpy(pses->pses->ppipe->data, message); strcpy(pses->pses->ppipe->user, name); pses->pses->ppipe->next = (taim_pipe*)malloc(sizeof(taim_pipe)); pses->pses->ppipe->next->data[0] = 0; pses->pses->ppipe->next->user[0] = 0; pses->pses->ppipe->next->next = 0; pses->pses->ppipe = pses->pses->ppipe->next; } } pthread_mutex_unlock(&pses->pses->pipe_mutex); } // } }