Ejemplo n.º 1
0
	int save_msg;
	custom_macro_t macros[] = {
		[M_a] = { .letter = 'a', .value = args, .uses_left = 1, .group = -1 },

		[M_u] = { .letter = 'u', .value = "",   .uses_left = 1, .group = -1 },
		[M_U] = { .letter = 'U', .value = "",   .uses_left = 1, .group = -1 },
	};

	static menu_info m;
	margs = (args[0] == '-') ? strdup(args) : shell_like_escape(args, 0);
	init_menu_info(&m, format_str("Locate %s", margs), strdup("No files found"));
	m.args = margs;
	m.execute_handler = &execute_locate_cb;
	m.key_handler = &filelist_khandler;

	cmd = expand_custom_macros(cfg.locate_prg, ARRAY_LEN(macros), macros);

	status_bar_message("locate...");
	save_msg = capture_output(view, cmd, 0, &m, macros[M_u].explicit_use,
			macros[M_U].explicit_use);
	free(cmd);

	return save_msg;
}

/* Callback that is called when menu item is selected.  Should return non-zero
 * to stay in menu mode. */
static int
execute_locate_cb(FileView *view, menu_info *m)
{
	(void)goto_selected_file(view, m->items[m->pos], 0);
Ejemplo n.º 2
0
#include <stic.h>

#include <stdlib.h>

#include "../../src/utils/macros.h"
#include "../../src/macros.h"

TEST(empty_string_ok)
{
	custom_macro_t macros[] = {
		{ .letter = 'y', .value = "xx", .uses_left = 0, .group = -1, },
	};

	const char *const pattern = "";
	char * expanded = expand_custom_macros(pattern, ARRAY_LEN(macros), macros);
	assert_string_equal("", expanded);
	free(expanded);
}

TEST(no_macros_ok)
{
	custom_macro_t macros[] = {
		{ .letter = 'i', .value = "xyz", .uses_left = 0, .group = -1, },
	};

	const char *const pattern = "no match in here";
	char * expanded = expand_custom_macros(pattern, ARRAY_LEN(macros), macros);
	assert_string_equal("no match in here", expanded);
	free(expanded);
}
Ejemplo n.º 3
0
show_apropos_menu(view_t *view, const char args[])
{
	char *cmd;
	int save_msg;
	custom_macro_t macros[] = {
		{ .letter = 'a', .value = args, .uses_left = 1, .group = -1 },
	};

	static menu_data_t m;
	menus_init_data(&m, view, format_str("Apropos %s", args),
			format_str("No matches for \'%s\'", args));
	m.execute_handler = &execute_apropos_cb;

	ui_sb_msg("apropos...");

	cmd = expand_custom_macros(cfg.apropos_prg, ARRAY_LEN(macros), macros);
	save_msg = menus_capture(view, cmd, 0, &m, 0, 0);
	free(cmd);
	return save_msg;
}

/* Callback that is called when menu item is selected.  Should return non-zero
 * to stay in menu mode. */
static int
execute_apropos_cb(view_t *view, menu_data_t *m)
{
	char section[64], topic[64];
	char command[256];
	int exit_code;

	if(parse_apropos_line(m->items[m->pos], section, sizeof(section), topic,