81#define HC_FIRST HC_CMD
111 if ((hclass >=
HC_MAX) || (c_history == 0))
130 for (
int i = 0; i <=
OldSize; i++)
160 uintptr_t count = (uintptr_t) he->
data;
168 he->
data = (
void *) count;
192 count = (uintptr_t) he->
data;
194 he->
data = (
void *) count;
205 int line, hclass, read;
206 char *linebuf = NULL, *p = NULL;
208 bool regen_file =
false;
218 if (c_history_remove_dups)
220 for (hclass = 0; hclass <
HC_MAX; hclass++)
227 if ((sscanf(linebuf,
"%d:%n", &hclass, &read) < 1) || (read == 0) ||
228 (*(p = linebuf + strlen(linebuf) - 1) !=
'|') || (hclass < 0))
230 mutt_error(
_(
"Bad history file format (line %d)"), line);
237 if (c_history_remove_dups && (
dup_hash_inc(dup_hashes[hclass], linebuf + read) > 1))
249 if (n[hclass] > c_save_history)
269 if ((sscanf(linebuf,
"%d:%n", &hclass, &read) < 1) || (read == 0) ||
270 (*(p = linebuf + strlen(linebuf) - 1) !=
'|') || (hclass < 0))
272 mutt_error(
_(
"Bad history file format (line %d)"), line);
278 if (c_history_remove_dups && (
dup_hash_dec(dup_hashes[hclass], linebuf + read) > 0))
283 if (n[hclass]-- <= c_save_history)
284 fprintf(fp_tmp,
"%s\n", linebuf);
293 if ((fflush(fp_tmp) == 0) && (fp = fopen(
NONULL(c_history_file),
"w")))
301 if (c_history_remove_dups)
302 for (hclass = 0; hclass <
HC_MAX; hclass++)
316 if (!str || (*str ==
'\0'))
329 fprintf(fp,
"%d:", (
int) hclass);
330 for (
char *p = tmp; *p; p++)
336 putc((
unsigned char) *p, fp);
370 while (source < h->
last)
375 h->
hist[dest++] = h->
hist[source++];
380 int old_last = h->
last;
384 while (source > h->
last)
385 h->
hist[source--] = NULL;
391 while (source > old_last)
396 h->
hist[dest--] = h->
hist[source--];
400 while (dest > old_last)
401 h->
hist[dest--] = NULL;
413 if (!search_buf || !matches)
431 matches[match_count++] = h->
hist[
cur];
432 }
while (match_count < c_history);
453 for (
int i = 0; i <= c_history; i++)
493 int prev = h->
last - 1;
504 if (c_history_remove_dups)
508 if (save && (c_save_history != 0) && c_history_file)
511 if (h->
last > c_history)
536 if (next > c_history)
540 }
while (!h->
hist[next]);
568 }
while (!h->
hist[prev]);
597 int line = 0, hclass, read;
598 char *linebuf = NULL, *p = NULL;
613 if ((sscanf(linebuf,
"%d:%n", &hclass, &read) < 1) || (read == 0) ||
614 (*(p = linebuf + strlen(linebuf) - 1) !=
'|') || (hclass < 0))
616 mutt_error(
_(
"Bad history file format (line %d)"), line);
const char * cc_charset(void)
Get the cached value of $charset.
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.
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.
FILE * mutt_file_fopen(const char *path, const char *mode)
Call fopen() safely.
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
#define MUTT_RL_NO_FLAGS
No flags are set.
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.
void mutt_hist_free(void)
Free all the history lists.
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.
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)
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
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.
#define mutt_file_mkstemp()