Overhaul sorting of state process column

Do not sort by ascii value of the state identifier, sort by relevance
This commit is contained in:
Christian Göttsche 2021-01-27 15:11:44 +01:00 committed by BenBE
parent a3c8285237
commit d5de1bc23d
2 changed files with 39 additions and 4 deletions

View File

@ -518,6 +518,44 @@ int Process_compare(const void* v1, const void* v2) {
return result; return result;
} }
static uint8_t stateCompareValue(char state) {
switch (state) {
case 'S':
return 10;
case 'I':
return 9;
case 'X':
return 8;
case 'Z':
return 7;
case 't':
return 6;
case 'T':
return 5;
case 'L':
return 4;
case 'D':
return 3;
case 'R':
return 2;
case '?':
return 1;
default:
return 0;
}
}
int Process_compareByKey_Base(const Process* p1, const Process* p2, ProcessField key) { int Process_compareByKey_Base(const Process* p1, const Process* p2, ProcessField key) {
int r; int r;
@ -557,7 +595,7 @@ int Process_compareByKey_Base(const Process* p1, const Process* p2, ProcessField
r = SPACESHIP_NUMBER(p1->starttime_ctime, p2->starttime_ctime); r = SPACESHIP_NUMBER(p1->starttime_ctime, p2->starttime_ctime);
return r != 0 ? r : SPACESHIP_NUMBER(p1->pid, p2->pid); return r != 0 ? r : SPACESHIP_NUMBER(p1->pid, p2->pid);
case STATE: case STATE:
return SPACESHIP_NUMBER(Process_sortState(p1->state), Process_sortState(p2->state)); return SPACESHIP_NUMBER(stateCompareValue(p1->state), stateCompareValue(p2->state));
case ST_UID: case ST_UID:
return SPACESHIP_NUMBER(p1->st_uid, p2->st_uid); return SPACESHIP_NUMBER(p1->st_uid, p2->st_uid);
case TIME: case TIME:

View File

@ -241,9 +241,6 @@ static inline bool Process_isChildOf(const Process* this, pid_t pid) {
return pid == Process_getParentPid(this); return pid == Process_getParentPid(this);
} }
#define Process_sortState(state) ((state) == 'I' ? 0x100 : (state))
#define ONE_K 1024UL #define ONE_K 1024UL
#define ONE_M (ONE_K * ONE_K) #define ONE_M (ONE_K * ONE_K)
#define ONE_G (ONE_M * ONE_K) #define ONE_G (ONE_M * ONE_K)