|
1 |
| -/* |
| 1 | +/* |
2 | 2 | * NTop - an htop clone for Windows
|
3 | 3 | * Copyright (c) 2019 Gian Sass
|
4 | 4 | *
|
@@ -549,20 +549,51 @@ static void ReadjustCursor(void)
|
549 | 549 | }
|
550 | 550 |
|
551 | 551 | static TCHAR SearchPattern[256];
|
| 552 | +static BOOLEAN CaseInsensitiveSearch = FALSE; |
552 | 553 | static BOOLEAN SearchActive;
|
553 | 554 |
|
554 | 555 | static void SearchNext(void);
|
555 | 556 |
|
556 | 557 | void StartSearch(const TCHAR *Pattern)
|
557 | 558 | {
|
558 | 559 | _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 | + |
559 | 576 | SearchActive = TRUE;
|
560 | 577 | SearchNext();
|
561 | 578 | }
|
562 | 579 |
|
563 | 580 | static BOOLEAN SearchMatchesProcess(const process *Process)
|
564 | 581 | {
|
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; |
566 | 597 | }
|
567 | 598 |
|
568 | 599 | static void SearchNext(void)
|
|
0 commit comments