Skip to content

Commit 36f8266

Browse files
authored
Merge pull request #65 from cobrce/master
Search is case insensitive if the pattern is lowercase
2 parents 7e75e98 + 6c3630f commit 36f8266

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

ntop.c

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* NTop - an htop clone for Windows
33
* Copyright (c) 2019 Gian Sass
44
*
@@ -549,20 +549,51 @@ static void ReadjustCursor(void)
549549
}
550550

551551
static TCHAR SearchPattern[256];
552+
static BOOLEAN CaseInsensitiveSearch = FALSE;
552553
static BOOLEAN SearchActive;
553554

554555
static void SearchNext(void);
555556

556557
void StartSearch(const TCHAR *Pattern)
557558
{
558559
_tcsncpy_s(SearchPattern, 256, Pattern, 256);
560+
561+
// if the whole string is lower case use case insensitive search
562+
CaseInsensitiveSearch = TRUE;
563+
for (int i = 0; i < 256; i++)
564+
{
565+
if (SearchPattern[i] == 0)
566+
{
567+
break;
568+
}
569+
if (isupper(SearchPattern[i]))
570+
{
571+
CaseInsensitiveSearch = FALSE;
572+
break;
573+
}
574+
}
575+
559576
SearchActive = TRUE;
560577
SearchNext();
561578
}
562579

563580
static BOOLEAN SearchMatchesProcess(const process *Process)
564581
{
565-
return _tcsstr(Process->ExeName, SearchPattern) != 0;
582+
TCHAR TempProcessName[MAX_PATH];
583+
_tcsncpy_s(TempProcessName, MAX_PATH, Process->ExeName, MAX_PATH);
584+
if (CaseInsensitiveSearch) // which means that the SearchPattern is already lower case,
585+
// so we convert the process name to lower case to make the
586+
// search case insensitive
587+
{
588+
for (int i = 0; i < MAX_PATH; i++)
589+
{
590+
if (TempProcessName[i] == 0)
591+
break;
592+
TempProcessName[i] = (TCHAR)tolower(TempProcessName[i]);
593+
}
594+
}
595+
596+
return _tcsstr(TempProcessName, SearchPattern) != 0;
566597
}
567598

568599
static void SearchNext(void)

0 commit comments

Comments
 (0)