Skip to content

Commit

Permalink
Merge pull request #65 from cobrce/master
Browse files Browse the repository at this point in the history
Search is case insensitive if the pattern is lowercase
  • Loading branch information
gsass1 authored Sep 19, 2024
2 parents 7e75e98 + 6c3630f commit 36f8266
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions ntop.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* NTop - an htop clone for Windows
* Copyright (c) 2019 Gian Sass
*
Expand Down Expand Up @@ -549,20 +549,51 @@ static void ReadjustCursor(void)
}

static TCHAR SearchPattern[256];
static BOOLEAN CaseInsensitiveSearch = FALSE;
static BOOLEAN SearchActive;

static void SearchNext(void);

void StartSearch(const TCHAR *Pattern)
{
_tcsncpy_s(SearchPattern, 256, Pattern, 256);

// if the whole string is lower case use case insensitive search
CaseInsensitiveSearch = TRUE;
for (int i = 0; i < 256; i++)
{
if (SearchPattern[i] == 0)
{
break;
}
if (isupper(SearchPattern[i]))
{
CaseInsensitiveSearch = FALSE;
break;
}
}

SearchActive = TRUE;
SearchNext();
}

static BOOLEAN SearchMatchesProcess(const process *Process)
{
return _tcsstr(Process->ExeName, SearchPattern) != 0;
TCHAR TempProcessName[MAX_PATH];
_tcsncpy_s(TempProcessName, MAX_PATH, Process->ExeName, MAX_PATH);
if (CaseInsensitiveSearch) // which means that the SearchPattern is already lower case,
// so we convert the process name to lower case to make the
// search case insensitive
{
for (int i = 0; i < MAX_PATH; i++)
{
if (TempProcessName[i] == 0)
break;
TempProcessName[i] = (TCHAR)tolower(TempProcessName[i]);
}
}

return _tcsstr(TempProcessName, SearchPattern) != 0;
}

static void SearchNext(void)
Expand Down

0 comments on commit 36f8266

Please sign in to comment.