Ejemplo n.º 1
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;
}
Ejemplo n.º 2
0
/* Finds record that corresponds to an external command that is available.
 * Returns the record on success or an empty record on failure. */
static assoc_record_t
find_existing_cmd_record(const assoc_records_t *records)
{
	static assoc_record_t empty_record;

	int i;
	for(i = 0; i < records->count; ++i)
	{
		char cmd_name[NAME_MAX];
		(void)extract_cmd_name(records->list[i].command, 0, sizeof(cmd_name),
				cmd_name);

		if(external_command_exists_func == NULL ||
				external_command_exists_func(cmd_name))
		{
			return records->list[i];
		}
	}

	return empty_record;
}
Ejemplo n.º 3
0
static void
complete_progs(const char *str, assoc_records_t records)
{
	int i;
	const size_t len = strlen(str);

	for(i = 0; i < records.count; i++)
	{
		char command[NAME_MAX];

		(void)extract_cmd_name(records.list[i].command, 1, sizeof(command),
				command);

		if(strnoscmp(command, str, len) == 0)
		{
			char *const escaped = escape_chars(command, "|");
			vle_compl_add_match(escaped);
			free(escaped);
		}
	}
}
Ejemplo n.º 4
0
int
get_default_program_for_file(const char *file, assoc_record_t *result)
{
    int j;
    assoc_records_t records;
    assoc_record_t prog;

    j = 0;
    records = get_all_programs_for_file(file);
    while(j < records.count)
    {
        char name_buf[NAME_MAX];
        (void)extract_cmd_name(records.list[j].command, 0, sizeof(name_buf),
                               name_buf);
        if(external_command_exists_func == NULL ||
                external_command_exists_func(name_buf))
            break;
        j++;
    }
    if(j >= records.count)
    {
        free(records.list);
        return 0;
    }

    prog = records.list[j];
    result->command = strdup(prog.command);
    result->description = strdup(prog.description);
    free(records.list);

    if(result->command == NULL || result->description == NULL)
    {
        free_assoc_record(result);
        return 0;
    }

    return 1;
}