mirror of
https://github.com/dvorka/hstr.git
synced 2025-01-01 20:51:45 +08:00
Fixed #124 by filtering HISTTIMEFORMAT emitted timestamps from history file.
This commit is contained in:
parent
dd45d78b61
commit
92cfb0fd1e
3 changed files with 31 additions and 0 deletions
|
@ -11,6 +11,7 @@
|
|||
#include <limits.h>
|
||||
#include <readline/history.h>
|
||||
#include "include/hstr_history.h"
|
||||
#include "include/hstr_regexp.h"
|
||||
|
||||
#define NDEBUG
|
||||
#include <assert.h>
|
||||
|
@ -112,6 +113,12 @@ HistoryItems *get_prioritized_history()
|
|||
radixsort_init(&rs, (radixMaxKeyEstimate<100000?100000:radixMaxKeyEstimate));
|
||||
rs.optFloorAndInsertBigKeys=true;
|
||||
|
||||
regex_t regexp;
|
||||
// HISTTIMEFORMAT defined > ^#1234567890$
|
||||
const char *histtimeformatTimestamp
|
||||
= "^#[[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]]$";
|
||||
regexp_compile(®exp, histtimeformatTimestamp);
|
||||
|
||||
RankedHistoryItem *r;
|
||||
RadixItem *radixItem;
|
||||
HIST_ENTRY **historyList=history_list();
|
||||
|
@ -119,6 +126,10 @@ HistoryItems *get_prioritized_history()
|
|||
int rawOffset=historyState->length-1;
|
||||
char *line;
|
||||
for(i=0; i<historyState->length; i++, rawOffset--) {
|
||||
if(!regexp_match(®exp, historyList[i]->line)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(line && strlen(historyList[i]->line)>itemOffset) {
|
||||
line=historyList[i]->line+itemOffset;
|
||||
} else {
|
||||
|
@ -153,6 +164,8 @@ HistoryItems *get_prioritized_history()
|
|||
}
|
||||
}
|
||||
|
||||
regfree(®exp);
|
||||
|
||||
DEBUG_RADIXSORT();
|
||||
|
||||
RadixItem **prioritizedRadix=radixsort_dump(&rs);
|
||||
|
|
|
@ -60,3 +60,18 @@ void hstr_regexp_destroy(HstrRegexp *hstrRegexp)
|
|||
{
|
||||
hashset_destroy(&hstrRegexp->cache, true);
|
||||
}
|
||||
|
||||
int regexp_compile(regex_t *regexp, const char *regexpText)
|
||||
{
|
||||
return regcomp(regexp, regexpText, 0);
|
||||
//return regcomp(regexp, regexpText, REG_NEWLINE);
|
||||
}
|
||||
|
||||
int regexp_match(regex_t *regexp, const char *text)
|
||||
{
|
||||
const char *p = text;
|
||||
// TODO study multi matches and make this safe
|
||||
const int n_matches = 100;
|
||||
regmatch_t m[n_matches];
|
||||
return regexec(regexp, p, n_matches, m, 0);
|
||||
}
|
||||
|
|
|
@ -25,4 +25,7 @@ void hstr_regexp_init(HstrRegexp *hstrRegexp);
|
|||
bool hstr_regexp_match(HstrRegexp *hstrRegexp, const char *regexp, const char *text, regmatch_t *match, char *errorMessage, const size_t errorMessageSize);
|
||||
void hstr_regexp_destroy(HstrRegexp *hstrRegexp);
|
||||
|
||||
int regexp_compile(regex_t *regexp, const char *regexpText);
|
||||
int regexp_match(regex_t *regexp, const char *text);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue