2016-04-18 05:47:37 +00:00
|
|
|
// Prototypes for history functions, part of the user interface.
|
2005-10-04 15:11:39 +00:00
|
|
|
#ifndef FISH_HISTORY_H
|
|
|
|
#define FISH_HISTORY_H
|
|
|
|
|
2016-04-21 06:00:54 +00:00
|
|
|
// IWYU pragma: no_include <cstddef>
|
2015-07-25 15:14:25 +00:00
|
|
|
#include <pthread.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <time.h>
|
2016-04-18 05:47:37 +00:00
|
|
|
#include <deque>
|
2016-05-03 23:23:30 +00:00
|
|
|
#include <memory>
|
2016-04-18 05:47:37 +00:00
|
|
|
#include <set>
|
2015-07-25 15:14:25 +00:00
|
|
|
#include <string>
|
2016-04-18 05:47:37 +00:00
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
2016-04-21 06:00:54 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
#include "common.h"
|
2016-04-21 06:00:54 +00:00
|
|
|
#include "wutil.h" // IWYU pragma: keep
|
2012-02-06 00:42:24 +00:00
|
|
|
|
2016-07-14 05:33:50 +00:00
|
|
|
struct io_streams_t;
|
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Fish supports multiple shells writing to history at once. Here is its strategy:
|
|
|
|
//
|
|
|
|
// 1. All history files are append-only. Data, once written, is never modified.
|
|
|
|
//
|
|
|
|
// 2. A history file may be re-written ("vacuumed"). This involves reading in the file and writing a
|
|
|
|
// new one, while performing maintenance tasks: discarding items in an LRU fashion until we reach
|
|
|
|
// the desired maximum count, removing duplicates, and sorting them by timestamp (eventually, not
|
|
|
|
// implemented yet). The new file is atomically moved into place via rename().
|
|
|
|
//
|
|
|
|
// 3. History files are mapped in via mmap(). Before the file is mapped, the file takes a fcntl read
|
|
|
|
// lock. The purpose of this lock is to avoid seeing a transient state where partial data has been
|
|
|
|
// written to the file.
|
|
|
|
//
|
|
|
|
// 4. History is appended to under a fcntl write lock.
|
|
|
|
//
|
|
|
|
// 5. The chaos_mode boolean can be set to true to do things like lower buffer sizes which can
|
|
|
|
// trigger race conditions. This is useful for testing.
|
2012-12-03 09:53:52 +00:00
|
|
|
|
2012-07-25 05:31:31 +00:00
|
|
|
typedef std::vector<wcstring> path_list_t;
|
2012-02-15 19:33:41 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
enum history_search_type_t {
|
2016-07-30 04:24:26 +00:00
|
|
|
// Search for commands exactly matching the given string.
|
|
|
|
HISTORY_SEARCH_TYPE_EXACT = 1,
|
|
|
|
// Search for commands containing the given string.
|
2012-02-06 18:52:13 +00:00
|
|
|
HISTORY_SEARCH_TYPE_CONTAINS,
|
2016-07-30 04:24:26 +00:00
|
|
|
// Search for commands starting with the given string.
|
2012-02-06 18:52:13 +00:00
|
|
|
HISTORY_SEARCH_TYPE_PREFIX
|
|
|
|
};
|
|
|
|
|
2014-03-29 06:22:03 +00:00
|
|
|
typedef uint32_t history_identifier_t;
|
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
class history_item_t {
|
2012-02-06 00:42:24 +00:00
|
|
|
friend class history_t;
|
2012-02-16 08:24:27 +00:00
|
|
|
friend class history_tests_t;
|
2012-02-06 00:42:24 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
private:
|
|
|
|
// Attempts to merge two compatible history items together.
|
2012-03-01 22:56:34 +00:00
|
|
|
bool merge(const history_item_t &item);
|
2012-02-06 00:42:24 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// The actual contents of the entry.
|
2016-09-24 03:12:15 +00:00
|
|
|
wcstring contents; // value as entered by the user
|
|
|
|
wcstring contents_lower; // value normalized to all lowercase for case insensitive comparisons
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Original creation time for the entry.
|
2012-11-19 00:30:30 +00:00
|
|
|
time_t creation_timestamp;
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Sometimes unique identifier used for hinting.
|
2014-03-29 06:22:03 +00:00
|
|
|
history_identifier_t identifier;
|
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Paths that we require to be valid for this item to be autosuggested.
|
2012-02-15 19:33:41 +00:00
|
|
|
path_list_t required_paths;
|
2015-09-19 03:47:38 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
public:
|
2016-09-24 03:12:15 +00:00
|
|
|
explicit history_item_t(const wcstring &str, time_t when = 0, history_identifier_t ident = 0);
|
2016-05-05 22:09:31 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
const wcstring &str() const { return contents; }
|
2016-09-24 03:12:15 +00:00
|
|
|
const wcstring &str_lower() const { return contents_lower; }
|
2014-01-15 09:40:40 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
bool empty() const { return contents.empty(); }
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Whether our contents matches a search term.
|
2016-09-24 03:12:15 +00:00
|
|
|
bool matches_search(const wcstring &term, enum history_search_type_t type,
|
|
|
|
bool case_sensitive) const;
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
time_t timestamp() const { return creation_timestamp; }
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
const path_list_t &get_required_paths() const { return required_paths; }
|
2016-05-05 22:09:31 +00:00
|
|
|
void set_required_paths(path_list_t paths) { required_paths = paths; }
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
bool operator==(const history_item_t &other) const {
|
|
|
|
return contents == other.contents && creation_timestamp == other.creation_timestamp &&
|
2012-02-16 08:24:27 +00:00
|
|
|
required_paths == other.required_paths;
|
|
|
|
}
|
2012-06-15 23:22:37 +00:00
|
|
|
};
|
2012-06-05 04:24:42 +00:00
|
|
|
|
2014-03-29 06:22:03 +00:00
|
|
|
typedef std::deque<history_item_t> history_item_list_t;
|
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// The type of file that we mmap'd.
|
|
|
|
enum history_file_type_t { history_type_unknown, history_type_fish_2_0, history_type_fish_1_x };
|
2012-02-06 00:42:24 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
class history_t {
|
2012-02-16 08:24:27 +00:00
|
|
|
friend class history_tests_t;
|
2012-02-06 00:42:24 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
private:
|
|
|
|
// No copying.
|
|
|
|
history_t(const history_t &);
|
|
|
|
history_t &operator=(const history_t &);
|
|
|
|
|
|
|
|
// Privately add an item. If pending, the item will not be returned by history searches until a
|
|
|
|
// call to resolve_pending.
|
2015-04-20 09:04:17 +00:00
|
|
|
void add(const history_item_t &item, bool pending = false);
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Lock for thread safety.
|
2012-02-06 00:42:24 +00:00
|
|
|
pthread_mutex_t lock;
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Internal function.
|
2012-02-16 08:24:27 +00:00
|
|
|
void clear_file_state();
|
2012-02-06 00:42:24 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// The name of this list. Used for picking a suitable filename and for switching modes.
|
2012-11-19 00:30:30 +00:00
|
|
|
const wcstring name;
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// New items. Note that these are NOT discarded on save. We need to keep these around so we can
|
|
|
|
// distinguish between items in our history and items in the history of other shells that were
|
|
|
|
// started after we were started.
|
2014-03-29 06:22:03 +00:00
|
|
|
history_item_list_t new_items;
|
2012-12-03 10:25:08 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// The index of the first new item that we have not yet written.
|
2012-12-03 00:39:35 +00:00
|
|
|
size_t first_unwritten_new_item_index;
|
2014-03-31 17:01:39 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Whether we have a pending item. If so, the most recently added item is ignored by
|
|
|
|
// item_at_index.
|
2015-04-20 09:04:17 +00:00
|
|
|
bool has_pending_item;
|
2015-09-19 03:47:38 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Whether we should disable saving to the file for a time.
|
2014-03-29 06:22:03 +00:00
|
|
|
uint32_t disable_automatic_save_counter;
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Deleted item contents.
|
2012-11-19 00:30:30 +00:00
|
|
|
std::set<wcstring> deleted_items;
|
2012-06-05 04:24:42 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// The mmaped region for the history file.
|
2012-11-19 00:30:30 +00:00
|
|
|
const char *mmap_start;
|
2012-02-06 00:42:24 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// The size of the mmap'd region.
|
2012-11-19 00:30:30 +00:00
|
|
|
size_t mmap_length;
|
2012-02-06 00:42:24 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// The type of file we mmap'd.
|
2012-06-15 23:22:37 +00:00
|
|
|
history_file_type_t mmap_type;
|
2012-12-03 10:25:08 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// The file ID of the file we mmap'd.
|
2012-12-03 07:38:38 +00:00
|
|
|
file_id_t mmap_file_id;
|
2012-06-15 23:22:37 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// The boundary timestamp distinguishes old items from new items. Items whose timestamps are <=
|
|
|
|
// the boundary are considered "old". Items whose timestemps are > the boundary are new, and are
|
|
|
|
// ignored by this instance (unless they came from this instance). The timestamp may be adjusted
|
|
|
|
// by incorporate_external_changes().
|
2014-07-25 17:08:21 +00:00
|
|
|
time_t boundary_timestamp;
|
2012-03-01 22:56:34 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// How many items we add until the next vacuum. Initially a random value.
|
2012-12-03 08:14:09 +00:00
|
|
|
int countdown_to_vacuum;
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Figure out the offsets of our mmap data.
|
2012-02-06 00:42:24 +00:00
|
|
|
void populate_from_mmap(void);
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// List of old items, as offsets into out mmap data.
|
2014-03-29 06:22:03 +00:00
|
|
|
std::deque<size_t> old_item_offsets;
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Whether we've loaded old items.
|
2012-02-06 00:42:24 +00:00
|
|
|
bool loaded_old;
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Loads old if necessary.
|
2012-03-26 08:21:10 +00:00
|
|
|
bool load_old_if_needed(void);
|
2012-12-05 21:33:07 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Memory maps the history file if necessary.
|
2012-12-05 00:00:35 +00:00
|
|
|
bool mmap_if_needed(void);
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Deletes duplicates in new_items.
|
2012-03-01 22:56:34 +00:00
|
|
|
void compact_new_items();
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Saves history by rewriting the file.
|
2012-12-03 00:39:35 +00:00
|
|
|
bool save_internal_via_rewrite();
|
2012-12-03 10:25:08 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Saves history by appending to the file.
|
2012-12-03 00:39:35 +00:00
|
|
|
bool save_internal_via_appending();
|
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Saves history.
|
2012-12-03 07:38:38 +00:00
|
|
|
void save_internal(bool vacuum);
|
2014-03-31 17:01:39 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Saves history unless doing so is disabled.
|
2014-03-29 06:22:03 +00:00
|
|
|
void save_internal_unless_disabled();
|
2012-12-03 07:38:38 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Do a private, read-only map of the entirety of a history file with the given name. Returns
|
|
|
|
// true if successful. Returns the mapped memory region by reference.
|
|
|
|
bool map_file(const wcstring &name, const char **out_map_start, size_t *out_map_len,
|
|
|
|
file_id_t *file_id);
|
2013-04-27 22:21:14 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Whether we're in maximum chaos mode, useful for testing.
|
2012-12-03 07:38:38 +00:00
|
|
|
bool chaos_mode;
|
2012-06-15 23:22:37 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
public:
|
|
|
|
explicit history_t(const wcstring &); // constructor
|
2016-07-14 05:33:50 +00:00
|
|
|
~history_t(); // destructor
|
2016-03-18 22:14:16 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Returns history with the given name, creating it if necessary.
|
|
|
|
static history_t &history_with_name(const wcstring &name);
|
2016-03-18 22:14:16 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Determines whether the history is empty. Unfortunately this cannot be const, since it may
|
|
|
|
// require populating the history.
|
2012-07-10 05:54:08 +00:00
|
|
|
bool is_empty(void);
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Add a new history item to the end. If pending is set, the item will not be returned by
|
|
|
|
// item_at_index until a call to resolve_pending(). Pending items are tracked with an offset
|
|
|
|
// into the array of new items, so adding a non-pending item has the effect of resolving all
|
|
|
|
// pending items.
|
2015-04-20 09:04:17 +00:00
|
|
|
void add(const wcstring &str, history_identifier_t ident = 0, bool pending = false);
|
2012-06-05 04:24:42 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Remove a history item.
|
2012-06-05 04:24:42 +00:00
|
|
|
void remove(const wcstring &str);
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Add a new pending history item to the end, and then begin file detection on the items to
|
|
|
|
// determine which arguments are paths
|
2015-04-20 09:04:17 +00:00
|
|
|
void add_pending_with_file_detection(const wcstring &str);
|
2015-09-19 03:47:38 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Resolves any pending history items, so that they may be returned in history searches.
|
2015-04-20 09:04:17 +00:00
|
|
|
void resolve_pending();
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Saves history.
|
2012-02-06 00:42:24 +00:00
|
|
|
void save();
|
2014-03-31 17:01:39 +00:00
|
|
|
|
2016-07-14 05:33:50 +00:00
|
|
|
// Searches history.
|
2016-09-19 03:21:27 +00:00
|
|
|
bool search(history_search_type_t search_type, wcstring_list_t search_args,
|
2016-09-24 03:12:15 +00:00
|
|
|
const wchar_t *show_time_format, long max_items, bool case_sensitive,
|
2016-10-17 03:33:33 +00:00
|
|
|
bool null_terminate, io_streams_t &streams);
|
2016-07-14 05:33:50 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Enable / disable automatic saving. Main thread only!
|
2014-03-29 06:22:03 +00:00
|
|
|
void disable_automatic_saving();
|
|
|
|
void enable_automatic_saving();
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Irreversibly clears history.
|
2012-02-16 08:24:27 +00:00
|
|
|
void clear();
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Populates from older location ()in config path, rather than data path).
|
2015-09-19 03:47:38 +00:00
|
|
|
void populate_from_config_path();
|
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Populates from a bash history file.
|
2012-06-15 23:22:37 +00:00
|
|
|
void populate_from_bash(FILE *f);
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Incorporates the history of other shells into this history.
|
2014-07-25 17:08:21 +00:00
|
|
|
void incorporate_external_changes();
|
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Gets all the history into a string with ARRAY_SEP_STR. This is intended for the $history
|
|
|
|
// environment variable. This may be long!
|
2014-07-29 21:41:21 +00:00
|
|
|
void get_string_representation(wcstring *result, const wcstring &separator);
|
2014-03-31 17:01:39 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Sets the valid file paths for the history item with the given identifier.
|
2014-03-29 06:22:03 +00:00
|
|
|
void set_valid_file_paths(const wcstring_list_t &valid_file_paths, history_identifier_t ident);
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Return the specified history at the specified index. 0 is the index of the current
|
|
|
|
// commandline. (So the most recent item is at index 1.)
|
2012-02-06 00:42:24 +00:00
|
|
|
history_item_t item_at_index(size_t idx);
|
|
|
|
};
|
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
class history_search_t {
|
2016-07-14 05:33:50 +00:00
|
|
|
private:
|
2016-04-18 05:47:37 +00:00
|
|
|
// The history in which we are searching.
|
|
|
|
history_t *history;
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2016-10-17 04:15:40 +00:00
|
|
|
// The search term.
|
|
|
|
wcstring term;
|
|
|
|
|
|
|
|
// Our search type.
|
2012-02-06 18:52:13 +00:00
|
|
|
enum history_search_type_t search_type;
|
2016-09-24 03:12:15 +00:00
|
|
|
bool case_sensitive;
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Our list of previous matches as index, value. The end is the current match.
|
2012-02-16 08:24:27 +00:00
|
|
|
typedef std::pair<size_t, history_item_t> prev_match_t;
|
2012-07-17 19:47:01 +00:00
|
|
|
std::vector<prev_match_t> prev_matches;
|
2012-02-06 06:30:42 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Returns yes if a given term is in prev_matches.
|
2012-02-06 06:30:42 +00:00
|
|
|
bool match_already_made(const wcstring &match) const;
|
2012-02-06 00:42:24 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Additional strings to skip (sorted).
|
2012-02-06 19:52:24 +00:00
|
|
|
wcstring_list_t external_skips;
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2012-02-06 19:52:24 +00:00
|
|
|
bool should_skip_match(const wcstring &str) const;
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
public:
|
|
|
|
// Gets the search term.
|
|
|
|
const wcstring &get_term() const { return term; }
|
2012-02-06 00:42:24 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Sets additional string matches to skip.
|
2012-02-06 19:52:24 +00:00
|
|
|
void skip_matches(const wcstring_list_t &skips);
|
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Finds the next search term (forwards in time). Returns true if one was found.
|
2012-02-06 00:42:24 +00:00
|
|
|
bool go_forwards(void);
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Finds the previous search result (backwards in time). Returns true if one was found.
|
2012-02-06 00:42:24 +00:00
|
|
|
bool go_backwards(void);
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Goes to the end (forwards).
|
2012-02-06 00:42:24 +00:00
|
|
|
void go_to_end(void);
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Returns if we are at the end. We start out at the end.
|
2012-02-06 07:22:18 +00:00
|
|
|
bool is_at_end(void) const;
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Goes to the beginning (backwards).
|
2012-02-06 00:42:24 +00:00
|
|
|
void go_to_beginning(void);
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Returns the current search result item. asserts if there is no current item.
|
2012-02-16 08:24:27 +00:00
|
|
|
history_item_t current_item(void) const;
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Returns the current search result item contents. asserts if there is no current item.
|
2012-02-16 08:24:27 +00:00
|
|
|
wcstring current_string(void) const;
|
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Constructor.
|
|
|
|
history_search_t(history_t &hist, const wcstring &str,
|
2016-09-24 03:12:15 +00:00
|
|
|
enum history_search_type_t type = HISTORY_SEARCH_TYPE_CONTAINS,
|
|
|
|
bool case_sensitive = true)
|
|
|
|
: history(&hist), term(str), search_type(type), case_sensitive(case_sensitive) {
|
|
|
|
if (!case_sensitive) {
|
|
|
|
term = wcstring();
|
|
|
|
for (wcstring::const_iterator it = str.begin(); it != str.end(); ++it) {
|
|
|
|
term.push_back(towlower(*it));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-06 00:42:24 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Default constructor.
|
2016-10-17 04:15:40 +00:00
|
|
|
history_search_t() : history(), term(), search_type(HISTORY_SEARCH_TYPE_CONTAINS), case_sensitive(true) {}
|
2012-02-06 00:42:24 +00:00
|
|
|
};
|
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Init history library. The history file won't actually be loaded until the first time a history
|
|
|
|
// search is performed.
|
2005-09-20 13:26:39 +00:00
|
|
|
void history_init();
|
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Saves the new history to disk.
|
2005-09-20 13:26:39 +00:00
|
|
|
void history_destroy();
|
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Perform sanity checks.
|
2005-09-20 13:26:39 +00:00
|
|
|
void history_sanity_check();
|
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// A helper class for threaded detection of paths.
|
|
|
|
struct file_detection_context_t {
|
|
|
|
// Constructor.
|
2016-02-28 03:38:15 +00:00
|
|
|
explicit file_detection_context_t(history_t *hist, history_identifier_t ident = 0);
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Determine which of potential_paths are valid, and put them in valid_paths.
|
2012-02-16 08:24:27 +00:00
|
|
|
int perform_file_detection();
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// The history associated with this context.
|
|
|
|
history_t *const history;
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// The working directory at the time the command was issued.
|
2012-02-16 08:24:27 +00:00
|
|
|
wcstring working_directory;
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Paths to test.
|
2012-02-16 08:24:27 +00:00
|
|
|
path_list_t potential_paths;
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Paths that were found to be valid.
|
2012-02-16 08:24:27 +00:00
|
|
|
path_list_t valid_paths;
|
2014-03-31 17:01:39 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Identifier of the history item to which we are associated.
|
2014-03-29 06:22:03 +00:00
|
|
|
const history_identifier_t history_item_identifier;
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Performs file detection. Returns 1 if every path in potential_paths is valid, 0 otherwise. If
|
|
|
|
// test_all is true, tests every path; otherwise stops as soon as it reaches an invalid path.
|
2012-02-16 08:24:27 +00:00
|
|
|
int perform_file_detection(bool test_all);
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2016-04-18 05:47:37 +00:00
|
|
|
// Determine whether the given paths are all valid.
|
2012-02-16 08:24:27 +00:00
|
|
|
bool paths_are_valid(const path_list_t &paths);
|
|
|
|
};
|
2005-10-04 15:11:39 +00:00
|
|
|
#endif
|