86#define HC_FIRST HC_EXT_COMMAND
116 if ((hclass >=
HC_MAX) || (c_history == 0))
135 for (
int i = 0; i <=
OldSize; i++)
165 uintptr_t count = (uintptr_t) he->
data;
173 he->
data = (
void *) count;
197 count = (uintptr_t) he->
data;
199 he->
data = (
void *) count;
210 int line, hclass = 0, read = 0;
211 char *linebuf = NULL, *p = NULL;
213 bool regen_file =
false;
223 if (c_history_remove_dups)
225 for (hclass = 0; hclass <
HC_MAX; hclass++)
232 if ((sscanf(linebuf,
"%d:%n", &hclass, &read) < 1) || (read == 0) ||
233 (*(p = linebuf + strlen(linebuf) - 1) !=
'|') || (hclass < 0))
235 mutt_error(
_(
"%s:%d: Bad history file format"), c_history_file, line);
243 if (c_history_remove_dups && (
dup_hash_inc(dup_hashes[hclass], linebuf + read) > 1))
255 if (n[hclass] > c_save_history)
275 if ((sscanf(linebuf,
"%d:%n", &hclass, &read) < 1) || (read == 0) ||
276 (*(p = linebuf + strlen(linebuf) - 1) !=
'|') || (hclass < 0))
283 if (c_history_remove_dups && (
dup_hash_dec(dup_hashes[hclass], linebuf + read) > 0))
288 if (n[hclass]-- <= c_save_history)
289 fprintf(fp_tmp,
"%s\n", linebuf);
298 if (fflush(fp_tmp) == 0)
300 if (truncate(c_history_file, 0) < 0)
312 if (c_history_remove_dups)
313 for (hclass = 0; hclass <
HC_MAX; hclass++)
326 if (!str || (*str ==
'\0'))
338 char *nl = strchr(tmp,
'\n');
344 fprintf(fp,
"%d:%s|\n", (
int) hclass, tmp);
376 while (source < h->
last)
381 h->
hist[dest++] = h->
hist[source++];
386 int old_last = h->
last;
390 while (source > h->
last)
391 h->
hist[source--] = NULL;
397 while (source > old_last)
402 h->
hist[dest--] = h->
hist[source--];
406 while (dest > old_last)
407 h->
hist[dest--] = NULL;
419 if (!find || !matches)
462 for (
int i = 0; i <= c_history; i++)
502 int prev = h->
last - 1;
513 if (c_history_remove_dups)
517 if (save && (c_save_history != 0) && c_history_file)
520 if (h->
last > c_history)
545 if (next > c_history)
549 }
while (!h->
hist[next]);
577 }
while (!h->
hist[prev]);
614 int line = 0, hclass = 0, read = 0;
615 char *linebuf = NULL, *p = NULL;
622 if ((sscanf(linebuf,
"%d:%n", &hclass, &read) < 1) || (read == 0) ||
623 (*(p = linebuf + strlen(linebuf) - 1) !=
'|') || (hclass < 0))
625 mutt_error(
_(
"%s:%d: Bad history file format"), c_history_file, line);
694 if (match_count != 0)
696 if (match_count == 1)
698 const char **pstr =
ARRAY_GET(&matches, 0);
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
#define ARRAY_SIZE(head)
The number of elements stored.
#define ARRAY_FREE(head)
Release all memory.
#define ARRAY_GET(head, idx)
Return the element at index.
#define ARRAY_HEAD_INITIALIZER
Static initializer for arrays.
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
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(struct Buffer *buf, struct HistoryArray *matches)
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.
void mutt_hist_complete(struct Buffer *buf, enum HistoryClass hclass)
Complete a string from 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.
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.
int mutt_hist_search(const char *find, enum HistoryClass hclass, struct HistoryArray *matches)
Find matches in a history list.
void mutt_hist_cleanup(void)
Free all the history lists.
@ LL_DEBUG5
Log at debug level 5.
@ LL_DEBUG1
Log at debug level 1.
#define MUTT_MEM_CALLOC(n, type)
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)
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
@ NT_CONFIG
Config has changed, NotifyConfig, EventConfig.
String manipulation buffer.
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()