Beispiel #1
0
void
execute_cmdline_command(const char cmd[])
{
	if(exec_command(cmd, curr_view, CIT_COMMAND) < 0)
	{
		status_bar_error("An error occurred while trying to execute command");
	}
	init_cmds(0, &cmds_conf);
}
Beispiel #2
0
char *
fast_run_complete(const char cmd[])
{
	char *result = NULL;
	const char *args;
	char command[NAME_MAX];
	char *completed;

	args = extract_cmd_name(cmd, 0, sizeof(command), command);

	if(is_path_absolute(command))
	{
		return strdup(cmd);
	}

	vle_compl_reset();
	complete_command_name(command);
	vle_compl_unite_groups();
	completed = vle_compl_next();

	if(vle_compl_get_count() > 2)
	{
		int c = vle_compl_get_count() - 1;
		while(c-- > 0)
		{
			if(stroscmp(command, completed) == 0)
			{
				result = strdup(cmd);
				break;
			}
			else
			{
				free(completed);
				completed = vle_compl_next();
			}
		}

		if(result == NULL)
		{
			status_bar_error("Command beginning is ambiguous");
		}
	}
	else
	{
		free(completed);
		completed = vle_compl_next();
		result = format_str("%s %s", completed, args);
	}
	free(completed);

	return result;
}
Beispiel #3
0
int
commands_scope_finish(void)
{
	if(!is_at_scope_bottom(&if_levels))
	{
		status_bar_error("Missing :endif");
		int_stack_pop_seq(&if_levels, IF_SCOPE_GUARD);
		return 1;
	}

	int_stack_pop(&if_levels);
	return 0;
}
Beispiel #4
0
/* Queries prompt input using external editor. */
static void
extedit_prompt(const char input[], int cursor_col)
{
	char *const ext_cmd = get_ext_command(input, cursor_col, GET_PROMPT_INPUT);

	if(ext_cmd != NULL)
	{
		finish_prompt_submode(ext_cmd);
	}
	else
	{
		save_prompt_history(input);

		status_bar_error("Error querying data from external source.");
		curr_stats.save_msg = 1;
	}

	free(ext_cmd);
}
Beispiel #5
0
static void
search(int backward)
{
	if(menu->regexp != NULL)
	{
		int was_msg;
		menu->match_dir = backward ? UP : DOWN;
		was_msg = search_menu_list(NULL, menu);
		wrefresh(menu_win);

		if(!was_msg)
			status_bar_messagef("%c%s", backward ? '?' : '/', menu->regexp);
	}
	else
	{
		status_bar_error("No search pattern set");
	}
	curr_stats.save_msg = 1;
}
Beispiel #6
0
void
menus_search(menu_state_t *m, int backward)
{
	if(m->regexp == NULL)
	{
		status_bar_error("No search pattern set");
		curr_stats.save_msg = 1;
		return;
	}

	m->backward_search = backward;
	(void)search_menu_list(NULL, m->d, 1);
	wrefresh(menu_win);

	if(m->matching_entries > 0)
	{
		status_bar_messagef("(%d of %d) %c%s", get_match_index(m),
				m->matching_entries, backward ? '?' : '/', m->regexp);
	}

	curr_stats.save_msg = 1;
}
Beispiel #7
0
int
compare_move(FileView *from, FileView *to)
{
	char from_path[PATH_MAX], to_path[PATH_MAX];
	char *from_fingerprint, *to_fingerprint;

	const CompareType ct = from->custom.diff_cmp_type;

	dir_entry_t *const curr = &from->dir_entry[from->list_pos];
	dir_entry_t *const other = &to->dir_entry[from->list_pos];

	if(from->custom.type != CV_DIFF || !from->custom.diff_path_group)
	{
		status_bar_error("Not in diff mode with path grouping");
		return 1;
	}

	if(curr->id == other->id && !fentry_is_fake(curr) && !fentry_is_fake(other))
	{
		/* Nothing to do if files are already equal. */
		return 0;
	}

	/* We're going at least to try to update one of views (which might refer to
	 * the same directory), so schedule a reload. */
	ui_view_schedule_reload(from);
	ui_view_schedule_reload(to);

	if(fentry_is_fake(curr))
	{
		/* Just remove the other file (it can't be fake entry too). */
		return fops_delete_current(to, 1, 0);
	}

	get_full_path_of(curr, sizeof(from_path), from_path);
	get_full_path_of(other, sizeof(to_path), to_path);

	if(fentry_is_fake(other))
	{
		char to_path[PATH_MAX];
		char canonical[PATH_MAX];
		snprintf(to_path, sizeof(to_path), "%s/%s/%s", flist_get_dir(to),
				curr->origin + strlen(flist_get_dir(from)), curr->name);
		canonicalize_path(to_path, canonical, sizeof(canonical));

		/* Copy current file to position of the other one using relative path with
		 * different base. */
		fops_replace(from, canonical, 0);

		/* Update the other entry to not be fake. */
		remove_last_path_component(canonical);
		replace_string(&other->name, curr->name);
		replace_string(&other->origin, canonical);
	}
	else
	{
		/* Overwrite file in the other pane with corresponding file from current
		 * pane. */
		fops_replace(from, to_path, 1);
	}

	/* Obtaining file fingerprint relies on size field of entries, so try to load
	 * it and ignore if it fails. */
	other->size = get_file_size(to_path);

	/* Try to update id of the other entry by computing fingerprint of both files
	 * and checking if they match. */

	from_fingerprint = get_file_fingerprint(from_path, curr, ct);
	to_fingerprint = get_file_fingerprint(to_path, other, ct);

	if(!is_null_or_empty(from_fingerprint) && !is_null_or_empty(to_fingerprint))
	{
		int match = (strcmp(from_fingerprint, to_fingerprint) == 0);
		if(match && ct == CT_CONTENTS)
		{
			match = files_are_identical(from_path, to_path);
		}
		if(match)
		{
			other->id = curr->id;
		}
	}

	free(from_fingerprint);
	free(to_fingerprint);

	return 0;
}
Beispiel #8
0
/* Returns negative value in case of error */
static int
execute_command(FileView *view, const char command[], int menu)
{
	int id;
	int result;

	if(command == NULL)
	{
		flist_sel_stash_if_nonempty(view);
		return 0;
	}

	command = skip_to_cmd_name(command);

	if(command[0] == '"')
		return 0;

	if(command[0] == '\0' && !menu)
	{
		flist_sel_stash_if_nonempty(view);
		return 0;
	}

	if(!menu)
	{
		init_cmds(1, &cmds_conf);
		cmds_conf.begin = 0;
		cmds_conf.current = view->list_pos;
		cmds_conf.end = view->list_rows - 1;
	}

	id = get_cmd_id(command);

	if(!cmd_should_be_processed(id))
	{
		return 0;
	}

	if(id == USER_CMD_ID)
	{
		char undo_msg[COMMAND_GROUP_INFO_LEN];

		snprintf(undo_msg, sizeof(undo_msg), "in %s: %s",
				replace_home_part(flist_get_dir(view)), command);

		cmd_group_begin(undo_msg);
		cmd_group_end();
	}

	keep_view_selection = 0;
	result = execute_cmd(command);

	if(result >= 0)
		return result;

	switch(result)
	{
		case CMDS_ERR_LOOP:
			status_bar_error("Loop in commands");
			break;
		case CMDS_ERR_NO_MEM:
			status_bar_error("Unable to allocate enough memory");
			break;
		case CMDS_ERR_TOO_FEW_ARGS:
			status_bar_error("Too few arguments");
			break;
		case CMDS_ERR_TRAILING_CHARS:
			status_bar_error("Trailing characters");
			break;
		case CMDS_ERR_INCORRECT_NAME:
			status_bar_error("Incorrect command name");
			break;
		case CMDS_ERR_NEED_BANG:
			status_bar_error("Add bang to force");
			break;
		case CMDS_ERR_NO_BUILTIN_REDEFINE:
			status_bar_error("Can't redefine builtin command");
			break;
		case CMDS_ERR_INVALID_CMD:
			status_bar_error("Invalid command name");
			break;
		case CMDS_ERR_NO_BANG_ALLOWED:
			status_bar_error("No ! is allowed");
			break;
		case CMDS_ERR_NO_RANGE_ALLOWED:
			status_bar_error("No range is allowed");
			break;
		case CMDS_ERR_NO_QMARK_ALLOWED:
			status_bar_error("No ? is allowed");
			break;
		case CMDS_ERR_INVALID_RANGE:
			/* message dialog is enough */
			break;
		case CMDS_ERR_NO_SUCH_UDF:
			status_bar_error("No such user defined command");
			break;
		case CMDS_ERR_UDF_IS_AMBIGUOUS:
			status_bar_error("Ambiguous use of user-defined command");
			break;
		case CMDS_ERR_ZERO_COUNT:
			status_bar_error("Zero count");
			break;
		case CMDS_ERR_INVALID_ARG:
			status_bar_error("Invalid argument");
			break;
		case CMDS_ERR_CUSTOM:
			/* error message is posted by command handler */
			break;
		default:
			status_bar_error("Unknown error");
			break;
	}

	if(!menu && vle_mode_is(NORMAL_MODE))
	{
		flist_sel_stash_if_nonempty(view);
	}

	return -1;
}