Exemplo n.º 1
0
char*
autocompleters_complete(const char * const input, gboolean previous)
{
    char *result = NULL;

    GList *ac_hashes = g_hash_table_get_values(plugin_to_acs);
    GList *curr_hash = ac_hashes;
    while (curr_hash) {
        GHashTable *key_to_ac = curr_hash->data;

        GList *keys = g_hash_table_get_keys(key_to_ac);
        GList *curr = keys;
        while (curr) {
            result = autocomplete_param_with_ac(input, curr->data, g_hash_table_lookup(key_to_ac, curr->data), TRUE, previous);
            if (result) {
                g_list_free(ac_hashes);
                g_list_free(keys);
                return result;
            }
            curr = g_list_next(curr);
        }
        g_list_free(keys);

        curr_hash = g_list_next(curr_hash);
    }
    g_list_free(ac_hashes);

    GList *filepath_hashes = g_hash_table_get_values(plugin_to_filepath_acs);
    curr_hash = filepath_hashes;
    while (curr_hash) {
        GHashTable *prefixes_hash = curr_hash->data;
        GList *prefixes = g_hash_table_get_keys(prefixes_hash);
        GList *curr_prefix = prefixes;
        while (curr_prefix) {
            char *prefix = curr_prefix->data;
            if (g_str_has_prefix(input, prefix)) {
                result = cmd_ac_complete_filepath(input, prefix, previous);
                if (result) {
                    g_list_free(filepath_hashes);
                    g_list_free(prefixes);
                    return result;
                }
            }

            curr_prefix = g_list_next(curr_prefix);
        }
        g_list_free(prefixes);

        curr_hash = g_list_next(curr_hash);
    }
    g_list_free(filepath_hashes);

    return NULL;
}
Exemplo n.º 2
0
void
muc_autocomplete(char *input, int *size)
{
    char *recipient = ui_current_recipient();
    Autocomplete nick_ac = muc_get_roster_ac(recipient);
    if (nick_ac != NULL) {
        input[*size] = '\0';
        gchar *last_space = g_strrstr(input, " ");
        char *result = NULL;
        if (last_space == NULL) {
            result = autocomplete_complete(nick_ac, input);
        } else {
            int len = (last_space - input);
            char *start_str = strndup(input, len);
            result = autocomplete_param_with_ac(input, size, start_str, nick_ac);
            free(start_str);
        }
        if (result != NULL) {
            ui_replace_input(input, result, size);
            g_free(result);
            return;
        }
    }
}