cex

C/Curses file EXplorer
git clone git://git.wimdupont.com/cex.git
Log | Files | Refs | README | LICENSE

commit fff06d4e32744e7461bc89a35606e9b1ff4c213b
parent e3f4f0a72cd184554b594310bad17410ef5d5a7b
Author: Wim Dupont <wim@wimdupont.com>
Date:   Fri,  3 Oct 2025 21:28:15 +0200

small fix

Diffstat:
Mcex.c | 18++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/cex.c b/cex.c @@ -107,6 +107,7 @@ static int rename_file(const char *fname); static char *human_readable_bytes(char *buf, intmax_t bytes); static char *prompt_answer(char *buf, size_t size, const char *question); static char *cpstr(char *dest, const char *src); +static char *substr(char *buf, const char *haystack, const char *needle, const bool casesens); static char *get_file_info(char *buf, const char *filepath); static char *get_fullpath(char *buf, DirWin *dirwin, size_t index); static char *get_dirname(char *buf, const char *path); @@ -595,8 +596,7 @@ print_win(DirWin *dirwin) } else mvwaddstr(dirwin->window, y, x, name); if (dirwin->wintype == CURRENT && searchc > 0 - && (((!searchcs && ((subs = strcasestr(name, searchq)) != NULL))) - || (((subs = strstr(name, searchq)) != NULL)))) { + && ((subs = substr(subs, name, searchq, searchcs)) != NULL)) { sindex = (int) (subs - name); wattron(dirwin->window, COLOR_PAIR(SEARCH_MATCH_COLOR)); if (dirwin->usehighlight && dirwin->highlight == i) @@ -1139,8 +1139,7 @@ next_search(void) return; for (int i = curwin.highlight; i < MAX(curwin.filecount-1, 0); i++) { - if ((!searchcs && ((strcasestr(curwin.winfiles[i+1].d_name, searchq) != NULL))) - || ((strstr(curwin.winfiles[i+1].d_name, searchq) != NULL))) { + if (substr(NULL, curwin.winfiles[i+1].d_name, searchq, searchcs) != NULL) { curwin.highlight = i+1; return; } @@ -1154,8 +1153,7 @@ prev_search(void) return; for (int i = curwin.highlight; i > 0; i--) { - if ((!searchcs && ((strcasestr(curwin.winfiles[i-1].d_name, searchq) != NULL))) - || ((strstr(curwin.winfiles[i-1].d_name, searchq) != NULL))) { + if (substr(NULL, curwin.winfiles[i-1].d_name, searchq, searchcs) != NULL) { curwin.highlight = i-1; return; } @@ -1663,6 +1661,14 @@ cpstr(char *dest, const char *src) } char * +substr(char *buf, const char *haystack, const char *needle, const bool casesens) +{ + casesens ? ((buf = strstr(haystack, needle)) != NULL) : ((buf = strcasestr(haystack, needle)) != NULL); + + return buf; +} + +char * get_fullpath(char *buf, DirWin *dirwin, size_t index) { index = MIN(index, dirwin->filecount-1);