85#define HC_FIRST HC_EXT_COMMAND
115 if ((hclass >=
HC_MAX) || (c_history == 0))
134 for (
int i = 0; i <=
OldSize; i++)
164 uintptr_t count = (uintptr_t) he->
data;
172 he->
data = (
void *) count;
196 count = (uintptr_t) he->
data;
198 he->
data = (
void *) count;
209 int line, hclass = 0, read = 0;
210 char *linebuf = NULL, *p = NULL;
212 bool regen_file =
false;
222 if (c_history_remove_dups)
224 for (hclass = 0; hclass <
HC_MAX; hclass++)
231 if ((sscanf(linebuf,
"%d:%n", &hclass, &read) < 1) || (read == 0) ||
232 (*(p = linebuf + strlen(linebuf) - 1) !=
'|') || (hclass < 0))
234 mutt_error(
_(
"%s:%d: Bad history file format"), c_history_file, line);
242 if (c_history_remove_dups && (
dup_hash_inc(dup_hashes[hclass], linebuf + read) > 1))
254 if (n[hclass] > c_save_history)
274 if ((sscanf(linebuf,
"%d:%n", &hclass, &read) < 1) || (read == 0) ||
275 (*(p = linebuf + strlen(linebuf) - 1) !=
'|') || (hclass < 0))
282 if (c_history_remove_dups && (
dup_hash_dec(dup_hashes[hclass], linebuf + read) > 0))
287 if (n[hclass]-- <= c_save_history)
288 fprintf(fp_tmp,
"%s\n", linebuf);
297 if (fflush(fp_tmp) == 0)
299 if (truncate(c_history_file, 0) < 0)
311 if (c_history_remove_dups)
312 for (hclass = 0; hclass <
HC_MAX; hclass++)
325 if (!str || (*str ==
'\0'))
337 char *nl = strchr(tmp,
'\n');
343 fprintf(fp,
"%d:%s|\n", (
int) hclass, tmp);
375 while (source < h->
last)
380 h->
hist[dest++] = h->
hist[source++];
385 int old_last = h->
last;
389 while (source > h->
last)
390 h->
hist[source--] = NULL;
396 while (source > old_last)
401 h->
hist[dest--] = h->
hist[source--];
405 while (dest > old_last)
406 h->
hist[dest--] = NULL;
418 if (!search_buf || !matches)
436 matches[match_count++] = h->
hist[
cur];
437 }
while (match_count < c_history);
458 for (
int i = 0; i <= c_history; i++)
498 int prev = h->
last - 1;
509 if (c_history_remove_dups)
513 if (save && (c_save_history != 0) && c_history_file)
516 if (h->
last > c_history)
541 if (next > c_history)
545 }
while (!h->
hist[next]);
573 }
while (!h->
hist[prev]);
610 int line = 0, hclass = 0, read = 0;
611 char *linebuf = NULL, *p = NULL;
618 if ((sscanf(linebuf,
"%d:%n", &hclass, &read) < 1) || (read == 0) ||
619 (*(p = linebuf + strlen(linebuf) - 1) !=
'|') || (hclass < 0))
621 mutt_error(
_(
"%s:%d: Bad history file format"), c_history_file, line);
693 if (match_count == 1)
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
const char * cs_subset_path(const struct ConfigSubset *sub, const char *name)
Get a path config item by name.
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Convenience wrapper for the config headers.
const char * cc_charset(void)
Get the cached value of $charset.
Convenience wrapper for the core headers.
int mutt_file_copy_stream(FILE *fp_in, FILE *fp_out)
Copy the contents of one file into another.
char * mutt_file_read_line(char *line, size_t *size, FILE *fp, int *line_num, ReadLineFlags flags)
Read a line from a file.
#define mutt_file_fclose(FP)
#define mutt_file_fopen(PATH, MODE)
#define MUTT_RL_NO_FLAGS
No flags are set.
void dlg_history(char *buf, size_t buflen, char **matches, int match_count)
Select an item from a history list -.
#define mutt_debug(LEVEL,...)
int main_hist_observer(struct NotifyCallback *nc)
Notification that a Config Variable has change - Implements observer_t -.
struct HashElem * mutt_hash_insert(struct HashTable *table, const char *strkey, void *data)
Add a new element to the Hash Table (with string keys)
void mutt_hash_delete(struct HashTable *table, const char *strkey, const void *data)
Remove an element from a Hash Table.
struct HashTable * mutt_hash_new(size_t num_elems, HashFlags flags)
Create a new Hash Table (with string keys)
struct HashElem * mutt_hash_find_elem(const struct HashTable *table, const char *strkey)
Find the HashElem in a Hash Table element using a key.
void mutt_hash_free(struct HashTable **ptr)
Free a hash table.
#define MUTT_HASH_STRDUP_KEYS
make a copy of the keys
HistoryClass
Type to differentiate different histories.
static void remove_history_dups(enum HistoryClass hclass, const char *str)
De-dupe the history.
char * mutt_hist_next(enum HistoryClass hclass)
Get the next string in a History.
static int OldSize
The previous number of history entries to save.
void mutt_hist_read_file(void)
Read the History from a file.
static int dup_hash_inc(struct HashTable *dup_hash, char *str)
Increase the refcount of a history string.
void mutt_hist_save_scratch(enum HistoryClass hclass, const char *str)
Save a temporary string to the History.
static struct History Histories[HC_MAX]
Command histories, one for each HistoryClass.
int mutt_hist_search(const char *search_buf, enum HistoryClass hclass, char **matches)
Find matches in a history list.
void mutt_hist_init(void)
Create a set of empty History ring buffers.
bool mutt_hist_at_scratch(enum HistoryClass hclass)
Is the current History position at the 'scratch' place?
static struct History * get_history(enum HistoryClass hclass)
Get a particular history.
static void save_history(enum HistoryClass hclass, const char *str)
Save one history string to a file.
void mutt_hist_add(enum HistoryClass hclass, const char *str, bool save)
Add a string to a history.
void mutt_hist_reset_state(enum HistoryClass hclass)
Move the 'current' position to the end of the History.
static int dup_hash_dec(struct HashTable *dup_hash, char *str)
Decrease the refcount of a history string.
char * mutt_hist_prev(enum HistoryClass hclass)
Get the previous string in a History.
void mutt_hist_complete(char *buf, size_t buflen, enum HistoryClass hclass)
Complete a string from a history list.
static void init_history(struct History *h)
Set up a new History ring buffer.
static void shrink_histfile(void)
Read, de-dupe and write the history file.
void mutt_hist_cleanup(void)
Free all the history lists.
@ LL_DEBUG5
Log at debug level 5.
@ LL_DEBUG1
Log at debug level 1.
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
int mutt_ch_convert_string(char **ps, const char *from, const char *to, uint8_t flags)
Convert a string between encodings.
#define MUTT_ICONV_NO_FLAGS
No flags are set.
Convenience wrapper for the library headers.
char * mutt_str_dup(const char *str)
Copy a string, safely.
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
const char * mutt_istr_find(const char *haystack, const char *needle)
Find first occurrence of string (ignoring case)
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
@ NT_CONFIG
Config has changed, NotifyConfig, EventConfig.
const char * name
Name of config item that changed.
The item stored in a Hash Table.
void * data
User-supplied data.
Saved list of user-entered commands/searches.
short cur
Current history item.
short last
Last history item.
char ** hist
Array of history items.
Container for Accounts, Notifications.
struct ConfigSubset * sub
Inherited config items.
Data passed to a notification function.
void * event_data
Data from notify_send()
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
#define mutt_file_mkstemp()