Esempio n. 1
0
/* 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);
	}
}
Esempio n. 2
0
/* 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);
}
Esempio n. 3
0
/* 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);
}
Esempio n. 4
0
static int
op_chmodr(void *data, const char *src, const char *dst)
{
	char cmd[128 + PATH_MAX];
	char *escaped;

	escaped = escape_filename(src, 0);
	snprintf(cmd, sizeof(cmd), "chmod -R %s %s", (char *)data, escaped);
	free(escaped);
	start_background_job(cmd, 0);
	return 0;
}
Esempio n. 5
0
int
run_ext_command(const char cmd[], MacroFlags flags, int bg, int *save_msg)
{
	if(bg && flags != MF_NONE && flags != MF_NO_TERM_MUX && flags != MF_IGNORE)
	{
		status_bar_errorf("\"%s\" macro can't be combined with \" &\"",
				macros_to_str(flags));
		*save_msg = 1;
		return -1;
	}

	if(flags == MF_STATUSBAR_OUTPUT)
	{
		output_to_statusbar(cmd);
		*save_msg = 1;
		return -1;
	}
	else if(flags == MF_IGNORE)
	{
		*save_msg = 0;
		if(bg)
		{
			int error;

			setup_shellout_env();
			error = (start_background_job(cmd, 1) != 0);
			cleanup_shellout_env();

			if(error)
			{
				status_bar_errorf("Failed to start in bg: %s", cmd);
				*save_msg = 1;
			}
		}
		else
		{
			output_to_nowhere(cmd);
		}
		return -1;
	}
	else if(flags == MF_MENU_OUTPUT || flags == MF_MENU_NAV_OUTPUT)
	{
		const int navigate = flags == MF_MENU_NAV_OUTPUT;
		setup_shellout_env();
		*save_msg = show_user_menu(curr_view, cmd, navigate) != 0;
		cleanup_shellout_env();
	}
	else if(flags == MF_SPLIT && curr_stats.term_multiplexer != TM_NONE)
	{
		run_in_split(curr_view, cmd);
	}
	else if(flags == MF_CUSTOMVIEW_OUTPUT || flags == MF_VERYCUSTOMVIEW_OUTPUT)
	{
		const int very = flags == MF_VERYCUSTOMVIEW_OUTPUT;
		output_to_custom_flist(curr_view, cmd, very);
	}
	else
	{
		return 0;
	}
	return 1;
}