File src/hstr.c changed (mode: 100644) (index 0d24c20..dfa2928) |
... |
... |
void print_help_label() |
279 |
279 |
refresh(); |
refresh(); |
280 |
280 |
} |
} |
281 |
281 |
|
|
282 |
|
void print_cmd_deleted_label(char *cmd, int occurences, Hstr *hstr) |
|
|
282 |
|
void print_cmd_deleted_label(const char *cmd, int occurences, Hstr *hstr) |
283 |
283 |
{ |
{ |
284 |
284 |
char screenLine[CMDLINE_LNG]; |
char screenLine[CMDLINE_LNG]; |
285 |
285 |
snprintf(screenLine, getmaxx(stdscr), "History item '%s' deleted (%d occurrence%s)", cmd, occurences, (occurences==1?"":"s")); |
snprintf(screenLine, getmaxx(stdscr), "History item '%s' deleted (%d occurrence%s)", cmd, occurences, (occurences==1?"":"s")); |
|
286 |
|
// TODO make this function |
286 |
287 |
if(hstr->hicolor) { |
if(hstr->hicolor) { |
287 |
288 |
color_attr_on(COLOR_PAIR(HH_COLOR_DELETE)); |
color_attr_on(COLOR_PAIR(HH_COLOR_DELETE)); |
288 |
289 |
color_attr_on(A_BOLD); |
color_attr_on(A_BOLD); |
|
... |
... |
void print_cmd_deleted_label(char *cmd, int occurences, Hstr *hstr) |
296 |
297 |
refresh(); |
refresh(); |
297 |
298 |
} |
} |
298 |
299 |
|
|
299 |
|
void print_cmd_added_favorite_label(char *cmd, Hstr *hstr) |
|
|
300 |
|
void print_regexp_error(const char *errorMessage) |
|
301 |
|
{ |
|
302 |
|
char screenLine[CMDLINE_LNG]; |
|
303 |
|
snprintf(screenLine, getmaxx(stdscr), "%s", errorMessage); |
|
304 |
|
if(hstr->hicolor) { |
|
305 |
|
color_attr_on(COLOR_PAIR(HH_COLOR_DELETE)); |
|
306 |
|
color_attr_on(A_BOLD); |
|
307 |
|
} |
|
308 |
|
mvprintw(Y_OFFSET_HELP, 0, "%s", screenLine); |
|
309 |
|
if(hstr->hicolor) { |
|
310 |
|
color_attr_off(A_BOLD); |
|
311 |
|
color_attr_on(COLOR_PAIR(1)); |
|
312 |
|
} |
|
313 |
|
clrtoeol(); |
|
314 |
|
refresh(); |
|
315 |
|
} |
|
316 |
|
|
|
317 |
|
void print_cmd_added_favorite_label(const char *cmd, Hstr *hstr) |
300 |
318 |
{ |
{ |
301 |
319 |
char screenLine[CMDLINE_LNG]; |
char screenLine[CMDLINE_LNG]; |
302 |
320 |
snprintf(screenLine, getmaxx(stdscr), "Command '%s' added to favorites (C-/ to show favorites)", cmd); |
snprintf(screenLine, getmaxx(stdscr), "Command '%s' added to favorites (C-/ to show favorites)", cmd); |
|
... |
... |
unsigned hstr_make_selection(char *prefix, HistoryItems *history, int maxSelecti |
402 |
420 |
} |
} |
403 |
421 |
|
|
404 |
422 |
regmatch_t regexpMatch; |
regmatch_t regexpMatch; |
|
423 |
|
char regexpErrorMessage[CMDLINE_LNG]; |
|
424 |
|
bool regexpCompilationError=false; |
405 |
425 |
for(i=0; i<count && selectionCount<maxSelectionCount; i++) { |
for(i=0; i<count && selectionCount<maxSelectionCount; i++) { |
406 |
426 |
if(source[i]) { |
if(source[i]) { |
407 |
427 |
if(!prefix || !strlen(prefix)) { |
if(!prefix || !strlen(prefix)) { |
|
... |
... |
unsigned hstr_make_selection(char *prefix, HistoryItems *history, int maxSelecti |
423 |
443 |
} |
} |
424 |
444 |
break; |
break; |
425 |
445 |
case HH_MATCH_REGEXP: |
case HH_MATCH_REGEXP: |
426 |
|
if(hstr_regexp_match(&(hstr->regexp), prefix, source[i], ®expMatch)) { |
|
|
446 |
|
if(hstr_regexp_match(&(hstr->regexp), prefix, source[i], ®expMatch, regexpErrorMessage, CMDLINE_LNG)) { |
427 |
447 |
hstr->selection[selectionCount]=source[i]; |
hstr->selection[selectionCount]=source[i]; |
428 |
448 |
hstr->selectionRegexpMatch[selectionCount].rm_so=regexpMatch.rm_so; |
hstr->selectionRegexpMatch[selectionCount].rm_so=regexpMatch.rm_so; |
429 |
449 |
hstr->selectionRegexpMatch[selectionCount].rm_eo=regexpMatch.rm_eo; |
hstr->selectionRegexpMatch[selectionCount].rm_eo=regexpMatch.rm_eo; |
430 |
450 |
selectionCount++; |
selectionCount++; |
|
451 |
|
} else { |
|
452 |
|
if(!regexpCompilationError) { |
|
453 |
|
// TODO fix broken messages - getting just escape sequences |
|
454 |
|
// print_regexp_error(regexpErrorMessage); |
|
455 |
|
regexpCompilationError=true; |
|
456 |
|
} |
431 |
457 |
} |
} |
432 |
458 |
break; |
break; |
433 |
459 |
} |
} |
|
... |
... |
void loop_to_select(Hstr *hstr) |
685 |
711 |
char pattern[SELECTION_PREFIX_MAX_LNG]; |
char pattern[SELECTION_PREFIX_MAX_LNG]; |
686 |
712 |
pattern[0]=0; |
pattern[0]=0; |
687 |
713 |
// TODO this is too late! > don't render twice |
// TODO this is too late! > don't render twice |
|
714 |
|
// TODO overflow |
688 |
715 |
strcpy(pattern, hstr->cmdline); |
strcpy(pattern, hstr->cmdline); |
689 |
716 |
while (!done) { |
while (!done) { |
690 |
717 |
maxHistoryItems=get_max_history_items(stdscr); |
maxHistoryItems=get_max_history_items(stdscr); |
File src/hstr_regexp.c changed (mode: 100644) (index 64690ed..5ac2bec) |
... |
... |
void hstr_regexp_init(HstrRegexp *hstrRegexp) |
18 |
18 |
hashset_init(&hstrRegexp->cache); |
hashset_init(&hstrRegexp->cache); |
19 |
19 |
} |
} |
20 |
20 |
|
|
21 |
|
bool hstr_regexp_match(HstrRegexp *hstrRegexp, char *regexp, char *text, regmatch_t *match) |
|
|
21 |
|
bool hstr_regexp_match( |
|
22 |
|
HstrRegexp *hstrRegexp, |
|
23 |
|
const char *regexp, |
|
24 |
|
const char *text, |
|
25 |
|
regmatch_t *match, |
|
26 |
|
char *errorMessage, |
|
27 |
|
const size_t errorMessageSize) |
22 |
28 |
{ |
{ |
23 |
|
regex_t* compiled=malloc(sizeof(regex_t)); |
|
|
29 |
|
regex_t* compiled; |
24 |
30 |
if(hashset_contains(&hstrRegexp->cache,regexp)) { |
if(hashset_contains(&hstrRegexp->cache,regexp)) { |
25 |
31 |
compiled=hashset_get(&hstrRegexp->cache, regexp); |
compiled=hashset_get(&hstrRegexp->cache, regexp); |
26 |
32 |
} else { |
} else { |
|
33 |
|
compiled=malloc(sizeof(regex_t)); |
27 |
34 |
int compilationFlags=(hstrRegexp->caseSensitive?0:REG_ICASE); |
int compilationFlags=(hstrRegexp->caseSensitive?0:REG_ICASE); |
28 |
|
//printf("Regular expressions matching:\n '%s'\n '%s'",text,regexp); |
|
29 |
35 |
int compilationStatus=regcomp(compiled, regexp, compilationFlags); |
int compilationStatus=regcomp(compiled, regexp, compilationFlags); |
30 |
|
//printf("\nCompilation: %d",compilationStatus); |
|
31 |
36 |
if(!compilationStatus) { |
if(!compilationStatus) { |
32 |
37 |
hashset_put(&hstrRegexp->cache, hstr_strdup(regexp), compiled); |
hashset_put(&hstrRegexp->cache, hstr_strdup(regexp), compiled); |
33 |
38 |
} else { |
} else { |
|
39 |
|
regerror(compilationStatus, compiled, errorMessage, errorMessageSize); |
34 |
40 |
free(compiled); |
free(compiled); |
35 |
|
// TODO error handling: regerror() to turn error codes to messages |
|
36 |
41 |
return false; |
return false; |
37 |
42 |
} |
} |
38 |
43 |
} |
} |
|
... |
... |
bool hstr_regexp_match(HstrRegexp *hstrRegexp, char *regexp, char *text, regmatc |
41 |
46 |
regmatch_t matchPtr[REGEXP_MATCH_BUFFER_SIZE]; |
regmatch_t matchPtr[REGEXP_MATCH_BUFFER_SIZE]; |
42 |
47 |
int matchingFlags=0; |
int matchingFlags=0; |
43 |
48 |
int matchingStatus=regexec(compiled, text, matches, matchPtr, matchingFlags); |
int matchingStatus=regexec(compiled, text, matches, matchPtr, matchingFlags); |
44 |
|
//printf("\nMatching (status/matches): %s %d",(!matchingStatus?"match":"no-match"),matches); |
|
45 |
|
|
|
46 |
49 |
if(!matchingStatus) { |
if(!matchingStatus) { |
47 |
|
//printf("\n %d %d",matchPtr[0].rm_so, matchPtr[0].rm_eo); |
|
48 |
50 |
if(matchPtr[0].rm_so != -1) { |
if(matchPtr[0].rm_so != -1) { |
49 |
|
//printf("\n* %d %d",matchPtr[0].rm_so,matchPtr[0].rm_eo); |
|
50 |
51 |
match->rm_so=matchPtr[0].rm_so; |
match->rm_so=matchPtr[0].rm_so; |
51 |
52 |
match->rm_eo=matchPtr[0].rm_eo; |
match->rm_eo=matchPtr[0].rm_eo; |
52 |
53 |
return true; |
return true; |
|
... |
... |
void hstr_regexp_destroy(HstrRegexp *hstrRegexp) |
59 |
60 |
{ |
{ |
60 |
61 |
// TODO hashset_destroy(); |
// TODO hashset_destroy(); |
61 |
62 |
} |
} |
62 |
|
|
|