Skip to content

Commit

Permalink
Use consistent style for process field output/compare functions
Browse files Browse the repository at this point in the history
  • Loading branch information
BenBE committed Dec 26, 2023
1 parent 6aa9ef2 commit 2aacbf8
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 17 deletions.
8 changes: 5 additions & 3 deletions Process.c
Original file line number Diff line number Diff line change
Expand Up @@ -542,13 +542,14 @@ static void Process_rowWriteField(const Row* super, RichString* str, RowField fi
}

void Process_writeField(const Process* this, RichString* str, RowField field) {
char buffer[256];
size_t n = sizeof(buffer);
int attr = CRT_colors[DEFAULT_COLOR];
const Row* super = (const Row*) &this->super;
const Machine* host = super->host;
const Settings* settings = host->settings;

bool coloring = settings->highlightMegabytes;
char buffer[256]; buffer[255] = '\0';
int attr = CRT_colors[DEFAULT_COLOR];
size_t n = sizeof(buffer) - 1;

switch (field) {
case COMM: {
Expand Down Expand Up @@ -754,6 +755,7 @@ void Process_writeField(const Process* this, RichString* str, RowField field) {
xSnprintf(buffer, n, "- ");
break;
}

RichString_appendAscii(str, attr, buffer);
}

Expand Down
5 changes: 4 additions & 1 deletion darwin/DarwinProcess.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,19 @@ void Process_delete(Object* cast) {

static void DarwinProcess_rowWriteField(const Row* super, RichString* str, ProcessField field) {
const DarwinProcess* dp = (const DarwinProcess*) super;

char buffer[256]; buffer[255] = '\0';
int attr = CRT_colors[DEFAULT_COLOR];
int n = sizeof(buffer) - 1;
size_t n = sizeof(buffer) - 1;

switch (field) {
// add Platform-specific fields here
case TRANSLATED: xSnprintf(buffer, n, "%c ", dp->translated ? 'T' : 'N'); break;
default:
Process_writeField(&dp->super, str, field);
return;
}

RichString_appendWide(str, attr, buffer);
}

Expand Down
7 changes: 5 additions & 2 deletions dragonflybsd/DragonFlyBSDProcess.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,22 @@ void Process_delete(Object* cast) {

static void DragonFlyBSDProcess_rowWriteField(const Row* super, RichString* str, ProcessField field) {
const Process* this = (const Process*) super;
const DragonFlyBSDProcess* fp = (const DragonFlyBSDProcess*) this;
const DragonFlyBSDProcess* fp = (const DragonFlyBSDProcess*) super;

char buffer[256]; buffer[255] = '\0';
int attr = CRT_colors[DEFAULT_COLOR];
size_t n = sizeof(buffer) - 1;

switch (field) {
// add Platform-specific fields here
case PID: xSnprintf(buffer, n, "%*d ", Process_pidDigits, Process_isKernelThread(this) ? -1 : Process_getPid(this)); break;
case JID: xSnprintf(buffer, n, "%*d ", Process_pidDigits, fp->jid); break;
case JAIL: Row_printLeftAlignedField(str, attr, fp->jname, 11); return;
default:
Process_writeField(this, str, field);
Process_writeField(&fp->super, str, field);
return;
}

RichString_appendWide(str, attr, buffer);
}

Expand Down
6 changes: 4 additions & 2 deletions freebsd/FreeBSDProcess.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ void Process_delete(Object* cast) {

static void FreeBSDProcess_rowWriteField(const Row* super, RichString* str, ProcessField field) {
const FreeBSDProcess* fp = (const FreeBSDProcess*) super;
char buffer[256];
size_t n = sizeof(buffer);

char buffer[256]; buffer[255] = '\0';
int attr = CRT_colors[DEFAULT_COLOR];
size_t n = sizeof(buffer) - 1;

switch (field) {
// add FreeBSD-specific fields here
Expand All @@ -92,6 +93,7 @@ static void FreeBSDProcess_rowWriteField(const Row* super, RichString* str, Proc
Process_writeField(&fp->super, str, field);
return;
}

RichString_appendWide(str, attr, buffer);
}

Expand Down
7 changes: 5 additions & 2 deletions linux/LinuxProcess.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,15 @@ static double LinuxProcess_totalIORate(const LinuxProcess* lp) {

static void LinuxProcess_rowWriteField(const Row* super, RichString* str, ProcessField field) {
const Process* this = (const Process*) super;
const LinuxProcess* lp = (const LinuxProcess*) super;
const Machine* host = (const Machine*) super->host;
const LinuxMachine* lhost = (const LinuxMachine*) host;
const LinuxProcess* lp = (const LinuxProcess*) this;
const LinuxMachine* lhost = (const LinuxMachine*) super->host;

bool coloring = host->settings->highlightMegabytes;
char buffer[256]; buffer[255] = '\0';
int attr = CRT_colors[DEFAULT_COLOR];
size_t n = sizeof(buffer) - 1;

switch (field) {
case CMINFLT: Row_printCount(str, lp->cminflt, coloring); return;
case CMAJFLT: Row_printCount(str, lp->cmajflt, coloring); return;
Expand Down Expand Up @@ -330,6 +332,7 @@ static void LinuxProcess_rowWriteField(const Row* super, RichString* str, Proces
Process_writeField(this, str, field);
return;
}

RichString_appendAscii(str, attr, buffer);
}

Expand Down
7 changes: 5 additions & 2 deletions netbsd/NetBSDProcess.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,16 +228,19 @@ void Process_delete(Object* cast) {
}

static void NetBSDProcess_rowWriteField(const Row* super, RichString* str, ProcessField field) {
const Process* this = (const Process*) super;
const NetBSDProcess* np = (const NetBSDProcess*) super;

char buffer[256]; buffer[255] = '\0';
int attr = CRT_colors[DEFAULT_COLOR];
//size_t n = sizeof(buffer) - 1;

switch (field) {
// add NetBSD-specific fields here
default:
Process_writeField(this, str, field);
Process_writeField(np->super, str, field);
return;
}

RichString_appendWide(str, attr, buffer);
}

Expand Down
10 changes: 6 additions & 4 deletions openbsd/OpenBSDProcess.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,17 +220,19 @@ void Process_delete(Object* cast) {
}

static void OpenBSDProcess_rowWriteField(const Row* super, RichString* str, ProcessField field) {
//const OpenBSDProcess* op = (const OpenBSDProcess*) super;
const Process* this = (const Process*) super;
const OpenBSDProcess* op = (const OpenBSDProcess*) super;

char buffer[256]; buffer[255] = '\0';
int attr = CRT_colors[DEFAULT_COLOR];
//int n = sizeof(buffer) - 1;
//size_t n = sizeof(buffer) - 1;

switch (field) {
// add OpenBSD-specific fields here
default:
Process_writeField(this, str, field);
Process_writeField(&op->super, str, field);
return;
}

RichString_appendWide(str, attr, buffer);
}

Expand Down
3 changes: 3 additions & 0 deletions pcp/PCPProcess.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,12 @@ static double PCPProcess_totalIORate(const PCPProcess* pp) {

static void PCPProcess_rowWriteField(const Row* super, RichString* str, ProcessField field) {
const PCPProcess* pp = (const PCPProcess*) super;

bool coloring = super->host->settings->highlightMegabytes;
char buffer[256]; buffer[255] = '\0';
int attr = CRT_colors[DEFAULT_COLOR];
size_t n = sizeof(buffer) - 1;

switch ((int)field) {
case CMINFLT: Row_printCount(str, pp->cminflt, coloring); return;
case CMAJFLT: Row_printCount(str, pp->cmajflt, coloring); return;
Expand Down Expand Up @@ -205,6 +207,7 @@ static void PCPProcess_rowWriteField(const Row* super, RichString* str, ProcessF
Process_writeField(&pp->super, str, field);
return;
}

RichString_appendWide(str, attr, buffer);
}

Expand Down
5 changes: 4 additions & 1 deletion solaris/SolarisProcess.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ void Process_delete(Object* cast) {

static void SolarisProcess_rowWriteField(const Row* super, RichString* str, ProcessField field) {
const SolarisProcess* sp = (const SolarisProcess*) super;

char buffer[256]; buffer[255] = '\0';
int attr = CRT_colors[DEFAULT_COLOR];
int n = sizeof(buffer) - 1;
size_t n = sizeof(buffer) - 1;

switch (field) {
// add Solaris-specific fields here
case ZONEID: xSnprintf(buffer, n, "%*d ", Process_pidDigits, sp->zoneid); break;
Expand All @@ -94,6 +96,7 @@ static void SolarisProcess_rowWriteField(const Row* super, RichString* str, Proc
Process_writeField(&sp->super, str, field);
return;
}

RichString_appendWide(str, attr, buffer);
}

Expand Down
2 changes: 2 additions & 0 deletions unsupported/UnsupportedProcess.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ void Process_delete(Object* cast) {

static void UnsupportedProcess_rowWriteField(const Row* super, RichString* str, ProcessField field) {
const UnsupportedProcess* up = (const UnsupportedProcess*) super;

bool coloring = super->host->settings->highlightMegabytes;
char buffer[256]; buffer[255] = '\0';
int attr = CRT_colors[DEFAULT_COLOR];
Expand All @@ -74,6 +75,7 @@ static void UnsupportedProcess_rowWriteField(const Row* super, RichString* str,
Process_writeField(&up->super, str, field);
return;
}

RichString_appendWide(str, attr, buffer);
}

Expand Down

0 comments on commit 2aacbf8

Please sign in to comment.