/* * autocomplete.c * vim: expandtab:ts=4:sts=4:sw=4 * * Copyright (C) 2012 - 2019 James Booth * * This file is part of Profanity. * * Profanity is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Profanity is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Profanity. If not, see . * * In addition, as a special exception, the copyright holders give permission to * link the code of portions of this program with the OpenSSL library under * certain conditions as described in each individual source file, and * distribute linked combinations including the two. * * You must obey the GNU General Public License in all respects for all of the * code used other than OpenSSL. If you modify file(s) with this exception, you * may extend this exception to your version of the file(s), but you are not * obligated to do so. If you do not wish to do so, delete this exception * statement from your version. If you delete this exception statement from all * source files in the program, then also delete it here. * */ #include "config.h" #include #include #include #include #include "common.h" #include "tools/autocomplete.h" #include "tools/parser.h" #include "ui/ui.h" typedef enum { PREVIOUS, NEXT } search_direction; struct autocomplete_t { GList* items; GList* last_found; gchar* search_str; }; static gchar* _search(Autocomplete ac, GList* curr, gboolean quote, search_direction direction); Autocomplete autocomplete_new(void) { Autocomplete new = malloc(sizeof(struct autocomplete_t)); new->items = NULL; new->last_found = NULL; new->search_str = NULL; return new; } void autocomplete_clear(Autocomplete ac) { if (ac) { if (ac->items) { g_list_free_full(ac->items, free); ac->items = NULL; } autocomplete_reset(ac); } } void autocomplete_reset(Autocomplete ac) { ac->last_found = NULL; FREE_SET_NULL(ac->search_str); } void autocomplete_free(Autocomplete ac) { if (ac) { autocomplete_clear(ac); free(ac); } } gint autocomplete_length(Autocomplete ac) { if (!ac) { return 0; } else if (!ac->items) { return 0; } else { return g_list_length(ac->items); } } void autocomplete_update(Autocomplete ac, char** items) { gchar* last_found = NULL; gchar* search_str = NULL; if (ac->last_found) { last_found = strdup(ac->last_found->data); } if (ac->search_str) { search_str = strdup(ac->search_str); } autocomplete_clear(ac); autocomplete_add_all(ac, items); if (last_found) { // NULL if last_found was removed on update. ac->last_found = g_list_find_custom(ac->items, last_found, (GCompareFunc)strcmp); free(last_found); } if (search_str) { ac->search_str = strdup(search_str); free(search_str); } } void autocomplete_add_reverse(Autocomplete ac, const char* item) { if (ac) { char* item_cpy; GList* curr = g_list_find_custom(ac->items, item, (GCompareFunc)strcmp); // if item already exists if (curr) { return; } item_cpy = strdup(item); ac->items = g_list_prepend(ac->items, item_cpy); } } void autocomplete_add(Autocomplete ac, const char* item) { if (ac) { char* item_cpy; GList* curr = g_list_find_custom(ac->items, item, (GCompareFunc)strcmp); // if item already exists if (curr) { return; } item_cpy = strdup(item); ac->items = g_list_insert_sorted(ac->items, item_cpy, (GCompareFunc)strcmp); } } void autocomplete_add_all(Autocomplete ac, char** items) { for (int i = 0; i < g_strv_length(items); i++) { autocomplete_add(ac, items[i]); } } void autocomplete_remove(Autocomplete ac, const char* const item) { if (ac) { GList* curr = g_list_find_custom(ac->items, item, (GCompareFunc)strcmp); if (!curr) { return; } // reset last found if it points to the item to be removed if (ac->last_found == curr) { ac->last_found = NULL; } free(
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module ranger.ext.human_readable</title>
</head><body bgcolor="#f0f0f8">

<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom>&nbsp;<br>
<font color=&quo